@ 2014-09-17T17:35:53Z <?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;
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Fatal error: Uncaught Error: Class "PHPUnit_Framework_TestCase" not found in /in/4v1tM:17
Stack trace:
#0 {main}
thrown in /in/4v1tM on line 17
Process exited with code 255 . Output for 7.3.16 - 7.3.33 , 7.4.0 - 7.4.33 Fatal error: Uncaught Error: Class 'PHPUnit_Framework_TestCase' not found in /in/4v1tM:17
Stack trace:
#0 {main}
thrown in /in/4v1tM on line 17
Process exited with code 255 . Output for 7.0.0 - 7.0.20 , 7.1.0 - 7.1.20 , 7.2.6 - 7.2.33 Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /in/4v1tM on line 17
Process exited with code 255 . Output for 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.8 - 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.1.6 , 5.2.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.3.11 , 4.4.0 - 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 . preferences:dark mode live preview
245.73 ms | 401 KiB | 310 Q