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.
- Loading branch information
1 parent
35a73dc
commit 1f1635e
Showing
5 changed files
with
96 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\RoadRunnerLaravel\Listeners; | ||
|
||
use Livewire\LivewireManager; | ||
use Spiral\RoadRunnerLaravel\Events\Contracts\WithApplication; | ||
|
||
/** | ||
* Target package: <https://github.com/livewire/livewire>. | ||
*/ | ||
class ResetLivewireListener implements ListenerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle($event): void | ||
{ | ||
if (!\class_exists(LivewireManager::class)) { | ||
return; | ||
} | ||
|
||
if ($event instanceof WithApplication) { | ||
$app = $event->application(); | ||
|
||
if (!$app->resolved($manager_abstract = LivewireManager::class)) { | ||
return; | ||
} | ||
|
||
/** @var LivewireManager $manager */ | ||
$manager = $app->make($manager_abstract); | ||
|
||
if (\method_exists($manager, 'flushState')) { | ||
$manager->flushState(); | ||
} | ||
} | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\RoadRunnerLaravel\Tests\Unit\Listeners; | ||
|
||
use Mockery as m; | ||
use Livewire\LivewireManager; | ||
use Spiral\RoadRunnerLaravel\Listeners\ResetLivewireListener; | ||
use Spiral\RoadRunnerLaravel\Events\Contracts\WithApplication; | ||
|
||
/** | ||
* @covers \Spiral\RoadRunnerLaravel\Listeners\ResetLivewireListener | ||
*/ | ||
class ResetLivewireListenerTest extends AbstractListenerTestCase | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function testHandle(): void | ||
{ | ||
/** @var LivewireManager $manager */ | ||
$manager = $this->app->make($manager_abstract = LivewireManager::class); | ||
|
||
$manager_mock = m::mock($manager) | ||
->makePartial() | ||
->expects('flushState') | ||
->withNoArgs() | ||
->getMock(); | ||
|
||
$this->app->instance($manager_abstract, $manager_mock); | ||
|
||
/** @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 ResetLivewireListener | ||
*/ | ||
protected function listenerFactory(): ResetLivewireListener | ||
{ | ||
return new ResetLivewireListener(); | ||
} | ||
} |