diff --git a/src/Prime/Stamp/HopsStamp.php b/src/Prime/Stamp/HopsStamp.php index e28c5319..c9caea2d 100644 --- a/src/Prime/Stamp/HopsStamp.php +++ b/src/Prime/Stamp/HopsStamp.php @@ -2,7 +2,7 @@ namespace Flasher\Prime\Stamp; -final class HopsStamp implements StampInterface, \Flasher\Prime\Stamp\OrderableStampInterface +final class HopsStamp implements StampInterface { /** * @var int diff --git a/src/Prime/Storage/ArrayStorage.php b/src/Prime/Storage/ArrayStorage.php index 46c1d98e..2ee3a1a4 100644 --- a/src/Prime/Storage/ArrayStorage.php +++ b/src/Prime/Storage/ArrayStorage.php @@ -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 */ diff --git a/src/Prime/Tests/Config/ConfigTest.php b/src/Prime/Tests/Config/ConfigTest.php index a8073984..c35dfaaa 100644 --- a/src/Prime/Tests/Config/ConfigTest.php +++ b/src/Prime/Tests/Config/ConfigTest.php @@ -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')); } diff --git a/src/Prime/Tests/Middleware/FlasherBusTest.php b/src/Prime/Tests/Middleware/FlasherBusTest.php index 69a3d39e..05943d69 100644 --- a/src/Prime/Tests/Middleware/FlasherBusTest.php +++ b/src/Prime/Tests/Middleware/FlasherBusTest.php @@ -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()); } } diff --git a/src/Prime/Tests/Storage/StorageManagerTest.php b/src/Prime/Tests/Storage/StorageManagerTest.php index 5d81d3fb..a5430dce 100644 --- a/src/Prime/Tests/Storage/StorageManagerTest.php +++ b/src/Prime/Tests/Storage/StorageManagerTest.php @@ -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'), diff --git a/src/Prime/phpunit.xml.dist b/src/Prime/phpunit.xml.dist index 8b8227e4..3b5c944f 100644 --- a/src/Prime/phpunit.xml.dist +++ b/src/Prime/phpunit.xml.dist @@ -16,7 +16,7 @@ - src/ + ./