diff options
Diffstat (limited to 'vendor/symfony/event-dispatcher/Tests/Debug')
| -rw-r--r-- | vendor/symfony/event-dispatcher/Tests/Debug/TraceableEventDispatcherTest.php | 50 | ||||
| -rw-r--r-- | vendor/symfony/event-dispatcher/Tests/Debug/WrappedListenerTest.php | 3 |
2 files changed, 34 insertions, 19 deletions
diff --git a/vendor/symfony/event-dispatcher/Tests/Debug/TraceableEventDispatcherTest.php b/vendor/symfony/event-dispatcher/Tests/Debug/TraceableEventDispatcherTest.php index 9a3697a36f..ea476eee04 100644 --- a/vendor/symfony/event-dispatcher/Tests/Debug/TraceableEventDispatcherTest.php +++ b/vendor/symfony/event-dispatcher/Tests/Debug/TraceableEventDispatcherTest.php @@ -18,6 +18,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Stopwatch\Stopwatch; +use Symfony\Contracts\EventDispatcher\Event as ContractsEvent; class TraceableEventDispatcherTest extends TestCase { @@ -69,7 +70,7 @@ class TraceableEventDispatcherTest extends TestCase // Verify that priority is preserved when listener is removed and re-added // in preProcess() and postProcess(). - $tdispatcher->dispatch('foo', new Event()); + $tdispatcher->dispatch(new Event(), 'foo'); $listeners = $dispatcher->getListeners('foo'); $this->assertSame(123, $tdispatcher->getListenerPriority('foo', $listeners[0])); } @@ -84,7 +85,7 @@ class TraceableEventDispatcherTest extends TestCase }; $tdispatcher->addListener('bar', $listener, 5); - $tdispatcher->dispatch('bar'); + $tdispatcher->dispatch(new Event(), 'bar'); $this->assertSame(5, $priorityWhileDispatching); } @@ -115,7 +116,7 @@ class TraceableEventDispatcherTest extends TestCase $this->assertEquals([], $tdispatcher->getCalledListeners()); $this->assertEquals([['event' => 'foo', 'pretty' => 'closure', 'priority' => 5]], $listeners); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $listeners = $tdispatcher->getCalledListeners(); $this->assertArrayHasKey('stub', $listeners[0]); @@ -129,7 +130,7 @@ class TraceableEventDispatcherTest extends TestCase $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $tdispatcher->addListener('foo', function () {}, 5); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $tdispatcher->reset(); $listeners = $tdispatcher->getNotCalledListeners(); @@ -139,13 +140,26 @@ class TraceableEventDispatcherTest extends TestCase $this->assertEquals([['event' => 'foo', 'pretty' => 'closure', 'priority' => 5]], $listeners); } + public function testDispatchContractsEvent() + { + $expectedEvent = new ContractsEvent(); + $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); + $tdispatcher->addListener('foo', function ($event) use ($expectedEvent) { + $this->assertSame($event, $expectedEvent); + }, 5); + $tdispatcher->dispatch($expectedEvent, 'foo'); + + $listeners = $tdispatcher->getCalledListeners(); + $this->assertArrayHasKey('stub', $listeners[0]); + } + public function testDispatchAfterReset() { $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $tdispatcher->addListener('foo', function () {}, 5); $tdispatcher->reset(); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $listeners = $tdispatcher->getCalledListeners(); $this->assertArrayHasKey('stub', $listeners[0]); @@ -157,10 +171,10 @@ class TraceableEventDispatcherTest extends TestCase $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $dispatcher->addListener('foo', function (Event $event, $eventName, $dispatcher) use (&$tdispatcher) { $tdispatcher = $dispatcher; - $dispatcher->dispatch('bar'); + $dispatcher->dispatch(new Event(), 'bar'); }); $dispatcher->addListener('bar', function (Event $event) {}); - $dispatcher->dispatch('foo'); + $dispatcher->dispatch(new Event(), 'foo'); $this->assertSame($dispatcher, $tdispatcher); $this->assertCount(2, $dispatcher->getCalledListeners()); } @@ -175,7 +189,7 @@ class TraceableEventDispatcherTest extends TestCase public function testItReturnsOrphanedEventsAfterDispatch() { $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $events = $tdispatcher->getOrphanedEvents(); $this->assertCount(1, $events); $this->assertEquals(['foo'], $events); @@ -185,7 +199,7 @@ class TraceableEventDispatcherTest extends TestCase { $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $tdispatcher->addListener('foo', function () {}); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $events = $tdispatcher->getOrphanedEvents(); $this->assertEmpty($events); } @@ -202,7 +216,7 @@ class TraceableEventDispatcherTest extends TestCase $logger->expects($this->at(0))->method('debug')->with('Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']); $logger->expects($this->at(1))->method('debug')->with('Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); } public function testLoggerWithStoppedEvent() @@ -218,7 +232,7 @@ class TraceableEventDispatcherTest extends TestCase $logger->expects($this->at(1))->method('debug')->with('Listener "{listener}" stopped propagation of the event "{event}".', ['event' => 'foo', 'listener' => 'closure']); $logger->expects($this->at(2))->method('debug')->with('Listener "{listener}" was not called for event "{event}".', ['event' => 'foo', 'listener' => 'closure']); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); } public function testDispatchCallListeners() @@ -230,7 +244,7 @@ class TraceableEventDispatcherTest extends TestCase $tdispatcher->addListener('foo', function () use (&$called) { $called[] = 'foo1'; }, 10); $tdispatcher->addListener('foo', function () use (&$called) { $called[] = 'foo2'; }, 20); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $this->assertSame(['foo2', 'foo1'], $called); } @@ -243,14 +257,14 @@ class TraceableEventDispatcherTest extends TestCase $dispatcher->addListener('foo', $listener1 = function () use ($dispatcher, &$loop) { ++$loop; if (2 == $loop) { - $dispatcher->dispatch('foo'); + $dispatcher->dispatch(new Event(), 'foo'); } }); $dispatcher->addListener('foo', function () use (&$dispatchedEvents) { ++$dispatchedEvents; }); - $dispatcher->dispatch('foo'); + $dispatcher->dispatch(new Event(), 'foo'); $this->assertSame(2, $dispatchedEvents); } @@ -260,14 +274,14 @@ class TraceableEventDispatcherTest extends TestCase $nestedCall = false; $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $dispatcher->addListener('foo', function (Event $e) use ($dispatcher) { - $dispatcher->dispatch('bar', $e); + $dispatcher->dispatch(new Event(), 'bar', $e); }); $dispatcher->addListener('bar', function (Event $e) use (&$nestedCall) { $nestedCall = true; }); $this->assertFalse($nestedCall); - $dispatcher->dispatch('foo'); + $dispatcher->dispatch(new Event(), 'foo'); $this->assertTrue($nestedCall); } @@ -279,7 +293,7 @@ class TraceableEventDispatcherTest extends TestCase }; $eventDispatcher->addListener('foo', $listener1); $eventDispatcher->addListener('foo', function () {}); - $eventDispatcher->dispatch('foo'); + $eventDispatcher->dispatch(new Event(), 'foo'); $this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed'); } @@ -287,7 +301,7 @@ class TraceableEventDispatcherTest extends TestCase public function testClearOrphanedEvents() { $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $events = $tdispatcher->getOrphanedEvents(); $this->assertCount(1, $events); $tdispatcher->reset(); diff --git a/vendor/symfony/event-dispatcher/Tests/Debug/WrappedListenerTest.php b/vendor/symfony/event-dispatcher/Tests/Debug/WrappedListenerTest.php index 56792fe33a..75e9012073 100644 --- a/vendor/symfony/event-dispatcher/Tests/Debug/WrappedListenerTest.php +++ b/vendor/symfony/event-dispatcher/Tests/Debug/WrappedListenerTest.php @@ -21,7 +21,7 @@ class WrappedListenerTest extends TestCase /** * @dataProvider provideListenersToDescribe */ - public function testListenerDescription(callable $listener, $expected) + public function testListenerDescription($listener, $expected) { $wrappedListener = new WrappedListener($listener, null, $this->getMockBuilder(Stopwatch::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock()); @@ -34,6 +34,7 @@ class WrappedListenerTest extends TestCase [new FooListener(), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::__invoke'], [[new FooListener(), 'listen'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'], [['Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'], + [['Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'invalidMethod'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::invalidMethod'], ['var_dump', 'var_dump'], [function () {}, 'closure'], [\Closure::fromCallable([new FooListener(), 'listen']), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'], |
