mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
add tests for helper functions
This commit is contained in:
@@ -0,0 +1,154 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Flasher\Tests\Laravel\Helper;
|
||||||
|
|
||||||
|
use Flasher\Noty\Prime\NotyInterface;
|
||||||
|
use Flasher\Notyf\Prime\NotyfInterface;
|
||||||
|
use Flasher\Prime\FlasherInterface;
|
||||||
|
use Flasher\Prime\Notification\Envelope;
|
||||||
|
use Flasher\SweetAlert\Prime\SweetAlertInterface;
|
||||||
|
use Flasher\Tests\Laravel\TestCase;
|
||||||
|
use Flasher\Toastr\Prime\ToastrInterface;
|
||||||
|
|
||||||
|
final class GlobalHelperTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testFlashReturnsFactoryWithNoArgs(): void
|
||||||
|
{
|
||||||
|
$result = flash();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(FlasherInterface::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFlashReturnsEnvelopeWithMessage(): void
|
||||||
|
{
|
||||||
|
$result = flash('Test message');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Envelope::class, $result);
|
||||||
|
$this->assertSame('Test message', $result->getMessage());
|
||||||
|
$this->assertSame('success', $result->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFlashWithCustomType(): void
|
||||||
|
{
|
||||||
|
$result = flash('Error message', 'error');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Envelope::class, $result);
|
||||||
|
$this->assertSame('error', $result->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFlashWithOptions(): void
|
||||||
|
{
|
||||||
|
$result = flash('Test', 'warning', ['timeout' => 5000]);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Envelope::class, $result);
|
||||||
|
$this->assertSame('warning', $result->getType());
|
||||||
|
$this->assertSame(['timeout' => 5000], $result->getOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFlashWithTitle(): void
|
||||||
|
{
|
||||||
|
$result = flash('Test message', 'info', [], 'My Title');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Envelope::class, $result);
|
||||||
|
$this->assertSame('info', $result->getType());
|
||||||
|
$this->assertSame('My Title', $result->getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToastrReturnsFactoryWithNoArgs(): void
|
||||||
|
{
|
||||||
|
$result = toastr();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(ToastrInterface::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToastrReturnsEnvelopeWithMessage(): void
|
||||||
|
{
|
||||||
|
$result = toastr('Test message');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Envelope::class, $result);
|
||||||
|
$this->assertSame('Test message', $result->getMessage());
|
||||||
|
$this->assertSame('success', $result->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToastrWithCustomType(): void
|
||||||
|
{
|
||||||
|
$result = toastr('Error message', 'error');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Envelope::class, $result);
|
||||||
|
$this->assertSame('error', $result->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotyReturnsFactoryWithNoArgs(): void
|
||||||
|
{
|
||||||
|
$result = noty();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(NotyInterface::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotyReturnsEnvelopeWithMessage(): void
|
||||||
|
{
|
||||||
|
$result = noty('Test message');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Envelope::class, $result);
|
||||||
|
$this->assertSame('Test message', $result->getMessage());
|
||||||
|
$this->assertSame('success', $result->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotyWithCustomType(): void
|
||||||
|
{
|
||||||
|
$result = noty('Warning message', 'warning');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Envelope::class, $result);
|
||||||
|
$this->assertSame('warning', $result->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotyfReturnsFactoryWithNoArgs(): void
|
||||||
|
{
|
||||||
|
$result = notyf();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(NotyfInterface::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotyfReturnsEnvelopeWithMessage(): void
|
||||||
|
{
|
||||||
|
$result = notyf('Test message');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Envelope::class, $result);
|
||||||
|
$this->assertSame('Test message', $result->getMessage());
|
||||||
|
$this->assertSame('success', $result->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotyfWithCustomType(): void
|
||||||
|
{
|
||||||
|
$result = notyf('Error message', 'error');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Envelope::class, $result);
|
||||||
|
$this->assertSame('error', $result->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSweetalertReturnsFactoryWithNoArgs(): void
|
||||||
|
{
|
||||||
|
$result = sweetalert();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(SweetAlertInterface::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSweetalertReturnsEnvelopeWithMessage(): void
|
||||||
|
{
|
||||||
|
$result = sweetalert('Test message');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Envelope::class, $result);
|
||||||
|
$this->assertSame('Test message', $result->getMessage());
|
||||||
|
$this->assertSame('success', $result->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSweetalertWithCustomType(): void
|
||||||
|
{
|
||||||
|
$result = sweetalert('Question?', 'question');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Envelope::class, $result);
|
||||||
|
$this->assertSame('question', $result->getType());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Flasher\Tests\Laravel\Helper;
|
||||||
|
|
||||||
|
use Flasher\Tests\Laravel\TestCase;
|
||||||
|
|
||||||
|
final class NamespacedHelperTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testPrimeFlashFunctionExists(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(\function_exists('Flasher\Prime\flash'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPrimeFlashReturnsFactoryWithNoArgs(): void
|
||||||
|
{
|
||||||
|
$result = \Flasher\Prime\flash();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(\Flasher\Prime\FlasherInterface::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPrimeFlashReturnsEnvelopeWithMessage(): void
|
||||||
|
{
|
||||||
|
$result = \Flasher\Prime\flash('Test message');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(\Flasher\Prime\Notification\Envelope::class, $result);
|
||||||
|
$this->assertSame('Test message', $result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToastrFunctionExists(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(\function_exists('Flasher\Toastr\Prime\toastr'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToastrReturnsFactoryWithNoArgs(): void
|
||||||
|
{
|
||||||
|
$result = \Flasher\Toastr\Prime\toastr();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(\Flasher\Toastr\Prime\ToastrInterface::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToastrReturnsEnvelopeWithMessage(): void
|
||||||
|
{
|
||||||
|
$result = \Flasher\Toastr\Prime\toastr('Test message');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(\Flasher\Prime\Notification\Envelope::class, $result);
|
||||||
|
$this->assertSame('Test message', $result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotyFunctionExists(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(\function_exists('Flasher\Noty\Prime\noty'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotyReturnsFactoryWithNoArgs(): void
|
||||||
|
{
|
||||||
|
$result = \Flasher\Noty\Prime\noty();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(\Flasher\Noty\Prime\NotyInterface::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotyReturnsEnvelopeWithMessage(): void
|
||||||
|
{
|
||||||
|
$result = \Flasher\Noty\Prime\noty('Test message');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(\Flasher\Prime\Notification\Envelope::class, $result);
|
||||||
|
$this->assertSame('Test message', $result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotyfFunctionExists(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(\function_exists('Flasher\Notyf\Prime\notyf'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotyfReturnsFactoryWithNoArgs(): void
|
||||||
|
{
|
||||||
|
$result = \Flasher\Notyf\Prime\notyf();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(\Flasher\Notyf\Prime\NotyfInterface::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotyfReturnsEnvelopeWithMessage(): void
|
||||||
|
{
|
||||||
|
$result = \Flasher\Notyf\Prime\notyf('Test message');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(\Flasher\Prime\Notification\Envelope::class, $result);
|
||||||
|
$this->assertSame('Test message', $result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSweetalertFunctionExists(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(\function_exists('Flasher\SweetAlert\Prime\sweetalert'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSweetalertReturnsFactoryWithNoArgs(): void
|
||||||
|
{
|
||||||
|
$result = \Flasher\SweetAlert\Prime\sweetalert();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(\Flasher\SweetAlert\Prime\SweetAlertInterface::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSweetalertReturnsEnvelopeWithMessage(): void
|
||||||
|
{
|
||||||
|
$result = \Flasher\SweetAlert\Prime\sweetalert('Test message');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(\Flasher\Prime\Notification\Envelope::class, $result);
|
||||||
|
$this->assertSame('Test message', $result->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,7 +60,7 @@ final class FilterCriteriaTest extends TestCase
|
|||||||
new Envelope(new Notification()),
|
new Envelope(new Notification()),
|
||||||
];
|
];
|
||||||
|
|
||||||
$criteria = new FilterCriteria(fn ($e) => array_slice($e, 0, 2));
|
$criteria = new FilterCriteria(fn ($e) => \array_slice($e, 0, 2));
|
||||||
|
|
||||||
$result = $criteria->apply($envelopes);
|
$result = $criteria->apply($envelopes);
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ final class FilterCriteriaTest extends TestCase
|
|||||||
|
|
||||||
$criteria = new FilterCriteria([
|
$criteria = new FilterCriteria([
|
||||||
fn ($e) => array_filter($e, fn (Envelope $envelope) => 'success' === $envelope->getType()),
|
fn ($e) => array_filter($e, fn (Envelope $envelope) => 'success' === $envelope->getType()),
|
||||||
fn ($e) => array_slice($e, 0, 1),
|
fn ($e) => \array_slice($e, 0, 1),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$result = $criteria->apply($envelopes);
|
$result = $criteria->apply($envelopes);
|
||||||
@@ -157,7 +157,7 @@ final class FilterCriteriaTest extends TestCase
|
|||||||
function ($e) use (&$order) {
|
function ($e) use (&$order) {
|
||||||
$order[] = 'second';
|
$order[] = 'second';
|
||||||
|
|
||||||
return array_slice($e, 0, 2);
|
return \array_slice($e, 0, 2);
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ final class RangeExtractorTest extends TestCase
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->traitInstance = new class() {
|
$this->traitInstance = new class {
|
||||||
use RangeExtractor;
|
use RangeExtractor;
|
||||||
|
|
||||||
public function testExtractRange(string $name, mixed $criteria): array
|
public function testExtractRange(string $name, mixed $criteria): array
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ namespace Flasher\Tests\Symfony\Translation;
|
|||||||
|
|
||||||
use Flasher\Symfony\Translation\Translator;
|
use Flasher\Symfony\Translation\Translator;
|
||||||
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
|
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
|
||||||
use Mockery\MockInterface;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\Translation\MessageCatalogueInterface;
|
use Symfony\Component\Translation\MessageCatalogueInterface;
|
||||||
use Symfony\Component\Translation\TranslatorBagInterface;
|
use Symfony\Component\Translation\TranslatorBagInterface;
|
||||||
|
|||||||
Reference in New Issue
Block a user