Skip to content

Commit

Permalink
Fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
slavarazum committed Mar 24, 2024
1 parent f78c982 commit 6696120
Showing 1 changed file with 58 additions and 38 deletions.
96 changes: 58 additions & 38 deletions tests/Feature/BroadcastingInstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,61 @@

use function Qruto\Wave\laravel11OrHigher;

it('completely installs all required assets for broadcasting in default scenario', function () {
File::shouldReceive('copy')
->once()
->withArgs(fn ($path, $target) => str_ends_with($path, 'broadcasting-routes.stub') && str_ends_with($target, 'routes/channels.php'));

File::shouldReceive('copy')
->once()
->withArgs(fn ($path, $target) => str_ends_with($path, 'echo-js.stub') && str_ends_with($target, 'js/echo.js'));

File::shouldReceive('missing')
->once()
->withArgs([app()->environmentFile()])
->andReturn(false);

File::shouldReceive('get')
->once()
->withArgs([app()->environmentFile()])
->andReturn('BROADCAST_CONNECTION=log');

File::shouldReceive('put')
->once()
->withArgs([app()->environmentFile(), 'BROADCAST_CONNECTION=redis']);

Process::fake([
'npm install --save-dev laravel-echo laravel-wave && npm run build' => Process::result(),
]);

$this->artisan('install:broadcasting')
->expectsConfirmation('Would you like to enable the Redis broadcasting driver for Wave?', 'yes')
->expectsConfirmation('Would you like to install and build the Node dependencies required for broadcasting?', 'yes')
->expectsOutputToContain('Installing and building Node dependencies.')
->expectsOutputToContain('Node dependencies installed successfully.')
->expectsConfirmation('Would you like to publish the Wave configuration file?')
->assertExitCode(0);

$this->assertFileExists($this->app->configPath('broadcasting.php'));
unlink($this->app->configPath('broadcasting.php'));
})->skip(! laravel11OrHigher(), '`install:broadcasting` command is only available for Laravel 11 or higher.');
it('completely installs all required assets for broadcasting in default scenario',
function () {
File::shouldReceive('copy')
->once()
->withArgs(fn ($path, $target) => str_ends_with($path,
'broadcasting-routes.stub') && str_ends_with($target,
'routes/channels.php'));

File::shouldReceive('copy')
->once()
->withArgs(fn ($path, $target) => str_ends_with($path,
'echo-js.stub') && str_ends_with($target, 'js/echo.js'));

File::shouldReceive('missing')
->once()
->withArgs([app()->environmentFile()])
->andReturn(false);

File::shouldReceive('get')
->once()
->withArgs([app()->environmentFile()])
->andReturn('BROADCAST_CONNECTION=log');

File::shouldReceive('put')
->once()
->withArgs([
app()->environmentFile(), 'BROADCAST_CONNECTION=redis',
]);

Process::fake([
'npm install --save-dev laravel-echo laravel-wave && npm run build' => Process::result(),
]);

$this->artisan('install:broadcasting')
->expectsConfirmation(
'Would you like to enable the Redis broadcasting driver in .env?',
'yes'
)
->expectsConfirmation(
'Install and build the Node dependencies required for broadcasting?',
'yes'
)
->expectsConfirmation(
'Publish the Wave configuration file?',
'no'
)
->expectsConfirmation(
'Star our repo on GitHub during installation?',
'no'
)
->expectsOutputToContain('Installing and building Node dependencies.')
->expectsOutputToContain('Node dependencies installed successfully.')
->assertExitCode(0);

$this->assertFileExists($this->app->configPath('broadcasting.php'));
unlink($this->app->configPath('broadcasting.php'));
})->skip(! laravel11OrHigher(),
'`install:broadcasting` command is only available for Laravel 11 or higher.');

0 comments on commit 6696120

Please sign in to comment.