test: add stamps tests

This commit is contained in:
Khoubza Younes
2023-01-31 01:02:27 +01:00
parent 42c267aa53
commit 02733b0d92
12 changed files with 223 additions and 43 deletions
+27
View File
@@ -0,0 +1,27 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
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());
}
}
+12 -11
View File
@@ -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)));
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
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());
}
}
+5 -8
View File
@@ -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());
}
}
+3 -8
View File
@@ -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());
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
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());
}
}
+6 -8
View File
@@ -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)));
}
}
@@ -0,0 +1,36 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
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);
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
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());
}
}
+7 -8
View File
@@ -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());
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
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());
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
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());
}
}