3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Bridge\Doctrine\Tests\DependencyInjection\CompilerPass; use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterEventListenersAndSubscribersPass; use Symfony\Component\DependencyInjection\ContainerBuilder; class RegisterEventListenersAndSubscribersPassTest extends \PHPUnit_Framework_TestCase { public function testProcessEventListenersWithPriorities() { $container = $this->createBuilder(); $container ->register('a', 'stdClass') ->addTag('doctrine.event_listener', array( 'event' => 'foo', 'priority' => -5, )) ->addTag('doctrine.event_listener', array( 'event' => 'bar', )) ; $container ->register('b', 'stdClass') ->addTag('doctrine.event_listener', array( 'event' => 'foo', )) ; $this->process($container); $this->assertEquals(array('b', 'a'), $this->getServiceOrder($container, 'addEventListener')); $calls = $container->getDefinition('doctrine.dbal.default_connection.event_manager')->getMethodCalls(); $this->assertEquals(array('foo', 'bar'), $calls[1][1][0]); } public function testProcessEventListenersWithMultipleConnections() { $container = $this->createBuilder(true); $container ->register('a', 'stdClass') ->addTag('doctrine.event_listener', array( 'event' => 'onFlush', )) ; $this->process($container); $callsDefault = $container->getDefinition('doctrine.dbal.default_connection.event_manager')->getMethodCalls(); $this->assertEquals('addEventListener', $callsDefault[0][0]); $this->assertEquals(array('onFlush'), $callsDefault[0][1][0]); $callsSecond = $container->getDefinition('doctrine.dbal.second_connection.event_manager')->getMethodCalls(); $this->assertEquals($callsDefault, $callsSecond); } public function testProcessEventSubscribersWithPriorities() { $container = $this->createBuilder(); $container ->register('a', 'stdClass') ->addTag('doctrine.event_subscriber') ; $container ->register('b', 'stdClass') ->addTag('doctrine.event_subscriber', array( 'priority' => 5, )) ; $container ->register('c', 'stdClass') ->addTag('doctrine.event_subscriber', array( 'priority' => 10, )) ; $container ->register('d', 'stdClass') ->addTag('doctrine.event_subscriber', array( 'priority' => 10, )) ; $container ->register('e', 'stdClass') ->addTag('doctrine.event_subscriber', array( 'priority' => 10, )) ; $this->process($container); $this->assertEquals(array('c', 'd', 'e', 'b', 'a'), $this->getServiceOrder($container, 'addEventSubscriber')); } public function testProcessNoTaggedServices() { $container = $this->createBuilder(true); $this->process($container); $this->assertEquals(array(), $container->getDefinition('doctrine.dbal.default_connection.event_manager')->getMethodCalls()); $this->assertEquals(array(), $container->getDefinition('doctrine.dbal.second_connection.event_manager')->getMethodCalls()); } private function process(ContainerBuilder $container) { $pass = new RegisterEventListenersAndSubscribersPass('doctrine.connections', 'doctrine.dbal.%s_connection.event_manager', 'doctrine'); $pass->process($container); } private function getServiceOrder(ContainerBuilder $container, $method) { $order = array(); foreach ($container->getDefinition('doctrine.dbal.default_connection.event_manager')->getMethodCalls() as $call) { list($name, $arguments) = $call; if ($method !== $name) { continue; } if ('addEventListener' === $name) { $order[] = (string) $arguments[1]; continue; } $order[] = (string) $arguments[0]; } return $order; } private function createBuilder($multipleConnections = false) { $container = new ContainerBuilder(); $connections = array('default' => 'doctrine.dbal.default_connection'); $container->register('doctrine.dbal.default_connection.event_manager', 'stdClass'); $container->register('doctrine.dbal.default_connection', 'stdClass'); if ($multipleConnections) { $container->register('doctrine.dbal.second_connection.event_manager', 'stdClass'); $container->register('doctrine.dbal.second_connection', 'stdClass'); $connections['second'] = 'doctrine.dbal.second_connection'; } $container->setParameter('doctrine.connections', $connections); return $container; } }
Output for 7.0.0 - 7.1.0
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /in/4v1tM on line 17
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
Fatal error: unknown class PHPUnit_Framework_TestCase in /in/4v1tM on line 17
Process exited with code 255.
Output for 5.3.0 - 5.6.28
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /in/4v1tM on line 18
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/4v1tM on line 12
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/4v1tM on line 12
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/4v1tM on line 12
Process exited with code 255.