init fix tests

This commit is contained in:
Khoubza Younes
2020-12-06 18:10:44 +01:00
parent e7d019da87
commit 9e61bd9b8c
21 changed files with 61 additions and 169 deletions
+8 -2
View File
@@ -13,12 +13,18 @@
],
"require": {
"php": ">=5.3",
"ext-json": "*"
"ext-json": "*",
"phpunit/phpunit": "^4.8"
},
"autoload": {
"psr-4": {
"Flasher\\": "src/"
}
},
"minimum-stability": "dev"
"minimum-stability": "dev",
"config": {
"platform": {
"php": "5.4"
}
}
}
+3
View File
@@ -32,6 +32,9 @@
"illuminate/support": "^4.0|^5.0|^6.0|^7.0|^8.0",
"php-flasher/flasher": "dev-main"
},
"require-dev": {
"orchestra/testbench": "^2.0|^3.0|^4.0|^5.0|^6.0"
},
"autoload": {
"psr-4": {
"Flasher\\Laravel\\": "",
+1 -1
View File
@@ -2,7 +2,7 @@
namespace Flasher\Prime\Stamp;
final class HopsStamp implements StampInterface
final class HopsStamp implements StampInterface, \Flasher\Prime\Stamp\OrderableStampInterface
{
/**
* @var int
+5 -5
View File
@@ -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'));
+1 -1
View File
@@ -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());
@@ -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)));
@@ -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));
@@ -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)));
}
}
@@ -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));
@@ -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));
@@ -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());
+1 -1
View File
@@ -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;
+3 -3
View File
@@ -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) {
+9 -9
View File
@@ -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');
@@ -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(
@@ -1,72 +0,0 @@
<?php
namespace Flasher\Prime\Tests\Factory;
use Flasher\Prime\EventDispatcher\Event\BeforeFilter;
use Flasher\Prime\EventDispatcher\EventDispatcher;
use Flasher\Prime\EventDispatcher\FlusherEvents;
use Flasher\Prime\Notification\Notification;
use Flasher\Prime\Tests\TestCase;
use ReflectionClass;
final class ProducerManagerTest extends TestCase
{
public function testExtendToAddMoreNotifiersFactory()
{
$config = $this->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());
}
}
@@ -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'),
@@ -1,13 +0,0 @@
<?php
namespace Flasher\Prime\Tests\Stubs\Factory;
use Flasher\Prime\AbstractFlasher;
class FakeProducer extends AbstractFlasher
{
public function getRenderer()
{
return 'fake';
}
}
@@ -1,37 +0,0 @@
<?php
namespace Flasher\Prime\Tests\Stubs\Renderer;
use Flasher\Prime\Envelope;
use Flasher\Prime\Renderer\HasGlobalOptionsInterface;
use Flasher\Prime\Renderer\HasScriptsInterface;
use Flasher\Prime\Renderer\HasStylesInterface;
use Flasher\Prime\Renderer\RendererInterface;
class FakeRenderer implements RendererInterface, HasScriptsInterface, HasGlobalOptionsInterface, HasStylesInterface
{
public function renderOptions()
{
return 'fake.options = []';
}
public function getScripts()
{
return array('jquery.min.js', 'fake.min.js');
}
public function getStyles()
{
return array('fake.min.css');
}
public function render(Envelope $envelope)
{
return sprintf(
"fake.%s('%s', '%s');",
$envelope->getType(),
$envelope->getMessage(),
$envelope->getTitle()
);
}
}
+3
View File
@@ -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\\": "",
-1
View File
@@ -36,7 +36,6 @@
"symfony/yaml": "^2.7|^3.0|^4.0|^5.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.7|^6.0|^7.0|^8.3|^9.0",
"twig/twig": "^1.34|^2.0|^3.0"
},
"suggest": {