summaryrefslogtreecommitdiff
path: root/vendor/symfony/event-dispatcher/Tests
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2017-12-15 11:24:35 -0800
committerFrédéric Guillot <fred@kanboard.net>2017-12-15 11:55:42 -0800
commita93b8e10f5954be0853eec693c13e84c4bd9e6f2 (patch)
treeeda5de9494b819235616e8623bb3393e9cc373af /vendor/symfony/event-dispatcher/Tests
parent2c72a283f2d51034f85f4e2ca8b194d304a3c433 (diff)
Kanboard requires at least PHP 5.6 now
Diffstat (limited to 'vendor/symfony/event-dispatcher/Tests')
-rw-r--r--vendor/symfony/event-dispatcher/Tests/AbstractEventDispatcherTest.php108
-rw-r--r--vendor/symfony/event-dispatcher/Tests/ContainerAwareEventDispatcherTest.php85
-rw-r--r--vendor/symfony/event-dispatcher/Tests/Debug/TraceableEventDispatcherTest.php102
-rw-r--r--vendor/symfony/event-dispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php83
-rw-r--r--vendor/symfony/event-dispatcher/Tests/EventTest.php45
-rw-r--r--vendor/symfony/event-dispatcher/Tests/GenericEventTest.php9
-rw-r--r--vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php9
7 files changed, 218 insertions, 223 deletions
diff --git a/vendor/symfony/event-dispatcher/Tests/AbstractEventDispatcherTest.php b/vendor/symfony/event-dispatcher/Tests/AbstractEventDispatcherTest.php
index 2e4c3fd9..9443f216 100644
--- a/vendor/symfony/event-dispatcher/Tests/AbstractEventDispatcherTest.php
+++ b/vendor/symfony/event-dispatcher/Tests/AbstractEventDispatcherTest.php
@@ -11,11 +11,12 @@
namespace Symfony\Component\EventDispatcher\Tests;
+use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
+abstract class AbstractEventDispatcherTest extends TestCase
{
/* Some pseudo events */
const preFoo = 'pre.foo';
@@ -55,6 +56,7 @@ abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
{
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
+ $this->assertTrue($this->dispatcher->hasListeners());
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
$this->assertCount(1, $this->dispatcher->getListeners(self::preFoo));
@@ -108,6 +110,20 @@ abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
$this->assertSame($expected, $this->dispatcher->getListeners());
}
+ public function testGetListenerPriority()
+ {
+ $listener1 = new TestEventListener();
+ $listener2 = new TestEventListener();
+
+ $this->dispatcher->addListener('pre.foo', $listener1, -10);
+ $this->dispatcher->addListener('pre.foo', $listener2);
+
+ $this->assertSame(-10, $this->dispatcher->getListenerPriority('pre.foo', $listener1));
+ $this->assertSame(0, $this->dispatcher->getListenerPriority('pre.foo', $listener2));
+ $this->assertNull($this->dispatcher->getListenerPriority('pre.bar', $listener2));
+ $this->assertNull($this->dispatcher->getListenerPriority('pre.foo', function () {}));
+ }
+
public function testDispatch()
{
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
@@ -122,16 +138,6 @@ abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
$this->assertSame($event, $return);
}
- /**
- * @group legacy
- */
- public function testLegacyDispatch()
- {
- $event = new Event();
- $return = $this->dispatcher->dispatch(self::preFoo, $event);
- $this->assertEquals('pre.foo', $event->getName());
- }
-
public function testDispatchForClosure()
{
$invoked = 0;
@@ -249,19 +255,6 @@ abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
}
- /**
- * @group legacy
- */
- public function testLegacyEventReceivesTheDispatcherInstance()
- {
- $dispatcher = null;
- $this->dispatcher->addListener('test', function ($event) use (&$dispatcher) {
- $dispatcher = $event->getDispatcher();
- });
- $this->dispatcher->dispatch('test');
- $this->assertSame($this->dispatcher, $dispatcher);
- }
-
public function testEventReceivesTheDispatcherInstanceAsArgument()
{
$listener = new TestWithDispatcher();
@@ -310,6 +303,73 @@ abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($this->dispatcher->hasListeners('foo'));
$this->assertFalse($this->dispatcher->hasListeners());
}
+
+ public function testHasListenersIsLazy()
+ {
+ $called = 0;
+ $listener = array(function () use (&$called) { ++$called; }, 'onFoo');
+ $this->dispatcher->addListener('foo', $listener);
+ $this->assertTrue($this->dispatcher->hasListeners());
+ $this->assertTrue($this->dispatcher->hasListeners('foo'));
+ $this->assertSame(0, $called);
+ }
+
+ public function testDispatchLazyListener()
+ {
+ $called = 0;
+ $factory = function () use (&$called) {
+ ++$called;
+
+ return new TestWithDispatcher();
+ };
+ $this->dispatcher->addListener('foo', array($factory, 'foo'));
+ $this->assertSame(0, $called);
+ $this->dispatcher->dispatch('foo', new Event());
+ $this->dispatcher->dispatch('foo', new Event());
+ $this->assertSame(1, $called);
+ }
+
+ public function testRemoveFindsLazyListeners()
+ {
+ $test = new TestWithDispatcher();
+ $factory = function () use ($test) { return $test; };
+
+ $this->dispatcher->addListener('foo', array($factory, 'foo'));
+ $this->assertTrue($this->dispatcher->hasListeners('foo'));
+ $this->dispatcher->removeListener('foo', array($test, 'foo'));
+ $this->assertFalse($this->dispatcher->hasListeners('foo'));
+
+ $this->dispatcher->addListener('foo', array($test, 'foo'));
+ $this->assertTrue($this->dispatcher->hasListeners('foo'));
+ $this->dispatcher->removeListener('foo', array($factory, 'foo'));
+ $this->assertFalse($this->dispatcher->hasListeners('foo'));
+ }
+
+ public function testPriorityFindsLazyListeners()
+ {
+ $test = new TestWithDispatcher();
+ $factory = function () use ($test) { return $test; };
+
+ $this->dispatcher->addListener('foo', array($factory, 'foo'), 3);
+ $this->assertSame(3, $this->dispatcher->getListenerPriority('foo', array($test, 'foo')));
+ $this->dispatcher->removeListener('foo', array($factory, 'foo'));
+
+ $this->dispatcher->addListener('foo', array($test, 'foo'), 5);
+ $this->assertSame(5, $this->dispatcher->getListenerPriority('foo', array($factory, 'foo')));
+ }
+
+ public function testGetLazyListeners()
+ {
+ $test = new TestWithDispatcher();
+ $factory = function () use ($test) { return $test; };
+
+ $this->dispatcher->addListener('foo', array($factory, 'foo'), 3);
+ $this->assertSame(array(array($test, 'foo')), $this->dispatcher->getListeners('foo'));
+
+ $this->dispatcher->removeListener('foo', array($test, 'foo'));
+ $this->dispatcher->addListener('bar', array($factory, 'foo'), 3);
+ $this->assertSame(array('bar' => array(array($test, 'foo'))), $this->dispatcher->getListeners());
+ }
}
class CallableClass
diff --git a/vendor/symfony/event-dispatcher/Tests/ContainerAwareEventDispatcherTest.php b/vendor/symfony/event-dispatcher/Tests/ContainerAwareEventDispatcherTest.php
index 0f3f5ba7..9d5eecc5 100644
--- a/vendor/symfony/event-dispatcher/Tests/ContainerAwareEventDispatcherTest.php
+++ b/vendor/symfony/event-dispatcher/Tests/ContainerAwareEventDispatcherTest.php
@@ -12,11 +12,13 @@
namespace Symfony\Component\EventDispatcher\Tests;
use Symfony\Component\DependencyInjection\Container;
-use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+/**
+ * @group legacy
+ */
class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
{
protected function createEventDispatcher()
@@ -30,7 +32,7 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
{
$event = new Event();
- $service = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
+ $service = $this->getMockBuilder('Symfony\Component\EventDispatcher\Tests\Service')->getMock();
$service
->expects($this->once())
@@ -51,7 +53,7 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
{
$event = new Event();
- $service = $this->getMock('Symfony\Component\EventDispatcher\Tests\SubscriberService');
+ $service = $this->getMockBuilder('Symfony\Component\EventDispatcher\Tests\SubscriberService')->getMock();
$service
->expects($this->once())
@@ -86,7 +88,7 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
{
$event = new Event();
- $service = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
+ $service = $this->getMockBuilder('Symfony\Component\EventDispatcher\Tests\Service')->getMock();
$service
->expects($this->once())
@@ -104,73 +106,11 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
$dispatcher->dispatch('onEvent', $event);
}
- /**
- * @expectedException \InvalidArgumentException
- */
- public function testTriggerAListenerServiceOutOfScope()
- {
- $service = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
-
- $scope = new Scope('scope');
- $container = new Container();
- $container->addScope($scope);
- $container->enterScope('scope');
-
- $container->set('service.listener', $service, 'scope');
-
- $dispatcher = new ContainerAwareEventDispatcher($container);
- $dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent'));
-
- $container->leaveScope('scope');
- $dispatcher->dispatch('onEvent');
- }
-
- public function testReEnteringAScope()
- {
- $event = new Event();
-
- $service1 = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
-
- $service1
- ->expects($this->exactly(2))
- ->method('onEvent')
- ->with($event)
- ;
-
- $scope = new Scope('scope');
- $container = new Container();
- $container->addScope($scope);
- $container->enterScope('scope');
-
- $container->set('service.listener', $service1, 'scope');
-
- $dispatcher = new ContainerAwareEventDispatcher($container);
- $dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent'));
- $dispatcher->dispatch('onEvent', $event);
-
- $service2 = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
-
- $service2
- ->expects($this->once())
- ->method('onEvent')
- ->with($event)
- ;
-
- $container->enterScope('scope');
- $container->set('service.listener', $service2, 'scope');
-
- $dispatcher->dispatch('onEvent', $event);
-
- $container->leaveScope('scope');
-
- $dispatcher->dispatch('onEvent');
- }
-
public function testHasListenersOnLazyLoad()
{
$event = new Event();
- $service = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
+ $service = $this->getMockBuilder('Symfony\Component\EventDispatcher\Tests\Service')->getMock();
$container = new Container();
$container->set('service.listener', $service);
@@ -178,9 +118,6 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
$dispatcher = new ContainerAwareEventDispatcher($container);
$dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent'));
- $event->setDispatcher($dispatcher);
- $event->setName('onEvent');
-
$service
->expects($this->once())
->method('onEvent')
@@ -196,7 +133,7 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
public function testGetListenersOnLazyLoad()
{
- $service = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
+ $service = $this->getMockBuilder('Symfony\Component\EventDispatcher\Tests\Service')->getMock();
$container = new Container();
$container->set('service.listener', $service);
@@ -206,14 +143,14 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
$listeners = $dispatcher->getListeners();
- $this->assertTrue(isset($listeners['onEvent']));
+ $this->assertArrayHasKey('onEvent', $listeners);
$this->assertCount(1, $dispatcher->getListeners('onEvent'));
}
public function testRemoveAfterDispatch()
{
- $service = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
+ $service = $this->getMockBuilder('Symfony\Component\EventDispatcher\Tests\Service')->getMock();
$container = new Container();
$container->set('service.listener', $service);
@@ -228,7 +165,7 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
public function testRemoveBeforeDispatch()
{
- $service = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
+ $service = $this->getMockBuilder('Symfony\Component\EventDispatcher\Tests\Service')->getMock();
$container = new Container();
$container->set('service.listener', $service);
diff --git a/vendor/symfony/event-dispatcher/Tests/Debug/TraceableEventDispatcherTest.php b/vendor/symfony/event-dispatcher/Tests/Debug/TraceableEventDispatcherTest.php
index 4aa6226e..53a3421a 100644
--- a/vendor/symfony/event-dispatcher/Tests/Debug/TraceableEventDispatcherTest.php
+++ b/vendor/symfony/event-dispatcher/Tests/Debug/TraceableEventDispatcherTest.php
@@ -11,6 +11,7 @@
namespace Symfony\Component\EventDispatcher\Tests\Debug;
+use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -18,14 +19,14 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Stopwatch\Stopwatch;
-class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
+class TraceableEventDispatcherTest extends TestCase
{
public function testAddRemoveListener()
{
$dispatcher = new EventDispatcher();
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
- $tdispatcher->addListener('foo', $listener = function () {; });
+ $tdispatcher->addListener('foo', $listener = function () {});
$listeners = $dispatcher->getListeners('foo');
$this->assertCount(1, $listeners);
$this->assertSame($listener, $listeners[0]);
@@ -39,7 +40,7 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
$dispatcher = new EventDispatcher();
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
- $tdispatcher->addListener('foo', $listener = function () {; });
+ $tdispatcher->addListener('foo', $listener = function () {});
$this->assertSame($dispatcher->getListeners('foo'), $tdispatcher->getListeners('foo'));
}
@@ -51,11 +52,42 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($dispatcher->hasListeners('foo'));
$this->assertFalse($tdispatcher->hasListeners('foo'));
- $tdispatcher->addListener('foo', $listener = function () {; });
+ $tdispatcher->addListener('foo', $listener = function () {});
$this->assertTrue($dispatcher->hasListeners('foo'));
$this->assertTrue($tdispatcher->hasListeners('foo'));
}
+ public function testGetListenerPriority()
+ {
+ $dispatcher = new EventDispatcher();
+ $tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
+
+ $tdispatcher->addListener('foo', function () {}, 123);
+
+ $listeners = $dispatcher->getListeners('foo');
+ $this->assertSame(123, $tdispatcher->getListenerPriority('foo', $listeners[0]));
+
+ // Verify that priority is preserved when listener is removed and re-added
+ // in preProcess() and postProcess().
+ $tdispatcher->dispatch('foo', new Event());
+ $listeners = $dispatcher->getListeners('foo');
+ $this->assertSame(123, $tdispatcher->getListenerPriority('foo', $listeners[0]));
+ }
+
+ public function testGetListenerPriorityWhileDispatching()
+ {
+ $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
+ $priorityWhileDispatching = null;
+
+ $listener = function () use ($tdispatcher, &$priorityWhileDispatching, &$listener) {
+ $priorityWhileDispatching = $tdispatcher->getListenerPriority('bar', $listener);
+ };
+
+ $tdispatcher->addListener('bar', $listener, 5);
+ $tdispatcher->dispatch('bar');
+ $this->assertSame(5, $priorityWhileDispatching);
+ }
+
public function testAddRemoveSubscriber()
{
$dispatcher = new EventDispatcher();
@@ -74,19 +106,39 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
public function testGetCalledListeners()
{
- $dispatcher = new EventDispatcher();
- $tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
- $tdispatcher->addListener('foo', $listener = function () {; });
+ $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
+ $tdispatcher->addListener('foo', function () {}, 5);
+ $listeners = $tdispatcher->getNotCalledListeners();
+ $this->assertArrayHasKey('stub', $listeners['foo.closure']);
+ unset($listeners['foo.closure']['stub']);
$this->assertEquals(array(), $tdispatcher->getCalledListeners());
- $this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure')), $tdispatcher->getNotCalledListeners());
+ $this->assertEquals(array('foo.closure' => array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
$tdispatcher->dispatch('foo');
- $this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure')), $tdispatcher->getCalledListeners());
+ $listeners = $tdispatcher->getCalledListeners();
+ $this->assertArrayHasKey('stub', $listeners['foo.closure']);
+ unset($listeners['foo.closure']['stub']);
+ $this->assertEquals(array('foo.closure' => array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
$this->assertEquals(array(), $tdispatcher->getNotCalledListeners());
}
+ public function testClearCalledListeners()
+ {
+ $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
+ $tdispatcher->addListener('foo', function () {}, 5);
+
+ $tdispatcher->dispatch('foo');
+ $tdispatcher->reset();
+
+ $listeners = $tdispatcher->getNotCalledListeners();
+ $this->assertArrayHasKey('stub', $listeners['foo.closure']);
+ unset($listeners['foo.closure']['stub']);
+ $this->assertEquals(array(), $tdispatcher->getCalledListeners());
+ $this->assertEquals(array('foo.closure' => array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
+ }
+
public function testGetCalledListenersNested()
{
$tdispatcher = null;
@@ -103,31 +155,31 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
public function testLogger()
{
- $logger = $this->getMock('Psr\Log\LoggerInterface');
+ $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$dispatcher = new EventDispatcher();
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch(), $logger);
- $tdispatcher->addListener('foo', $listener1 = function () {; });
- $tdispatcher->addListener('foo', $listener2 = function () {; });
+ $tdispatcher->addListener('foo', $listener1 = function () {});
+ $tdispatcher->addListener('foo', $listener2 = function () {});
- $logger->expects($this->at(0))->method('debug')->with('Notified event "foo" to listener "closure".');
- $logger->expects($this->at(1))->method('debug')->with('Notified event "foo" to listener "closure".');
+ $logger->expects($this->at(0))->method('debug')->with('Notified event "{event}" to listener "{listener}".', array('event' => 'foo', 'listener' => 'closure'));
+ $logger->expects($this->at(1))->method('debug')->with('Notified event "{event}" to listener "{listener}".', array('event' => 'foo', 'listener' => 'closure'));
$tdispatcher->dispatch('foo');
}
public function testLoggerWithStoppedEvent()
{
- $logger = $this->getMock('Psr\Log\LoggerInterface');
+ $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$dispatcher = new EventDispatcher();
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch(), $logger);
$tdispatcher->addListener('foo', $listener1 = function (Event $event) { $event->stopPropagation(); });
- $tdispatcher->addListener('foo', $listener2 = function () {; });
+ $tdispatcher->addListener('foo', $listener2 = function () {});
- $logger->expects($this->at(0))->method('debug')->with('Notified event "foo" to listener "closure".');
- $logger->expects($this->at(1))->method('debug')->with('Listener "closure" stopped propagation of the event "foo".');
- $logger->expects($this->at(2))->method('debug')->with('Listener "closure" was not called for event "foo".');
+ $logger->expects($this->at(0))->method('debug')->with('Notified event "{event}" to listener "{listener}".', array('event' => 'foo', 'listener' => 'closure'));
+ $logger->expects($this->at(1))->method('debug')->with('Listener "{listener}" stopped propagation of the event "{event}".', array('event' => 'foo', 'listener' => 'closure'));
+ $logger->expects($this->at(2))->method('debug')->with('Listener "{listener}" was not called for event "{event}".', array('event' => 'foo', 'listener' => 'closure'));
$tdispatcher->dispatch('foo');
}
@@ -138,26 +190,32 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
$dispatcher = new EventDispatcher();
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
- $tdispatcher->addListener('foo', $listener1 = function () use (&$called) { $called[] = 'foo1'; });
- $tdispatcher->addListener('foo', $listener2 = function () use (&$called) { $called[] = 'foo2'; });
+ $tdispatcher->addListener('foo', function () use (&$called) { $called[] = 'foo1'; }, 10);
+ $tdispatcher->addListener('foo', function () use (&$called) { $called[] = 'foo2'; }, 20);
$tdispatcher->dispatch('foo');
- $this->assertEquals(array('foo1', 'foo2'), $called);
+ $this->assertSame(array('foo2', 'foo1'), $called);
}
public function testDispatchNested()
{
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
$loop = 1;
+ $dispatchedEvents = 0;
$dispatcher->addListener('foo', $listener1 = function () use ($dispatcher, &$loop) {
++$loop;
if (2 == $loop) {
$dispatcher->dispatch('foo');
}
});
+ $dispatcher->addListener('foo', function () use (&$dispatchedEvents) {
+ ++$dispatchedEvents;
+ });
$dispatcher->dispatch('foo');
+
+ $this->assertSame(2, $dispatchedEvents);
}
public function testDispatchReusedEventNested()
diff --git a/vendor/symfony/event-dispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php b/vendor/symfony/event-dispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php
index 0fdd6372..dbb1aa5c 100644
--- a/vendor/symfony/event-dispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php
+++ b/vendor/symfony/event-dispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php
@@ -11,10 +11,13 @@
namespace Symfony\Component\EventDispatcher\Tests\DependencyInjection;
+use PHPUnit\Framework\TestCase;
+use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
-class RegisterListenersPassTest extends \PHPUnit_Framework_TestCase
+class RegisterListenersPassTest extends TestCase
{
/**
* Tests that event subscribers not implementing EventSubscriberInterface
@@ -29,18 +32,12 @@ class RegisterListenersPassTest extends \PHPUnit_Framework_TestCase
'my_event_subscriber' => array(0 => array()),
);
- $definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
- $definition->expects($this->atLeastOnce())
- ->method('isPublic')
- ->will($this->returnValue(true));
+ $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
$definition->expects($this->atLeastOnce())
->method('getClass')
->will($this->returnValue('stdClass'));
- $builder = $this->getMock(
- 'Symfony\Component\DependencyInjection\ContainerBuilder',
- array('hasDefinition', 'findTaggedServiceIds', 'getDefinition')
- );
+ $builder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
$builder->expects($this->any())
->method('hasDefinition')
->will($this->returnValue(true));
@@ -64,18 +61,12 @@ class RegisterListenersPassTest extends \PHPUnit_Framework_TestCase
'my_event_subscriber' => array(0 => array()),
);
- $definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
- $definition->expects($this->atLeastOnce())
- ->method('isPublic')
- ->will($this->returnValue(true));
+ $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
$definition->expects($this->atLeastOnce())
->method('getClass')
->will($this->returnValue('Symfony\Component\EventDispatcher\Tests\DependencyInjection\SubscriberService'));
- $builder = $this->getMock(
- 'Symfony\Component\DependencyInjection\ContainerBuilder',
- array('hasDefinition', 'findTaggedServiceIds', 'getDefinition', 'findDefinition')
- );
+ $builder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition', 'findDefinition'))->getMock();
$builder->expects($this->any())
->method('hasDefinition')
->will($this->returnValue(true));
@@ -99,35 +90,7 @@ class RegisterListenersPassTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The service "foo" must be public as event listeners are lazy-loaded.
- */
- public function testPrivateEventListener()
- {
- $container = new ContainerBuilder();
- $container->register('foo', 'stdClass')->setPublic(false)->addTag('kernel.event_listener', array());
- $container->register('event_dispatcher', 'stdClass');
-
- $registerListenersPass = new RegisterListenersPass();
- $registerListenersPass->process($container);
- }
-
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The service "foo" must be public as event subscribers are lazy-loaded.
- */
- public function testPrivateEventSubscriber()
- {
- $container = new ContainerBuilder();
- $container->register('foo', 'stdClass')->setPublic(false)->addTag('kernel.event_subscriber', array());
- $container->register('event_dispatcher', 'stdClass');
-
- $registerListenersPass = new RegisterListenersPass();
- $registerListenersPass->process($container);
- }
-
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The service "foo" must not be abstract as event listeners are lazy-loaded.
+ * @expectedExceptionMessage The service "foo" tagged "kernel.event_listener" must not be abstract.
*/
public function testAbstractEventListener()
{
@@ -141,7 +104,7 @@ class RegisterListenersPassTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The service "foo" must not be abstract as event subscribers are lazy-loaded.
+ * @expectedExceptionMessage The service "foo" tagged "kernel.event_subscriber" must not be abstract.
*/
public function testAbstractEventSubscriber()
{
@@ -165,16 +128,29 @@ class RegisterListenersPassTest extends \PHPUnit_Framework_TestCase
$registerListenersPass->process($container);
$definition = $container->getDefinition('event_dispatcher');
- $expected_calls = array(
+ $expectedCalls = array(
array(
- 'addSubscriberService',
+ 'addListener',
array(
- 'foo',
- 'Symfony\Component\EventDispatcher\Tests\DependencyInjection\SubscriberService',
+ 'event',
+ array(new ServiceClosureArgument(new Reference('foo')), 'onEvent'),
+ 0,
),
),
);
- $this->assertSame($expected_calls, $definition->getMethodCalls());
+ $this->assertEquals($expectedCalls, $definition->getMethodCalls());
+ }
+
+ public function testHotPathEvents()
+ {
+ $container = new ContainerBuilder();
+
+ $container->register('foo', SubscriberService::class)->addTag('kernel.event_subscriber', array());
+ $container->register('event_dispatcher', 'stdClass');
+
+ (new RegisterListenersPass())->setHotPathEvents(array('event'))->process($container);
+
+ $this->assertTrue($container->getDefinition('foo')->hasTag('container.hot_path'));
}
/**
@@ -196,5 +172,8 @@ class SubscriberService implements \Symfony\Component\EventDispatcher\EventSubsc
{
public static function getSubscribedEvents()
{
+ return array(
+ 'event' => 'onEvent',
+ );
}
}
diff --git a/vendor/symfony/event-dispatcher/Tests/EventTest.php b/vendor/symfony/event-dispatcher/Tests/EventTest.php
index 9a822670..5be2ea09 100644
--- a/vendor/symfony/event-dispatcher/Tests/EventTest.php
+++ b/vendor/symfony/event-dispatcher/Tests/EventTest.php
@@ -11,13 +11,13 @@
namespace Symfony\Component\EventDispatcher\Tests;
+use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\Event;
-use Symfony\Component\EventDispatcher\EventDispatcher;
/**
* Test class for Event.
*/
-class EventTest extends \PHPUnit_Framework_TestCase
+class EventTest extends TestCase
{
/**
* @var \Symfony\Component\EventDispatcher\Event
@@ -25,18 +25,12 @@ class EventTest extends \PHPUnit_Framework_TestCase
protected $event;
/**
- * @var \Symfony\Component\EventDispatcher\EventDispatcher
- */
- protected $dispatcher;
-
- /**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->event = new Event();
- $this->dispatcher = new EventDispatcher();
}
/**
@@ -46,7 +40,6 @@ class EventTest extends \PHPUnit_Framework_TestCase
protected function tearDown()
{
$this->event = null;
- $this->dispatcher = null;
}
public function testIsPropagationStopped()
@@ -59,38 +52,4 @@ class EventTest extends \PHPUnit_Framework_TestCase
$this->event->stopPropagation();
$this->assertTrue($this->event->isPropagationStopped());
}
-
- /**
- * @group legacy
- */
- public function testLegacySetDispatcher()
- {
- $this->event->setDispatcher($this->dispatcher);
- $this->assertSame($this->dispatcher, $this->event->getDispatcher());
- }
-
- /**
- * @group legacy
- */
- public function testLegacyGetDispatcher()
- {
- $this->assertNull($this->event->getDispatcher());
- }
-
- /**
- * @group legacy
- */
- public function testLegacyGetName()
- {
- $this->assertNull($this->event->getName());
- }
-
- /**
- * @group legacy
- */
- public function testLegacySetName()
- {
- $this->event->setName('foo');
- $this->assertEquals('foo', $this->event->getName());
- }
}
diff --git a/vendor/symfony/event-dispatcher/Tests/GenericEventTest.php b/vendor/symfony/event-dispatcher/Tests/GenericEventTest.php
index aebd82da..9cf68c98 100644
--- a/vendor/symfony/event-dispatcher/Tests/GenericEventTest.php
+++ b/vendor/symfony/event-dispatcher/Tests/GenericEventTest.php
@@ -11,12 +11,13 @@
namespace Symfony\Component\EventDispatcher\Tests;
+use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Test class for Event.
*/
-class GenericEventTest extends \PHPUnit_Framework_TestCase
+class GenericEventTest extends TestCase
{
/**
* @var GenericEvent
@@ -95,7 +96,7 @@ class GenericEventTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('Event', $this->event['name']);
// test getting invalid arg
- $this->setExpectedException('InvalidArgumentException');
+ $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
$this->assertFalse($this->event['nameNotExist']);
}
@@ -113,8 +114,8 @@ class GenericEventTest extends \PHPUnit_Framework_TestCase
public function testOffsetIsset()
{
- $this->assertTrue(isset($this->event['name']));
- $this->assertFalse(isset($this->event['nameNotExist']));
+ $this->assertArrayHasKey('name', $this->event);
+ $this->assertArrayNotHasKey('nameNotExist', $this->event);
}
public function testHasArgument()
diff --git a/vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php b/vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php
index 80a7e43b..04f2861e 100644
--- a/vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php
+++ b/vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php
@@ -11,13 +11,14 @@
namespace Symfony\Component\EventDispatcher\Tests;
+use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\ImmutableEventDispatcher;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
-class ImmutableEventDispatcherTest extends \PHPUnit_Framework_TestCase
+class ImmutableEventDispatcherTest extends TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -31,7 +32,7 @@ class ImmutableEventDispatcherTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
- $this->innerDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+ $this->innerDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
$this->dispatcher = new ImmutableEventDispatcher($this->innerDispatcher);
}
@@ -80,7 +81,7 @@ class ImmutableEventDispatcherTest extends \PHPUnit_Framework_TestCase
*/
public function testAddSubscriberDisallowed()
{
- $subscriber = $this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface');
+ $subscriber = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventSubscriberInterface')->getMock();
$this->dispatcher->addSubscriber($subscriber);
}
@@ -98,7 +99,7 @@ class ImmutableEventDispatcherTest extends \PHPUnit_Framework_TestCase
*/
public function testRemoveSubscriberDisallowed()
{
- $subscriber = $this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface');
+ $subscriber = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventSubscriberInterface')->getMock();
$this->dispatcher->removeSubscriber($subscriber);
}