mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
add Laravel Facade tests
This commit is contained in:
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flasher\Tests\Laravel\Facade;
|
||||
|
||||
use Flasher\Laravel\Facade\Flasher;
|
||||
use Flasher\Prime\Notification\Envelope;
|
||||
use Flasher\Prime\Notification\NotificationBuilderInterface;
|
||||
use Flasher\Tests\Laravel\TestCase;
|
||||
|
||||
final class FlasherFacadeTest extends TestCase
|
||||
{
|
||||
public function testFacadeAccessor(): void
|
||||
{
|
||||
$this->assertSame('flasher', $this->getFacadeAccessor(Flasher::class));
|
||||
}
|
||||
|
||||
public function testSuccess(): void
|
||||
{
|
||||
$envelope = Flasher::success('Success message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
$this->assertSame('Success message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testError(): void
|
||||
{
|
||||
$envelope = Flasher::error('Error message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('error', $envelope->getType());
|
||||
$this->assertSame('Error message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testWarning(): void
|
||||
{
|
||||
$envelope = Flasher::warning('Warning message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('warning', $envelope->getType());
|
||||
$this->assertSame('Warning message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testInfo(): void
|
||||
{
|
||||
$envelope = Flasher::info('Info message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('info', $envelope->getType());
|
||||
$this->assertSame('Info message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testFlash(): void
|
||||
{
|
||||
$envelope = Flasher::flash('success', 'Flash message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
$this->assertSame('Flash message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testFlashWithNullType(): void
|
||||
{
|
||||
$envelope = Flasher::flash();
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testCreated(): void
|
||||
{
|
||||
$envelope = Flasher::created('User');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
}
|
||||
|
||||
public function testUpdated(): void
|
||||
{
|
||||
$envelope = Flasher::updated('User');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
}
|
||||
|
||||
public function testDeleted(): void
|
||||
{
|
||||
$envelope = Flasher::deleted('User');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
}
|
||||
|
||||
public function testSaved(): void
|
||||
{
|
||||
$envelope = Flasher::saved('User');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
}
|
||||
|
||||
public function testOperation(): void
|
||||
{
|
||||
$envelope = Flasher::operation('created', 'Resource');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
}
|
||||
|
||||
public function testPush(): void
|
||||
{
|
||||
$envelope = Flasher::push();
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testTitle(): void
|
||||
{
|
||||
$envelope = Flasher::title('Test Title')->success('Test message');
|
||||
|
||||
$this->assertSame('Test Title', $envelope->getTitle());
|
||||
}
|
||||
|
||||
public function testMessage(): void
|
||||
{
|
||||
$envelope = Flasher::message('Test message')->getEnvelope();
|
||||
|
||||
$this->assertSame('Test message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testType(): void
|
||||
{
|
||||
$envelope = Flasher::type('warning')->getEnvelope();
|
||||
|
||||
$this->assertSame('warning', $envelope->getType());
|
||||
}
|
||||
|
||||
public function testOptions(): void
|
||||
{
|
||||
$envelope = Flasher::options(['timeout' => 5000, 'position' => 'top-right'])->success('Test');
|
||||
|
||||
$this->assertSame(['timeout' => 5000, 'position' => 'top-right'], $envelope->getOptions());
|
||||
}
|
||||
|
||||
public function testOption(): void
|
||||
{
|
||||
$envelope = Flasher::option('timeout', 3000)->success('Test');
|
||||
|
||||
$this->assertSame(3000, $envelope->getOptions()['timeout']);
|
||||
}
|
||||
|
||||
public function testPriority(): void
|
||||
{
|
||||
$envelope = Flasher::priority(10)->success('Test');
|
||||
|
||||
$priorityStamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertNotNull($priorityStamp);
|
||||
$this->assertSame(10, $priorityStamp->getPriority());
|
||||
}
|
||||
|
||||
public function testHops(): void
|
||||
{
|
||||
$envelope = Flasher::hops(3)->success('Test');
|
||||
|
||||
$hopsStamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
||||
$this->assertNotNull($hopsStamp);
|
||||
$this->assertSame(3, $hopsStamp->getAmount());
|
||||
}
|
||||
|
||||
public function testKeep(): void
|
||||
{
|
||||
$envelope = Flasher::keep()->success('Test');
|
||||
|
||||
$hopsStamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
||||
$this->assertNotNull($hopsStamp);
|
||||
$this->assertSame(2, $hopsStamp->getAmount());
|
||||
}
|
||||
|
||||
public function testDelay(): void
|
||||
{
|
||||
$envelope = Flasher::delay(1000)->success('Test');
|
||||
|
||||
$delayStamp = $envelope->get('Flasher\Prime\Stamp\DelayStamp');
|
||||
$this->assertNotNull($delayStamp);
|
||||
$this->assertSame(1000, $delayStamp->getDelay());
|
||||
}
|
||||
|
||||
public function testHandler(): void
|
||||
{
|
||||
$envelope = Flasher::handler('toastr')->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\PluginStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame('toastr', $stamp->getPlugin());
|
||||
}
|
||||
|
||||
public function testContext(): void
|
||||
{
|
||||
$envelope = Flasher::context(['user_id' => 123])->success('Test');
|
||||
|
||||
$contextStamp = $envelope->get('Flasher\Prime\Stamp\ContextStamp');
|
||||
$this->assertNotNull($contextStamp);
|
||||
$this->assertSame(['user_id' => 123], $contextStamp->getContext());
|
||||
}
|
||||
|
||||
public function testWhenTrue(): void
|
||||
{
|
||||
$envelope = Flasher::when(true)->success('Conditional message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
}
|
||||
|
||||
public function testWhenFalse(): void
|
||||
{
|
||||
$envelope = Flasher::when(false)->success('Conditional message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\WhenStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertFalse($stamp->getCondition());
|
||||
}
|
||||
|
||||
public function testWhenClosure(): void
|
||||
{
|
||||
$envelope = Flasher::when(fn () => true)->success('Closure conditional');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
}
|
||||
|
||||
public function testUnlessTrue(): void
|
||||
{
|
||||
$envelope = Flasher::unless(true)->success('Unless message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\UnlessStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertTrue($stamp->getCondition());
|
||||
}
|
||||
|
||||
public function testUnlessFalse(): void
|
||||
{
|
||||
$envelope = Flasher::unless(false)->success('Unless message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
}
|
||||
|
||||
public function testTranslate(): void
|
||||
{
|
||||
$envelope = Flasher::translate(['resource' => 'User'])->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testWithStamps(): void
|
||||
{
|
||||
$stamp = new \Flasher\Prime\Stamp\PriorityStamp(5);
|
||||
$envelope = Flasher::with([$stamp])->success('Test');
|
||||
|
||||
$priorityStamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertNotNull($priorityStamp);
|
||||
$this->assertSame(5, $priorityStamp->getPriority());
|
||||
}
|
||||
|
||||
public function testWithStamp(): void
|
||||
{
|
||||
$stamp = new \Flasher\Prime\Stamp\HopsStamp(3);
|
||||
$envelope = Flasher::with([$stamp])->success('Test');
|
||||
|
||||
$hopsStamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
||||
$this->assertNotNull($hopsStamp);
|
||||
$this->assertSame(3, $hopsStamp->getAmount());
|
||||
}
|
||||
|
||||
public function testChainedMethods(): void
|
||||
{
|
||||
$envelope = Flasher::title('My Title')
|
||||
->message('My Message')
|
||||
->type('warning')
|
||||
->option('timeout', 5000)
|
||||
->priority(10)
|
||||
->getEnvelope();
|
||||
|
||||
$this->assertSame('My Title', $envelope->getTitle());
|
||||
$this->assertSame('My Message', $envelope->getMessage());
|
||||
$this->assertSame('warning', $envelope->getType());
|
||||
$this->assertSame(5000, $envelope->getOptions()['timeout']);
|
||||
}
|
||||
|
||||
public function testFacadeReturnsBuilder(): void
|
||||
{
|
||||
$result = Flasher::title('Test');
|
||||
|
||||
$this->assertInstanceOf(NotificationBuilderInterface::class, $result);
|
||||
}
|
||||
|
||||
private function getFacadeAccessor(string $facadeClass): string
|
||||
{
|
||||
$reflection = new \ReflectionClass($facadeClass);
|
||||
$method = $reflection->getMethod('getFacadeAccessor');
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invoke(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flasher\Tests\Laravel\Facade;
|
||||
|
||||
use Flasher\Noty\Laravel\Facade\Noty;
|
||||
use Flasher\Prime\Notification\Envelope;
|
||||
use Flasher\Tests\Laravel\TestCase;
|
||||
|
||||
final class NotyFacadeTest extends TestCase
|
||||
{
|
||||
public function testFacadeAccessor(): void
|
||||
{
|
||||
$this->assertSame('flasher.noty', $this->getFacadeAccessor(Noty::class));
|
||||
}
|
||||
|
||||
public function testSuccess(): void
|
||||
{
|
||||
$envelope = Noty::success('Success message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
$this->assertSame('Success message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testError(): void
|
||||
{
|
||||
$envelope = Noty::error('Error message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('error', $envelope->getType());
|
||||
$this->assertSame('Error message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testWarning(): void
|
||||
{
|
||||
$envelope = Noty::warning('Warning message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('warning', $envelope->getType());
|
||||
$this->assertSame('Warning message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testInfo(): void
|
||||
{
|
||||
$envelope = Noty::info('Info message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('info', $envelope->getType());
|
||||
$this->assertSame('Info message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testFlash(): void
|
||||
{
|
||||
$envelope = Noty::flash();
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testPriority(): void
|
||||
{
|
||||
$envelope = Noty::priority(5)->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(5, $stamp->getPriority());
|
||||
}
|
||||
|
||||
public function testHops(): void
|
||||
{
|
||||
$envelope = Noty::hops(2)->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(2, $stamp->getAmount());
|
||||
}
|
||||
|
||||
public function testKeep(): void
|
||||
{
|
||||
$envelope = Noty::keep()->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(2, $stamp->getAmount());
|
||||
}
|
||||
|
||||
public function testDelay(): void
|
||||
{
|
||||
$envelope = Noty::delay(1000)->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\DelayStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(1000, $stamp->getDelay());
|
||||
}
|
||||
|
||||
public function testHandler(): void
|
||||
{
|
||||
$envelope = Noty::handler('noty')->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\PluginStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame('noty', $stamp->getPlugin());
|
||||
}
|
||||
|
||||
public function testWith(): void
|
||||
{
|
||||
$stamp = new \Flasher\Prime\Stamp\PriorityStamp(5);
|
||||
$envelope = Noty::with([$stamp])->success('Test');
|
||||
|
||||
$priorityStamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertNotNull($priorityStamp);
|
||||
$this->assertSame(5, $priorityStamp->getPriority());
|
||||
}
|
||||
|
||||
public function testLayout(): void
|
||||
{
|
||||
$envelope = Noty::layout('topCenter')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
}
|
||||
|
||||
public function testTheme(): void
|
||||
{
|
||||
$envelope = Noty::theme('bootstrap')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testTimeout(): void
|
||||
{
|
||||
$envelope = Noty::timeout(5000)->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testTimeoutFalse(): void
|
||||
{
|
||||
$envelope = Noty::timeout(false)->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testProgressBar(): void
|
||||
{
|
||||
$envelope = Noty::progressBar(true)->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testCloseWith(): void
|
||||
{
|
||||
$envelope = Noty::closeWith(['click', 'button'])->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testAnimation(): void
|
||||
{
|
||||
$envelope = Noty::animation('open', 'fadeIn')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testSounds(): void
|
||||
{
|
||||
$envelope = Noty::sounds('source', '/sounds/notification.mp3')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testDocTitle(): void
|
||||
{
|
||||
$envelope = Noty::docTitle('onTitle', 'New Notification')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testModal(): void
|
||||
{
|
||||
$envelope = Noty::modal(true)->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testId(): void
|
||||
{
|
||||
$envelope = Noty::id('my-notification')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testForce(): void
|
||||
{
|
||||
$envelope = Noty::force(true)->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testQueue(): void
|
||||
{
|
||||
$envelope = Noty::queue('global')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testKiller(): void
|
||||
{
|
||||
$envelope = Noty::killer('my-killer')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testContainer(): void
|
||||
{
|
||||
$envelope = Noty::container('flasher-container')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testButtons(): void
|
||||
{
|
||||
$envelope = Noty::buttons([
|
||||
['text' => 'Ok', 'onClick' => 'function() {}'],
|
||||
])->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testVisibilityControl(): void
|
||||
{
|
||||
$envelope = Noty::visibilityControl(true)->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testChainedMethods(): void
|
||||
{
|
||||
$envelope = Noty::message('Test message')
|
||||
->layout('topCenter')
|
||||
->theme('bootstrap')
|
||||
->timeout(5000)
|
||||
->progressBar(true)
|
||||
->flash();
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('Test message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
private function getFacadeAccessor(string $facadeClass): string
|
||||
{
|
||||
$reflection = new \ReflectionClass($facadeClass);
|
||||
$method = $reflection->getMethod('getFacadeAccessor');
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invoke(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flasher\Tests\Laravel\Facade;
|
||||
|
||||
use Flasher\Notyf\Laravel\Facade\Notyf;
|
||||
use Flasher\Prime\Notification\Envelope;
|
||||
use Flasher\Tests\Laravel\TestCase;
|
||||
|
||||
final class NotyfFacadeTest extends TestCase
|
||||
{
|
||||
public function testFacadeAccessor(): void
|
||||
{
|
||||
$this->assertSame('flasher.notyf', $this->getFacadeAccessor(Notyf::class));
|
||||
}
|
||||
|
||||
public function testSuccess(): void
|
||||
{
|
||||
$envelope = Notyf::success('Success message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
$this->assertSame('Success message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testError(): void
|
||||
{
|
||||
$envelope = Notyf::error('Error message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('error', $envelope->getType());
|
||||
$this->assertSame('Error message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testWarning(): void
|
||||
{
|
||||
$envelope = Notyf::warning('Warning message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('warning', $envelope->getType());
|
||||
$this->assertSame('Warning message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testInfo(): void
|
||||
{
|
||||
$envelope = Notyf::info('Info message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('info', $envelope->getType());
|
||||
$this->assertSame('Info message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testFlash(): void
|
||||
{
|
||||
$envelope = Notyf::flash();
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testDuration(): void
|
||||
{
|
||||
$envelope = Notyf::duration(5000)->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testRipple(): void
|
||||
{
|
||||
$envelope = Notyf::ripple(true)->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testPosition(): void
|
||||
{
|
||||
$envelope = Notyf::position('x', 'right')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testDismissible(): void
|
||||
{
|
||||
$envelope = Notyf::dismissible(true)->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testBackground(): void
|
||||
{
|
||||
$envelope = Notyf::background('#ff0000')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testPriority(): void
|
||||
{
|
||||
$envelope = Notyf::priority(5)->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(5, $stamp->getPriority());
|
||||
}
|
||||
|
||||
public function testHops(): void
|
||||
{
|
||||
$envelope = Notyf::hops(2)->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(2, $stamp->getAmount());
|
||||
}
|
||||
|
||||
public function testKeep(): void
|
||||
{
|
||||
$envelope = Notyf::keep()->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(2, $stamp->getAmount());
|
||||
}
|
||||
|
||||
public function testDelay(): void
|
||||
{
|
||||
$envelope = Notyf::delay(1000)->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\DelayStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(1000, $stamp->getDelay());
|
||||
}
|
||||
|
||||
public function testHandler(): void
|
||||
{
|
||||
$envelope = Notyf::handler('notyf')->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\PluginStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame('notyf', $stamp->getPlugin());
|
||||
}
|
||||
|
||||
public function testWith(): void
|
||||
{
|
||||
$stamp = new \Flasher\Prime\Stamp\PriorityStamp(5);
|
||||
$envelope = Notyf::with([$stamp])->success('Test');
|
||||
|
||||
$priorityStamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertNotNull($priorityStamp);
|
||||
$this->assertSame(5, $priorityStamp->getPriority());
|
||||
}
|
||||
|
||||
public function testChainedMethods(): void
|
||||
{
|
||||
$envelope = Notyf::message('Test message')
|
||||
->duration(5000)
|
||||
->ripple(true)
|
||||
->position('x', 'right')
|
||||
->position('y', 'top')
|
||||
->dismissible(true)
|
||||
->flash();
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('Test message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
private function getFacadeAccessor(string $facadeClass): string
|
||||
{
|
||||
$reflection = new \ReflectionClass($facadeClass);
|
||||
$method = $reflection->getMethod('getFacadeAccessor');
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invoke(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flasher\Tests\Laravel\Facade;
|
||||
|
||||
use Flasher\Prime\Notification\Envelope;
|
||||
use Flasher\SweetAlert\Laravel\Facade\SweetAlert;
|
||||
use Flasher\Tests\Laravel\TestCase;
|
||||
|
||||
final class SweetAlertFacadeTest extends TestCase
|
||||
{
|
||||
public function testFacadeAccessor(): void
|
||||
{
|
||||
$this->assertSame('flasher.sweetalert', $this->getFacadeAccessor(SweetAlert::class));
|
||||
}
|
||||
|
||||
public function testSuccess(): void
|
||||
{
|
||||
$envelope = SweetAlert::success('Success message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
$this->assertSame('Success message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testError(): void
|
||||
{
|
||||
$envelope = SweetAlert::error('Error message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('error', $envelope->getType());
|
||||
$this->assertSame('Error message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testWarning(): void
|
||||
{
|
||||
$envelope = SweetAlert::warning('Warning message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('warning', $envelope->getType());
|
||||
$this->assertSame('Warning message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testInfo(): void
|
||||
{
|
||||
$envelope = SweetAlert::info('Info message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('info', $envelope->getType());
|
||||
$this->assertSame('Info message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testQuestion(): void
|
||||
{
|
||||
$envelope = SweetAlert::question('Question message')->flash();
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('question', $envelope->getType());
|
||||
$this->assertSame('Question message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testFlash(): void
|
||||
{
|
||||
$envelope = SweetAlert::flash();
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testToast(): void
|
||||
{
|
||||
$envelope = SweetAlert::toast()->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testPosition(): void
|
||||
{
|
||||
$envelope = SweetAlert::position('center')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testTimer(): void
|
||||
{
|
||||
$envelope = SweetAlert::timer(3000)->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testShowConfirmButton(): void
|
||||
{
|
||||
$envelope = SweetAlert::showConfirmButton()->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testShowCancelButton(): void
|
||||
{
|
||||
$envelope = SweetAlert::showCancelButton()->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testPriority(): void
|
||||
{
|
||||
$envelope = SweetAlert::priority(5)->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(5, $stamp->getPriority());
|
||||
}
|
||||
|
||||
public function testHops(): void
|
||||
{
|
||||
$envelope = SweetAlert::hops(2)->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(2, $stamp->getAmount());
|
||||
}
|
||||
|
||||
public function testKeep(): void
|
||||
{
|
||||
$envelope = SweetAlert::keep()->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(2, $stamp->getAmount());
|
||||
}
|
||||
|
||||
public function testDelay(): void
|
||||
{
|
||||
$envelope = SweetAlert::delay(1000)->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\DelayStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(1000, $stamp->getDelay());
|
||||
}
|
||||
|
||||
public function testHandler(): void
|
||||
{
|
||||
$envelope = SweetAlert::handler('sweetalert')->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\PluginStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame('sweetalert', $stamp->getPlugin());
|
||||
}
|
||||
|
||||
public function testWith(): void
|
||||
{
|
||||
$stamp = new \Flasher\Prime\Stamp\PriorityStamp(5);
|
||||
$envelope = SweetAlert::with([$stamp])->success('Test');
|
||||
|
||||
$priorityStamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertNotNull($priorityStamp);
|
||||
$this->assertSame(5, $priorityStamp->getPriority());
|
||||
}
|
||||
|
||||
public function testChainedMethods(): void
|
||||
{
|
||||
$envelope = SweetAlert::message('Test message')
|
||||
->title('Test Title')
|
||||
->icon('success')
|
||||
->toast()
|
||||
->position('top-end')
|
||||
->timer(3000)
|
||||
->timerProgressBar()
|
||||
->flash();
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('Test message', $envelope->getMessage());
|
||||
$this->assertSame('Test Title', $envelope->getTitle());
|
||||
}
|
||||
|
||||
private function getFacadeAccessor(string $facadeClass): string
|
||||
{
|
||||
$reflection = new \ReflectionClass($facadeClass);
|
||||
$method = $reflection->getMethod('getFacadeAccessor');
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invoke(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flasher\Tests\Laravel\Facade;
|
||||
|
||||
use Flasher\Prime\Notification\Envelope;
|
||||
use Flasher\Tests\Laravel\TestCase;
|
||||
use Flasher\Toastr\Laravel\Facade\Toastr;
|
||||
|
||||
final class ToastrFacadeTest extends TestCase
|
||||
{
|
||||
public function testFacadeAccessor(): void
|
||||
{
|
||||
$this->assertSame('flasher.toastr', $this->getFacadeAccessor(Toastr::class));
|
||||
}
|
||||
|
||||
public function testSuccess(): void
|
||||
{
|
||||
$envelope = Toastr::success('Success message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('success', $envelope->getType());
|
||||
$this->assertSame('Success message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testError(): void
|
||||
{
|
||||
$envelope = Toastr::error('Error message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('error', $envelope->getType());
|
||||
$this->assertSame('Error message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testWarning(): void
|
||||
{
|
||||
$envelope = Toastr::warning('Warning message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('warning', $envelope->getType());
|
||||
$this->assertSame('Warning message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testInfo(): void
|
||||
{
|
||||
$envelope = Toastr::info('Info message');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('info', $envelope->getType());
|
||||
$this->assertSame('Info message', $envelope->getMessage());
|
||||
}
|
||||
|
||||
public function testFlash(): void
|
||||
{
|
||||
$envelope = Toastr::flash();
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testCloseButton(): void
|
||||
{
|
||||
$envelope = Toastr::closeButton()->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testProgressBar(): void
|
||||
{
|
||||
$envelope = Toastr::progressBar()->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testPositionClass(): void
|
||||
{
|
||||
$envelope = Toastr::positionClass('toast-top-right')->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testTimeOut(): void
|
||||
{
|
||||
$envelope = Toastr::timeOut(5000)->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testPriority(): void
|
||||
{
|
||||
$envelope = Toastr::priority(5)->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(5, $stamp->getPriority());
|
||||
}
|
||||
|
||||
public function testHops(): void
|
||||
{
|
||||
$envelope = Toastr::hops(2)->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(2, $stamp->getAmount());
|
||||
}
|
||||
|
||||
public function testKeep(): void
|
||||
{
|
||||
$envelope = Toastr::keep()->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(2, $stamp->getAmount());
|
||||
}
|
||||
|
||||
public function testDelay(): void
|
||||
{
|
||||
$envelope = Toastr::delay(1000)->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\DelayStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame(1000, $stamp->getDelay());
|
||||
}
|
||||
|
||||
public function testHandler(): void
|
||||
{
|
||||
$envelope = Toastr::handler('toastr')->success('Test');
|
||||
|
||||
$stamp = $envelope->get('Flasher\Prime\Stamp\PluginStamp');
|
||||
$this->assertNotNull($stamp);
|
||||
$this->assertSame('toastr', $stamp->getPlugin());
|
||||
}
|
||||
|
||||
public function testWith(): void
|
||||
{
|
||||
$stamp = new \Flasher\Prime\Stamp\PriorityStamp(5);
|
||||
$envelope = Toastr::with([$stamp])->success('Test');
|
||||
|
||||
$priorityStamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertNotNull($priorityStamp);
|
||||
$this->assertSame(5, $priorityStamp->getPriority());
|
||||
}
|
||||
|
||||
public function testPersistent(): void
|
||||
{
|
||||
$envelope = Toastr::persistent()->success('Test');
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
}
|
||||
|
||||
public function testChainedMethods(): void
|
||||
{
|
||||
$envelope = Toastr::message('Test message')
|
||||
->title('Test Title')
|
||||
->closeButton()
|
||||
->progressBar()
|
||||
->positionClass('toast-top-right')
|
||||
->timeOut(5000)
|
||||
->flash();
|
||||
|
||||
$this->assertInstanceOf(Envelope::class, $envelope);
|
||||
$this->assertSame('Test message', $envelope->getMessage());
|
||||
$this->assertSame('Test Title', $envelope->getTitle());
|
||||
}
|
||||
|
||||
private function getFacadeAccessor(string $facadeClass): string
|
||||
{
|
||||
$reflection = new \ReflectionClass($facadeClass);
|
||||
$method = $reflection->getMethod('getFacadeAccessor');
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invoke(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user