|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace BlameButton\LaravelDockerBuilder\Tests\Commands\GenerateQuestions; |
| 4 | + |
| 5 | +use BlameButton\LaravelDockerBuilder\Commands\BaseCommand; |
| 6 | +use BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\Choices\NodeBuildTool; |
| 7 | +use BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\NodeBuildToolQuestion; |
| 8 | +use BlameButton\LaravelDockerBuilder\Detector\NodeBuildToolDetector; |
| 9 | +use BlameButton\LaravelDockerBuilder\Exceptions\InvalidOptionValueException; |
| 10 | +use BlameButton\LaravelDockerBuilder\Tests\TestCase; |
| 11 | +use Mockery\MockInterface; |
| 12 | + |
| 13 | +class NodeBuildToolQuestionTest extends TestCase |
| 14 | +{ |
| 15 | + public function testItThrowsErrorOnInvalidInput(): void |
| 16 | + { |
| 17 | + $stub = $this->createMock(BaseCommand::class); |
| 18 | + $stub->expects($this->once()) |
| 19 | + ->method('option') |
| 20 | + ->willReturnMap([ |
| 21 | + ['node-build-tool', 'invalid-value'], |
| 22 | + ]); |
| 23 | + |
| 24 | + $this->expectException(InvalidOptionValueException::class); |
| 25 | + |
| 26 | + app(NodeBuildToolQuestion::class)->getAnswer($stub); |
| 27 | + } |
| 28 | + |
| 29 | + public function provideDetectedBuildTools(): array |
| 30 | + { |
| 31 | + return [ |
| 32 | + 'vite' => [NodeBuildTool::VITE, NodeBuildTool::VITE], |
| 33 | + 'mix' => [NodeBuildTool::MIX, NodeBuildTool::MIX], |
| 34 | + ]; |
| 35 | + } |
| 36 | + |
| 37 | + /** @dataProvider provideDetectedBuildTools */ |
| 38 | + public function testItDetectsBuildTools($expected, $detected): void |
| 39 | + { |
| 40 | + $mock = $this->createMock(BaseCommand::class); |
| 41 | + $mock->expects($this->exactly(2)) |
| 42 | + ->method('option') |
| 43 | + ->willReturnMap([ |
| 44 | + ['node-build-tool', null], |
| 45 | + ['detect', true], |
| 46 | + ]); |
| 47 | + $this->mock(NodeBuildToolDetector::class, function (MockInterface $mock) use ($detected) { |
| 48 | + $mock->shouldReceive('detect')->once()->andReturn($detected); |
| 49 | + }); |
| 50 | + |
| 51 | + $answer = app(NodeBuildToolQuestion::class)->getAnswer($mock); |
| 52 | + |
| 53 | + self::assertEquals($expected, $answer); |
| 54 | + } |
| 55 | +} |
0 commit comments