|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace BlameButton\LaravelDockerBuilder\Tests\Commands\GenerateQuestions; |
| 4 | + |
| 5 | +use BlameButton\LaravelDockerBuilder\Commands\BaseCommand; |
| 6 | +use BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\ArtisanOptimizeQuestion; |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | + |
| 9 | +class ArtisanOptimizeQuestionTest extends TestCase |
| 10 | +{ |
| 11 | + private function provideOptions(): array |
| 12 | + { |
| 13 | + return [ |
| 14 | + 'it returns true when detect is true' => [true, null, true], |
| 15 | + 'it returns true when optimize is true' => [true, true, null], |
| 16 | + 'it returns true when optimize and detect are true' => [true, true, true], |
| 17 | + 'it returns false when optimize and detect are false' => [false, null, null], |
| 18 | + ]; |
| 19 | + } |
| 20 | + |
| 21 | + /** @dataProvider provideOptions */ |
| 22 | + public function testItHandlesOptionsCorrectly($expected, $optimize, $detect): void |
| 23 | + { |
| 24 | + $stub = $this->createStub(BaseCommand::class); |
| 25 | + $stub->method('option') |
| 26 | + ->willReturnMap([ |
| 27 | + ['optimize', $optimize], |
| 28 | + ['detect', $detect], |
| 29 | + ]); |
| 30 | + |
| 31 | + $answer = app(ArtisanOptimizeQuestion::class)->getAnswer($stub); |
| 32 | + |
| 33 | + self::assertEquals($expected, $answer); |
| 34 | + } |
| 35 | + |
| 36 | + private function provideInputs(): array |
| 37 | + { |
| 38 | + return [ |
| 39 | + 'it returns true with yes' => [true, 'yes'], |
| 40 | + 'it returns false with no' => [false, 'no'], |
| 41 | + ]; |
| 42 | + } |
| 43 | + |
| 44 | + /** @dataProvider provideInputs */ |
| 45 | + public function testItHandlesAnswersCorrectly($expected, $input): void |
| 46 | + { |
| 47 | + $stub = $this->createStub(BaseCommand::class); |
| 48 | + $stub->method('option') |
| 49 | + ->willReturn(false); |
| 50 | + $stub->method('choice') |
| 51 | + ->willReturn($input); |
| 52 | + |
| 53 | + $answer = app(ArtisanOptimizeQuestion::class)->getAnswer($stub); |
| 54 | + |
| 55 | + self::assertEquals($expected, $answer); |
| 56 | + } |
| 57 | +} |
0 commit comments