diff --git a/.travis.yml b/.travis.yml index 0ca7444ea..d0d0e6144 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,11 +7,9 @@ cache: - $HOME/.composer/cache php: - - 5.5 - - 5.6 - - 7.0 - 7.1 - 7.2 + - 7.3 - nightly env: @@ -31,45 +29,53 @@ script: jobs: include: - - php: 5.5 - env: deps=low SYMFONY_DEPRECATIONS_HELPER=weak + # Tests the lowest set of dependencies + - php: 7.1 + env: deps=low SYMFONY_DEPRECATIONS_HELPER=999999 install: - COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update -n --prefer-lowest --prefer-stable --prefer-dist - - php: 5.6 - env: SYMFONY_VERSION="2.8.*" - - - php: 7.0 - env: SYMFONY_VERSION="3.2.*" + # Test against latest Symfony 3.4 stable + - php: 7.1 + env: SYMFONY_VERSION="3.4.*" SYMFONY_DEPRECATIONS_HELPER=999999 + # Test against latest Symfony 3.4 dev version - php: 7.1 - env: stability=RC SYMFONY_DEPRECATIONS_HELPER=weak SYMFONY_VERSION="3.4.*" + env: stability=dev SYMFONY_DEPRECATIONS_HELPER=999999 SYMFONY_VERSION="3.4.*" install: - travis_retry composer update -n --prefer-dist + # Test against latest Symfony 4.1 dev version - php: 7.1 - env: stability=dev SYMFONY_DEPRECATIONS_HELPER=weak SYMFONY_VERSION="4.1.*" + env: stability=dev SYMFONY_DEPRECATIONS_HELPER=999999 SYMFONY_VERSION="4.1.*" install: - composer require --dev "symfony/messenger:4.1.*" --no-update - travis_retry composer update -n --prefer-dist + # Test against latest Symfony 4.2 dev version - php: 7.1 - env: stability=dev SYMFONY_DEPRECATIONS_HELPER=weak SYMFONY_VERSION="4.2.*" + env: stability=dev SYMFONY_VERSION="4.2.*" install: - composer require --dev "symfony/messenger:4.2.*" --no-update - travis_retry composer update -n --prefer-dist + # Test alpha packages - php: 7.2 env: stability=alpha install: - composer config minimum-stability alpha - travis_retry composer update -n --prefer-dist + # Test dev level software + - php: nightly + env: stability=dev + install: + - composer config minimum-stability dev + - travis_retry composer update -n --prefer-dist + - stage: Code Quality env: CODING_STANDARDS php: 7.1 - install: - - travis_retry composer require -n --prefer-dist --dev doctrine/coding-standard:^5.0 script: - ./vendor/bin/phpcs diff --git a/Command/Proxy/CollectionRegionDoctrineCommand.php b/Command/Proxy/CollectionRegionDoctrineCommand.php index 35b08aa90..d12614537 100644 --- a/Command/Proxy/CollectionRegionDoctrineCommand.php +++ b/Command/Proxy/CollectionRegionDoctrineCommand.php @@ -3,11 +3,14 @@ namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy; use Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; /** * Command to clear a collection cache region. */ -class CollectionRegionDoctrineCommand extends DelegateCommand +class CollectionRegionDoctrineCommand extends CollectionRegionCommand { /** * {@inheritDoc} @@ -16,22 +19,15 @@ protected function configure() { parent::configure(); - $this->setName('doctrine:cache:clear-collection-region'); + $this + ->setName('doctrine:cache:clear-collection-region') + ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } - /** - * {@inheritDoc} - */ - protected function createCommand() + protected function execute(InputInterface $input, OutputInterface $output) { - return new CollectionRegionCommand(); - } + DoctrineCommandHelper::setApplicationConnection($this->getApplication(), $input->getOption('connection')); - /** - * {@inheritDoc} - */ - protected function getMinimalVersion() - { - return '2.5.0-DEV'; + return parent::execute($input, $output); } } diff --git a/Command/Proxy/EntityRegionCacheDoctrineCommand.php b/Command/Proxy/EntityRegionCacheDoctrineCommand.php index 0969c01e7..4b2d40d56 100644 --- a/Command/Proxy/EntityRegionCacheDoctrineCommand.php +++ b/Command/Proxy/EntityRegionCacheDoctrineCommand.php @@ -3,11 +3,14 @@ namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy; use Doctrine\ORM\Tools\Console\Command\ClearCache\EntityRegionCommand; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; /** * Command to clear a entity cache region. */ -class EntityRegionCacheDoctrineCommand extends DelegateCommand +class EntityRegionCacheDoctrineCommand extends EntityRegionCommand { /** * {@inheritDoc} @@ -16,22 +19,15 @@ protected function configure() { parent::configure(); - $this->setName('doctrine:cache:clear-entity-region'); + $this + ->setName('doctrine:cache:clear-entity-region') + ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } - /** - * {@inheritDoc} - */ - protected function createCommand() + protected function execute(InputInterface $input, OutputInterface $output) { - return new EntityRegionCommand(); - } + DoctrineCommandHelper::setApplicationConnection($this->getApplication(), $input->getOption('connection')); - /** - * {@inheritDoc} - */ - protected function getMinimalVersion() - { - return '2.5.0-DEV'; + return parent::execute($input, $output); } } diff --git a/Command/Proxy/QueryRegionCacheDoctrineCommand.php b/Command/Proxy/QueryRegionCacheDoctrineCommand.php index 7200646af..084841b90 100644 --- a/Command/Proxy/QueryRegionCacheDoctrineCommand.php +++ b/Command/Proxy/QueryRegionCacheDoctrineCommand.php @@ -3,11 +3,14 @@ namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy; use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; /** * Command to clear a query cache region. */ -class QueryRegionCacheDoctrineCommand extends DelegateCommand +class QueryRegionCacheDoctrineCommand extends QueryRegionCommand { /** * {@inheritDoc} @@ -16,22 +19,15 @@ protected function configure() { parent::configure(); - $this->setName('doctrine:cache:clear-query-region'); + $this + ->setName('doctrine:cache:clear-query-region') + ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } - /** - * {@inheritDoc} - */ - protected function createCommand() + protected function execute(InputInterface $input, OutputInterface $output) { - return new QueryRegionCommand(); - } + DoctrineCommandHelper::setApplicationConnection($this->getApplication(), $input->getOption('connection')); - /** - * {@inheritDoc} - */ - protected function getMinimalVersion() - { - return '2.5.0-DEV'; + return parent::execute($input, $output); } } diff --git a/DataCollector/DoctrineDataCollector.php b/DataCollector/DoctrineDataCollector.php index b1e2af663..6fddfd485 100644 --- a/DataCollector/DoctrineDataCollector.php +++ b/DataCollector/DoctrineDataCollector.php @@ -10,7 +10,6 @@ use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Tools\SchemaValidator; -use Doctrine\ORM\Version; use Exception; use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector as BaseCollector; use Symfony\Component\HttpFoundation\Request; @@ -84,10 +83,6 @@ public function collect(Request $request, Response $response, Exception $excepti $errors[$name][$class->getName()] = $classErrors; } - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - continue; - } - /** @var Configuration $emConfig */ $emConfig = $em->getConfiguration(); $slcEnabled = $emConfig->isSecondLevelCacheEnabled(); @@ -140,14 +135,11 @@ public function collect(Request $request, Response $response, Exception $excepti } } - // HttpKernel < 3.2 compatibility layer - if (method_exists($this, 'cloneVar')) { - // Might be good idea to replicate this block in doctrine bridge so we can drop this from here after some time. - // This code is compatible with such change, because cloneVar is supposed to check if input is already cloned. - foreach ($this->data['queries'] as &$queries) { - foreach ($queries as &$query) { - $query['params'] = $this->cloneVar($query['params']); - } + // Might be good idea to replicate this block in doctrine bridge so we can drop this from here after some time. + // This code is compatible with such change, because cloneVar is supposed to check if input is already cloned. + foreach ($this->data['queries'] as &$queries) { + foreach ($queries as &$query) { + $query['params'] = $this->cloneVar($query['params']); } } diff --git a/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php b/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php index 7ccafb74e..988155741 100644 --- a/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php +++ b/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php @@ -5,7 +5,6 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Reference; final class ServiceRepositoryCompilerPass implements CompilerPassInterface @@ -23,15 +22,6 @@ public function process(ContainerBuilder $container) $repoServiceIds = array_keys($container->findTaggedServiceIds(self::REPOSITORY_SERVICE_TAG)); - // Symfony 3.2 and lower sanity check - if (! class_exists(ServiceLocatorTagPass::class)) { - if (! empty($repoServiceIds)) { - throw new RuntimeException(sprintf('The "%s" tag can only be used with Symfony 3.3 or higher. Remove the tag from the following services (%s) or upgrade to Symfony 3.3 or higher.', self::REPOSITORY_SERVICE_TAG, implode(', ', $repoServiceIds))); - } - - return; - } - $repoReferences = array_map(static function ($id) { return new Reference($id); }, $repoServiceIds); diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index ba76ef9c4..7d494e6d0 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -10,7 +10,6 @@ use Doctrine\ORM\Version; use LogicException; use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension; -use Symfony\Bridge\Doctrine\Form\Type\DoctrineType; use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware; use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor; use Symfony\Component\Config\FileLocator; @@ -18,12 +17,9 @@ use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\DependencyInjection\ServiceLocator; -use Symfony\Component\Form\AbstractType; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface; @@ -65,7 +61,7 @@ public function load(array $configs, ContainerBuilder $container) throw new LogicException('Configuring the ORM layer requires to configure the DBAL layer as well.'); } - if (! class_exists('Doctrine\ORM\Version')) { + if (! class_exists(Version::class)) { throw new LogicException('To configure the ORM layer, you must first install the doctrine/orm package.'); } @@ -123,10 +119,7 @@ protected function dbalLoad(array $config, ContainerBuilder $container) */ protected function loadDbalConnection($name, array $connection, ContainerBuilder $container) { - // configuration - $definitionClassname = $this->getDefinitionClassname(); - - $configuration = $container->setDefinition(sprintf('doctrine.dbal.%s_connection.configuration', $name), new $definitionClassname('doctrine.dbal.connection.configuration')); + $configuration = $container->setDefinition(sprintf('doctrine.dbal.%s_connection.configuration', $name), new ChildDefinition('doctrine.dbal.connection.configuration')); $logger = null; if ($connection['logging']) { $logger = new Reference('doctrine.dbal.logger'); @@ -134,12 +127,12 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder unset($connection['logging']); if ($connection['profiling']) { $profilingLoggerId = 'doctrine.dbal.logger.profiling.' . $name; - $container->setDefinition($profilingLoggerId, new $definitionClassname('doctrine.dbal.logger.profiling')); + $container->setDefinition($profilingLoggerId, new ChildDefinition('doctrine.dbal.logger.profiling')); $profilingLogger = new Reference($profilingLoggerId); $container->getDefinition('data_collector.doctrine')->addMethodCall('addLogger', [$name, $profilingLogger]); if ($logger !== null) { - $chainLogger = new $definitionClassname('doctrine.dbal.logger.chain'); + $chainLogger = new ChildDefinition('doctrine.dbal.logger.chain'); $chainLogger->addMethodCall('addLogger', [$profilingLogger]); $loggerId = 'doctrine.dbal.logger.chain.' . $name; @@ -168,13 +161,13 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder } // event manager - $container->setDefinition(sprintf('doctrine.dbal.%s_connection.event_manager', $name), new $definitionClassname('doctrine.dbal.connection.event_manager')); + $container->setDefinition(sprintf('doctrine.dbal.%s_connection.event_manager', $name), new ChildDefinition('doctrine.dbal.connection.event_manager')); // connection $options = $this->getConnectionOptions($connection); $def = $container - ->setDefinition(sprintf('doctrine.dbal.%s_connection', $name), new $definitionClassname('doctrine.dbal.connection')) + ->setDefinition(sprintf('doctrine.dbal.%s_connection', $name), new ChildDefinition('doctrine.dbal.connection')) ->setPublic(true) ->setArguments([ $options, @@ -328,10 +321,6 @@ protected function ormLoad(array $config, ContainerBuilder $container) $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('orm.xml'); - if (class_exists(AbstractType::class) && method_exists(DoctrineType::class, 'reset')) { - $container->getDefinition('form.type.entity')->addTag('kernel.reset', ['method' => 'reset']); - } - $entityManagers = []; foreach (array_keys($config['entity_managers']) as $name) { $entityManagers[$name] = sprintf('doctrine.orm.%s_entity_manager', $name); @@ -354,17 +343,10 @@ protected function ormLoad(array $config, ContainerBuilder $container) $config['entity_managers'] = $this->fixManagersAutoMappings($config['entity_managers'], $container->getParameter('kernel.bundles')); - $loadPropertyInfoExtractor = interface_exists('Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface') - && class_exists('Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor'); - foreach ($config['entity_managers'] as $name => $entityManager) { $entityManager['name'] = $name; $this->loadOrmEntityManager($entityManager, $container); - if (! $loadPropertyInfoExtractor) { - continue; - } - $this->loadPropertyInfoExtractor($name, $container); } @@ -378,41 +360,19 @@ protected function ormLoad(array $config, ContainerBuilder $container) ]); } - // BC: ResolveTargetEntityListener implements the subscriber interface since - // v2.5.0-beta1 (Commit 437f812) - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - $def->addTag('doctrine.event_listener', ['event' => 'loadClassMetadata']); - } else { - $def->addTag('doctrine.event_subscriber'); - } + $def->addTag('doctrine.event_subscriber'); } - // if is for Symfony 3.2 and lower compat - if (method_exists($container, 'registerForAutoconfiguration')) { - $container->registerForAutoconfiguration(ServiceEntityRepositoryInterface::class) - ->addTag(ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG); - } + $container->registerForAutoconfiguration(ServiceEntityRepositoryInterface::class) + ->addTag(ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG); // If the Messenger component is installed and the doctrine transaction middleware is available, wire it: - if (interface_exists(MessageBusInterface::class) && class_exists(DoctrineTransactionMiddleware::class)) { - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - $loader->load('messenger.xml'); - } - - /* - * Compatibility for Symfony 3.2 and lower: gives the service a default argument. - * When DoctrineBundle requires 3.3 or higher, this can be moved to an anonymous - * service in orm.xml. - * - * This is replaced with a true locator by ServiceRepositoryCompilerPass. - * This makes that pass technically optional (good for tests). - */ - if (! class_exists(ServiceLocator::class)) { + if (! interface_exists(MessageBusInterface::class) || ! class_exists(DoctrineTransactionMiddleware::class)) { return; } - $container->getDefinition('doctrine.orm.container_repository_factory') - ->replaceArgument(0, (new Definition(ServiceLocator::class))->setArgument(0, [])); + $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader->load('messenger.xml'); } /** @@ -423,8 +383,7 @@ protected function ormLoad(array $config, ContainerBuilder $container) */ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $container) { - $definitionClassname = $this->getDefinitionClassname(); - $ormConfigDef = $container->setDefinition(sprintf('doctrine.orm.%s_configuration', $entityManager['name']), new $definitionClassname('doctrine.orm.configuration')); + $ormConfigDef = $container->setDefinition(sprintf('doctrine.orm.%s_configuration', $entityManager['name']), new ChildDefinition('doctrine.orm.configuration')); $this->loadOrmEntityManagerMappingInformation($entityManager, $ormConfigDef, $container); $this->loadOrmCacheDrivers($entityManager, $container); @@ -447,30 +406,18 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $ 'setAutoGenerateProxyClasses' => '%doctrine.orm.auto_generate_proxy_classes%', 'setClassMetadataFactoryName' => $entityManager['class_metadata_factory_name'], 'setDefaultRepositoryClassName' => $entityManager['default_repository_class'], + 'setNamingStrategy' => new Reference($entityManager['naming_strategy']), + 'setQuoteStrategy' => new Reference($entityManager['quote_strategy']), + 'setEntityListenerResolver' => new Reference(sprintf('doctrine.orm.%s_entity_listener_resolver', $entityManager['name'])), ]; - // check for version to keep BC - if (version_compare(Version::VERSION, '2.3.0-DEV') >= 0) { - $methods = array_merge($methods, [ - 'setNamingStrategy' => new Reference($entityManager['naming_strategy']), - 'setQuoteStrategy' => new Reference($entityManager['quote_strategy']), - ]); - } - - if (version_compare(Version::VERSION, '2.4.0-DEV') >= 0) { - $methods = array_merge($methods, [ - 'setEntityListenerResolver' => new Reference(sprintf('doctrine.orm.%s_entity_listener_resolver', $entityManager['name'])), - ]); - } - if (version_compare(Version::VERSION, '2.5.0-DEV') >= 0) { - $listenerId = sprintf('doctrine.orm.%s_listeners.attach_entity_listeners', $entityManager['name']); - $listenerDef = $container->setDefinition($listenerId, new Definition('%doctrine.orm.listeners.attach_entity_listeners.class%')); - $listenerTagParams = ['event' => 'loadClassMetadata']; - if (isset($entityManager['connection'])) { - $listenerTagParams['connection'] = $entityManager['connection']; - } - $listenerDef->addTag('doctrine.event_listener', $listenerTagParams); + $listenerId = sprintf('doctrine.orm.%s_listeners.attach_entity_listeners', $entityManager['name']); + $listenerDef = $container->setDefinition($listenerId, new Definition('%doctrine.orm.listeners.attach_entity_listeners.class%')); + $listenerTagParams = ['event' => 'loadClassMetadata']; + if (isset($entityManager['connection'])) { + $listenerTagParams['connection'] = $entityManager['connection']; } + $listenerDef->addTag('doctrine.event_listener', $listenerTagParams); if (isset($entityManager['second_level_cache'])) { $this->loadOrmSecondLevelCache($entityManager, $ormConfigDef, $container); @@ -516,7 +463,7 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $ $managerConfiguratorName = sprintf('doctrine.orm.%s_manager_configurator', $entityManager['name']); $container - ->setDefinition($managerConfiguratorName, new $definitionClassname('doctrine.orm.manager_configurator.abstract')) + ->setDefinition($managerConfiguratorName, new ChildDefinition('doctrine.orm.manager_configurator.abstract')) ->replaceArgument(0, $enabledFilters) ->replaceArgument(1, $filtersParameters); @@ -525,7 +472,7 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $ } $container - ->setDefinition(sprintf('doctrine.orm.%s_entity_manager', $entityManager['name']), new $definitionClassname('doctrine.orm.entity_manager.abstract')) + ->setDefinition(sprintf('doctrine.orm.%s_entity_manager', $entityManager['name']), new ChildDefinition('doctrine.orm.entity_manager.abstract')) ->setPublic(true) ->setArguments([ new Reference(sprintf('doctrine.dbal.%s_connection', $entityManager['connection'])), @@ -640,10 +587,6 @@ protected function loadOrmEntityManagerMappingInformation(array $entityManager, */ protected function loadOrmSecondLevelCache(array $entityManager, Definition $ormConfigDef, ContainerBuilder $container) { - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - throw new \InvalidArgumentException('Second-level cache requires doctrine-orm 2.5.0 or newer'); - } - $driverId = null; $enabled = $entityManager['second_level_cache']['enabled']; @@ -849,12 +792,4 @@ public function getConfiguration(array $config, ContainerBuilder $container) { return new Configuration($container->getParameter('kernel.debug')); } - - /** - * @return string - */ - private function getDefinitionClassname() - { - return class_exists(ChildDefinition::class) ? ChildDefinition::class : DefinitionDecorator::class; - } } diff --git a/DoctrineBundle.php b/DoctrineBundle.php index d1f84ae5d..5aeee62cd 100644 --- a/DoctrineBundle.php +++ b/DoctrineBundle.php @@ -105,7 +105,7 @@ public function shutdown() // Clear all entity managers to clear references to entities for GC if ($this->container->hasParameter('doctrine.entity_managers')) { foreach ($this->container->getParameter('doctrine.entity_managers') as $id) { - if (method_exists($this->container, 'initialized') && ! $this->container->initialized($id)) { + if (! $this->container->initialized($id)) { continue; } @@ -119,7 +119,7 @@ public function shutdown() } foreach ($this->container->getParameter('doctrine.connections') as $id) { - if (method_exists($this->container, 'initialized') && ! $this->container->initialized($id)) { + if (! $this->container->initialized($id)) { continue; } diff --git a/Repository/ContainerRepositoryFactory.php b/Repository/ContainerRepositoryFactory.php index cd1b47202..ae668e097 100644 --- a/Repository/ContainerRepositoryFactory.php +++ b/Repository/ContainerRepositoryFactory.php @@ -10,7 +10,6 @@ use InvalidArgumentException; use Psr\Container\ContainerInterface; use RuntimeException; -use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; /** * Fetches repositories from the container or falls back to normal creation. @@ -30,7 +29,7 @@ public function __construct(ContainerInterface $container = null) { // When DoctrineBundle requires Symfony 3.3+, this can be removed // and the $container argument can become required. - if ($container === null && class_exists(ServiceLocatorTagPass::class)) { + if ($container === null) { throw new InvalidArgumentException(sprintf('The first argument of %s::__construct() is required on Symfony 3.3 or higher.', self::class)); } @@ -60,11 +59,6 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName // if not in the container but the class/id implements the interface, throw an error if (is_a($customRepositoryName, ServiceEntityRepositoryInterface::class, true)) { - // can be removed when DoctrineBundle requires Symfony 3.3 - if ($this->container === null) { - throw new RuntimeException(sprintf('Support for loading entities from the service container only works for Symfony 3.3 or higher. Upgrade your version of Symfony or make sure your "%s" class does not implement "%s"', $customRepositoryName, ServiceEntityRepositoryInterface::class)); - } - throw new RuntimeException(sprintf('The "%s" entity repository implements "%s", but its service could not be found. Make sure the service exists and is tagged with "%s".', $customRepositoryName, ServiceEntityRepositoryInterface::class, ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG)); } diff --git a/Resources/config/orm.xml b/Resources/config/orm.xml index 78b039c55..0fe60c165 100644 --- a/Resources/config/orm.xml +++ b/Resources/config/orm.xml @@ -103,7 +103,11 @@ - null + + + + + diff --git a/Tests/ConnectionFactoryTest.php b/Tests/ConnectionFactoryTest.php index 04ff6fad9..ea0873911 100644 --- a/Tests/ConnectionFactoryTest.php +++ b/Tests/ConnectionFactoryTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Exception\DriverException; +use Doctrine\ORM\Version; use Exception; class ConnectionFactoryTest extends TestCase @@ -14,7 +15,7 @@ protected function setUp() { parent::setUp(); - if (class_exists('Doctrine\\ORM\\Version')) { + if (class_exists(Version::class)) { return; } diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index 07d393db4..073ecb0c7 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Bundle\DoctrineBundle\Tests; use Doctrine\DBAL\Types\Type; +use Doctrine\ORM\Version; use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface; class ContainerTest extends TestCase @@ -11,7 +12,7 @@ protected function setUp() { parent::setUp(); - if (class_exists('Doctrine\\ORM\\Version')) { + if (class_exists(Version::class)) { return; } @@ -48,14 +49,9 @@ public function testContainer() $this->assertFalse($container->has('doctrine.dbal.default_connection.events.mysqlsessioninit')); - if (interface_exists('Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface') && class_exists('Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor')) { - if (! interface_exists(PropertyInitializableExtractorInterface::class)) { - $this->assertInstanceOf('Doctrine\Common\Persistence\Mapping\ClassMetadataFactory', $container->get('doctrine.orm.default_entity_manager.metadata_factory')); - } - $this->assertInstanceOf('Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor', $container->get('doctrine.orm.default_entity_manager.property_info_extractor')); - } else { - $this->assertFalse($container->has('doctrine.orm.default_entity_manager.metadata_factory')); - $this->assertFalse($container->has('doctrine.orm.default_entity_manager.property_info_extractor')); + if (! interface_exists(PropertyInitializableExtractorInterface::class)) { + $this->assertInstanceOf('Doctrine\Common\Persistence\Mapping\ClassMetadataFactory', $container->get('doctrine.orm.default_entity_manager.metadata_factory')); } + $this->assertInstanceOf('Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor', $container->get('doctrine.orm.default_entity_manager.property_info_extractor')); } } diff --git a/Tests/DataCollector/DoctrineDataCollectorTest.php b/Tests/DataCollector/DoctrineDataCollectorTest.php index c6e121279..2ab96ce13 100644 --- a/Tests/DataCollector/DoctrineDataCollectorTest.php +++ b/Tests/DataCollector/DoctrineDataCollectorTest.php @@ -29,11 +29,9 @@ public function testCollectEntities() ->method('getConfiguration') ->will($this->returnValue($config)); - if (method_exists($config, 'isSecondLevelCacheEnabled')) { - $config->expects($this->once()) - ->method('isSecondLevelCacheEnabled') - ->will($this->returnValue(false)); - } + $config->expects($this->once()) + ->method('isSecondLevelCacheEnabled') + ->will($this->returnValue(false)); $metadatas = [ $this->createEntityMetadata(self::FIRST_ENTITY), diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index bf1fd58a1..1f24100bd 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -5,12 +5,10 @@ use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\EntityListenerPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Version; use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterEventListenersAndSubscribersPass; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; -use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; @@ -210,12 +208,7 @@ public function testLoadSimpleSingleConnection() $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); - if (method_exists($definition, 'getFactory')) { - $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); - } else { - $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - } + $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); $this->assertDICConstructorArguments($definition, [ new Reference('doctrine.dbal.default_connection'), @@ -250,12 +243,7 @@ public function testLoadSimpleSingleConnectionWithoutDbName() $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); - if (method_exists($definition, 'getFactory')) { - $factory = $definition->getFactory(); - } else { - $factory[0] = $definition->getFactoryClass(); - $factory[1] = $definition->getFactoryMethod(); - } + $factory = $definition->getFactory(); $this->assertEquals('%doctrine.orm.entity_manager.class%', $factory[0]); $this->assertEquals('create', $factory[1]); @@ -291,12 +279,7 @@ public function testLoadSingleConnection() $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); - if (method_exists($definition, 'setFactory')) { - $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); - } else { - $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - } + $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); $this->assertDICConstructorArguments($definition, [ new Reference('doctrine.dbal.default_connection'), @@ -324,12 +307,7 @@ public function testLoadMultipleConnections() $definition = $container->getDefinition('doctrine.orm.em1_entity_manager'); $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); - if (method_exists($definition, 'getFactory')) { - $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); - } else { - $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - } + $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); $arguments = $definition->getArguments(); $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); @@ -348,12 +326,7 @@ public function testLoadMultipleConnections() $definition = $container->getDefinition('doctrine.orm.em2_entity_manager'); $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); - if (method_exists($definition, 'getFactory')) { - $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); - } else { - $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - } + $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); $arguments = $definition->getArguments(); $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); @@ -567,9 +540,6 @@ public function testSetCustomFunctions() public function testSetNamingStrategy() { - if (version_compare(Version::VERSION, '2.3.0-DEV') < 0) { - $this->markTestSkipped('Naming Strategies are not available'); - } $container = $this->loadContainer('orm_namingstrategy'); $def1 = $container->getDefinition('doctrine.orm.em1_configuration'); @@ -581,9 +551,6 @@ public function testSetNamingStrategy() public function testSetQuoteStrategy() { - if (version_compare(Version::VERSION, '2.3.0-DEV') < 0) { - $this->markTestSkipped('Quote Strategies are not available'); - } $container = $this->loadContainer('orm_quotestrategy'); $def1 = $container->getDefinition('doctrine.orm.em1_configuration'); @@ -595,10 +562,6 @@ public function testSetQuoteStrategy() public function testSecondLevelCache() { - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - $this->markTestSkipped('Second-level cache requires doctrine-orm 2.5.0 or newer'); - } - $container = $this->loadContainer('orm_second_level_cache'); $this->assertTrue($container->has('doctrine.orm.default_configuration')); @@ -698,19 +661,11 @@ public function testResolveTargetEntity() $definition = $container->getDefinition('doctrine.orm.listeners.resolve_target_entity'); $this->assertDICDefinitionMethodCallOnce($definition, 'addResolveTargetEntity', ['Symfony\Component\Security\Core\User\UserInterface', 'MyUserClass', []]); - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - $this->assertEquals(['doctrine.event_listener' => [['event' => 'loadClassMetadata']]], $definition->getTags()); - } else { - $this->assertEquals(['doctrine.event_subscriber' => [[]]], $definition->getTags()); - } + $this->assertEquals(['doctrine.event_subscriber' => [[]]], $definition->getTags()); } public function testAttachEntityListeners() { - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - $this->markTestSkipped('This test requires ORM 2.5-dev.'); - } - $container = $this->loadContainer('orm_attach_entity_listener'); $definition = $container->getDefinition('doctrine.orm.default_listeners.attach_entity_listeners'); @@ -817,14 +772,10 @@ public function testEntityListenerResolver() $container = $this->loadContainer('orm_entity_listener_resolver', ['YamlBundle'], new EntityListenerPass()); $definition = $container->getDefinition('doctrine.orm.em1_configuration'); - if (version_compare(Version::VERSION, '2.4.0-DEV') >= 0) { - $this->assertDICDefinitionMethodCallOnce($definition, 'setEntityListenerResolver', [new Reference('doctrine.orm.em1_entity_listener_resolver')]); - } + $this->assertDICDefinitionMethodCallOnce($definition, 'setEntityListenerResolver', [new Reference('doctrine.orm.em1_entity_listener_resolver')]); $definition = $container->getDefinition('doctrine.orm.em2_configuration'); - if (version_compare(Version::VERSION, '2.4.0-DEV') >= 0) { - $this->assertDICDefinitionMethodCallOnce($definition, 'setEntityListenerResolver', [new Reference('doctrine.orm.em2_entity_listener_resolver')]); - } + $this->assertDICDefinitionMethodCallOnce($definition, 'setEntityListenerResolver', [new Reference('doctrine.orm.em2_entity_listener_resolver')]); $listener = $container->getDefinition('doctrine.orm.em1_entity_listener_resolver'); $this->assertDICDefinitionMethodCallOnce($listener, 'register', [new Reference('entity_listener1')]); @@ -835,10 +786,6 @@ public function testEntityListenerResolver() public function testAttachEntityListenerTag() { - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - $this->markTestSkipped('Attaching entity listeners by tag requires doctrine-orm 2.5.0 or newer'); - } - $container = $this->getContainer([]); $loader = new DoctrineExtension(); $container->registerExtension($loader); @@ -863,10 +810,6 @@ public function testAttachEntityListenerTag() public function testAttachEntityListenersTwoConnections() { - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - $this->markTestSkipped('Attaching entity listeners by tag requires doctrine-orm 2.5.0 or newer'); - } - $container = $this->getContainer(['YamlBundle']); $loader = new DoctrineExtension(); $container->registerExtension($loader); @@ -887,10 +830,6 @@ public function testAttachEntityListenersTwoConnections() public function testAttachLazyEntityListener() { - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - $this->markTestSkipped('Attaching entity listeners by tag requires doctrine-orm 2.5.0 or newer'); - } - $container = $this->getContainer([]); $loader = new DoctrineExtension(); $container->registerExtension($loader); @@ -913,10 +852,6 @@ public function testAttachLazyEntityListener() */ public function testLazyEntityListenerResolverWithoutCorrectInterface() { - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - $this->markTestSkipped('Attaching entity listeners by tag requires doctrine-orm 2.5.0 or newer'); - } - $container = $this->getContainer([]); $loader = new DoctrineExtension(); $container->registerExtension($loader); @@ -929,10 +864,6 @@ public function testLazyEntityListenerResolverWithoutCorrectInterface() public function testPrivateLazyEntityListener() { - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - $this->markTestSkipped('Attaching entity listeners by tag requires doctrine-orm 2.5.0 or newer'); - } - $container = $this->getContainer([]); $loader = new DoctrineExtension(); $container->registerExtension($loader); @@ -951,10 +882,6 @@ public function testPrivateLazyEntityListener() */ public function testAbstractLazyEntityListener() { - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - $this->markTestSkipped('Attaching entity listeners by tag requires doctrine-orm 2.5.0 or newer'); - } - $container = $this->getContainer([]); $loader = new DoctrineExtension(); $container->registerExtension($loader); @@ -1116,7 +1043,7 @@ private function assertDICDefinitionNoMethodCall(Definition $definition, $method private function compileContainer(ContainerBuilder $container) { - $container->getCompilerPassConfig()->setOptimizationPasses([class_exists(ResolveChildDefinitionsPass::class) ? new ResolveChildDefinitionsPass() : new ResolveDefinitionTemplatesPass()]); + $container->getCompilerPassConfig()->setOptimizationPasses([new ResolveChildDefinitionsPass()]); $container->getCompilerPassConfig()->setRemovingPasses([]); $container->compile(); } diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index 54312c952..cd20392d6 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -10,10 +10,8 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Version; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; -use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; @@ -147,10 +145,6 @@ public function testAutomapping(array $entityManagers) { $extension = new DoctrineExtension(); - if (! method_exists($extension, 'fixManagersAutoMappings')) { - $this->markTestSkipped('Auto mapping with multiple managers available with Symfony ~2.6'); - } - $container = $this->getContainer([ 'YamlBundle', 'XmlBundle', @@ -303,12 +297,7 @@ public function testDependencyInjectionConfigurationDefaults() $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); - if (method_exists($definition, 'getFactory')) { - $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); - } else { - $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - } + $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); $this->assertEquals(['default' => 'doctrine.orm.default_entity_manager'], $container->getParameter('doctrine.entity_managers'), 'Set of the existing EntityManagers names is incorrect.'); $this->assertEquals('%doctrine.entity_managers%', $container->getDefinition('doctrine')->getArgument(2), 'Set of the existing EntityManagers names is incorrect.'); @@ -326,13 +315,9 @@ public function testDependencyInjectionConfigurationDefaults() $this->assertEquals('doctrine.orm.default_query_cache', (string) $calls[2][1][0]); $this->assertEquals('doctrine.orm.default_result_cache', (string) $calls[3][1][0]); - if (version_compare(Version::VERSION, '2.3.0-DEV') >= 0) { - $this->assertEquals('doctrine.orm.naming_strategy.default', (string) $calls[10][1][0]); - $this->assertEquals('doctrine.orm.quote_strategy.default', (string) $calls[11][1][0]); - } - if (version_compare(Version::VERSION, '2.4.0-DEV') >= 0) { - $this->assertEquals('doctrine.orm.default_entity_listener_resolver', (string) $calls[12][1][0]); - } + $this->assertEquals('doctrine.orm.naming_strategy.default', (string) $calls[10][1][0]); + $this->assertEquals('doctrine.orm.quote_strategy.default', (string) $calls[11][1][0]); + $this->assertEquals('doctrine.orm.default_entity_listener_resolver', (string) $calls[12][1][0]); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_metadata_cache')); $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); @@ -400,12 +385,7 @@ public function testSingleEntityManagerWithDefaultConfiguration() $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); - if (method_exists($definition, 'getFactory')) { - $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); - } else { - $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - } + $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); $this->assertDICConstructorArguments($definition, [ new Reference('doctrine.dbal.default_connection'), @@ -415,9 +395,6 @@ public function testSingleEntityManagerWithDefaultConfiguration() public function testSingleEntityManagerWithDefaultSecondLevelCacheConfiguration() { - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - $this->markTestSkipped(sprintf('Second Level cache not supported by this version of the ORM : %s', Version::VERSION)); - } $container = $this->getContainer(); $extension = new DoctrineExtension(); @@ -430,12 +407,7 @@ public function testSingleEntityManagerWithDefaultSecondLevelCacheConfiguration( $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); - if (method_exists($definition, 'getFactory')) { - $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); - } else { - $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - } + $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); $this->assertDICConstructorArguments($definition, [ new Reference('doctrine.dbal.default_connection'), @@ -448,9 +420,6 @@ public function testSingleEntityManagerWithDefaultSecondLevelCacheConfiguration( public function testSingleEntityManagerWithCustomSecondLevelCacheConfiguration() { - if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { - $this->markTestSkipped(sprintf('Second Level cache not supported by this version of the ORM : %s', Version::VERSION)); - } $container = $this->getContainer(); $extension = new DoctrineExtension(); @@ -469,12 +438,7 @@ public function testSingleEntityManagerWithCustomSecondLevelCacheConfiguration() $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); - if (method_exists($definition, 'getFactory')) { - $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); - } else { - $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - } + $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); $this->assertDICConstructorArguments($definition, [ new Reference('doctrine.dbal.default_connection'), @@ -829,7 +793,7 @@ private function assertDICDefinitionMethodCallOnce(Definition $definition, $meth private function compileContainer(ContainerBuilder $container) { - $container->getCompilerPassConfig()->setOptimizationPasses([class_exists(ResolveChildDefinitionsPass::class) ? new ResolveChildDefinitionsPass() : new ResolveDefinitionTemplatesPass()]); + $container->getCompilerPassConfig()->setOptimizationPasses([new ResolveChildDefinitionsPass()]); $container->getCompilerPassConfig()->setRemovingPasses([]); $container->compile(); } diff --git a/Tests/Mapping/ContainerAwareEntityListenerResolverTest.php b/Tests/Mapping/ContainerAwareEntityListenerResolverTest.php index cbfad8b00..696c77419 100644 --- a/Tests/Mapping/ContainerAwareEntityListenerResolverTest.php +++ b/Tests/Mapping/ContainerAwareEntityListenerResolverTest.php @@ -17,10 +17,6 @@ class ContainerAwareEntityListenerResolverTest extends TestCase protected function setUp() { - if (! interface_exists('\Doctrine\ORM\Mapping\EntityListenerResolver')) { - $this->markTestSkipped('Entity listeners are not supported in this Doctrine version'); - } - parent::setUp(); $this->container = $this->getMockForAbstractClass('\Symfony\Component\DependencyInjection\ContainerInterface'); diff --git a/Tests/Mapping/DisconnectedMetadataFactoryTest.php b/Tests/Mapping/DisconnectedMetadataFactoryTest.php index a1c18fc70..012d0c488 100644 --- a/Tests/Mapping/DisconnectedMetadataFactoryTest.php +++ b/Tests/Mapping/DisconnectedMetadataFactoryTest.php @@ -6,6 +6,7 @@ use Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory; use Doctrine\Bundle\DoctrineBundle\Tests\TestCase; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Version; class DisconnectedMetadataFactoryTest extends TestCase { @@ -13,7 +14,7 @@ protected function setUp() { parent::setUp(); - if (class_exists('Doctrine\\ORM\\Version')) { + if (class_exists(Version::class)) { return; } diff --git a/Tests/ProfilerTest.php b/Tests/ProfilerTest.php index 158341d2d..8391a36f2 100644 --- a/Tests/ProfilerTest.php +++ b/Tests/ProfilerTest.php @@ -14,7 +14,6 @@ use Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; use Symfony\Component\HttpKernel\Fragment\FragmentHandler; use Symfony\Component\HttpKernel\Profiler\Profile; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -70,14 +69,6 @@ public function testRender() $profile = new Profile('foo'); - // This is only needed for WebProfilerBundle=3.2, remove when support for it is dropped - $requestCollector = new RequestDataCollector(); - $requestCollector->collect($request, $response); - if (method_exists($requestCollector, 'lateCollect')) { - $requestCollector->lateCollect(); - } - $profile->addCollector($requestCollector); - $output = $this->twig->render('db.html.twig', [ 'request' => $request, 'token' => 'foo', diff --git a/Tests/Repository/ContainerRepositoryFactoryTest.php b/Tests/Repository/ContainerRepositoryFactoryTest.php index a3a3b47b8..63a44368a 100644 --- a/Tests/Repository/ContainerRepositoryFactoryTest.php +++ b/Tests/Repository/ContainerRepositoryFactoryTest.php @@ -17,10 +17,6 @@ class ContainerRepositoryFactoryTest extends TestCase { public function testGetRepositoryReturnsService() { - if (! interface_exists(ContainerInterface::class)) { - $this->markTestSkipped('Symfony 3.3 is needed for this feature.'); - } - $em = $this->createEntityManager(['Foo\CoolEntity' => 'my_repo']); $repo = new StubRepository($em, new ClassMetadata('')); $container = $this->createContainer(['my_repo' => $repo]); @@ -31,10 +27,6 @@ public function testGetRepositoryReturnsService() public function testGetRepositoryReturnsEntityRepository() { - if (! interface_exists(ContainerInterface::class)) { - $this->markTestSkipped('Symfony 3.3 is needed for this feature.'); - } - $container = $this->createContainer([]); $em = $this->createEntityManager(['Foo\BoringEntity' => null]); @@ -47,10 +39,6 @@ public function testGetRepositoryReturnsEntityRepository() public function testCustomRepositoryIsReturned() { - if (! interface_exists(ContainerInterface::class)) { - $this->markTestSkipped('Symfony 3.3 is needed for this feature.'); - } - $container = $this->createContainer([]); $em = $this->createEntityManager([ 'Foo\CustomNormalRepoEntity' => StubRepository::class, @@ -69,10 +57,6 @@ public function testCustomRepositoryIsReturned() */ public function testServiceRepositoriesMustExtendObjectRepository() { - if (! interface_exists(ContainerInterface::class)) { - $this->markTestSkipped('Symfony 3.3 is needed for this feature.'); - } - $repo = new stdClass(); $container = $this->createContainer(['my_repo' => $repo]); @@ -85,10 +69,6 @@ public function testServiceRepositoriesMustExtendObjectRepository() public function testServiceRepositoriesCanNotExtendsEntityRepository() { - if (! interface_exists(ContainerInterface::class)) { - $this->markTestSkipped('Symfony 3.3 is needed for this feature.'); - } - $repo = $this->getMockBuilder(ObjectRepository::class)->getMock(); $container = $this->createContainer(['my_repo' => $repo]); @@ -108,10 +88,6 @@ public function testServiceRepositoriesCanNotExtendsEntityRepository() */ public function testRepositoryMatchesServiceInterfaceButServiceNotFound() { - if (! interface_exists(ContainerInterface::class)) { - $this->markTestSkipped('Symfony 3.3 is needed for this feature.'); - } - $container = $this->createContainer([]); $em = $this->createEntityManager([ @@ -128,12 +104,7 @@ public function testRepositoryMatchesServiceInterfaceButServiceNotFound() */ public function testCustomRepositoryIsNotAValidClass() { - if (interface_exists(ContainerInterface::class)) { - $container = $this->createContainer([]); - } else { - // Symfony 3.2 and lower support - $container = null; - } + $container = $this->createContainer([]); $em = $this->createEntityManager(['Foo\CoolEntity' => 'not_a_real_class']); diff --git a/Tests/ServiceRepositoryTest.php b/Tests/ServiceRepositoryTest.php index 983c46d64..21754f707 100644 --- a/Tests/ServiceRepositoryTest.php +++ b/Tests/ServiceRepositoryTest.php @@ -8,15 +8,14 @@ use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; +use Doctrine\ORM\Version; use Fixtures\Bundles\RepositoryServiceBundle\Entity\TestCustomClassRepoEntity; use Fixtures\Bundles\RepositoryServiceBundle\Entity\TestCustomServiceRepoEntity; use Fixtures\Bundles\RepositoryServiceBundle\Entity\TestDefaultRepoEntity; use Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomClassRepoRepository; use Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomServiceRepoRepository; use Fixtures\Bundles\RepositoryServiceBundle\RepositoryServiceBundle; -use RuntimeException; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; @@ -26,7 +25,7 @@ protected function setUp() { parent::setUp(); - if (class_exists('Doctrine\\ORM\\Version')) { + if (class_exists(Version::class)) { return; } @@ -71,15 +70,8 @@ public function testRepositoryServiceWiring() // create a public alias so we can use it below for testing $container->setAlias('test_alias__' . TestCustomServiceRepoRepository::class, new Alias(TestCustomServiceRepoRepository::class, true)); - // Symfony 2.7 compat - can be moved above later - if (method_exists($def, 'setAutowired')) { - $def->setAutowired(true); - } - - // Symfony 3.3 and higher: autowire definition so it receives the tags - if (class_exists(ServiceLocatorTagPass::class)) { - $def->setAutoconfigured(true); - } + $def->setAutowired(true); + $def->setAutoconfigured(true); $container->addCompilerPass(new ServiceRepositoryCompilerPass()); $container->compile(); @@ -100,19 +92,6 @@ public function testRepositoryServiceWiring() // a smoke test, trying one of the methods $this->assertSame(TestDefaultRepoEntity::class, $genericRepository->getClassName()); - // Symfony 3.2 and lower should work normally in traditional cases (tested above) - // the code below should *not* work (by design) - if (! class_exists(ServiceLocatorTagPass::class)) { - $message = '/Support for loading entities from the service container only works for Symfony 3\.3/'; - if (method_exists($this, 'expectException')) { - $this->expectException(RuntimeException::class); - $this->expectExceptionMessageRegExp($message); - } else { - // PHPUnit 4 compat - $this->setExpectedExceptionRegExp(RuntimeException::class, $message); - } - } - // custom service repository $customServiceRepo = $em->getRepository(TestCustomServiceRepoEntity::class); $this->assertSame($customServiceRepo, $container->get('test_alias__' . TestCustomServiceRepoRepository::class)); diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 5a7c8375c..09a976f3a 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -5,10 +5,10 @@ use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType; use Doctrine\Common\Annotations\AnnotationReader; +use Doctrine\ORM\Version; use PHPUnit\Framework\TestCase as BaseTestCase; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; -use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; @@ -17,7 +17,7 @@ class TestCase extends BaseTestCase { protected function setUp() { - if (class_exists('Doctrine\\Common\\Version')) { + if (class_exists(Version::class)) { return; } @@ -70,7 +70,7 @@ public function createYamlBundleTestContainer() $container->setDefinition('my.platform', new Definition('Doctrine\DBAL\Platforms\MySqlPlatform'))->setPublic(true); - $container->getCompilerPassConfig()->setOptimizationPasses([class_exists(ResolveChildDefinitionsPass::class) ? new ResolveChildDefinitionsPass() : new ResolveDefinitionTemplatesPass()]); + $container->getCompilerPassConfig()->setOptimizationPasses([new ResolveChildDefinitionsPass()]); $container->getCompilerPassConfig()->setRemovingPasses([]); // make all Doctrine services public, so we can fetch them in the test $container->getCompilerPassConfig()->addPass(new TestCaseAllPublicCompilerPass()); diff --git a/Twig/DoctrineExtension.php b/Twig/DoctrineExtension.php index 6df74cdbe..7361bc085 100644 --- a/Twig/DoctrineExtension.php +++ b/Twig/DoctrineExtension.php @@ -277,8 +277,7 @@ public static function escapeFunction($parameter) public function replaceQueryParameters($query, $parameters) { if ($parameters instanceof Data) { - // VarDumper < 3.3 compatibility layer - $parameters = method_exists($parameters, 'getValue') ? $parameters->getValue(true) : $parameters->getRawData(); + $parameters = $parameters->getValue(true); } $i = 0; diff --git a/composer.json b/composer.json index 86e04d70f..3910633e8 100644 --- a/composer.json +++ b/composer.json @@ -24,28 +24,30 @@ } ], "require": { - "php": "^5.5.9|^7.0", - "symfony/framework-bundle": "^2.7.22|~3.0|~4.0", - "symfony/console": "~2.7|~3.0|~4.0", - "symfony/dependency-injection": "~2.7|~3.0|~4.0", + "php": "^7.1", + "symfony/framework-bundle": "^3.4|^4.1", + "symfony/config": "^3.4|^4.1", + "symfony/console": "^3.4|^4.1", + "symfony/dependency-injection": "^3.4|^4.1", "doctrine/dbal": "^2.5.12", "jdorn/sql-formatter": "^1.2.16", - "symfony/doctrine-bridge": "~2.7|~3.0|~4.0", + "symfony/doctrine-bridge": "^3.4|^4.1", "doctrine/doctrine-cache-bundle": "~1.2" }, "require-dev": { - "doctrine/orm": "~2.4", - "symfony/yaml": "~2.7|~3.0|~4.0", - "symfony/validator": "~2.7|~3.0|~4.0", - "symfony/property-info": "~2.8|~3.0|~4.0", - "symfony/phpunit-bridge": "~2.7|~3.0|~4.0", - "twig/twig": "~1.26|~2.0", + "doctrine/orm": "^2.6", + "symfony/yaml": "^3.4|^4.1", + "symfony/validator": "^3.4|^4.1", + "symfony/property-info": "^3.4|^4.1", + "symfony/phpunit-bridge": "^4.2", + "twig/twig": "^1.26|^2.0", "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^4.8.36|^5.7|^6.4", - "symfony/web-profiler-bundle": "~2.7|~3.0|~4.0" + "phpunit/phpunit": "7.0", + "symfony/web-profiler-bundle": "^3.4|^4.1", + "doctrine/coding-standard": "^5.0" }, "conflict": { - "symfony/http-foundation": "<2.6" + "doctrine/orm": "<2.6" }, "suggest": { "symfony/web-profiler-bundle": "To use the data collector.", @@ -59,7 +61,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.9.x-dev" + "dev-master": "1.11.x-dev" } } }