This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
laravel-ignition integration and CLI mode detection (#88)
- Loading branch information
1 parent
dfd5bf6
commit 5d53c36
Showing
8 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\RoadRunnerLaravel\Listeners; | ||
|
||
use Spiral\RoadRunnerLaravel\Events\Contracts\WithApplication; | ||
|
||
/** | ||
* Target package: <https://github.com/spatie/laravel-ignition/>. | ||
*/ | ||
class ResetLaravelIgnitionListener implements ListenerInterface | ||
{ | ||
use Traits\InvokerTrait; | ||
|
||
/** | ||
* @var array<class-string> | ||
*/ | ||
private static array $abstracts = [ | ||
\Spatie\Ignition\Ignition::class, | ||
\Spatie\LaravelIgnition\Support\SentReports::class, | ||
\Spatie\LaravelIgnition\Recorders\DumpRecorder\DumpRecorder::class, | ||
\Spatie\LaravelIgnition\Recorders\LogRecorder\LogRecorder::class, | ||
\Spatie\LaravelIgnition\Recorders\QueryRecorder\QueryRecorder::class, | ||
\Spatie\LaravelIgnition\Recorders\JobRecorder\JobRecorder::class, | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle($event): void | ||
{ | ||
if (!\class_exists(\Spatie\LaravelIgnition\IgnitionServiceProvider::class)) { | ||
return; | ||
} | ||
|
||
if ($event instanceof WithApplication) { | ||
$app = $event->application(); | ||
|
||
/** @see \Spatie\LaravelIgnition\IgnitionServiceProvider::resetFlareAndLaravelIgnition */ | ||
foreach (self::$abstracts as $abstract) { | ||
if ($app->resolved($abstract)) { | ||
$instance = $app->make($abstract); | ||
|
||
if (!\is_object($instance)) { | ||
continue; | ||
} | ||
|
||
foreach (['reset', 'clear'] as $method_name) { | ||
if ($this->invokeMethod($instance, $method_name)) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\RoadRunnerLaravel\Tests\Unit\Listeners; | ||
|
||
use Mockery as m; | ||
use Spatie\LaravelIgnition\Recorders; | ||
use Spiral\RoadRunnerLaravel\Events\Contracts\WithApplication; | ||
use Spiral\RoadRunnerLaravel\Listeners\ResetLaravelIgnitionListener; | ||
|
||
/** | ||
* @covers \Spiral\RoadRunnerLaravel\Listeners\ResetLaravelIgnitionListener | ||
*/ | ||
class ResetLaravelIgnitionListenerTest extends AbstractListenerTestCase | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function testHandle(): void | ||
{ | ||
if (!\class_exists(\Spatie\LaravelIgnition\IgnitionServiceProvider::class)) { | ||
$this->markTestSkipped("Run 'composer require --dev spatie/laravel-ignition' for enabling this test"); | ||
} | ||
|
||
$this->spy(\Spatie\Ignition\Ignition::class, function (m\MockInterface $m) { | ||
$m->shouldReceive('reset')->once(); | ||
}); | ||
|
||
$this->spy(\Spatie\LaravelIgnition\Support\SentReports::class, function (m\MockInterface $m) { | ||
$m->shouldReceive('clear')->once(); | ||
}); | ||
|
||
$this->spy(Recorders\DumpRecorder\DumpRecorder::class, function (m\MockInterface $m) { | ||
$m->shouldReceive('reset')->once(); | ||
}); | ||
|
||
$this->spy(Recorders\LogRecorder\LogRecorder::class, function (m\MockInterface $m) { | ||
$m->shouldReceive('reset')->once(); | ||
}); | ||
|
||
$this->spy(Recorders\QueryRecorder\QueryRecorder::class, function (m\MockInterface $m) { | ||
$m->shouldReceive('reset')->once(); | ||
}); | ||
|
||
$this->spy(Recorders\JobRecorder\JobRecorder::class, function (m\MockInterface $m) { | ||
$m->shouldReceive('reset')->once(); | ||
}); | ||
|
||
/** @var m\MockInterface|WithApplication $event_mock */ | ||
$event_mock = m::mock(WithApplication::class) | ||
->makePartial() | ||
->expects('application') | ||
->andReturn($this->app) | ||
->getMock(); | ||
|
||
$this->listenerFactory()->handle($event_mock); | ||
} | ||
|
||
/** | ||
* @return ResetLaravelIgnitionListener | ||
*/ | ||
protected function listenerFactory(): ResetLaravelIgnitionListener | ||
{ | ||
return new ResetLaravelIgnitionListener(); | ||
} | ||
} |