Skip to content

Commit

Permalink
updates tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gcavanunez committed Aug 15, 2024
1 parent 81c13ef commit fa611a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
4 changes: 2 additions & 2 deletions app/Commands/EnableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function handle(Environment $environment, Services $services): void
}

$option = $this->selectService();
if (!$option) {
if (! $option) {
return;
}

Expand Down Expand Up @@ -87,7 +87,7 @@ public function serverArguments(): array
*/
public function extractPassthroughOptions(array $arguments): array
{
if (!in_array('--', $arguments)) {
if (! in_array('--', $arguments)) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"ext-pcntl": "*",
"ext-posix": "*",
"guzzlehttp/psr7": "^1.7",
"laravel/prompts": "^0.1.21"
"laravel/prompts": "^0.1.24"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.5",
Expand Down
49 changes: 26 additions & 23 deletions tests/Feature/EnableCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use App\Services\PostgreSql;
use App\Shell\Docker;
use Illuminate\Console\Command;
use Laravel\Prompts\Prompt;
use Laravel\Prompts\SearchPrompt;
use NunoMaduro\LaravelConsoleMenu\Menu;
use PHPUnit\Framework\Assert;
use Tests\TestCase;
Expand All @@ -33,14 +35,6 @@ function it_can_enable_a_service_from_menu()
$postgres = 'postgresql' => $fqcn = 'App\Services\PostgreSql',
];

$menuItems = [
'<fg=white;bg=blue;options=bold> DATABASE </>',
'PostgreSQL',
'<fg=white;bg=blue;options=bold> SEARCH </>',
'MeiliSearch',
'<info>Exit</>',
];

$this->mock(Docker::class, function ($mock) {
$mock->shouldReceive('isInstalled')->andReturn(true);
$mock->shouldReceive('isDockerServiceRunning')->andReturn(true);
Expand All @@ -56,28 +50,37 @@ function it_can_enable_a_service_from_menu()
});

if ($this->isWindows()) {
$menuItems = [
'<fg=white;bg=blue;options=bold> DATABASE </>',
'PostgreSQL',
'<fg=white;bg=blue;options=bold> SEARCH </>',
'MeiliSearch',
'<info>Exit</>',
];

$this->artisan('enable')
->expectsChoice('Takeout containers to enable', 'PostgreSQL', $menuItems)
->assertExitCode(0);
} else {
$menuMock = $this->mock(Menu::class, function ($mock) use ($postgres) {
$mock->shouldReceive('setTitleSeparator')->andReturnSelf();
$mock->shouldReceive('addStaticItem')->andReturnSelf()->times(4);
$mock->shouldReceive('addOptions')->andReturnSelf();
$mock->shouldReceive('addLineBreak')->andReturnSelf();
$mock->shouldReceive('open')->andReturn($postgres)->once();
});
$menuItems = [
'Database: PostgreSQL',
'Search: MeiliSearch',
'meilisearch',
'postgresql',
];

Command::macro(
'menu',
function (string $title) use ($menuMock) {
Assert::assertEquals('Takeout containers to enable', $title);
$this->artisan('enable')
->expectsChoice('Takeout containers to enable', '', $menuItems)
->assertExitCode(0);

return $menuMock;
}
);
$menuItems = [
'Database: PostgreSQL',
'postgresql',
];

$this->artisan('enable');
$this->artisan('enable')
->expectsChoice('Takeout containers to enable', 'PostgreSQL', $menuItems)
->assertExitCode(0);
}
}

Expand Down

0 comments on commit fa611a4

Please sign in to comment.