mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
fix test for flasher prime
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Flasher\Prime\Stamp;
|
||||
|
||||
final class HopsStamp implements StampInterface, \Flasher\Prime\Stamp\OrderableStampInterface
|
||||
final class HopsStamp implements StampInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
|
||||
@@ -36,6 +36,25 @@ final class ArrayStorage implements StorageInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function update($envelopes)
|
||||
{
|
||||
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
|
||||
$map = UuidStamp::indexWithUuid($envelopes);
|
||||
|
||||
foreach ($this->envelopes as $index => $envelope) {
|
||||
$uuid = $envelope->get('Flasher\Prime\Stamp\UuidStamp')->getUuid();
|
||||
|
||||
if (!isset($map[$uuid])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->envelopes[$index] = $map[$uuid];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Envelope[] $envelopes
|
||||
*/
|
||||
|
||||
@@ -31,8 +31,8 @@ final class ConfigTest extends TestCase
|
||||
),
|
||||
$config->get('drivers.toastr')
|
||||
);
|
||||
$this->assertEquals(array('styles.css'), $config->get('drivers.flasher.styles'));
|
||||
$this->assertEquals(array(), $config->get('drivers.flasher.options'));
|
||||
$this->assertEquals(array('styles.css'), $config->get('drivers.toastr.styles'));
|
||||
$this->assertEquals(array(), $config->get('drivers.toastr.options'));
|
||||
$this->assertEquals(null, $config->get('drivers.not_exists.options'));
|
||||
$this->assertEquals('now_it_exists', $config->get('drivers.not_exists.options', 'now_it_exists'));
|
||||
}
|
||||
|
||||
@@ -14,73 +14,44 @@ final class FlasherBusTest extends TestCase
|
||||
{
|
||||
public function testHandle()
|
||||
{
|
||||
$config = new Config(array(
|
||||
'default' => 'notify',
|
||||
'adapters' => array(
|
||||
'notify' => array(
|
||||
'scripts' => array('script.js'),
|
||||
'styles' => array('styles.css'),
|
||||
'options' => array()
|
||||
)
|
||||
),
|
||||
'stamps_middlewares' => array(
|
||||
new AddPriorityStampMiddleware(),
|
||||
new AddCreatedAtStampMiddleware(),
|
||||
)
|
||||
));
|
||||
|
||||
$stack = new FlasherBus($config);
|
||||
$flasherBus = new FlasherBus();
|
||||
$flasherBus->addMiddleware(new AddPriorityStampMiddleware());
|
||||
$flasherBus->addMiddleware(new AddCreatedAtStampMiddleware());
|
||||
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock();
|
||||
$envelope = new Envelope($notification);
|
||||
|
||||
$stack->handle($envelope);
|
||||
$flasherBus->dispatch($envelope);
|
||||
|
||||
$this->assertSame($notification, $envelope->getNotification());
|
||||
$this->assertCount(3, $envelope->all());
|
||||
$this->assertCount(2, $envelope->all());
|
||||
|
||||
$priorityStamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertInstanceOf('Flasher\Prime\Stamp\PriorityStamp', $priorityStamp);
|
||||
// $this->assertEquals(0, $priorityStamp->getPriority());
|
||||
$this->assertEquals(0, $priorityStamp->getPriority());
|
||||
|
||||
$timeStamp = $envelope->get('Flasher\Prime\Stamp\CreatedAtStamp');
|
||||
$this->assertInstanceOf('Flasher\Prime\Stamp\CreatedAtStamp', $timeStamp);
|
||||
|
||||
$this->assertEquals(time(), $timeStamp->getCreatedAt()->getTimestamp());
|
||||
$createdAtStamp = $envelope->get('Flasher\Prime\Stamp\CreatedAtStamp');
|
||||
$this->assertInstanceOf('DateTime', $createdAtStamp->getCreatedAt());
|
||||
}
|
||||
|
||||
public function testHandleWithExistingStamps()
|
||||
{
|
||||
$config = new Config(array(
|
||||
'default' => 'notify',
|
||||
'adapters' => array(
|
||||
'notify' => array(
|
||||
'scripts' => array('script.js'),
|
||||
'styles' => array('styles.css'),
|
||||
'options' => array()
|
||||
)
|
||||
),
|
||||
'stamps_middlewares' => array(
|
||||
new AddPriorityStampMiddleware(),
|
||||
new AddCreatedAtStampMiddleware(),
|
||||
)
|
||||
));
|
||||
|
||||
$stack = new FlasherBus($config);
|
||||
$flasherBus = new FlasherBus();
|
||||
$flasherBus->addMiddleware(new AddPriorityStampMiddleware());
|
||||
$flasherBus->addMiddleware(new AddCreatedAtStampMiddleware());
|
||||
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock();
|
||||
$stamps = array(
|
||||
$stamps = array(
|
||||
new PriorityStamp(1),
|
||||
);
|
||||
$envelope = new Envelope($notification, $stamps);
|
||||
$envelope = new Envelope($notification, $stamps);
|
||||
|
||||
$stack->handle($envelope);
|
||||
$flasherBus->dispatch($envelope);
|
||||
|
||||
$this->assertSame($notification, $envelope->getNotification());
|
||||
$this->assertCount(3, $envelope->all());
|
||||
$this->assertCount(2, $envelope->all());
|
||||
|
||||
$priorityStamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertInstanceOf('Flasher\Prime\Stamp\PriorityStamp', $priorityStamp);
|
||||
// $this->assertEquals(1, $priorityStamp->getPriority());
|
||||
$this->assertEquals(1, $priorityStamp->getPriority());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Flasher\Prime\Tests\Storage;
|
||||
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\EventDispatcher\EventDispatcher;
|
||||
use Flasher\Prime\EventDispatcher\EventListener\PostFlushListener;
|
||||
use Flasher\Prime\Notification\Notification;
|
||||
use Flasher\Prime\Stamp\HopsStamp;
|
||||
use Flasher\Prime\Stamp\UuidStamp;
|
||||
@@ -56,7 +57,12 @@ class StorageManagerTest extends TestCase
|
||||
|
||||
public function testFlush()
|
||||
{
|
||||
$storageManager = new StorageManager(new ArrayStorage(), new EventDispatcher());
|
||||
$storage = new ArrayStorage();
|
||||
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
$eventDispatcher->addSubscriber(new PostFlushListener($storage));
|
||||
|
||||
$storageManager = new StorageManager($storage, $eventDispatcher);
|
||||
|
||||
$envelope = new Envelope(
|
||||
new Notification('error message', 'error'),
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">src/</directory>
|
||||
<directory suffix=".php">./</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
||||
Reference in New Issue
Block a user