Skip to content

Commit 44772d9

Browse files
committed
Add basic test for NodeBuildToolQuestion
1 parent 536cfe2 commit 44772d9

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

tests/Commands/GenerateQuestions/ArtisanOptimizeQuestionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use BlameButton\LaravelDockerBuilder\Commands\BaseCommand;
66
use BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\ArtisanOptimizeQuestion;
7-
use PHPUnit\Framework\TestCase;
7+
use BlameButton\LaravelDockerBuilder\Tests\TestCase;
88

99
class ArtisanOptimizeQuestionTest extends TestCase
1010
{
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
}

tests/TestCase.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
namespace BlameButton\LaravelDockerBuilder\Tests;
44

55
use BlameButton\LaravelDockerBuilder\DockerServiceProvider;
6-
use Illuminate\Foundation\Application;
76
use Orchestra\Testbench\TestCase as Orchestra;
87

98
class TestCase extends Orchestra
109
{
11-
protected function getPackageProviders(Application $app): array
10+
protected function getPackageProviders($app): array
1211
{
1312
return [
1413
DockerServiceProvider::class,

0 commit comments

Comments
 (0)