Skip to content

Commit

Permalink
fix: avoid workbench:install from stopping at InstallingWorkbench
Browse files Browse the repository at this point in the history
… event (#6)

* fix: avoid `workbench:install` from stopping at `InstallingWorkbench`
event

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone authored Dec 23, 2024
1 parent 600753e commit 053bd52
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 35 deletions.
10 changes: 2 additions & 8 deletions src/Listeners/InstallingWorkbench.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Laravel\Nova\DevTool\Listeners;

use Illuminate\Contracts\Console\Kernel as ConsoleKernel;
use Illuminate\Filesystem\Filesystem;
use Orchestra\Workbench\Events\InstallStarted;
use RuntimeException;
Expand All @@ -12,10 +11,8 @@ class InstallingWorkbench
/**
* Construct a new event listener.
*/
public function __construct(
public ConsoleKernel $kernel,
public Filesystem $files
) {
public function __construct(public Filesystem $files)
{
//
}

Expand All @@ -29,8 +26,5 @@ public function handle(InstallStarted $event)
if ($event->isBasicInstallation()) {
throw new RuntimeException('Nova Devtool does not support installation with --basic` option');
}

$this->kernel->call('make:user-model');
$this->kernel->call('make:user-factory');
}
}
28 changes: 1 addition & 27 deletions tests/Feature/Listeners/InstallingWorkbenchTest.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
<?php

use Illuminate\Console\View\Components\Factory as ViewComponent;
use Illuminate\Contracts\Console\Kernel as ConsoleKernel;
use Illuminate\Filesystem\Filesystem;
use Laravel\Nova\DevTool\Listeners\InstallingWorkbench;
use Mockery as m;
use Orchestra\Workbench\Events\InstallStarted;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

it('can make user model and factory if installation without `--basic` option', function () {
$kernel = m::mock(ConsoleKernel::class);

$listener = new InstallingWorkbench($kernel, new Filesystem);

$event = new InstallStarted(
$input = m::mock(InputInterface::class),
m::mock(OutputInterface::class),
m::mock(ViewComponent::class),
);

$input->shouldReceive('hasOption')->with('basic')->andReturnTrue();
$input->shouldReceive('getOption')->with('basic')->andReturnFalse();

$kernel->shouldReceive('call')->with('make:user-model')->once();
$kernel->shouldReceive('call')->with('make:user-factory')->once();

$listener->handle($event);
});

it('can throw exception if installation with `--basic` option', function () {
$kernel = m::mock(ConsoleKernel::class);

$listener = new InstallingWorkbench($kernel, new Filesystem);
$listener = new InstallingWorkbench(new Filesystem);

$event = new InstallStarted(
$input = m::mock(InputInterface::class),
Expand All @@ -43,8 +20,5 @@
$input->shouldReceive('hasOption')->with('basic')->andReturnTrue();
$input->shouldReceive('getOption')->with('basic')->andReturnTrue();

$kernel->shouldReceive('call')->with('make:user-model')->never();
$kernel->shouldReceive('call')->with('make:user-factory')->never();

$listener->handle($event);
})->throws(RuntimeException::class, 'Nova Devtool does not support installation with --basic` option');

0 comments on commit 053bd52

Please sign in to comment.