From 9fcb2247500395f3a064ec92aab9129150055023 Mon Sep 17 00:00:00 2001 From: Khoubza Younes Date: Sun, 6 Dec 2020 18:10:44 +0100 Subject: [PATCH] init fix tests --- Stamp/HopsStamp.php | 2 +- Tests/Config/ConfigTest.php | 10 +-- Tests/Envelope/EnvelopeTest.php | 2 +- Tests/Envelope/Stamp/CreatedAtStampTest.php | 4 +- .../{LifeStampTest.php => HopsStampTest.php} | 5 +- Tests/Envelope/Stamp/PriorityStampTest.php | 5 +- Tests/Envelope/Stamp/RendererStampTest.php | 3 +- Tests/Envelope/Stamp/UuidStampTest.php | 3 +- Tests/Filter/CriteriaBuilderTest.php | 14 ++-- Tests/Filter/DefaultFilterTest.php | 2 +- Tests/Filter/FilterManagerTest.php | 6 +- Tests/Manager/ManagerTest.php | 18 ++--- ...lewareStackTest.php => FlasherBusTest.php} | 8 +-- Tests/Producer/ProducerManagerTest.php | 72 ------------------- Tests/Storage/StorageManagerTest.php | 9 +-- Tests/Stubs/Producer/FakeProducer.php | 13 ---- Tests/Stubs/Renderer/FakeRenderer.php | 37 ---------- composer.json | 3 + 18 files changed, 50 insertions(+), 166 deletions(-) rename Tests/Envelope/Stamp/{LifeStampTest.php => HopsStampTest.php} (82%) rename Tests/Middleware/{MiddlewareStackTest.php => FlasherBusTest.php} (93%) delete mode 100644 Tests/Producer/ProducerManagerTest.php delete mode 100644 Tests/Stubs/Producer/FakeProducer.php delete mode 100644 Tests/Stubs/Renderer/FakeRenderer.php diff --git a/Stamp/HopsStamp.php b/Stamp/HopsStamp.php index c9caea2d..e28c5319 100644 --- a/Stamp/HopsStamp.php +++ b/Stamp/HopsStamp.php @@ -2,7 +2,7 @@ namespace Flasher\Prime\Stamp; -final class HopsStamp implements StampInterface +final class HopsStamp implements StampInterface, \Flasher\Prime\Stamp\OrderableStampInterface { /** * @var int diff --git a/Tests/Config/ConfigTest.php b/Tests/Config/ConfigTest.php index 7c5088ea..a8073984 100644 --- a/Tests/Config/ConfigTest.php +++ b/Tests/Config/ConfigTest.php @@ -2,7 +2,7 @@ namespace Flasher\Prime\Tests\Config; -use Notify\Config\Config; +use Flasher\Prime\Config\Config; use PHPUnit\Framework\TestCase; final class ConfigTest extends TestCase @@ -11,9 +11,9 @@ final class ConfigTest extends TestCase { $config = new Config( array( - 'default' => 'notify', + 'default' => 'default_flasher', 'drivers' => array( - 'notify' => array( + 'toastr' => array( 'scripts' => array('script.js'), 'styles' => array('styles.css'), 'options' => array() @@ -22,14 +22,14 @@ final class ConfigTest extends TestCase ) ); - $this->assertEquals('notify', $config->get('default')); + $this->assertEquals('default_flasher', $config->get('default')); $this->assertEquals( array( 'scripts' => array('script.js'), 'styles' => array('styles.css'), 'options' => array() ), - $config->get('drivers.notify') + $config->get('drivers.toastr') ); $this->assertEquals(array('styles.css'), $config->get('drivers.flasher.styles')); $this->assertEquals(array(), $config->get('drivers.flasher.options')); diff --git a/Tests/Envelope/EnvelopeTest.php b/Tests/Envelope/EnvelopeTest.php index 426b3e5e..80910194 100644 --- a/Tests/Envelope/EnvelopeTest.php +++ b/Tests/Envelope/EnvelopeTest.php @@ -67,7 +67,7 @@ final class EnvelopeTest extends TestCase $this->getMockBuilder('Flasher\Prime\Stamp\StampInterface')->getMock(), ); - $envelope = new \Flasher\Prime\Envelope($notification, $stamps); + $envelope = new Envelope($notification, $stamps); $this->assertSame($notification, $envelope->getNotification()); diff --git a/Tests/Envelope/Stamp/CreatedAtStampTest.php b/Tests/Envelope/Stamp/CreatedAtStampTest.php index 4c340e65..e2d688a5 100644 --- a/Tests/Envelope/Stamp/CreatedAtStampTest.php +++ b/Tests/Envelope/Stamp/CreatedAtStampTest.php @@ -22,8 +22,8 @@ final class CreatedAtStampTest extends TestCase public function testCompare() { - $createdAt1 = new \Flasher\Prime\Stamp\CreatedAtStamp(new \DateTime('+2 h')); - $createdAt2 = new \Flasher\Prime\Stamp\CreatedAtStamp(new \DateTime('+1 h')); + $createdAt1 = new CreatedAtStamp(new \DateTime('+2 h')); + $createdAt2 = new CreatedAtStamp(new \DateTime('+1 h')); $this->assertFalse($createdAt1->compare($createdAt2)); $this->assertSame(0, $createdAt1->compare(new HopsStamp(1))); diff --git a/Tests/Envelope/Stamp/LifeStampTest.php b/Tests/Envelope/Stamp/HopsStampTest.php similarity index 82% rename from Tests/Envelope/Stamp/LifeStampTest.php rename to Tests/Envelope/Stamp/HopsStampTest.php index f39b55ac..86dcd6d8 100644 --- a/Tests/Envelope/Stamp/LifeStampTest.php +++ b/Tests/Envelope/Stamp/HopsStampTest.php @@ -3,14 +3,15 @@ namespace Flasher\Prime\Tests\Envelope\Stamp; use Flasher\Prime\Envelope; +use Flasher\Prime\Stamp\HopsStamp; use PHPUnit\Framework\TestCase; -final class LifeStampTest extends TestCase +final class HopsStampTest extends TestCase { public function testConstruct() { $notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock(); - $stamp = new \Flasher\Prime\Stamp\HopsStamp(5); + $stamp = new HopsStamp(5); $envelop = new Envelope($notification, array($stamp)); diff --git a/Tests/Envelope/Stamp/PriorityStampTest.php b/Tests/Envelope/Stamp/PriorityStampTest.php index 92ba7a7a..f6469b1a 100644 --- a/Tests/Envelope/Stamp/PriorityStampTest.php +++ b/Tests/Envelope/Stamp/PriorityStampTest.php @@ -3,6 +3,7 @@ namespace Flasher\Prime\Tests\Envelope\Stamp; use Flasher\Prime\Envelope; +use Flasher\Prime\Stamp\HopsStamp; use Flasher\Prime\Stamp\PriorityStamp; use PHPUnit\Framework\TestCase; @@ -23,9 +24,9 @@ final class PriorityStampTest extends TestCase public function testCompare() { $stamp1 = new PriorityStamp(1); - $stamp2 = new \Flasher\Prime\Stamp\PriorityStamp(2); + $stamp2 = new PriorityStamp(2); $this->assertFalse($stamp1->compare($stamp2)); - $this->assertSame(0, $stamp1->compare(new \Flasher\Prime\Stamp\HopsStamp(1))); + $this->assertSame(0, $stamp1->compare(new HopsStamp(1))); } } diff --git a/Tests/Envelope/Stamp/RendererStampTest.php b/Tests/Envelope/Stamp/RendererStampTest.php index d5661546..5ca1ba5f 100644 --- a/Tests/Envelope/Stamp/RendererStampTest.php +++ b/Tests/Envelope/Stamp/RendererStampTest.php @@ -3,6 +3,7 @@ namespace Flasher\Prime\Tests\Envelope\Stamp; use Flasher\Prime\Envelope; +use Flasher\Prime\Stamp\HandlerStamp; use PHPUnit\Framework\TestCase; final class RendererStampTest extends TestCase @@ -10,7 +11,7 @@ final class RendererStampTest extends TestCase public function testConstruct() { $notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock(); - $stamp = new \Flasher\Prime\Stamp\HandlerStamp('toastr'); + $stamp = new HandlerStamp('toastr'); $envelop = new Envelope($notification, array($stamp)); diff --git a/Tests/Envelope/Stamp/UuidStampTest.php b/Tests/Envelope/Stamp/UuidStampTest.php index b1a2ef3c..92fb432d 100644 --- a/Tests/Envelope/Stamp/UuidStampTest.php +++ b/Tests/Envelope/Stamp/UuidStampTest.php @@ -3,6 +3,7 @@ namespace Flasher\Prime\Tests\Envelope\Stamp; use Flasher\Prime\Envelope; +use Flasher\Prime\Stamp\UuidStamp; use PHPUnit\Framework\TestCase; final class UuidStampTest extends TestCase @@ -10,7 +11,7 @@ final class UuidStampTest extends TestCase public function testConstruct() { $notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock(); - $stamp = new \Flasher\Prime\Stamp\UuidStamp(); + $stamp = new UuidStamp(); $envelop = new Envelope($notification, array($stamp)); diff --git a/Tests/Filter/CriteriaBuilderTest.php b/Tests/Filter/CriteriaBuilderTest.php index a661b648..ecd2d94b 100644 --- a/Tests/Filter/CriteriaBuilderTest.php +++ b/Tests/Filter/CriteriaBuilderTest.php @@ -10,14 +10,12 @@ final class CriteriaBuilderTest extends TestCase { public function testCriteria() { - $criteria = new CriteriaBuilder( - new FilterBuilder(), array( - 'priority' => 1, - 'life' => 2, - 'limit' => 2, - 'order_by' => 'Flasher\Prime\Stamp\HopsStamp', - ) - ); + $criteria = new CriteriaBuilder(new FilterBuilder(), array( + 'priority' => 1, + 'life' => 2, + 'limit' => 2, + 'order_by' => 'Flasher\Prime\Stamp\HopsStamp', + )); $this->assertInstanceOf('Flasher\Prime\Filter\FilterBuilder', $criteria->build()); $this->assertNotEmpty($criteria->build()->getSpecification()); diff --git a/Tests/Filter/DefaultFilterTest.php b/Tests/Filter/DefaultFilterTest.php index bbe974fd..feaec16e 100644 --- a/Tests/Filter/DefaultFilterTest.php +++ b/Tests/Filter/DefaultFilterTest.php @@ -2,7 +2,7 @@ namespace Flasher\Prime\Tests\Filter; -use Notify\Config\Config; +use Flasher\Prime\Config\Config; use Flasher\Prime\Envelope; use Flasher\Prime\Middleware\AddCreatedAtStampMiddleware; use Flasher\Prime\Middleware\AddPriorityStampMiddleware; diff --git a/Tests/Filter/FilterManagerTest.php b/Tests/Filter/FilterManagerTest.php index 29ef137c..1184858f 100644 --- a/Tests/Filter/FilterManagerTest.php +++ b/Tests/Filter/FilterManagerTest.php @@ -2,13 +2,13 @@ namespace Flasher\Prime\Tests\Filter; -use Notify\Config\Config; +use Flasher\Prime\Config\Config; use Flasher\Prime\Envelope; use Flasher\Prime\Filter\FilterBuilder; use Flasher\Prime\Filter\Specification\PrioritySpecification; use Flasher\Prime\Middleware\AddCreatedAtStampMiddleware; use Flasher\Prime\Middleware\AddPriorityStampMiddleware; -use Flasher\Prime\MiddlewareFlasher\PrimeBus; +use Flasher\Prime\Middleware\FlasherBus; use Flasher\Prime\Stamp\PriorityStamp; use PHPUnit\Framework\TestCase; @@ -54,7 +54,7 @@ final class FilterManagerTest extends TestCase ) ); - $middleware = new NotifyBus($config); + $middleware = new FlasherBus($config); $envelopes = array(); foreach ($notifications as $notification) { diff --git a/Tests/Manager/ManagerTest.php b/Tests/Manager/ManagerTest.php index d37b1677..f200a426 100644 --- a/Tests/Manager/ManagerTest.php +++ b/Tests/Manager/ManagerTest.php @@ -2,32 +2,32 @@ namespace Flasher\Prime\Tests\Manager; -use NotifyFlasher\Prime; +use Flasher\Prime\Flasher; use Flasher\Prime\Tests\TestCase; final class ManagerTest extends TestCase { public function testDefaultDriver() { - $config = $this->getMockBuilder('Notify\Config\ConfigInterface')->getMock(); + $config = $this->getMockBuilder('Flasher\Prime\Config\ConfigInterface')->getMock(); $config->method('get') ->with('default') ->willReturn('default_notifier'); - $manager = new Notify($config); + $manager = new Flasher($config); $this->assertEquals('default_notifier', $manager->getDefaultDriver()); } public function testMakeDriver() { - $config = $this->getMockBuilder('Notify\Config\ConfigInterface')->getMock(); + $config = $this->getMockBuilder('Flasher\Prime\Config\ConfigInterface')->getMock(); $config->method('get') ->with('default') ->willReturn('default_notifier'); - $manager = new Notify($config); + $manager = new Flasher($config); - $producer = $this->getMockBuilder('NotifyFlasher\PrimeFactory')->getMock(); + $producer = $this->getMockBuilder('Flasher\Prime\Factory\FlasherFactoryInterface')->getMock(); $producer->method('supports')->willReturn(true); $manager->addDriver($producer); @@ -38,14 +38,14 @@ final class ManagerTest extends TestCase { $this->setExpectedException('InvalidArgumentException', 'Driver [test_driver] not supported.'); - $config = $this->getMockBuilder('Notify\Config\ConfigInterface')->getMock(); + $config = $this->getMockBuilder('Flasher\Prime\Config\ConfigInterface')->getMock(); $config->method('get') ->with('default') ->willReturn('default_notifier'); - $manager = new Notify($config); + $manager = new Flasher($config); - $producer = $this->getMockBuilder('NotifyFlasher\PrimeFactory')->getMock(); + $producer = $this->getMockBuilder('Flasher\Prime\Factory\FlasherFactoryInterface')->getMock(); $manager->addDriver($producer); $manager->make('test_driver'); diff --git a/Tests/Middleware/MiddlewareStackTest.php b/Tests/Middleware/FlasherBusTest.php similarity index 93% rename from Tests/Middleware/MiddlewareStackTest.php rename to Tests/Middleware/FlasherBusTest.php index c7a40056..69a3d39e 100644 --- a/Tests/Middleware/MiddlewareStackTest.php +++ b/Tests/Middleware/FlasherBusTest.php @@ -6,11 +6,11 @@ use Flasher\Prime\Config\Config; use Flasher\Prime\Envelope; use Flasher\Prime\Middleware\AddCreatedAtStampMiddleware; use Flasher\Prime\Middleware\AddPriorityStampMiddleware; -use Flasher\Prime\Middleware\MiddlewareManager; +use Flasher\Prime\Middleware\FlasherBus; use Flasher\Prime\Stamp\PriorityStamp; use PHPUnit\Framework\TestCase; -final class MiddlewareStackTest extends TestCase +final class FlasherBusTest extends TestCase { public function testHandle() { @@ -29,7 +29,7 @@ final class MiddlewareStackTest extends TestCase ) )); - $stack = new MiddlewareManager($config); + $stack = new FlasherBus($config); $notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock(); $envelope = new Envelope($notification); @@ -66,7 +66,7 @@ final class MiddlewareStackTest extends TestCase ) )); - $stack = new MiddlewareManager($config); + $stack = new FlasherBus($config); $notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock(); $stamps = array( diff --git a/Tests/Producer/ProducerManagerTest.php b/Tests/Producer/ProducerManagerTest.php deleted file mode 100644 index ab0874a5..00000000 --- a/Tests/Producer/ProducerManagerTest.php +++ /dev/null @@ -1,72 +0,0 @@ -getMockBuilder('Notify\Config\ConfigInterface')->getMock(); - $manager = new Flasher\PrimeFlasher\Prime($config); - - $producer = $this->getMockBuilder('NotifyFlasher\PrimeFactory')->getMock(); - $producer->method('supports')->willReturn(true); - $manager->addDriver($producer); - - $reflection = new ReflectionClass(get_class($manager)); - $extensions = $reflection->getProperty('drivers'); - $extensions->setAccessible(true); - - $drivers = $extensions->getValue($manager); - $this->assertCount(1, $drivers); - - $producer1 = $manager->make('producer_1'); - $this->assertSame($producer, $producer1); - } - - public function testNullDriver() - { - $this->setExpectedException('InvalidArgumentException', 'Driver [] not supported.'); - - $config = $this->getMockBuilder('Notify\Config\ConfigInterface')->getMock(); - $config->method('get')->willReturn(null); - - $manager = new \Flasher\PrimeFlasher\Prime($config); - - $producer = $this->getMockBuilder('NotifyFlasher\PrimeFactory')->getMock(); - $manager->addDriver($producer); - - $this->assertSame($producer, $manager->make()); - } - - public function testNotSupportedDriver() - { - $this->setExpectedException('InvalidArgumentException', 'Driver [not_supported] not supported.'); - - $config = $this->getMockBuilder('Notify\Config\ConfigInterface')->getMock(); - $manager = new Flasher\PrimeFlasher\Prime($config); - - $producer = $this->getMockBuilder('NotifyFlasher\PrimeFactory')->getMock(); - $manager->addDriver($producer); - - $this->assertSame($producer, $manager->make('not_supported')); - } - - public function testDispatcher() - { - $dispatcher = new EventDispatcher(); - $dispatcher->addListener(FlusherEvents::NOTIFICATION_CLEARED, function ($event) { - - return $event; - }); - - $dispatcher->dispatch(new Notification()); - } -} diff --git a/Tests/Storage/StorageManagerTest.php b/Tests/Storage/StorageManagerTest.php index 9ef22b1f..5d81d3fb 100644 --- a/Tests/Storage/StorageManagerTest.php +++ b/Tests/Storage/StorageManagerTest.php @@ -3,6 +3,7 @@ namespace Flasher\Prime\Tests\Storage; use Flasher\Prime\Envelope; +use Flasher\Prime\EventDispatcher\EventDispatcher; use Flasher\Prime\Notification\Notification; use Flasher\Prime\Stamp\HopsStamp; use Flasher\Prime\Stamp\UuidStamp; @@ -14,7 +15,7 @@ class StorageManagerTest extends TestCase { public function testAll() { - $storageManager = new StorageManager(new ArrayStorage()); + $storageManager = new StorageManager(new ArrayStorage(), new EventDispatcher()); $envelopes = array(); foreach (range(0, 4) as $index) { @@ -27,7 +28,7 @@ class StorageManagerTest extends TestCase public function testClear() { - $storageManager = new StorageManager(new ArrayStorage()); + $storageManager = new StorageManager(new ArrayStorage(), new EventDispatcher()); $envelopes = array(); foreach (range(0, 4) as $index) { @@ -42,7 +43,7 @@ class StorageManagerTest extends TestCase public function testAdd() { - $storageManager = new StorageManager(new ArrayStorage()); + $storageManager = new StorageManager(new ArrayStorage(),new EventDispatcher()); $storageManager->add(new Envelope(new Notification('success'))); $envelopes = $storageManager->all(); @@ -55,7 +56,7 @@ class StorageManagerTest extends TestCase public function testFlush() { - $storageManager = new StorageManager(new ArrayStorage()); + $storageManager = new StorageManager(new ArrayStorage(), new EventDispatcher()); $envelope = new Envelope( new Notification('error message', 'error'), diff --git a/Tests/Stubs/Producer/FakeProducer.php b/Tests/Stubs/Producer/FakeProducer.php deleted file mode 100644 index 51687b69..00000000 --- a/Tests/Stubs/Producer/FakeProducer.php +++ /dev/null @@ -1,13 +0,0 @@ -getType(), - $envelope->getMessage(), - $envelope->getTitle() - ); - } -} diff --git a/composer.json b/composer.json index b42998f6..385fbf44 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,9 @@ "require": { "php": ">=5.3" }, + "require-dev": { + "phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0|^8.0|^9.0" + }, "autoload": { "psr-4": { "Flasher\\Prime\\": "",