You are here

public function TraceableEventDispatcherTest::testAddListenerNested in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-kernel/Tests/Debug/TraceableEventDispatcherTest.php \Symfony\Component\HttpKernel\Tests\Debug\TraceableEventDispatcherTest::testAddListenerNested()

File

vendor/symfony/http-kernel/Tests/Debug/TraceableEventDispatcherTest.php, line 78

Class

TraceableEventDispatcherTest

Namespace

Symfony\Component\HttpKernel\Tests\Debug

Code

public function testAddListenerNested() {
  $called1 = false;
  $called2 = false;
  $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
  $dispatcher
    ->addListener('my-event', function () use ($dispatcher, &$called1, &$called2) {
    $called1 = true;
    $dispatcher
      ->addListener('my-event', function () use (&$called2) {
      $called2 = true;
    });
  });
  $dispatcher
    ->dispatch('my-event');
  $this
    ->assertTrue($called1);
  $this
    ->assertFalse($called2);
  $dispatcher
    ->dispatch('my-event');
  $this
    ->assertTrue($called2);
}