|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace App\Tests\Handler; |
| 5 | + |
| 6 | +use App\CodeRepository\CodeRepository; |
| 7 | +use App\Generator\Generator; |
| 8 | +use App\Handler\GenerateHandler; |
| 9 | +use App\SniffFinder\SniffFinder; |
| 10 | +use App\Value\Folder; |
| 11 | +use App\Value\Sniff; |
| 12 | +use App\Value\Urls; |
| 13 | +use App\Value\Violation; |
| 14 | +use PHPUnit\Framework\MockObject\MockObject; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | + |
| 17 | +/** @covers \App\Handler\GenerateHandler */ |
| 18 | +class GenerateHandlerTest extends TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var GenerateHandler |
| 22 | + */ |
| 23 | + private GenerateHandler $handler; |
| 24 | + /** |
| 25 | + * @var CodeRepository|MockObject |
| 26 | + */ |
| 27 | + private $codeRepository; |
| 28 | + /** |
| 29 | + * @var Generator|MockObject |
| 30 | + */ |
| 31 | + private $generator; |
| 32 | + /** |
| 33 | + * @var SniffFinder|MockObject |
| 34 | + */ |
| 35 | + private $sniffFinder; |
| 36 | + |
| 37 | + protected function setUp(): void |
| 38 | + { |
| 39 | + $this->codeRepository = $this->createMock(CodeRepository::class); |
| 40 | + $this->generator = $this->createMock(Generator::class); |
| 41 | + $this->sniffFinder = $this->createMock(SniffFinder::class); |
| 42 | + |
| 43 | + $this->handler = new GenerateHandler( |
| 44 | + $this->codeRepository, |
| 45 | + $this->generator, |
| 46 | + $this->sniffFinder |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + /** @test */ |
| 51 | + public function handle() |
| 52 | + { |
| 53 | + $this->codeRepository->method('downloadCode')->willReturn(new Folder('var/tests/src/')); |
| 54 | + $this->sniffFinder->method('getSniffs')->willReturn($this->createSniffs()); |
| 55 | + |
| 56 | + $this->handler->handle(); |
| 57 | + |
| 58 | + self::assertFileExists('var/markdown/Standard/Category/My.md'); |
| 59 | + self::assertFileExists('var/markdown/Standard/Category/My/ErrorCode.md'); |
| 60 | + } |
| 61 | + |
| 62 | + private function createSniffs() |
| 63 | + { |
| 64 | + yield new Sniff( |
| 65 | + 'Standard.Category.My', |
| 66 | + '', |
| 67 | + [], |
| 68 | + new Urls([]), |
| 69 | + 'Description', |
| 70 | + [], |
| 71 | + [ |
| 72 | + new Violation( |
| 73 | + 'Standard.Category.My.ErrorCode', |
| 74 | + 'Description', |
| 75 | + [], |
| 76 | + new Urls([]) |
| 77 | + ) |
| 78 | + ] |
| 79 | + ); |
| 80 | + } |
| 81 | +} |
0 commit comments