Skip to content

Commit 471c5ee

Browse files
committed
Add test for ArtisanOptimizeQuestion
1 parent b8ba1ce commit 471c5ee

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
"BlameButton\\LaravelDockerBuilder\\": "src/"
3131
}
3232
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"BlameButton\\LaravelDockerBuilder\\Tests\\": "tests/"
36+
}
37+
},
3338
"config": {
3439
"optimize-autoloader": true,
3540
"preferred-install": "dist",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
}

tests/TestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace BlameButton\LaravelDockerBuilder\Tests;
4+
5+
use BlameButton\LaravelDockerBuilder\DockerServiceProvider;
6+
use Illuminate\Foundation\Application;
7+
use Orchestra\Testbench\TestCase as Orchestra;
8+
9+
class TestCase extends Orchestra
10+
{
11+
protected function getPackageProviders(Application $app): array
12+
{
13+
return [
14+
DockerServiceProvider::class,
15+
];
16+
}
17+
}

0 commit comments

Comments
 (0)