From 02733b0d9271cc85b62ec4a95c3bce5425fedd3e Mon Sep 17 00:00:00 2001 From: Khoubza Younes Date: Tue, 31 Jan 2023 01:02:27 +0100 Subject: [PATCH] test: add stamps tests --- tests/Prime/Stamp/ContextStampTest.php | 27 ++++++++++++++++ tests/Prime/Stamp/CreatedAtStampTest.php | 23 +++++++------- tests/Prime/Stamp/DelayStampTest.php | 25 +++++++++++++++ tests/Prime/Stamp/HandlerStampTest.php | 13 +++----- tests/Prime/Stamp/HopsStampTest.php | 11 ++----- tests/Prime/Stamp/PresetStampTest.php | 26 ++++++++++++++++ tests/Prime/Stamp/PriorityStampTest.php | 14 ++++----- tests/Prime/Stamp/TranslationStampTest.php | 36 ++++++++++++++++++++++ tests/Prime/Stamp/UnlessStampTest.php | 25 +++++++++++++++ tests/Prime/Stamp/UuidStampTest.php | 15 +++++---- tests/Prime/Stamp/ViewStampTest.php | 26 ++++++++++++++++ tests/Prime/Stamp/WhenStampTest.php | 25 +++++++++++++++ 12 files changed, 223 insertions(+), 43 deletions(-) create mode 100644 tests/Prime/Stamp/ContextStampTest.php create mode 100644 tests/Prime/Stamp/DelayStampTest.php create mode 100644 tests/Prime/Stamp/PresetStampTest.php create mode 100644 tests/Prime/Stamp/TranslationStampTest.php create mode 100644 tests/Prime/Stamp/UnlessStampTest.php create mode 100644 tests/Prime/Stamp/ViewStampTest.php create mode 100644 tests/Prime/Stamp/WhenStampTest.php diff --git a/tests/Prime/Stamp/ContextStampTest.php b/tests/Prime/Stamp/ContextStampTest.php new file mode 100644 index 00000000..3b3dc893 --- /dev/null +++ b/tests/Prime/Stamp/ContextStampTest.php @@ -0,0 +1,27 @@ + + */ + +namespace Flasher\Tests\Prime\Stamp; + +use Flasher\Prime\Stamp\ContextStamp; +use Flasher\Tests\Prime\TestCase; + +class ContextStampTest extends TestCase +{ + /** + * @return void + */ + public function testContextStamp() + { + $stamp = new ContextStamp(array('component' => 'livewire')); + + $this->assertInstanceOf('Flasher\Prime\Stamp\StampInterface', $stamp); + $this->assertInstanceOf('Flasher\Prime\Stamp\PresentableStampInterface', $stamp); + $this->assertEquals(array('component' => 'livewire'), $stamp->getContext()); + $this->assertEquals(array('context' => array('component' => 'livewire')), $stamp->toArray()); + } +} diff --git a/tests/Prime/Stamp/CreatedAtStampTest.php b/tests/Prime/Stamp/CreatedAtStampTest.php index b6481dd0..6fb05ac1 100644 --- a/tests/Prime/Stamp/CreatedAtStampTest.php +++ b/tests/Prime/Stamp/CreatedAtStampTest.php @@ -7,25 +7,26 @@ namespace Flasher\Tests\Prime\Stamp; -use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Stamp\CreatedAtStamp; use Flasher\Prime\Stamp\HopsStamp; -use PHPUnit\Framework\TestCase; +use Flasher\Tests\Prime\TestCase; final class CreatedAtStampTest extends TestCase { /** * @return void */ - public function testConstruct() + public function testCreatedAtStamp() { - $notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock(); - $stamp = new CreatedAtStamp(); + $createdAt = new \DateTime('2023-01-30 23:33:51'); + $stamp = new CreatedAtStamp($createdAt, 'Y-m-d H:i:s'); - $envelop = new Envelope($notification, array($stamp)); - - $this->assertEquals($stamp, $envelop->get('Flasher\Prime\Stamp\CreatedAtStamp')); $this->assertInstanceOf('Flasher\Prime\Stamp\StampInterface', $stamp); + $this->assertInstanceOf('Flasher\Prime\Stamp\PresentableStampInterface', $stamp); + $this->assertInstanceOf('Flasher\Prime\Stamp\OrderableStampInterface', $stamp); + $this->assertInstanceOf('DateTime', $stamp->getCreatedAt()); + $this->assertEquals('2023-01-30 23:33:51', $stamp->getCreatedAt()->format('Y-m-d H:i:s')); + $this->assertEquals(array('created_at' => '2023-01-30 23:33:51'), $stamp->toArray()); } /** @@ -33,10 +34,10 @@ final class CreatedAtStampTest extends TestCase */ public function testCompare() { - $createdAt1 = new CreatedAtStamp(new \DateTime('+2 h')); - $createdAt2 = new CreatedAtStamp(new \DateTime('+1 h')); + $createdAt1 = new CreatedAtStamp(new \DateTime('2023-01-30 23:35:49')); + $createdAt2 = new CreatedAtStamp(new \DateTime('2023-01-30 23:36:06')); - $this->assertNotNull($createdAt1->compare($createdAt2)); + $this->assertEquals(-17, $createdAt1->compare($createdAt2)); $this->assertEquals(1, $createdAt1->compare(new HopsStamp(1))); } } diff --git a/tests/Prime/Stamp/DelayStampTest.php b/tests/Prime/Stamp/DelayStampTest.php new file mode 100644 index 00000000..325f06a0 --- /dev/null +++ b/tests/Prime/Stamp/DelayStampTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Flasher\Tests\Prime\Stamp; + +use Flasher\Prime\Stamp\DelayStamp; +use Flasher\Tests\Prime\TestCase; + +class DelayStampTest extends TestCase +{ + /** + * @return void + */ + public function testDelayStamp() + { + $stamp = new DelayStamp(2); + + $this->assertInstanceOf('Flasher\Prime\Stamp\StampInterface', $stamp); + $this->assertEquals(2, $stamp->getDelay()); + } +} diff --git a/tests/Prime/Stamp/HandlerStampTest.php b/tests/Prime/Stamp/HandlerStampTest.php index a343e23f..8275e4d5 100644 --- a/tests/Prime/Stamp/HandlerStampTest.php +++ b/tests/Prime/Stamp/HandlerStampTest.php @@ -7,24 +7,21 @@ namespace Flasher\Tests\Prime\Stamp; -use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Stamp\HandlerStamp; -use PHPUnit\Framework\TestCase; +use Flasher\Tests\Prime\TestCase; final class HandlerStampTest extends TestCase { /** * @return void */ - public function testConstruct() + public function testHandlerStamp() { - $notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock(); $stamp = new HandlerStamp('toastr'); - $envelop = new Envelope($notification, array($stamp)); - - $this->assertEquals($stamp, $envelop->get('Flasher\Prime\Stamp\HandlerStamp')); - $this->assertInstanceOf('Flasher\Prime\Stamp\HandlerStamp', $stamp); + $this->assertInstanceOf('Flasher\Prime\Stamp\StampInterface', $stamp); + $this->assertInstanceOf('Flasher\Prime\Stamp\PresentableStampInterface', $stamp); $this->assertEquals('toastr', $stamp->getHandler()); + $this->assertEquals(array('handler' => 'toastr'), $stamp->toArray()); } } diff --git a/tests/Prime/Stamp/HopsStampTest.php b/tests/Prime/Stamp/HopsStampTest.php index 42a3448c..6e9d3663 100644 --- a/tests/Prime/Stamp/HopsStampTest.php +++ b/tests/Prime/Stamp/HopsStampTest.php @@ -7,24 +7,19 @@ namespace Flasher\Tests\Prime\Stamp; -use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Stamp\HopsStamp; -use PHPUnit\Framework\TestCase; +use Flasher\Tests\Prime\TestCase; final class HopsStampTest extends TestCase { /** * @return void */ - public function testConstruct() + public function testHopsStamp() { - $notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock(); $stamp = new HopsStamp(5); - $envelop = new Envelope($notification, array($stamp)); - - $this->assertEquals($stamp, $envelop->get('Flasher\Prime\Stamp\HopsStamp')); - $this->assertInstanceOf('Flasher\Prime\Stamp\HopsStamp', $stamp); + $this->assertInstanceOf('Flasher\Prime\Stamp\StampInterface', $stamp); $this->assertEquals(5, $stamp->getAmount()); } } diff --git a/tests/Prime/Stamp/PresetStampTest.php b/tests/Prime/Stamp/PresetStampTest.php new file mode 100644 index 00000000..8a865d60 --- /dev/null +++ b/tests/Prime/Stamp/PresetStampTest.php @@ -0,0 +1,26 @@ + + */ + +namespace Flasher\Tests\Prime\Stamp; + +use Flasher\Prime\Stamp\PresetStamp; +use Flasher\Tests\Prime\TestCase; + +class PresetStampTest extends TestCase +{ + /** + * @return void + */ + public function testPresetStamp() + { + $stamp = new PresetStamp('entity_saved', array('resource' => 'resource')); + + $this->assertInstanceOf('Flasher\Prime\Stamp\StampInterface', $stamp); + $this->assertEquals('entity_saved', $stamp->getPreset()); + $this->assertEquals(array('resource' => 'resource'), $stamp->getParameters()); + } +} diff --git a/tests/Prime/Stamp/PriorityStampTest.php b/tests/Prime/Stamp/PriorityStampTest.php index 23442b62..67c45cdc 100644 --- a/tests/Prime/Stamp/PriorityStampTest.php +++ b/tests/Prime/Stamp/PriorityStampTest.php @@ -7,26 +7,24 @@ namespace Flasher\Tests\Prime\Stamp; -use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Stamp\HopsStamp; use Flasher\Prime\Stamp\PriorityStamp; -use PHPUnit\Framework\TestCase; +use Flasher\Tests\Prime\TestCase; final class PriorityStampTest extends TestCase { /** * @return void */ - public function testConstruct() + public function testPriorityStamp() { - $notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock(); $stamp = new PriorityStamp(5); - $envelop = new Envelope($notification, array($stamp)); - - $this->assertEquals($stamp, $envelop->get('Flasher\Prime\Stamp\PriorityStamp')); $this->assertInstanceOf('Flasher\Prime\Stamp\StampInterface', $stamp); + $this->assertInstanceOf('Flasher\Prime\Stamp\OrderableStampInterface', $stamp); + $this->assertInstanceOf('Flasher\Prime\Stamp\PresentableStampInterface', $stamp); $this->assertEquals(5, $stamp->getPriority()); + $this->assertEquals(array('priority' => 5), $stamp->toArray()); } /** @@ -37,7 +35,7 @@ final class PriorityStampTest extends TestCase $stamp1 = new PriorityStamp(1); $stamp2 = new PriorityStamp(2); - $this->assertNotNull($stamp1->compare($stamp2)); + $this->assertEquals(-1, $stamp1->compare($stamp2)); $this->assertEquals(1, $stamp1->compare(new HopsStamp(1))); } } diff --git a/tests/Prime/Stamp/TranslationStampTest.php b/tests/Prime/Stamp/TranslationStampTest.php new file mode 100644 index 00000000..d669b198 --- /dev/null +++ b/tests/Prime/Stamp/TranslationStampTest.php @@ -0,0 +1,36 @@ + + */ + +namespace Flasher\Tests\Prime\Stamp; + +use Flasher\Prime\Stamp\TranslationStamp; +use Flasher\Tests\Prime\TestCase; + +class TranslationStampTest extends TestCase +{ + /** + * @return void + */ + public function testTranslationStamp() + { + $stamp = new TranslationStamp(array('foo' => 'bar'), 'ar'); + + $this->assertInstanceOf('Flasher\Prime\Stamp\StampInterface', $stamp); + $this->assertEquals(array('foo' => 'bar'), $stamp->getParameters()); + $this->assertEquals('ar', $stamp->getLocale()); + } + + /** + * @return void + */ + public function testParametersOrder() + { + $parameters = TranslationStamp::parametersOrder('ar'); + + $this->assertEquals(array('locale' => 'ar', 'parameters' => array()), $parameters); + } +} diff --git a/tests/Prime/Stamp/UnlessStampTest.php b/tests/Prime/Stamp/UnlessStampTest.php new file mode 100644 index 00000000..c3a921d1 --- /dev/null +++ b/tests/Prime/Stamp/UnlessStampTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Flasher\Tests\Prime\Stamp; + +use Flasher\Prime\Stamp\UnlessStamp; +use Flasher\Tests\Prime\TestCase; + +class UnlessStampTest extends TestCase +{ + /** + * @return void + */ + public function testUnlessStamp() + { + $stamp = new UnlessStamp(true); + + $this->assertInstanceOf('Flasher\Prime\Stamp\StampInterface', $stamp); + $this->assertTrue($stamp->getCondition()); + } +} diff --git a/tests/Prime/Stamp/UuidStampTest.php b/tests/Prime/Stamp/UuidStampTest.php index a7d64e21..13d33a88 100644 --- a/tests/Prime/Stamp/UuidStampTest.php +++ b/tests/Prime/Stamp/UuidStampTest.php @@ -7,24 +7,23 @@ namespace Flasher\Tests\Prime\Stamp; -use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Stamp\UuidStamp; -use PHPUnit\Framework\TestCase; +use Flasher\Tests\Prime\TestCase; final class UuidStampTest extends TestCase { /** * @return void */ - public function testConstruct() + public function testUuidStamp() { - $notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock(); $stamp = new UuidStamp(); - $envelop = new Envelope($notification, array($stamp)); - - $this->assertEquals($stamp, $envelop->get('Flasher\Prime\Stamp\UuidStamp')); - $this->assertInstanceOf('Flasher\Prime\Stamp\UuidStamp', $stamp); + $this->assertInstanceOf('Flasher\Prime\Stamp\StampInterface', $stamp); $this->assertNotEmpty($stamp->getUuid()); + + $stamp = new UuidStamp('aaaa-bbbb-cccc'); + $this->assertEquals('aaaa-bbbb-cccc', $stamp->getUuid()); + $this->assertEquals(array('uuid' => 'aaaa-bbbb-cccc'), $stamp->toArray()); } } diff --git a/tests/Prime/Stamp/ViewStampTest.php b/tests/Prime/Stamp/ViewStampTest.php new file mode 100644 index 00000000..82e4b2ee --- /dev/null +++ b/tests/Prime/Stamp/ViewStampTest.php @@ -0,0 +1,26 @@ + + */ + +namespace Flasher\Tests\Prime\Stamp; + +use Flasher\Prime\Stamp\ViewStamp; +use Flasher\Tests\Prime\TestCase; + +class ViewStampTest extends TestCase +{ + /** + * @return void + */ + public function testViewStamp() + { + $stamp = new ViewStamp('template.html.twig'); + + $this->assertInstanceOf('Flasher\Prime\Stamp\StampInterface', $stamp); + $this->assertEquals('template.html.twig', $stamp->getView()); + $this->assertEquals(array('view' => 'template.html.twig'), $stamp->toArray()); + } +} diff --git a/tests/Prime/Stamp/WhenStampTest.php b/tests/Prime/Stamp/WhenStampTest.php new file mode 100644 index 00000000..06461c02 --- /dev/null +++ b/tests/Prime/Stamp/WhenStampTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Flasher\Tests\Prime\Stamp; + +use Flasher\Prime\Stamp\WhenStamp; +use Flasher\Tests\Prime\TestCase; + +class WhenStampTest extends TestCase +{ + /** + * @return void + */ + public function testWhenStamp() + { + $stamp = new WhenStamp(true); + + $this->assertInstanceOf('Flasher\Prime\Stamp\StampInterface', $stamp); + $this->assertTrue($stamp->getCondition()); + } +}