class TraceableEventDispatcherTest in Zircon Profile 8
Same name in this branch
- 8 vendor/symfony/event-dispatcher/Tests/Debug/TraceableEventDispatcherTest.php \Symfony\Component\EventDispatcher\Tests\Debug\TraceableEventDispatcherTest
- 8 vendor/symfony/http-kernel/Tests/Debug/TraceableEventDispatcherTest.php \Symfony\Component\HttpKernel\Tests\Debug\TraceableEventDispatcherTest
Same name and namespace in other branches
- 8.0 vendor/symfony/http-kernel/Tests/Debug/TraceableEventDispatcherTest.php \Symfony\Component\HttpKernel\Tests\Debug\TraceableEventDispatcherTest
Hierarchy
- class \Symfony\Component\HttpKernel\Tests\Debug\TraceableEventDispatcherTest extends \Symfony\Component\HttpKernel\Tests\Debug\PHPUnit_Framework_TestCase
Expanded class hierarchy of TraceableEventDispatcherTest
File
- vendor/
symfony/ http-kernel/ Tests/ Debug/ TraceableEventDispatcherTest.php, line 21
Namespace
Symfony\Component\HttpKernel\Tests\DebugView source
class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase {
public function testStopwatchSections() {
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch = new Stopwatch());
$kernel = $this
->getHttpKernel($dispatcher, function () {
return new Response();
});
$request = Request::create('/');
$response = $kernel
->handle($request);
$kernel
->terminate($request, $response);
$events = $stopwatch
->getSectionEvents($response->headers
->get('X-Debug-Token'));
$this
->assertEquals(array(
'__section__',
'kernel.request',
'kernel.controller',
'controller',
'kernel.response',
'kernel.terminate',
), array_keys($events));
}
public function testStopwatchCheckControllerOnRequestEvent() {
$stopwatch = $this
->getMockBuilder('Symfony\\Component\\Stopwatch\\Stopwatch')
->setMethods(array(
'isStarted',
))
->getMock();
$stopwatch
->expects($this
->once())
->method('isStarted')
->will($this
->returnValue(false));
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch);
$kernel = $this
->getHttpKernel($dispatcher, function () {
return new Response();
});
$request = Request::create('/');
$kernel
->handle($request);
}
public function testStopwatchStopControllerOnRequestEvent() {
$stopwatch = $this
->getMockBuilder('Symfony\\Component\\Stopwatch\\Stopwatch')
->setMethods(array(
'isStarted',
'stop',
'stopSection',
))
->getMock();
$stopwatch
->expects($this
->once())
->method('isStarted')
->will($this
->returnValue(true));
$stopwatch
->expects($this
->once())
->method('stop');
$stopwatch
->expects($this
->once())
->method('stopSection');
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch);
$kernel = $this
->getHttpKernel($dispatcher, function () {
return new Response();
});
$request = Request::create('/');
$kernel
->handle($request);
}
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);
}
public function testListenerCanRemoveItselfWhenExecuted() {
$eventDispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
$listener1 = function () use ($eventDispatcher, &$listener1) {
$eventDispatcher
->removeListener('foo', $listener1);
};
$eventDispatcher
->addListener('foo', $listener1);
$eventDispatcher
->addListener('foo', function () {
});
$eventDispatcher
->dispatch('foo');
$this
->assertCount(1, $eventDispatcher
->getListeners('foo'), 'expected listener1 to be removed');
}
protected function getHttpKernel($dispatcher, $controller) {
$resolver = $this
->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
$resolver
->expects($this
->once())
->method('getController')
->will($this
->returnValue($controller));
$resolver
->expects($this
->once())
->method('getArguments')
->will($this
->returnValue(array()));
return new HttpKernel($dispatcher, $resolver);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TraceableEventDispatcherTest:: |
protected | function | ||
TraceableEventDispatcherTest:: |
public | function | ||
TraceableEventDispatcherTest:: |
public | function | ||
TraceableEventDispatcherTest:: |
public | function | ||
TraceableEventDispatcherTest:: |
public | function | ||
TraceableEventDispatcherTest:: |
public | function |