Skip to content

Commit 901be76

Browse files
authored
Merge pull request #7 from blamebutton/6-node-package-manager-throwing-unhandledmatcherror-exception-when-none-is-selected
Add test and fix #6
2 parents b032b19 + 762c160 commit 901be76

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/Commands/DockerGenerateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function printConfigurationTable(Configuration $config): void
7979
'<comment>'.json_encode($config->isAlpine()).'</comment>',
8080
],
8181
['Node package manager',
82-
NodePackageManager::name($config->getNodePackageManager()),
82+
$config->getNodePackageManager() ? NodePackageManager::name($config->getNodePackageManager()) : 'None',
8383
],
8484
['Node build tool',
8585
$config->getNodePackageManager()

tests/Feature/Commands/DockerGenerateCommandTest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace BlameButton\LaravelDockerBuilder\Tests\Feature\Commands;
44

5+
use BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\AlpineQuestion;
6+
use BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\ArtisanOptimizeQuestion;
7+
use BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\PhpExtensionsQuestion;
8+
use BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\PhpVersionQuestion;
9+
use BlameButton\LaravelDockerBuilder\Detectors\NodePackageManagerDetector;
510
use BlameButton\LaravelDockerBuilder\Integrations\SupportedPhpExtensions;
611
use BlameButton\LaravelDockerBuilder\Tests\TestCase;
712
use Illuminate\Support\Facades\File;
@@ -113,7 +118,7 @@ public function testItAsksQuestions(string $isCorrect): void
113118
$command->expectsChoice('Which Node package manager do you use?', 'npm', ['npm', 'yarn', 'none']);
114119
$command->expectsChoice('Which Node build tool do you use?', 'vite', ['vite', 'mix']);
115120
$command->expectsConfirmation('Does this look correct?', $isCorrect);
116-
if ($isCorrect == 'yes') {
121+
if ($isCorrect === 'yes') {
117122
$command->expectsOutput('Configuration:');
118123
$command->expectsTable(['Key', 'Value'], [
119124
['PHP version', '8.2'],
@@ -164,4 +169,27 @@ public function testItThrowsExceptions(string $expected, string $command): void
164169
$command->expectsOutput($expected);
165170
$command->assertFailed();
166171
}
172+
173+
public function testItAcceptsNodePackageManagerNone(): void
174+
{
175+
$this->mock(PhpVersionQuestion::class, function (MockInterface $mock) {
176+
$mock->shouldReceive('getAnswer')->once()->andReturn('8.2');
177+
});
178+
$this->mock(PhpExtensionsQuestion::class, function (MockInterface $mock) {
179+
$mock->shouldReceive('getAnswer')->once()->andReturn(['bcmath']);
180+
});
181+
$this->mock(ArtisanOptimizeQuestion::class, function (MockInterface $mock) {
182+
$mock->shouldReceive('getAnswer')->once()->andReturn(true);
183+
});
184+
$this->mock(AlpineQuestion::class, function (MockInterface $mock) {
185+
$mock->shouldReceive('getAnswer')->once()->andReturn(true);
186+
});
187+
$this->mock(NodePackageManagerDetector::class, function (MockInterface $mock) {
188+
$mock->shouldReceive('detect')->once()->andReturn(false);
189+
});
190+
191+
$this->artisan('docker:generate', ['--detect' => true])
192+
->expectsChoice('Which Node package manager do you use?', 'none', ['npm', 'yarn', 'none'])
193+
->expectsConfirmation('Does this look correct?', 'yes');
194+
}
167195
}

0 commit comments

Comments
 (0)