mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
7d6e9b46b8
Implement consistent event dispatching across Noty, Notyf, Toastr adapters and
themes, following the existing SweetAlert pattern. This enables Livewire
integration for all notification types.
JavaScript Events:
- Noty: flasher:noty:show, flasher:noty:click, flasher:noty:close, flasher:noty:hover
- Notyf: flasher:notyf:click, flasher:notyf:dismiss
- Toastr: flasher:toastr:show, flasher:toastr:click, flasher:toastr:close, flasher:toastr:hidden
- Themes: flasher:theme:click (generic), flasher:theme:{name}:click (specific)
PHP Livewire Listeners:
- LivewireListener for each adapter (Noty, Notyf, Toastr)
- ThemeLivewireListener for theme click events
- Registered in service providers when Livewire is bound
This allows Livewire users to listen for notification events and react
accordingly (e.g., noty:click, theme:flasher:click).
98 lines
3.2 KiB
PHP
98 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Flasher\Tests\Notyf\Laravel;
|
|
|
|
use Flasher\Notyf\Laravel\FlasherNotyfServiceProvider;
|
|
use Flasher\Notyf\Prime\NotyfPlugin;
|
|
use Illuminate\Contracts\Config\Repository;
|
|
use Illuminate\Contracts\Foundation\Application;
|
|
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
|
|
use Mockery\MockInterface;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class FlasherNotyfServiceProviderTest extends TestCase
|
|
{
|
|
use MockeryPHPUnitIntegration;
|
|
|
|
private MockInterface&Application $app;
|
|
private FlasherNotyfServiceProvider $serviceProvider;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->app = \Mockery::mock(Application::class);
|
|
$this->serviceProvider = new FlasherNotyfServiceProvider($this->app);
|
|
}
|
|
|
|
public function testCreatePlugin(): void
|
|
{
|
|
$this->assertInstanceOf(NotyfPlugin::class, $this->serviceProvider->createPlugin());
|
|
}
|
|
|
|
public function testRegister(): void
|
|
{
|
|
$this->app->expects()->make('config')->andReturns($configMock = \Mockery::mock(Repository::class));
|
|
$configMock->expects('get')->andReturns([]);
|
|
$configMock->expects('set');
|
|
|
|
$this->app->expects('configurationIsCached')->never();
|
|
|
|
$this->serviceProvider->register();
|
|
$this->addToAssertionCount(1);
|
|
}
|
|
|
|
public function testBoot(): void
|
|
{
|
|
$this->app->expects()->make('config')->andReturns($configMock = \Mockery::mock(Repository::class));
|
|
$configMock->expects('get')->andReturns([]);
|
|
$configMock->expects('set');
|
|
|
|
$this->app->expects('singleton');
|
|
$this->app->expects('alias');
|
|
$this->app->expects('extend');
|
|
$this->app->expects('bound')->with('livewire')->andReturn(false);
|
|
|
|
$this->serviceProvider->register();
|
|
$this->serviceProvider->boot();
|
|
$this->addToAssertionCount(1);
|
|
}
|
|
|
|
public function testBootWithLivewire(): void
|
|
{
|
|
$this->app->expects()->make('config')->andReturns($configMock = \Mockery::mock(Repository::class));
|
|
$configMock->expects('get')->andReturns([]);
|
|
$configMock->expects('set');
|
|
|
|
$this->app->expects('singleton');
|
|
$this->app->expects('alias');
|
|
$this->app->expects('extend')->twice();
|
|
$this->app->expects('bound')->with('livewire')->andReturn(true);
|
|
|
|
$this->serviceProvider->register();
|
|
$this->serviceProvider->boot();
|
|
$this->addToAssertionCount(1);
|
|
}
|
|
|
|
public function testGetConfigurationFile(): void
|
|
{
|
|
$expectedPath = $this->getResourcesPathFromServiceProvider();
|
|
$this->assertStringEndsWith('/Resources/config.php', $this->serviceProvider->getConfigurationFile());
|
|
$this->assertStringContainsString($expectedPath, $this->serviceProvider->getConfigurationFile());
|
|
}
|
|
|
|
private function getResourcesPathFromServiceProvider(): string
|
|
{
|
|
$reflection = new \ReflectionClass(FlasherNotyfServiceProvider::class);
|
|
$method = $reflection->getMethod('getResourcesDir');
|
|
$method->setAccessible(true);
|
|
|
|
/** @var string $string */
|
|
$string = $method->invoke($this->serviceProvider);
|
|
|
|
return rtrim($string, '/').'/';
|
|
}
|
|
}
|