diff --git a/Command/CreateDatabaseDoctrineCommand.php b/Command/CreateDatabaseDoctrineCommand.php index e3eddb70a..6e4fbfe01 100644 --- a/Command/CreateDatabaseDoctrineCommand.php +++ b/Command/CreateDatabaseDoctrineCommand.php @@ -48,6 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (empty($connectionName)) { $connectionName = $this->getDoctrine()->getDefaultConnectionName(); } + $connection = $this->getDoctrineConnection($connectionName); $ifNotExists = $input->getOption('if-not-exists'); @@ -86,6 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (! $name) { throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be created."); } + // Need to get rid of _every_ occurrence of dbname from connection configuration and we have already extracted all relevant info from url unset($params['dbname'], $params['path'], $params['url']); diff --git a/Command/DropDatabaseDoctrineCommand.php b/Command/DropDatabaseDoctrineCommand.php index 12368d4dc..b9f29566d 100644 --- a/Command/DropDatabaseDoctrineCommand.php +++ b/Command/DropDatabaseDoctrineCommand.php @@ -57,6 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (empty($connectionName)) { $connectionName = $this->getDoctrine()->getDefaultConnectionName(); } + $connection = $this->getDoctrineConnection($connectionName); $ifExists = $input->getOption('if-exists'); @@ -91,6 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (! $name) { throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped."); } + unset($params['dbname'], $params['url']); if (! $input->getOption('force')) { diff --git a/Command/ImportMappingDoctrineCommand.php b/Command/ImportMappingDoctrineCommand.php index ea09dea1e..9b5b290c3 100644 --- a/Command/ImportMappingDoctrineCommand.php +++ b/Command/ImportMappingDoctrineCommand.php @@ -142,12 +142,14 @@ protected function execute(InputInterface $input, OutputInterface $output) } else { $path = $destPath . '/' . str_replace('\\', '.', $className) . '.orm.' . $type; } + $output->writeln(sprintf(' > writing %s', $path)); $code = $exporter->exportClassMetadata($class); $dir = dirname($path); if (! is_dir($dir)) { mkdir($dir, 0775, true); } + file_put_contents($path, $code); chmod($path, 0664); } diff --git a/Command/Proxy/CollectionRegionDoctrineCommand.php b/Command/Proxy/CollectionRegionDoctrineCommand.php index c5df01599..fbacd8eb8 100644 --- a/Command/Proxy/CollectionRegionDoctrineCommand.php +++ b/Command/Proxy/CollectionRegionDoctrineCommand.php @@ -24,6 +24,9 @@ protected function configure() ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } + /** + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) { DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em')); diff --git a/Command/Proxy/ConvertMappingDoctrineCommand.php b/Command/Proxy/ConvertMappingDoctrineCommand.php index 7060d7faa..2fa65c4dc 100644 --- a/Command/Proxy/ConvertMappingDoctrineCommand.php +++ b/Command/Proxy/ConvertMappingDoctrineCommand.php @@ -10,6 +10,8 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use function assert; + /** * Convert Doctrine ORM metadata mapping information between the various supported * formats. @@ -45,8 +47,8 @@ protected function execute(InputInterface $input, OutputInterface $output) */ protected function getExporter($toType, $destPath) { - /** @var AbstractExporter $exporter */ $exporter = parent::getExporter($toType, $destPath); + assert($exporter instanceof AbstractExporter); if ($exporter instanceof XmlExporter) { $exporter->setExtension('.orm.xml'); } elseif ($exporter instanceof YamlExporter) { diff --git a/Command/Proxy/DoctrineCommandHelper.php b/Command/Proxy/DoctrineCommandHelper.php index fee03f9d4..b049f2ed5 100644 --- a/Command/Proxy/DoctrineCommandHelper.php +++ b/Command/Proxy/DoctrineCommandHelper.php @@ -7,6 +7,8 @@ use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; use Symfony\Bundle\FrameworkBundle\Console\Application; +use function assert; + /** * Provides some helper and convenience methods to configure doctrine commands in the context of bundles * and multiple connections/entity managers. @@ -20,8 +22,8 @@ abstract class DoctrineCommandHelper */ public static function setApplicationEntityManager(Application $application, $emName) { - /** @var EntityManager $em */ - $em = $application->getKernel()->getContainer()->get('doctrine')->getManager($emName); + $em = $application->getKernel()->getContainer()->get('doctrine')->getManager($emName); + assert($em instanceof EntityManager); $helperSet = $application->getHelperSet(); $helperSet->set(new ConnectionHelper($em->getConnection()), 'db'); $helperSet->set(new EntityManagerHelper($em), 'em'); diff --git a/Command/Proxy/EntityRegionCacheDoctrineCommand.php b/Command/Proxy/EntityRegionCacheDoctrineCommand.php index 55ea3b86f..ae7a7b6de 100644 --- a/Command/Proxy/EntityRegionCacheDoctrineCommand.php +++ b/Command/Proxy/EntityRegionCacheDoctrineCommand.php @@ -24,6 +24,9 @@ protected function configure() ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } + /** + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) { DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em')); diff --git a/Command/Proxy/QueryRegionCacheDoctrineCommand.php b/Command/Proxy/QueryRegionCacheDoctrineCommand.php index b7b761bb7..6adb3aa50 100644 --- a/Command/Proxy/QueryRegionCacheDoctrineCommand.php +++ b/Command/Proxy/QueryRegionCacheDoctrineCommand.php @@ -24,6 +24,9 @@ protected function configure() ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); } + /** + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) { DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em')); diff --git a/ConnectionFactory.php b/ConnectionFactory.php index 6b40566dc..b32b7da53 100644 --- a/ConnectionFactory.php +++ b/ConnectionFactory.php @@ -12,6 +12,7 @@ use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; + use function is_subclass_of; class ConnectionFactory @@ -51,6 +52,7 @@ public function createConnection(array $params, Configuration $config = null, Ev if (class_exists(DBALException::class)) { throw DBALException::invalidWrapperClass($params['wrapperClass']); } + throw Exception::invalidWrapperClass($params['wrapperClass']); } @@ -103,12 +105,13 @@ public function createConnection(array $params, Configuration $config = null, Ev * @throws DBALException * @throws Exception */ - private function getDatabasePlatform(Connection $connection) : AbstractPlatform + private function getDatabasePlatform(Connection $connection): AbstractPlatform { try { return $connection->getDatabasePlatform(); } catch (DriverException $driverException) { - $exceptionClass = class_exists(DBALException::class)? DBALException::class : Exception::class; + $exceptionClass = class_exists(DBALException::class) ? DBALException::class : Exception::class; + throw new $exceptionClass( 'An exception occurred while establishing a connection to figure out your platform version.' . PHP_EOL . "You can circumvent this by setting a 'server_version' configuration value" . PHP_EOL . PHP_EOL . @@ -123,7 +126,7 @@ private function getDatabasePlatform(Connection $connection) : AbstractPlatform /** * initialize the types */ - private function initializeTypes() : void + private function initializeTypes(): void { foreach ($this->typesConfig as $typeName => $typeConfig) { if (Type::hasType($typeName)) { diff --git a/Controller/ProfilerController.php b/Controller/ProfilerController.php index ab8a49ea7..a5197c78e 100644 --- a/Controller/ProfilerController.php +++ b/Controller/ProfilerController.php @@ -13,6 +13,8 @@ use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\VarDumper\Cloner\Data; +use function assert; + class ProfilerController implements ContainerAwareInterface { /** @var ContainerInterface */ @@ -37,8 +39,8 @@ public function setContainer(ContainerInterface $container = null) */ public function explainAction($token, $connectionName, $query) { - /** @var Profiler $profiler */ $profiler = $this->container->get('profiler'); + assert($profiler instanceof Profiler); $profiler->disable(); $profile = $profiler->loadProfile($token); @@ -53,8 +55,8 @@ public function explainAction($token, $connectionName, $query) return new Response('This query cannot be explained.'); } - /** @var Connection $connection */ $connection = $this->container->get('doctrine')->getConnection($connectionName); + assert($connection instanceof Connection); try { $platform = $connection->getDatabasePlatform(); if ($platform instanceof SqlitePlatform) { @@ -76,8 +78,10 @@ public function explainAction($token, $connectionName, $query) /** * @param mixed[] $query + * + * @return mixed[] */ - private function explainSQLitePlatform(Connection $connection, array $query) + private function explainSQLitePlatform(Connection $connection, array $query): array { $params = $query['params']; @@ -89,7 +93,10 @@ private function explainSQLitePlatform(Connection $connection, array $query) ->fetchAll(PDO::FETCH_ASSOC); } - private function explainSQLServerPlatform(Connection $connection, $query) + /** + * @return mixed[] + */ + private function explainSQLServerPlatform(Connection $connection, string $query): array { if (stripos($query['sql'], 'SELECT') === 0) { $sql = 'SET STATISTICS PROFILE ON; ' . $query['sql'] . '; SET STATISTICS PROFILE OFF;'; @@ -109,7 +116,10 @@ private function explainSQLServerPlatform(Connection $connection, $query) return $stmt->fetchAll(PDO::FETCH_ASSOC); } - private function explainOtherPlatform(Connection $connection, $query) + /** + * @return mixed[] + */ + private function explainOtherPlatform(Connection $connection, string $query): array { $params = $query['params']; diff --git a/DataCollector/DoctrineDataCollector.php b/DataCollector/DoctrineDataCollector.php index 63c240cf5..1987fbb04 100644 --- a/DataCollector/DoctrineDataCollector.php +++ b/DataCollector/DoctrineDataCollector.php @@ -2,11 +2,11 @@ namespace Doctrine\Bundle\DoctrineBundle\DataCollector; +use Doctrine\ORM\Cache\CacheConfiguration; use Doctrine\ORM\Cache\Logging\CacheLoggerChain; use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Tools\SchemaValidator; use Doctrine\Persistence\ManagerRegistry; @@ -15,6 +15,8 @@ use Symfony\Component\HttpFoundation\Response; use Throwable; +use function assert; + class DoctrineDataCollector extends BaseCollector { /** @var ManagerRegistry */ @@ -61,17 +63,16 @@ public function collect(Request $request, Response $response, Throwable $excepti ], ]; - /** @var EntityManager $em */ foreach ($this->registry->getManagers() as $name => $em) { + assert($em instanceof EntityManager); if ($this->shouldValidateSchema) { $entities[$name] = []; - /** @var ClassMetadataFactory $factory */ $factory = $em->getMetadataFactory(); $validator = new SchemaValidator($em); - /** @var ClassMetadataInfo $class */ foreach ($factory->getLoadedMetadata() as $class) { + assert($class instanceof ClassMetadataInfo); if (isset($entities[$name][$class->getName()])) { continue; } @@ -87,8 +88,8 @@ public function collect(Request $request, Response $response, Throwable $excepti } } - /** @var Configuration $emConfig */ - $emConfig = $em->getConfiguration(); + $emConfig = $em->getConfiguration(); + assert($emConfig instanceof Configuration); $slcEnabled = $emConfig->isSecondLevelCacheEnabled(); if (! $slcEnabled) { @@ -97,17 +98,17 @@ public function collect(Request $request, Response $response, Throwable $excepti $caches['enabled'] = true; - /** @var $cacheConfiguration \Doctrine\ORM\Cache\CacheConfiguration */ - /** @var CacheLoggerChain $cacheLoggerChain */ $cacheConfiguration = $emConfig->getSecondLevelCacheConfiguration(); - $cacheLoggerChain = $cacheConfiguration->getCacheLogger(); + assert($cacheConfiguration instanceof CacheConfiguration); + $cacheLoggerChain = $cacheConfiguration->getCacheLogger(); + assert($cacheLoggerChain instanceof CacheLoggerChain); if (! $cacheLoggerChain || ! $cacheLoggerChain->getLogger('statistics')) { continue; } - /** @var StatisticsCacheLogger $cacheLoggerStats */ - $cacheLoggerStats = $cacheLoggerChain->getLogger('statistics'); + $cacheLoggerStats = $cacheLoggerChain->getLogger('statistics'); + assert($cacheLoggerStats instanceof StatisticsCacheLogger); $caches['log_enabled'] = true; $caches['counts']['puts'] += $cacheLoggerStats->getPutCount(); @@ -155,46 +156,73 @@ public function collect(Request $request, Response $response, Throwable $excepti $this->groupedQueries = null; } + /** + * @return array> + */ public function getEntities() { return $this->data['entities']; } + /** + * @return array>> + */ public function getMappingErrors() { return $this->data['errors']; } + /** + * @return int + */ public function getCacheHitsCount() { return $this->data['caches']['counts']['hits']; } + /** + * @return int + */ public function getCachePutsCount() { return $this->data['caches']['counts']['puts']; } + /** + * @return int + */ public function getCacheMissesCount() { return $this->data['caches']['counts']['misses']; } + /** + * @return bool + */ public function getCacheEnabled() { return $this->data['caches']['enabled']; } + /** + * @return array> + */ public function getCacheRegions() { return $this->data['caches']['regions']; } + /** + * @return array + */ public function getCacheCounts() { return $this->data['caches']['counts']; } + /** + * @return int + */ public function getInvalidEntityCount() { if ($this->invalidEntityCount === null) { @@ -204,6 +232,9 @@ public function getInvalidEntityCount() return $this->invalidEntityCount; } + /** + * @return string[] + */ public function getGroupedQueries() { if ($this->groupedQueries !== null) { @@ -222,10 +253,12 @@ public function getGroupedQueries() $connectionGroupedQueries[$key]['count'] = 0; $connectionGroupedQueries[$key]['index'] = $i; // "Explain query" relies on query index in 'queries'. } + $connectionGroupedQueries[$key]['executionMS'] += $query['executionMS']; $connectionGroupedQueries[$key]['count']++; $totalExecutionMS += $query['executionMS']; } + usort($connectionGroupedQueries, static function ($a, $b) { if ($a['executionMS'] === $b['executionMS']) { return 0; @@ -246,7 +279,7 @@ public function getGroupedQueries() return $this->groupedQueries; } - private function executionTimePercentage($executionTimeMS, $totalExecutionTimeMS) + private function executionTimePercentage(int $executionTimeMS, int $totalExecutionTimeMS): float { if ($totalExecutionTimeMS === 0.0 || $totalExecutionTimeMS === 0) { return 0; @@ -255,6 +288,9 @@ private function executionTimePercentage($executionTimeMS, $totalExecutionTimeMS return $executionTimeMS / $totalExecutionTimeMS * 100; } + /** + * @return int + */ public function getGroupedQueryCount() { $count = 0; diff --git a/Dbal/BlacklistSchemaAssetFilter.php b/Dbal/BlacklistSchemaAssetFilter.php index 493e5fb42..58c4a3bd2 100644 --- a/Dbal/BlacklistSchemaAssetFilter.php +++ b/Dbal/BlacklistSchemaAssetFilter.php @@ -3,6 +3,7 @@ namespace Doctrine\Bundle\DoctrineBundle\Dbal; use Doctrine\DBAL\Schema\AbstractAsset; + use function in_array; class BlacklistSchemaAssetFilter @@ -18,7 +19,10 @@ public function __construct(array $blacklist) $this->blacklist = $blacklist; } - public function __invoke($assetName) : bool + /** + * @param string|AbstractAsset $assetName + */ + public function __invoke($assetName): bool { if ($assetName instanceof AbstractAsset) { $assetName = $assetName->getName(); diff --git a/Dbal/Logging/BacktraceLogger.php b/Dbal/Logging/BacktraceLogger.php index 9cd29494a..b761e0e81 100644 --- a/Dbal/Logging/BacktraceLogger.php +++ b/Dbal/Logging/BacktraceLogger.php @@ -9,7 +9,7 @@ final class BacktraceLogger extends DebugStack /** * {@inheritdoc} */ - public function startQuery($sql, ?array $params = null, ?array $types = null) : void + public function startQuery($sql, ?array $params = null, ?array $types = null): void { parent::startQuery($sql, $params, $types); diff --git a/Dbal/ManagerRegistryAwareConnectionProvider.php b/Dbal/ManagerRegistryAwareConnectionProvider.php index 9ef8969df..07e8fdc14 100644 --- a/Dbal/ManagerRegistryAwareConnectionProvider.php +++ b/Dbal/ManagerRegistryAwareConnectionProvider.php @@ -16,12 +16,12 @@ public function __construct(AbstractManagerRegistry $managerRegistry) $this->managerRegistry = $managerRegistry; } - public function getDefaultConnection() : Connection + public function getDefaultConnection(): Connection { return $this->managerRegistry->getConnection(); } - public function getConnection(string $name) : Connection + public function getConnection(string $name): Connection { return $this->managerRegistry->getConnection($name); } diff --git a/Dbal/RegexSchemaAssetFilter.php b/Dbal/RegexSchemaAssetFilter.php index 2a9cbf986..400de2250 100644 --- a/Dbal/RegexSchemaAssetFilter.php +++ b/Dbal/RegexSchemaAssetFilter.php @@ -14,7 +14,10 @@ public function __construct(string $filterExpression) $this->filterExpression = $filterExpression; } - public function __invoke($assetName) : bool + /** + * @param string|AbstractAsset $assetName + */ + public function __invoke($assetName): bool { if ($assetName instanceof AbstractAsset) { $assetName = $assetName->getName(); diff --git a/Dbal/SchemaAssetsFilterManager.php b/Dbal/SchemaAssetsFilterManager.php index 7389a4e53..2003113e9 100644 --- a/Dbal/SchemaAssetsFilterManager.php +++ b/Dbal/SchemaAssetsFilterManager.php @@ -2,6 +2,8 @@ namespace Doctrine\Bundle\DoctrineBundle\Dbal; +use Doctrine\DBAL\Schema\AbstractAsset; + /** * Manages schema filters passed to Connection::setSchemaAssetsFilter() */ @@ -18,7 +20,10 @@ public function __construct(array $schemaAssetFilters) $this->schemaAssetFilters = $schemaAssetFilters; } - public function __invoke($assetName) : bool + /** + * @param string|AbstractAsset $assetName + */ + public function __invoke($assetName): bool { foreach ($this->schemaAssetFilters as $schemaAssetFilter) { if ($schemaAssetFilter($assetName) === false) { diff --git a/DependencyInjection/Compiler/EntityListenerPass.php b/DependencyInjection/Compiler/EntityListenerPass.php index 70ee9db7e..6d8f25058 100644 --- a/DependencyInjection/Compiler/EntityListenerPass.php +++ b/DependencyInjection/Compiler/EntityListenerPass.php @@ -73,6 +73,7 @@ public function process(ContainerBuilder $container) if (! isset($lazyServiceReferencesByResolver[$resolverId])) { $lazyServiceReferencesByResolver[$resolverId] = []; } + $lazyServiceReferencesByResolver[$resolverId][$id] = new Reference($id); } else { $listener->setPublic(true); @@ -88,7 +89,7 @@ public function process(ContainerBuilder $container) } } - private function attachToListener(ContainerBuilder $container, string $name, string $class, array $attributes) : void + private function attachToListener(ContainerBuilder $container, string $name, string $class, array $attributes): void { $listenerId = sprintf('doctrine.orm.%s_listeners.attach_entity_listeners', $name); @@ -111,7 +112,7 @@ private function attachToListener(ContainerBuilder $container, string $name, str $container->findDefinition($listenerId)->addMethodCall('addEntityListener', $args); } - private function getResolverClass(Definition $resolver, ContainerBuilder $container, string $id) : string + private function getResolverClass(Definition $resolver, ContainerBuilder $container, string $id): string { $resolverClass = $this->getConcreteDefinitionClass($resolver, $container, $id); @@ -123,7 +124,7 @@ private function getResolverClass(Definition $resolver, ContainerBuilder $contai return $resolverClass; } - private function getConcreteDefinitionClass(Definition $definition, ContainerBuilder $container, string $id) : string + private function getConcreteDefinitionClass(Definition $definition, ContainerBuilder $container, string $id): string { $class = $definition->getClass(); if ($class) { diff --git a/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php b/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php index e67c8a501..d4f6c65b5 100644 --- a/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php +++ b/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php @@ -11,7 +11,7 @@ final class ServiceRepositoryCompilerPass implements CompilerPassInterface { const REPOSITORY_SERVICE_TAG = 'doctrine.repository_service'; - public function process(ContainerBuilder $container) : void + public function process(ContainerBuilder $container): void { // when ORM is not enabled if (! $container->hasDefinition('doctrine.orm.container_repository_factory')) { diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 0d153f1e6..fbc9a6f9d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -10,7 +10,9 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\DependencyInjection\Exception\LogicException; + use function array_key_exists; +use function assert; use function in_array; use function is_array; @@ -28,15 +30,12 @@ class Configuration implements ConfigurationInterface /** * @param bool $debug Whether to use the debug mode */ - public function __construct($debug) + public function __construct(bool $debug) { $this->debug = (bool) $debug; } - /** - * {@inheritDoc} - */ - public function getConfigTreeBuilder() : TreeBuilder + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('doctrine'); $rootNode = $treeBuilder->getRootNode(); @@ -50,7 +49,7 @@ public function getConfigTreeBuilder() : TreeBuilder /** * Add DBAL section to configuration tree */ - private function addDbalSection(ArrayNodeDefinition $node) : void + private function addDbalSection(ArrayNodeDefinition $node): void { $node ->children() @@ -67,9 +66,11 @@ private function addDbalSection(ArrayNodeDefinition $node) : void if (isset($excludedKeys[$key])) { continue; } + $connection[$key] = $v[$key]; unset($v[$key]); } + $v['default_connection'] = isset($v['default_connection']) ? (string) $v['default_connection'] : 'default'; $v['connections'] = [$v['default_connection'] => $connection]; @@ -105,16 +106,16 @@ private function addDbalSection(ArrayNodeDefinition $node) : void /** * Return the dbal connections node */ - private function getDbalConnectionsNode() : ArrayNodeDefinition + private function getDbalConnectionsNode(): ArrayNodeDefinition { $treeBuilder = new TreeBuilder('connections'); $node = $treeBuilder->getRootNode(); - /** @var ArrayNodeDefinition $connectionNode */ $connectionNode = $node ->requiresAtLeastOneElement() ->useAttributeAsKey('name') ->prototype('array'); + assert($connectionNode instanceof ArrayNodeDefinition); $this->configureDbalDriverNode($connectionNode); @@ -188,7 +189,7 @@ private function getDbalConnectionsNode() : ArrayNodeDefinition * * These keys are available for slave configurations too. */ - private function configureDbalDriverNode(ArrayNodeDefinition $node) : void + private function configureDbalDriverNode(ArrayNodeDefinition $node): void { $node ->children() @@ -298,7 +299,7 @@ private function configureDbalDriverNode(ArrayNodeDefinition $node) : void /** * Add the ORM section to configuration tree */ - private function addOrmSection(ArrayNodeDefinition $node) : void + private function addOrmSection(ArrayNodeDefinition $node): void { $node ->children() @@ -327,9 +328,11 @@ private function addOrmSection(ArrayNodeDefinition $node) : void if (isset($excludedKeys[$key])) { continue; } + $entityManager[$key] = $v[$key]; unset($v[$key]); } + $v['default_entity_manager'] = isset($v['default_entity_manager']) ? (string) $v['default_entity_manager'] : 'default'; $v['entity_managers'] = [$v['default_entity_manager'] => $entityManager]; @@ -347,9 +350,11 @@ private function addOrmSection(ArrayNodeDefinition $node) : void if (is_int($v) && in_array($v, $generationModes['values']/*array(0, 1, 2, 3)*/)) { return false; } + if (is_bool($v)) { return false; } + if (is_string($v)) { if (in_array(strtoupper($v), $generationModes['names']/*array('NEVER', 'ALWAYS', 'FILE_NOT_EXISTS', 'EVAL')*/)) { return false; @@ -381,7 +386,7 @@ private function addOrmSection(ArrayNodeDefinition $node) : void /** * Return ORM target entity resolver node */ - private function getOrmTargetEntityResolverNode() : NodeDefinition + private function getOrmTargetEntityResolverNode(): NodeDefinition { $treeBuilder = new TreeBuilder('resolve_target_entities'); $node = $treeBuilder->getRootNode(); @@ -398,7 +403,7 @@ private function getOrmTargetEntityResolverNode() : NodeDefinition /** * Return ORM entity listener node */ - private function getOrmEntityListenersNode() : NodeDefinition + private function getOrmEntityListenersNode(): NodeDefinition { $treeBuilder = new TreeBuilder('entity_listeners'); $node = $treeBuilder->getRootNode(); @@ -482,7 +487,7 @@ private function getOrmEntityListenersNode() : NodeDefinition /** * Return ORM entity manager node */ - private function getOrmEntityManagersNode() : ArrayNodeDefinition + private function getOrmEntityManagersNode(): ArrayNodeDefinition { $treeBuilder = new TreeBuilder('entity_managers'); $node = $treeBuilder->getRootNode(); @@ -642,7 +647,7 @@ private function getOrmEntityManagersNode() : ArrayNodeDefinition /** * Return a ORM cache driver node for an given entity manager */ - private function getOrmCacheDriverNode(string $name) : ArrayNodeDefinition + private function getOrmCacheDriverNode(string $name): ArrayNodeDefinition { $treeBuilder = new TreeBuilder($name); $node = $treeBuilder->getRootNode(); @@ -651,7 +656,7 @@ private function getOrmCacheDriverNode(string $name) : ArrayNodeDefinition ->addDefaultsIfNotSet() ->beforeNormalization() ->ifString() - ->then(static function ($v) : array { + ->then(static function ($v): array { return ['type' => $v]; }) ->end() @@ -666,8 +671,10 @@ private function getOrmCacheDriverNode(string $name) : ArrayNodeDefinition /** * Find proxy auto generate modes for their names and int values + * + * @return array{names: list, values: list} */ - private function getAutoGenerateModes() : array + private function getAutoGenerateModes(): array { $constPrefix = 'AUTOGENERATE_'; $prefixLen = strlen($constPrefix); @@ -698,8 +705,10 @@ private function getAutoGenerateModes() : array * setDeprecation() with less than 3 args and the getDeprecation method was * introduced at the same time. By checking if getDeprecation() exists, * we can determine the correct param count to use when calling setDeprecated. + * + * @return list|array{0:string, 1: numeric-string, string} */ - private function getCommentedParamDeprecationMsg() : array + private function getCommentedParamDeprecationMsg(): array { $message = 'The doctrine-bundle type commenting features were removed; the corresponding config parameter was deprecated in 2.0 and will be dropped in 3.0.'; diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index a85d308c6..74f902ffb 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -32,6 +32,7 @@ use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransportFactory; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface; + use function class_exists; use function sprintf; @@ -124,6 +125,7 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder if ($connection['logging']) { $logger = new Reference('doctrine.dbal.logger'); } + unset($connection['logging']); if ($connection['profiling']) { @@ -149,6 +151,7 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder $logger = $profilingLogger; } } + unset( $connection['profiling'], $connection['profiling_collect_backtrace'], @@ -223,6 +226,7 @@ protected function getConnectionOptions($connection) $options['platform'] = new Reference($options['platform_service']); unset($options['platform_service']); } + unset($options['mapping_types']); if (isset($options['shard_choser_service'])) { @@ -230,16 +234,18 @@ protected function getConnectionOptions($connection) unset($options['shard_choser_service']); } - foreach ([ - 'options' => 'driverOptions', - 'driver_class' => 'driverClass', - 'wrapper_class' => 'wrapperClass', - 'keep_slave' => 'keepSlave', - 'shard_choser' => 'shardChoser', - 'shard_manager_class' => 'shardManagerClass', - 'server_version' => 'serverVersion', - 'default_table_options' => 'defaultTableOptions', - ] as $old => $new) { + foreach ( + [ + 'options' => 'driverOptions', + 'driver_class' => 'driverClass', + 'wrapper_class' => 'wrapperClass', + 'keep_slave' => 'keepSlave', + 'shard_choser' => 'shardChoser', + 'shard_manager_class' => 'shardManagerClass', + 'server_version' => 'serverVersion', + 'default_table_options' => 'defaultTableOptions', + ] as $old => $new + ) { if (! isset($options[$old])) { continue; } @@ -276,9 +282,11 @@ protected function getConnectionOptions($connection) if (isset($nonRewrittenKeys[$key])) { continue; } + $options['master'][$key] = $value; unset($options[$key]); } + if (empty($options['wrapperClass'])) { // Change the wrapper class only if the user does not already forced using a custom one. $options['wrapperClass'] = 'Doctrine\\DBAL\\Connections\\MasterSlaveConnection'; @@ -311,13 +319,16 @@ protected function getConnectionOptions($connection) if (isset($nonRewrittenKeys[$key])) { continue; } + $options['global'][$key] = $value; unset($options[$key]); } + if (empty($options['wrapperClass'])) { // Change the wrapper class only if the user does not already forced using a custom one. $options['wrapperClass'] = 'Doctrine\\DBAL\\Sharding\\PoolingShardConnection'; } + if (empty($options['shardManagerClass'])) { // Change the shard manager class only if the user does not already forced using a custom one. $options['shardManagerClass'] = 'Doctrine\\DBAL\\Sharding\\PoolingShardManager'; @@ -361,12 +372,14 @@ protected function ormLoad(array $config, ContainerBuilder $container) foreach (array_keys($config['entity_managers']) as $name) { $entityManagers[$name] = sprintf('doctrine.orm.%s_entity_manager', $name); } + $container->setParameter('doctrine.entity_managers', $entityManagers); if (empty($config['default_entity_manager'])) { $tmp = array_keys($entityManagers); $config['default_entity_manager'] = reset($tmp); } + $container->setParameter('doctrine.default_entity_manager', $config['default_entity_manager']); $options = ['auto_generate_proxy_classes', 'proxy_dir', 'proxy_namespace']; @@ -460,6 +473,7 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $ if (isset($entityManager['connection'])) { $listenerTagParams['connection'] = $entityManager['connection']; } + $listenerDef->addTag('doctrine.event_listener', $listenerTagParams); if (isset($entityManager['second_level_cache'])) { @@ -482,9 +496,11 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $ foreach ($entityManager['dql']['string_functions'] as $name => $function) { $ormConfigDef->addMethodCall('addCustomStringFunction', [$name, $function]); } + foreach ($entityManager['dql']['numeric_functions'] as $name => $function) { $ormConfigDef->addMethodCall('addCustomNumericFunction', [$name, $function]); } + foreach ($entityManager['dql']['datetime_functions'] as $name => $function) { $ormConfigDef->addMethodCall('addCustomDatetimeFunction', [$name, $function]); } @@ -497,6 +513,7 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $ if ($filter['enabled']) { $enabledFilters[] = $name; } + if (! $filter['parameters']) { continue; } @@ -724,28 +741,22 @@ protected function loadOrmSecondLevelCache(array $entityManager, Definition $orm /** * {@inheritDoc} */ - protected function getObjectManagerElementName($name) : string + protected function getObjectManagerElementName($name): string { return 'doctrine.orm.' . $name; } - protected function getMappingObjectDefaultName() : string + protected function getMappingObjectDefaultName(): string { return 'Entity'; } - /** - * {@inheritDoc} - */ - protected function getMappingResourceConfigDirectory() : string + protected function getMappingResourceConfigDirectory(): string { return 'Resources/config/doctrine'; } - /** - * {@inheritDoc} - */ - protected function getMappingResourceExtension() : string + protected function getMappingResourceExtension(): string { return 'orm'; } @@ -753,7 +764,7 @@ protected function getMappingResourceExtension() : string /** * {@inheritDoc} */ - protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheDriver, ContainerBuilder $container) : string + protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheDriver, ContainerBuilder $container): string { $serviceId = null; $aliasId = $this->getObjectManagerElementName(sprintf('%s_%s', $objectManagerName, $cacheName)); @@ -797,7 +808,7 @@ protected function loadOrmCacheDrivers(array $entityManager, ContainerBuilder $c /** * Loads a property info extractor for each defined entity manager. */ - private function loadPropertyInfoExtractor(string $entityManagerName, ContainerBuilder $container) : void + private function loadPropertyInfoExtractor(string $entityManagerName, ContainerBuilder $container): void { $propertyExtractorDefinition = $container->register(sprintf('doctrine.orm.%s_entity_manager.property_info_extractor', $entityManagerName), DoctrineExtractor::class); $argumentId = sprintf('doctrine.orm.%s_entity_manager', $entityManagerName); @@ -812,7 +823,7 @@ private function loadPropertyInfoExtractor(string $entityManagerName, ContainerB /** * Loads a validator loader for each defined entity manager. */ - private function loadValidatorLoader(string $entityManagerName, ContainerBuilder $container) : void + private function loadValidatorLoader(string $entityManagerName, ContainerBuilder $container): void { $validatorLoaderDefinition = $container->register(sprintf('doctrine.orm.%s_entity_manager.validator_loader', $entityManagerName), DoctrineLoader::class); $validatorLoaderDefinition->addArgument(new Reference(sprintf('doctrine.orm.%s_entity_manager', $entityManagerName))); @@ -829,18 +840,12 @@ public function loadObjectManagerCacheDriver(array $objectManager, ContainerBuil $this->loadCacheDriver($cacheName, $objectManager['name'], $objectManager[$cacheName . '_driver'], $container); } - /** - * {@inheritDoc} - */ - public function getXsdValidationBasePath() : string + public function getXsdValidationBasePath(): string { return __DIR__ . '/../Resources/config/schema'; } - /** - * {@inheritDoc} - */ - public function getNamespace() : string + public function getNamespace(): string { return 'http://symfony.com/schema/dic/doctrine'; } @@ -848,17 +853,17 @@ public function getNamespace() : string /** * {@inheritDoc} */ - public function getConfiguration(array $config, ContainerBuilder $container) : Configuration + public function getConfiguration(array $config, ContainerBuilder $container): Configuration { return new Configuration($container->getParameter('kernel.debug')); } - protected function getMetadataDriverClass(string $driverType) : string + protected function getMetadataDriverClass(string $driverType): string { return '%' . $this->getObjectManagerElementName('metadata.' . $driverType . '.class%'); } - private function loadMessengerServices(ContainerBuilder $container) : void + private function loadMessengerServices(ContainerBuilder $container): void { // If the Messenger component is installed and the doctrine transaction middleware is available, wire it: if (! interface_exists(MessageBusInterface::class) || ! class_exists(DoctrineTransactionMiddleware::class)) { @@ -891,7 +896,7 @@ private function loadMessengerServices(ContainerBuilder $container) : void $transportFactoryDefinition->addTag('messenger.transport_factory'); } - private function createPoolCacheDefinition(ContainerBuilder $container, string $poolName) : string + private function createPoolCacheDefinition(ContainerBuilder $container, string $poolName): string { $serviceId = sprintf('doctrine.orm.cache.provider.%s', $poolName); @@ -901,7 +906,7 @@ private function createPoolCacheDefinition(ContainerBuilder $container, string $ return $serviceId; } - private function createArrayAdapterCachePool(ContainerBuilder $container, string $objectManagerName, string $cacheName) : string + private function createArrayAdapterCachePool(ContainerBuilder $container, string $objectManagerName, string $cacheName): string { $id = sprintf('cache.doctrine.orm.%s.%s', $objectManagerName, str_replace('_cache', '', $cacheName)); diff --git a/DoctrineBundle.php b/DoctrineBundle.php index e8731e615..8a6e40311 100644 --- a/DoctrineBundle.php +++ b/DoctrineBundle.php @@ -19,6 +19,8 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; +use function assert; + class DoctrineBundle extends Bundle { /** @var callable|null */ @@ -70,14 +72,13 @@ public function boot() // See https://github.com/symfony/symfony/pull/3419 for usage of references $container = &$this->container; - $proxyGenerator = static function ($proxyDir, $proxyNamespace, $class) use (&$container) { + $proxyGenerator = static function ($proxyDir, $proxyNamespace, $class) use (&$container): void { $originalClassName = ClassUtils::getRealClass($class); - /** @var Registry $registry */ - $registry = $container->get('doctrine'); + $registry = $container->get('doctrine'); + assert($registry instanceof Registry); - // Tries to auto-generate the proxy file - /** @var EntityManager $em */ foreach ($registry->getManagers() as $em) { + assert($em instanceof EntityManager); if (! $em->getConfiguration()->getAutoGenerateProxyClasses()) { continue; } diff --git a/ManagerConfigurator.php b/ManagerConfigurator.php index c65055d64..13d60b002 100644 --- a/ManagerConfigurator.php +++ b/ManagerConfigurator.php @@ -37,7 +37,7 @@ public function configure(EntityManagerInterface $entityManager) /** * Enables filters for a given entity manager */ - private function enableFilters(EntityManagerInterface $entityManager) : void + private function enableFilters(EntityManagerInterface $entityManager): void { if (empty($this->enabledFilters)) { return; @@ -57,7 +57,7 @@ private function enableFilters(EntityManagerInterface $entityManager) : void /** * Sets default parameters for a given filter */ - private function setFilterParameters(string $name, SQLFilter $filter) : void + private function setFilterParameters(string $name, SQLFilter $filter): void { if (empty($this->filtersParameters[$name])) { return; diff --git a/Mapping/ContainerEntityListenerResolver.php b/Mapping/ContainerEntityListenerResolver.php index 9645838d8..6fee6ccda 100644 --- a/Mapping/ContainerEntityListenerResolver.php +++ b/Mapping/ContainerEntityListenerResolver.php @@ -96,7 +96,7 @@ private function resolveService(string $serviceId) return $this->container->get($serviceId); } - private function normalizeClassName(string $className) : string + private function normalizeClassName(string $className): string { return trim($className, '\\'); } diff --git a/Mapping/DisconnectedMetadataFactory.php b/Mapping/DisconnectedMetadataFactory.php index 5cd986b42..166a83616 100644 --- a/Mapping/DisconnectedMetadataFactory.php +++ b/Mapping/DisconnectedMetadataFactory.php @@ -128,7 +128,7 @@ public function findNamespaceAndPathForMetadata(ClassMetadataCollection $metadat * * @throws RuntimeException When base path not found. */ - private function getBasePathForClass(string $name, string $namespace, string $path) : string + private function getBasePathForClass(string $name, string $namespace, string $path): string { $namespace = str_replace('\\', '/', $namespace); $search = str_replace('\\', '/', $path); @@ -141,7 +141,7 @@ private function getBasePathForClass(string $name, string $namespace, string $pa return $destination; } - private function getMetadataForNamespace(string $namespace) : ClassMetadataCollection + private function getMetadataForNamespace(string $namespace): ClassMetadataCollection { $metadata = []; foreach ($this->getAllMetadata() as $m) { @@ -155,7 +155,7 @@ private function getMetadataForNamespace(string $namespace) : ClassMetadataColle return new ClassMetadataCollection($metadata); } - private function getMetadataForClass(string $entity) : ClassMetadataCollection + private function getMetadataForClass(string $entity): ClassMetadataCollection { foreach ($this->registry->getManagers() as $em) { $cmf = new DisconnectedClassMetadataFactory(); @@ -172,7 +172,7 @@ private function getMetadataForClass(string $entity) : ClassMetadataCollection /** * @return ClassMetadata[] */ - private function getAllMetadata() : array + private function getAllMetadata(): array { $metadata = []; foreach ($this->registry->getManagers() as $em) { diff --git a/Mapping/EntityListenerServiceResolver.php b/Mapping/EntityListenerServiceResolver.php index 3cb4960cd..03120ef90 100644 --- a/Mapping/EntityListenerServiceResolver.php +++ b/Mapping/EntityListenerServiceResolver.php @@ -10,5 +10,6 @@ interface EntityListenerServiceResolver extends EntityListenerResolver * @param string $className * @param string $serviceId */ + // phpcs:ignore public function registerService($className, $serviceId); } diff --git a/Registry.php b/Registry.php index 867607e3a..927800b47 100644 --- a/Registry.php +++ b/Registry.php @@ -17,10 +17,8 @@ class Registry extends ManagerRegistry implements ResetInterface /** * @param string[] $connections * @param string[] $entityManagers - * @param string $defaultConnection - * @param string $defaultEntityManager */ - public function __construct(ContainerInterface $container, array $connections, array $entityManagers, $defaultConnection, $defaultEntityManager) + public function __construct(ContainerInterface $container, array $connections, array $entityManagers, string $defaultConnection, string $defaultEntityManager) { $this->container = $container; @@ -50,14 +48,14 @@ public function getAliasNamespace($alias) throw ORMException::unknownEntityNamespace($alias); } - public function reset() : void + public function reset(): void { foreach ($this->getManagerNames() as $managerName => $serviceId) { $this->resetOrClearManager($managerName, $serviceId); } } - private function resetOrClearManager(string $managerName, string $serviceId) : void + private function resetOrClearManager(string $managerName, string $serviceId): void { if (! $this->container->initialized($serviceId)) { return; diff --git a/Repository/ContainerRepositoryFactory.php b/Repository/ContainerRepositoryFactory.php index aa6c7f0f5..3185b92f1 100644 --- a/Repository/ContainerRepositoryFactory.php +++ b/Repository/ContainerRepositoryFactory.php @@ -32,7 +32,7 @@ public function __construct(ContainerInterface $container) /** * {@inheritdoc} */ - public function getRepository(EntityManagerInterface $entityManager, $entityName) : ObjectRepository + public function getRepository(EntityManagerInterface $entityManager, $entityName): ObjectRepository { $metadata = $entityManager->getClassMetadata($entityName); $repositoryServiceId = $metadata->customRepositoryClassName; @@ -68,7 +68,7 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName private function getOrCreateRepository( EntityManagerInterface $entityManager, ClassMetadata $metadata - ) : ObjectRepository { + ): ObjectRepository { $repositoryHash = $metadata->getName() . spl_object_hash($entityManager); if (isset($this->managedRepositories[$repositoryHash])) { return $this->managedRepositories[$repositoryHash]; diff --git a/Repository/ServiceEntityRepository.php b/Repository/ServiceEntityRepository.php index 987d0b0bb..c8a169329 100644 --- a/Repository/ServiceEntityRepository.php +++ b/Repository/ServiceEntityRepository.php @@ -25,7 +25,7 @@ class ServiceEntityRepository extends EntityRepository implements ServiceEntityR /** * @param string $entityClass The class name of the entity this repository manages */ - public function __construct(ManagerRegistry $registry, $entityClass) + public function __construct(ManagerRegistry $registry, string $entityClass) { $manager = $registry->getManagerForClass($entityClass); diff --git a/Tests/Builder/BundleConfigurationBuilder.php b/Tests/Builder/BundleConfigurationBuilder.php index 670f57c93..817e1a536 100644 --- a/Tests/Builder/BundleConfigurationBuilder.php +++ b/Tests/Builder/BundleConfigurationBuilder.php @@ -4,7 +4,7 @@ class BundleConfigurationBuilder { - /** @var array */ + /** @var mixed[] */ private $configuration; public static function createBuilder() @@ -21,7 +21,7 @@ public static function createBuilderWithBaseValues() return $builder; } - public function addBaseConnection() : self + public function addBaseConnection(): self { $this->addConnection([ 'connections' => [ @@ -32,7 +32,7 @@ public function addBaseConnection() : self return $this; } - public function addBaseEntityManager() : self + public function addBaseEntityManager(): self { $this->addEntityManager([ 'default_entity_manager' => 'default', @@ -48,7 +48,7 @@ public function addBaseEntityManager() : self return $this; } - public function addBaseSecondLevelCache() : self + public function addBaseSecondLevelCache(): self { $this->addSecondLevelCache([ 'region_cache_driver' => ['type' => 'pool', 'pool' => 'my_pool'], @@ -60,28 +60,28 @@ public function addBaseSecondLevelCache() : self return $this; } - public function addConnection($config) : self + public function addConnection($config): self { $this->configuration['dbal'] = $config; return $this; } - public function addEntityManager($config) : self + public function addEntityManager($config): self { $this->configuration['orm'] = $config; return $this; } - public function addSecondLevelCache($config, $manager = 'default') : self + public function addSecondLevelCache($config, $manager = 'default'): self { $this->configuration['orm']['entity_managers'][$manager]['second_level_cache'] = $config; return $this; } - public function build() : array + public function build(): array { return $this->configuration; } diff --git a/Tests/BundleTest.php b/Tests/BundleTest.php index fedcdcd16..6b7bc1cb0 100644 --- a/Tests/BundleTest.php +++ b/Tests/BundleTest.php @@ -11,7 +11,7 @@ class BundleTest extends TestCase { - public function testBuildCompilerPasses() : void + public function testBuildCompilerPasses(): void { $container = new ContainerBuilder(); $bundle = new DoctrineBundle(); diff --git a/Tests/CacheSchemaSubscriberTest.php b/Tests/CacheSchemaSubscriberTest.php index d2f81e0f6..d9f68dbe5 100644 --- a/Tests/CacheSchemaSubscriberTest.php +++ b/Tests/CacheSchemaSubscriberTest.php @@ -15,11 +15,12 @@ class CacheSchemaSubscriberTest extends TestCase { - public function testSchemaSubscriberWiring() : void + public function testSchemaSubscriberWiring(): void { if (! class_exists(PdoCacheAdapterDoctrineSchemaSubscriber::class)) { $this->markTestSkipped('This test requires Symfony 5.1 or higher'); } + if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); } diff --git a/Tests/Command/CreateDatabaseDoctrineTest.php b/Tests/Command/CreateDatabaseDoctrineTest.php index 805661193..5eddf570e 100644 --- a/Tests/Command/CreateDatabaseDoctrineTest.php +++ b/Tests/Command/CreateDatabaseDoctrineTest.php @@ -11,14 +11,14 @@ class CreateDatabaseDoctrineTest extends TestCase { - public function tearDown() : void + public function tearDown(): void { @unlink(sys_get_temp_dir() . '/test'); @unlink(sys_get_temp_dir() . '/shard_1'); @unlink(sys_get_temp_dir() . '/shard_2'); } - public function testExecute() : void + public function testExecute(): void { $connectionName = 'default'; $dbName = 'test'; @@ -48,7 +48,7 @@ public function testExecute() : void /** * @dataProvider provideShardOption */ - public function testExecuteWithShardAlias(string $shardOption) : void + public function testExecuteWithShardAlias(string $shardOption): void { $connectionName = 'default'; $params = [ @@ -98,7 +98,7 @@ public function testExecuteWithShardAlias(string $shardOption) : void ); } - public function provideShardOption() : Generator + public function provideShardOption(): Generator { yield 'full name' => ['--shard']; yield 'short name' => ['-s']; @@ -107,7 +107,7 @@ public function provideShardOption() : Generator /** * @param mixed[]|null $params Connection parameters */ - private function getMockContainer(string $connectionName, array $params = null) : MockObject + private function getMockContainer(string $connectionName, array $params = null): MockObject { // Mock the container and everything you'll need here $mockDoctrine = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry') diff --git a/Tests/Command/DropDatabaseDoctrineTest.php b/Tests/Command/DropDatabaseDoctrineTest.php index aaced03d3..374b361e4 100644 --- a/Tests/Command/DropDatabaseDoctrineTest.php +++ b/Tests/Command/DropDatabaseDoctrineTest.php @@ -16,7 +16,7 @@ class DropDatabaseDoctrineTest extends TestCase /** * @dataProvider provideForceOption */ - public function testExecute(array $options) : void + public function testExecute(array $options): void { $connectionName = 'default'; $dbName = 'test'; @@ -51,17 +51,18 @@ public function testExecute(array $options) : void /** * @dataProvider provideIncompatibleDriverOptions */ - public function testItThrowsWhenUsingIfExistsWithAnIncompatibleDriver(array $options) : void + public function testItThrowsWhenUsingIfExistsWithAnIncompatibleDriver(array $options): void { if (class_exists(DBALException::class)) { $this->expectException(DBALException::class); } else { $this->expectException(Exception::class); } + $this->testExecute($options); } - public function testExecuteWithoutOptionForceWillFailWithAttentionMessage() : void + public function testExecuteWithoutOptionForceWillFailWithAttentionMessage(): void { $connectionName = 'default'; $dbName = 'test'; @@ -96,17 +97,18 @@ public function testExecuteWithoutOptionForceWillFailWithAttentionMessage() : vo ); } - public function provideForceOption() : Generator + public function provideForceOption(): Generator { yield 'full name' => [ ['--force' => true], ]; + yield 'short name' => [ ['-f' => true], ]; } - public function provideIncompatibleDriverOptions() : Generator + public function provideIncompatibleDriverOptions(): Generator { yield 'full name' => [ [ @@ -114,6 +116,7 @@ public function provideIncompatibleDriverOptions() : Generator '--if-exists' => true, ], ]; + yield 'short name' => [ [ '-f' => true, @@ -125,7 +128,7 @@ public function provideIncompatibleDriverOptions() : Generator /** * @param array|null $params Connection parameters */ - private function getMockContainer(string $connectionName, array $params = null) : MockObject + private function getMockContainer(string $connectionName, array $params = null): MockObject { // Mock the container and everything you'll need here $mockDoctrine = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry') diff --git a/Tests/Command/ImportMappingDoctrineCommandTest.php b/Tests/Command/ImportMappingDoctrineCommandTest.php index 095bd10d5..a772e9432 100644 --- a/Tests/Command/ImportMappingDoctrineCommandTest.php +++ b/Tests/Command/ImportMappingDoctrineCommandTest.php @@ -22,7 +22,7 @@ class ImportMappingDoctrineCommandTest extends TestCase /** @var CommandTester|null */ private $commandTester; - public static function setUpBeforeClass() : void + public static function setUpBeforeClass(): void { if (interface_exists(EntityManagerInterface::class)) { return; @@ -31,10 +31,10 @@ public static function setUpBeforeClass() : void self::markTestSkipped('This test requires ORM'); } - protected function setup() : void + protected function setup(): void { - $this->kernel = new class() extends TestKernel { - public function registerBundles() : iterable + $this->kernel = new class () extends TestKernel { + public function registerBundles(): iterable { yield from parent::registerBundles(); yield new ImportMappingTestFooBundle(); @@ -53,7 +53,7 @@ public function registerBundles() : iterable $this->commandTester = new CommandTester($command); } - protected function tearDown() : void + protected function tearDown(): void { $fs = new Filesystem(); if ($this->kernel !== null) { @@ -65,7 +65,7 @@ protected function tearDown() : void $this->commandTester = null; } - public function testExecuteXmlWithBundle() : void + public function testExecuteXmlWithBundle(): void { $this->commandTester->execute(['name' => 'ImportMappingTestFooBundle']); @@ -78,7 +78,7 @@ public function testExecuteXmlWithBundle() : void ); } - public function testExecuteAnnotationsWithBundle() : void + public function testExecuteAnnotationsWithBundle(): void { $this->commandTester->execute([ 'name' => 'ImportMappingTestFooBundle', @@ -94,14 +94,14 @@ public function testExecuteAnnotationsWithBundle() : void ); } - public function testExecuteThrowsExceptionWithNamespaceAndNoPath() : void + public function testExecuteThrowsExceptionWithNamespaceAndNoPath(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('The --path option is required'); $this->commandTester->execute(['name' => 'Some\Namespace']); } - public function testExecuteXmlWithNamespace() : void + public function testExecuteXmlWithNamespace(): void { $this->commandTester->execute([ 'name' => 'Some\Namespace\Entity', @@ -117,7 +117,7 @@ public function testExecuteXmlWithNamespace() : void ); } - public function testExecuteAnnotationsWithNamespace() : void + public function testExecuteAnnotationsWithNamespace(): void { $this->commandTester->execute([ 'name' => 'Some\Namespace\Entity', @@ -137,7 +137,7 @@ public function testExecuteAnnotationsWithNamespace() : void class ImportMappingTestFooBundle extends Bundle { - public function getPath() : string + public function getPath(): string { return sys_get_temp_dir() . '/import_mapping_bundle'; } diff --git a/Tests/ConnectionFactoryTest.php b/Tests/ConnectionFactoryTest.php index 4332e4dcc..3e4e6b86c 100644 --- a/Tests/ConnectionFactoryTest.php +++ b/Tests/ConnectionFactoryTest.php @@ -15,7 +15,7 @@ class ConnectionFactoryTest extends TestCase { - public function testContainer() : void + public function testContainer(): void { $typesConfig = []; $factory = new ConnectionFactory($typesConfig); @@ -37,17 +37,19 @@ class_exists(Driver\AbstractDriverException::class) ? } else { $this->expectException(\Doctrine\DBAL\Exception::class); } + try { $factory->createConnection($params, $config, $eventManager, $mappingTypes); } catch (Exception $e) { $this->assertTrue(strpos($e->getMessage(), 'can circumvent this by setting') > 0); + throw $e; } finally { FakeDriver::$exception = null; } } - public function testDefaultCharset() : void + public function testDefaultCharset(): void { $factory = new ConnectionFactory([]); $params = [ @@ -63,7 +65,7 @@ public function testDefaultCharset() : void $this->assertSame(1 + $creationCount, FakeConnection::$creationCount); } - public function testDefaultCharsetMySql() : void + public function testDefaultCharsetMySql(): void { $factory = new ConnectionFactory([]); $params = ['driver' => 'pdo_mysql']; @@ -98,7 +100,7 @@ class FakeDriver implements Driver * * @link https://github.com/doctrine/DoctrineBundle/issues/673 */ - public function getDatabasePlatform() : AbstractPlatform + public function getDatabasePlatform(): AbstractPlatform { if (self::$exception !== null) { throw self::$exception; @@ -110,32 +112,34 @@ public function getDatabasePlatform() : AbstractPlatform // ----- below this line follow only dummy methods to satisfy the interface requirements ---- /** + * {@inheritdoc} + * * @param mixed[] $params * @param string|null $username * @param string|null $password * @param mixed[] $driverOptions */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []) : void + public function connect(array $params, $username = null, $password = null, array $driverOptions = []): void { throw new Exception('not implemented'); } - public function getSchemaManager(Connection $conn, ?AbstractPlatform $platform = null) : void + public function getSchemaManager(Connection $conn, ?AbstractPlatform $platform = null): void { throw new Exception('not implemented'); } - public function getName() : string + public function getName(): string { return 'FakeDriver'; } - public function getDatabase(Connection $conn) : string + public function getDatabase(Connection $conn): string { return 'fake_db'; } - public function getExceptionConverter() : ExceptionConverter + public function getExceptionConverter(): ExceptionConverter { throw new Exception('not implemented'); } diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index dc465dd96..bf3ce2b95 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -22,7 +22,7 @@ class ContainerTest extends TestCase { - public static function setUpBeforeClass() : void + public static function setUpBeforeClass(): void { if (interface_exists(EntityManagerInterface::class)) { return; @@ -36,7 +36,7 @@ public static function setUpBeforeClass() : void * * @group legacy */ - public function testContainer() : void + public function testContainer(): void { $container = $this->createXmlBundleTestContainer(); diff --git a/Tests/DataCollector/DoctrineDataCollectorTest.php b/Tests/DataCollector/DoctrineDataCollectorTest.php index 6efb3f4a1..046676c4a 100644 --- a/Tests/DataCollector/DoctrineDataCollectorTest.php +++ b/Tests/DataCollector/DoctrineDataCollectorTest.php @@ -15,7 +15,7 @@ class DoctrineDataCollectorTest extends TestCase const FIRST_ENTITY = 'TestBundle\Test\Entity\Test1'; const SECOND_ENTITY = 'TestBundle\Test\Entity\Test2'; - public function testCollectEntities() : void + public function testCollectEntities(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -54,7 +54,7 @@ public function testCollectEntities() : void $this->assertCount(2, $entities['default']); } - public function testDoesNotCollectEntities() : void + public function testDoesNotCollectEntities(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -75,7 +75,7 @@ public function testDoesNotCollectEntities() : void $this->assertEmpty($collector->getEntities()); } - public function testGetGroupedQueries() : void + public function testGetGroupedQueries(): void { $logger = $this->getMockBuilder('Doctrine\DBAL\Logging\DebugStack')->getMock(); $logger->queries = []; @@ -112,7 +112,7 @@ public function testGetGroupedQueries() : void $this->assertSame(1, $groupedQueries['default'][1]['count']); } - private function createEntityMetadata(string $entityFQCN) : ClassMetadataInfo + private function createEntityMetadata(string $entityFQCN): ClassMetadataInfo { $metadata = new ClassMetadataInfo($entityFQCN); $metadata->name = $entityFQCN; @@ -121,7 +121,7 @@ private function createEntityMetadata(string $entityFQCN) : ClassMetadataInfo return $metadata; } - private function createCollector(array $managers, bool $shouldValidateSchema = true) : DoctrineDataCollector + private function createCollector(array $managers, bool $shouldValidateSchema = true): DoctrineDataCollector { $registry = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')->getMock(); $registry diff --git a/Tests/Dbal/Logging/BacktraceLoggerTest.php b/Tests/Dbal/Logging/BacktraceLoggerTest.php index c7adc01a5..9d3c6941d 100644 --- a/Tests/Dbal/Logging/BacktraceLoggerTest.php +++ b/Tests/Dbal/Logging/BacktraceLoggerTest.php @@ -7,7 +7,7 @@ class BacktraceLoggerTest extends TestCase { - public function testBacktraceLogged() : void + public function testBacktraceLogged(): void { $logger = new BacktraceLogger(); $logger->startQuery('SELECT column FROM table'); diff --git a/Tests/Dbal/RegexSchemaAssetFilterTest.php b/Tests/Dbal/RegexSchemaAssetFilterTest.php index cbc6be4d3..2f7bb68d9 100644 --- a/Tests/Dbal/RegexSchemaAssetFilterTest.php +++ b/Tests/Dbal/RegexSchemaAssetFilterTest.php @@ -7,7 +7,7 @@ class RegexSchemaAssetFilterTest extends TestCase { - public function testShouldIncludeAsset() : void + public function testShouldIncludeAsset(): void { $filter = new RegexSchemaAssetFilter('~^(?!t_)~'); diff --git a/Tests/Dbal/SchemaAssetsFilterManagerTest.php b/Tests/Dbal/SchemaAssetsFilterManagerTest.php index e6e4b9d67..e09534f3b 100644 --- a/Tests/Dbal/SchemaAssetsFilterManagerTest.php +++ b/Tests/Dbal/SchemaAssetsFilterManagerTest.php @@ -8,7 +8,7 @@ class SchemaAssetsFilterManagerTest extends TestCase { - public function testInvoke() : void + public function testInvoke(): void { $filterA = new RegexSchemaAssetFilter('~^(?!t_)~'); $filterB = new RegexSchemaAssetFilter('~^(?!s_)~'); diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 8e7b906e4..d9045a8d9 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -23,11 +23,13 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceLocator; +use function assert; + abstract class AbstractDoctrineExtensionTest extends TestCase { - abstract protected function loadFromFile(ContainerBuilder $container, string $file) : void; + abstract protected function loadFromFile(ContainerBuilder $container, string $file): void; - public function testDbalLoadFromXmlMultipleConnections() : void + public function testDbalLoadFromXmlMultipleConnections(): void { $container = $this->loadContainer('dbal_service_multiple_connections'); @@ -96,7 +98,7 @@ public function testDbalLoadFromXmlMultipleConnections() : void $this->assertSame('utf8', $config['charset']); } - public function testDbalLoadFromXmlSingleConnections() : void + public function testDbalLoadFromXmlSingleConnections(): void { $container = $this->loadContainer('dbal_service_single_connection'); @@ -110,7 +112,7 @@ public function testDbalLoadFromXmlSingleConnections() : void $this->assertEquals('5.6.20', $config['serverVersion']); } - public function testDbalLoadSingleMasterSlaveConnection() : void + public function testDbalLoadSingleMasterSlaveConnection(): void { $container = $this->loadContainer('dbal_service_single_master_slave_connection'); @@ -144,7 +146,7 @@ public function testDbalLoadSingleMasterSlaveConnection() : void $this->assertEquals(['engine' => 'InnoDB'], $param['defaultTableOptions']); } - public function testDbalLoadPoolShardingConnection() : void + public function testDbalLoadPoolShardingConnection(): void { $container = $this->loadContainer('dbal_service_pool_sharding_connection'); @@ -179,7 +181,7 @@ public function testDbalLoadPoolShardingConnection() : void $this->assertEquals(['engine' => 'InnoDB'], $param['defaultTableOptions']); } - public function testDbalLoadSavepointsForNestedTransactions() : void + public function testDbalLoadSavepointsForNestedTransactions(): void { $container = $this->loadContainer('dbal_savepoints'); @@ -195,7 +197,7 @@ public function testDbalLoadSavepointsForNestedTransactions() : void $this->assertCount(0, $calls); } - public function testLoadSimpleSingleConnection() : void + public function testLoadSimpleSingleConnection(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -234,7 +236,7 @@ public function testLoadSimpleSingleConnection() : void /** * The PDO driver doesn't require a database name to be to set when connecting to a database server */ - public function testLoadSimpleSingleConnectionWithoutDbName() : void + public function testLoadSimpleSingleConnectionWithoutDbName(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -242,8 +244,8 @@ public function testLoadSimpleSingleConnectionWithoutDbName() : void $container = $this->loadContainer('orm_service_simple_single_entity_manager_without_dbname'); - /** @var Definition $definition */ $definition = $container->getDefinition('doctrine.dbal.default_connection'); + assert($definition instanceof Definition); $this->assertDICConstructorArguments($definition, [ [ @@ -273,7 +275,7 @@ public function testLoadSimpleSingleConnectionWithoutDbName() : void ]); } - public function testLoadSingleConnection() : void + public function testLoadSingleConnection(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -313,7 +315,7 @@ public function testLoadSingleConnection() : void $this->assertDICDefinitionMethodCallOnce($configDef, 'setDefaultRepositoryClassName', ['Acme\Doctrine\Repository']); } - public function testLoadMultipleConnections() : void + public function testLoadMultipleConnections(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -377,7 +379,7 @@ public function testLoadMultipleConnections() : void $this->assertEquals('cache.doctrine.orm.em1.result', (string) $arguments[0]); } - public function testLoadLogging() : void + public function testLoadLogging(): void { $container = $this->loadContainer('dbal_logging'); @@ -397,7 +399,7 @@ public function testLoadLogging() : void $this->assertDICDefinitionMethodCallOnce($definition, 'setSQLLogger', [new Reference('doctrine.dbal.logger.chain.both')]); } - public function testEntityManagerMetadataCacheDriverConfiguration() : void + public function testEntityManagerMetadataCacheDriverConfiguration(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -412,7 +414,7 @@ public function testEntityManagerMetadataCacheDriverConfiguration() : void $this->assertDICDefinitionClass($definition, DoctrineProvider::class); } - public function testDependencyInjectionImportsOverrideDefaults() : void + public function testDependencyInjectionImportsOverrideDefaults(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -427,7 +429,7 @@ public function testDependencyInjectionImportsOverrideDefaults() : void $this->assertDICDefinitionMethodCallOnce($configDefinition, 'setAutoGenerateProxyClasses', ['%doctrine.orm.auto_generate_proxy_classes%']); } - public function testSingleEntityManagerMultipleMappingBundleDefinitions() : void + public function testSingleEntityManagerMultipleMappingBundleDefinitions(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -469,7 +471,7 @@ public function testSingleEntityManagerMultipleMappingBundleDefinitions() : void ]); } - public function testMultipleEntityManagersMappingBundleDefinitions() : void + public function testMultipleEntityManagersMappingBundleDefinitions(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -515,7 +517,7 @@ public function testMultipleEntityManagersMappingBundleDefinitions() : void ]); } - public function testSingleEntityManagerDefaultTableOptions() : void + public function testSingleEntityManagerDefaultTableOptions(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -538,7 +540,7 @@ public function testSingleEntityManagerDefaultTableOptions() : void $this->assertEquals('InnoDB', $defaults['engine']); } - public function testSetTypes() : void + public function testSetTypes(): void { $container = $this->loadContainer('dbal_types'); @@ -549,7 +551,7 @@ public function testSetTypes() : void $this->assertEquals('%doctrine.dbal.connection_factory.types%', $container->getDefinition('doctrine.dbal.connection_factory')->getArgument(0)); } - public function testSetCustomFunctions() : void + public function testSetCustomFunctions(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -563,7 +565,7 @@ public function testSetCustomFunctions() : void $this->assertDICDefinitionMethodCallOnce($definition, 'addCustomDatetimeFunction', ['test_datetime', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestDatetimeFunction']); } - public function testSetNamingStrategy() : void + public function testSetNamingStrategy(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -578,7 +580,7 @@ public function testSetNamingStrategy() : void $this->assertDICDefinitionMethodCallOnce($def2, 'setNamingStrategy', [0 => new Reference('doctrine.orm.naming_strategy.underscore')]); } - public function testSetQuoteStrategy() : void + public function testSetQuoteStrategy(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -593,7 +595,7 @@ public function testSetQuoteStrategy() : void $this->assertDICDefinitionMethodCallOnce($def2, 'setQuoteStrategy', [0 => new Reference('doctrine.orm.quote_strategy.ansi')]); } - public function testSecondLevelCache() : void + public function testSecondLevelCache(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -663,7 +665,7 @@ public function testSecondLevelCache() : void $this->assertEquals('doctrine.orm.default_second_level_cache.region_cache_driver', $slcFactoryArgs[1]); } - public function testSingleEMSetCustomFunctions() : void + public function testSingleEMSetCustomFunctions(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -675,7 +677,7 @@ public function testSingleEMSetCustomFunctions() : void $this->assertDICDefinitionMethodCallOnce($definition, 'addCustomStringFunction', ['test_string', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestStringFunction']); } - public function testAddCustomHydrationMode() : void + public function testAddCustomHydrationMode(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -687,7 +689,7 @@ public function testAddCustomHydrationMode() : void $this->assertDICDefinitionMethodCallOnce($definition, 'addCustomHydrationMode', ['test_hydrator', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestHydrator']); } - public function testAddFilter() : void + public function testAddFilter(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -705,13 +707,12 @@ public function testAddFilter() : void $definition = $container->getDefinition('doctrine.orm.default_manager_configurator'); $this->assertDICConstructorArguments($definition, [['soft_delete', 'myFilter'], ['myFilter' => ['myParameter' => 'myValue', 'mySecondParameter' => 'mySecondValue']]]); - // Let's create the instance to check the configurator work. - /** @var EntityManager $entityManager */ $entityManager = $container->get('doctrine.orm.entity_manager'); + assert($entityManager instanceof EntityManager); $this->assertCount(2, $entityManager->getFilters()->getEnabledFilters()); } - public function testResolveTargetEntity() : void + public function testResolveTargetEntity(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -727,7 +728,7 @@ public function testResolveTargetEntity() : void $this->assertEquals(['doctrine.event_subscriber' => [[]]], $tags); } - public function testAttachEntityListeners() : void + public function testAttachEntityListeners(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -741,7 +742,7 @@ public function testAttachEntityListeners() : void $this->assertDICDefinitionMethodCallCount($definition, 'addEntityListener', [], 6); $tags = $definition->getTags(); unset($tags['container.no_preload']); - $this->assertEquals(['doctrine.event_listener' => [ ['event' => 'loadClassMetadata'] ] ], $tags); + $this->assertEquals(['doctrine.event_listener' => [['event' => 'loadClassMetadata']]], $tags); $this->assertEquals($methodCalls[0], [ 'addEntityListener', @@ -804,7 +805,7 @@ public function testAttachEntityListeners() : void ]); } - public function testDbalAutoCommit() : void + public function testDbalAutoCommit(): void { $container = $this->loadContainer('dbal_auto_commit'); @@ -812,7 +813,7 @@ public function testDbalAutoCommit() : void $this->assertDICDefinitionMethodCallOnce($definition, 'setAutoCommit', [false]); } - public function testDbalOracleConnectstring() : void + public function testDbalOracleConnectstring(): void { $container = $this->loadContainer('dbal_oracle_connectstring'); @@ -820,7 +821,7 @@ public function testDbalOracleConnectstring() : void $this->assertSame('scott@sales-server:1521/sales.us.example.com', $config['connectstring']); } - public function testDbalOracleInstancename() : void + public function testDbalOracleInstancename(): void { $container = $this->loadContainer('dbal_oracle_instancename'); @@ -828,7 +829,7 @@ public function testDbalOracleInstancename() : void $this->assertSame('mySuperInstance', $config['instancename']); } - public function testDbalSchemaFilterNewConfig() : void + public function testDbalSchemaFilterNewConfig(): void { $container = $this->getContainer([]); $loader = new DoctrineExtension(); @@ -859,7 +860,7 @@ public function testDbalSchemaFilterNewConfig() : void $this->compileContainer($container); - $getConfiguration = static function (string $connectionName) use ($container) : Configuration { + $getConfiguration = static function (string $connectionName) use ($container): Configuration { return $container->get(sprintf('doctrine.dbal.%s_connection', $connectionName))->getConfiguration(); }; @@ -883,7 +884,7 @@ public static function dataWellKnownSchemaFilterServices() /** * @dataProvider dataWellKnownSchemaFilterServices */ - public function testWellKnownSchemaFilterDefaultTables(string $fileName, string $tableName) : void + public function testWellKnownSchemaFilterDefaultTables(string $fileName, string $tableName): void { $container = $this->getContainer([]); $loader = new DoctrineExtension(); @@ -921,7 +922,7 @@ public static function dataWellKnownSchemaOverriddenTablesFilterServices() /** * @dataProvider dataWellKnownSchemaOverriddenTablesFilterServices */ - public function testWellKnownSchemaFilterOverriddenTables(string $fileName, string $tableName) : void + public function testWellKnownSchemaFilterOverriddenTables(string $fileName, string $tableName): void { $container = $this->getContainer([]); $loader = new DoctrineExtension(); @@ -938,7 +939,7 @@ public function testWellKnownSchemaFilterOverriddenTables(string $fileName, stri $this->assertFalse($filter($tableName)); } - public function testEntityListenerResolver() : void + public function testEntityListenerResolver(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -959,7 +960,7 @@ public function testEntityListenerResolver() : void $this->assertDICDefinitionMethodCallOnce($listener, 'register', [new Reference('entity_listener2')]); } - public function testAttachEntityListenerTag() : void + public function testAttachEntityListenerTag(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -995,7 +996,7 @@ public function testAttachEntityListenerTag() : void $this->assertDICDefinitionMethodCallOnce($attachListener, 'addEntityListener', ['My/Entity2', 'EntityListener2', 'preFlush', 'preFlushHandler']); } - public function testAttachEntityListenersTwoConnections() : void + public function testAttachEntityListenersTwoConnections(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -1019,7 +1020,7 @@ public function testAttachEntityListenersTwoConnections() : void $this->assertDICDefinitionMethodCallOnce($foobarEventManager, 'addEventListener', [['loadClassMetadata'], new Reference('doctrine.orm.em2_listeners.attach_entity_listeners')]); } - public function testAttachLazyEntityListener() : void + public function testAttachLazyEntityListener(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -1050,7 +1051,7 @@ public function testAttachLazyEntityListener() : void $this->assertDICDefinitionMethodCallOnce($resolver2, 'registerService', ['EntityListener2', 'entity_listener2']); } - public function testAttachLazyEntityListenerForCustomResolver() : void + public function testAttachLazyEntityListenerForCustomResolver(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -1072,7 +1073,7 @@ public function testAttachLazyEntityListenerForCustomResolver() : void $this->assertTrue($container->getDefinition('entity_listener')->isPublic()); } - public function testLazyEntityListenerResolverWithoutCorrectInterface() : void + public function testLazyEntityListenerResolverWithoutCorrectInterface(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -1090,7 +1091,7 @@ public function testLazyEntityListenerResolverWithoutCorrectInterface() : void $this->compileContainer($container); } - public function testPrivateLazyEntityListener() : void + public function testPrivateLazyEntityListener(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -1108,7 +1109,7 @@ public function testPrivateLazyEntityListener() : void $this->assertTrue($container->getDefinition('doctrine.orm.em1_entity_listener_resolver')->isPublic()); } - public function testAbstractEntityListener() : void + public function testAbstractEntityListener(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -1127,10 +1128,11 @@ public function testAbstractEntityListener() : void } else { $this->expectExceptionMessageRegExp('/The service ".*" must not be abstract\./'); } + $this->compileContainer($container); } - public function testRepositoryFactory() : void + public function testRepositoryFactory(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -1146,7 +1148,7 @@ private function loadContainer( string $fixture, array $bundles = ['YamlBundle'], CompilerPassInterface $compilerPass = null - ) : ContainerBuilder { + ): ContainerBuilder { $container = $this->getContainer($bundles); $container->registerExtension(new DoctrineExtension()); @@ -1161,7 +1163,7 @@ private function loadContainer( return $container; } - private function getContainer(array $bundles) : ContainerBuilder + private function getContainer(array $bundles): ContainerBuilder { $map = []; foreach ($bundles as $bundle) { @@ -1192,12 +1194,12 @@ private function getContainer(array $bundles) : ContainerBuilder /** * Assertion on the Class of a DIC Service Definition. */ - private function assertDICDefinitionClass(Definition $definition, string $expectedClass) : void + private function assertDICDefinitionClass(Definition $definition, string $expectedClass): void { $this->assertEquals($expectedClass, $definition->getClass(), 'Expected Class of the DIC Container Service Definition is wrong.'); } - private function assertDICConstructorArguments(Definition $definition, array $args) : void + private function assertDICConstructorArguments(Definition $definition, array $args): void { $this->assertEquals($args, $definition->getArguments(), "Expected and actual DIC Service constructor arguments of definition '" . $definition->getClass() . "' don't match."); } @@ -1207,7 +1209,7 @@ private function assertDICDefinitionMethodCallAt( Definition $definition, string $methodName, array $params = null - ) : void { + ): void { $calls = $definition->getMethodCalls(); if (! isset($calls[$pos][0])) { $this->fail(sprintf('Method call at position %s not found!', $pos)); @@ -1231,7 +1233,7 @@ private function assertDICDefinitionMethodCallOnce( Definition $definition, string $methodName, array $params = null - ) : void { + ): void { $calls = $definition->getMethodCalls(); $called = false; foreach ($calls as $call) { @@ -1248,6 +1250,7 @@ private function assertDICDefinitionMethodCallOnce( } } } + if ($called) { return; } @@ -1260,7 +1263,7 @@ private function assertDICDefinitionMethodCallCount( string $methodName, array $params = [], int $nbCalls = 1 - ) : void { + ): void { $calls = $definition->getMethodCalls(); $called = 0; foreach ($calls as $call) { @@ -1275,6 +1278,7 @@ private function assertDICDefinitionMethodCallCount( if (isset($params[$called])) { $this->assertEquals($params[$called], $call[1], "Expected parameters to methods '" . $methodName . "' do not match the actual parameters."); } + $called++; } @@ -1288,7 +1292,7 @@ private function assertDICDefinitionNoMethodCall( Definition $definition, string $methodName, array $params = null - ) : void { + ): void { $calls = $definition->getMethodCalls(); foreach ($calls as $call) { if ($call[0] !== $methodName) { @@ -1303,7 +1307,7 @@ private function assertDICDefinitionNoMethodCall( } } - private function compileContainer(ContainerBuilder $container) : void + private function compileContainer(ContainerBuilder $container): void { $container->getCompilerPassConfig()->setOptimizationPasses([new ResolveChildDefinitionsPass()]); $container->getCompilerPassConfig()->setRemovingPasses([]); @@ -1321,7 +1325,7 @@ public function __construct(string $tableToIgnore) $this->tableToIgnore = $tableToIgnore; } - public function __invoke($assetName) : bool + public function __invoke($assetName): bool { if ($assetName instanceof AbstractAsset) { $assetName = $assetName->getName(); diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index f9666644d..b0cf54311 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -21,7 +21,7 @@ class ConfigurationTest extends TestCase /** * @runInSeparateProcess */ - public function testGetConfigTreeBuilderDoNotUseDoctrineCommon() : void + public function testGetConfigTreeBuilderDoNotUseDoctrineCommon(): void { $configuration = new Configuration(true); $configuration->getConfigTreeBuilder(); diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index fc5434e8c..a0e568e8f 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -27,7 +27,7 @@ class DoctrineExtensionTest extends TestCase * * @group legacy */ - public function testAutowiringAlias() : void + public function testAutowiringAlias(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -54,7 +54,7 @@ public function testAutowiringAlias() : void } } - public function testPublicServicesAndAliases() : void + public function testPublicServicesAndAliases(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -71,7 +71,7 @@ public function testPublicServicesAndAliases() : void $this->assertTrue($container->getAlias('database_connection')->isPublic()); } - public function testDbalGenerateDefaultConnectionConfiguration() : void + public function testDbalGenerateDefaultConnectionConfiguration(): void { $container = $this->getContainer(); $extension = new DoctrineExtension(); @@ -91,7 +91,7 @@ public function testDbalGenerateDefaultConnectionConfiguration() : void $this->assertEquals([], $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0)['driverOptions']); } - public function testDbalOverrideDefaultConnection() : void + public function testDbalOverrideDefaultConnection(): void { $container = $this->getContainer(); $extension = new DoctrineExtension(); @@ -105,7 +105,7 @@ public function testDbalOverrideDefaultConnection() : void $this->assertEquals('foo', $container->getParameter('doctrine.default_connection'), '->load() overrides existing configuration options'); } - public function testOrmRequiresDbal() : void + public function testOrmRequiresDbal(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -120,7 +120,7 @@ public function testOrmRequiresDbal() : void $extension->load([['orm' => ['auto_mapping' => true]]], $this->getContainer()); } - public function getAutomappingConfigurations() : array + public function getAutomappingConfigurations(): array { return [ [ @@ -158,7 +158,7 @@ public function getAutomappingConfigurations() : array /** * @dataProvider getAutomappingConfigurations */ - public function testAutomapping(array $entityManagers) : void + public function testAutomapping(array $entityManagers): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -211,7 +211,7 @@ public function testAutomapping(array $entityManagers) : void ); } - public function testDbalLoad() : void + public function testDbalLoad(): void { $container = $this->getContainer(); $extension = new DoctrineExtension(); @@ -229,7 +229,7 @@ public function testDbalLoad() : void $this->assertEquals('root', $config['user']); } - public function testDbalWrapperClass() : void + public function testDbalWrapperClass(): void { $container = $this->getContainer(); $extension = new DoctrineExtension(); @@ -255,7 +255,7 @@ public function testDbalWrapperClass() : void $this->assertNull($container->getDefinition('doctrine.dbal.second_connection')->getClass()); } - public function testDependencyInjectionConfigurationDefaults() : void + public function testDependencyInjectionConfigurationDefaults(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -366,7 +366,7 @@ public function testDependencyInjectionConfigurationDefaults() : void $this->assertSame(ArrayAdapter::class, $container->getDefinition((string) $arguments[0])->getClass()); } - public function testUseSavePointsAddMethodCallToAddSavepointsToTheConnection() : void + public function testUseSavePointsAddMethodCallToAddSavepointsToTheConnection(): void { $container = $this->getContainer(); $extension = new DoctrineExtension(); @@ -387,7 +387,7 @@ public function testUseSavePointsAddMethodCallToAddSavepointsToTheConnection() : $this->assertTrue($calls[0][1][0]); } - public function testAutoGenerateProxyClasses() : void + public function testAutoGenerateProxyClasses(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -415,7 +415,7 @@ public function testAutoGenerateProxyClasses() : void $this->assertEquals(3 /* \Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_EVAL */, $container->getParameter('doctrine.orm.auto_generate_proxy_classes')); } - public function testSingleEntityManagerWithDefaultConfiguration() : void + public function testSingleEntityManagerWithDefaultConfiguration(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -439,7 +439,7 @@ public function testSingleEntityManagerWithDefaultConfiguration() : void ]); } - public function testSingleEntityManagerWithDefaultSecondLevelCacheConfiguration() : void + public function testSingleEntityManagerWithDefaultSecondLevelCacheConfiguration(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -468,7 +468,7 @@ public function testSingleEntityManagerWithDefaultSecondLevelCacheConfiguration( $this->assertEquals('%doctrine.orm.second_level_cache.default_cache_factory.class%', $slcDefinition->getClass()); } - public function testSingleEntityManagerWithCustomSecondLevelCacheConfiguration() : void + public function testSingleEntityManagerWithCustomSecondLevelCacheConfiguration(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -503,7 +503,7 @@ public function testSingleEntityManagerWithCustomSecondLevelCacheConfiguration() $this->assertEquals('YamlBundle\Cache\MyCacheFactory', $slcDefinition->getClass()); } - public function testBundleEntityAliases() : void + public function testBundleEntityAliases(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -526,7 +526,7 @@ public function testBundleEntityAliases() : void ); } - public function testOverwriteEntityAliases() : void + public function testOverwriteEntityAliases(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -549,7 +549,7 @@ public function testOverwriteEntityAliases() : void ); } - public function testYamlBundleMappingDetection() : void + public function testYamlBundleMappingDetection(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -571,7 +571,7 @@ public function testYamlBundleMappingDetection() : void ]); } - public function testXmlBundleMappingDetection() : void + public function testXmlBundleMappingDetection(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -602,7 +602,7 @@ public function testXmlBundleMappingDetection() : void ]); } - public function testAnnotationsBundleMappingDetection() : void + public function testAnnotationsBundleMappingDetection(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -633,7 +633,7 @@ public function testAnnotationsBundleMappingDetection() : void ]); } - public function testOrmMergeConfigs() : void + public function testOrmMergeConfigs(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -694,7 +694,7 @@ public function testOrmMergeConfigs() : void } } - public function testAnnotationsBundleMappingDetectionWithVendorNamespace() : void + public function testAnnotationsBundleMappingDetectionWithVendorNamespace(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -723,7 +723,7 @@ public function testAnnotationsBundleMappingDetectionWithVendorNamespace() : voi $this->assertEquals('Fixtures\Bundles\Vendor\AnnotationsBundle\Entity', $calls[0][1][1]); } - public function testMessengerIntegration() : void + public function testMessengerIntegration(): void { if (! interface_exists(MessageBusInterface::class)) { $this->markTestSkipped('Symfony Messenger component is not installed'); @@ -752,7 +752,7 @@ public function testMessengerIntegration() : void } } - public function testInvalidCacheConfiguration() : void + public function testInvalidCacheConfiguration(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -777,7 +777,7 @@ public function testInvalidCacheConfiguration() : void * * @dataProvider cacheConfigurationProvider */ - public function testCacheConfiguration(string $expectedAliasName, string $expectedAliasTarget, string $cacheName, $cacheConfig) : void + public function testCacheConfiguration(string $expectedAliasName, string $expectedAliasTarget, string $cacheName, $cacheConfig): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -798,7 +798,7 @@ public function testCacheConfiguration(string $expectedAliasName, string $expect $this->assertEquals($expectedAliasTarget, (string) $alias); } - public static function cacheConfigurationProvider() : array + public static function cacheConfigurationProvider(): array { return [ 'metadata_cache_default' => [ @@ -860,7 +860,7 @@ public static function cacheConfigurationProvider() : array ]; } - public function testShardManager() : void + public function testShardManager(): void { $container = $this->getContainer(); $extension = new DoctrineExtension(); @@ -884,7 +884,7 @@ public function testShardManager() : void $this->assertFalse($container->hasDefinition('doctrine.dbal.bar_shard_manager')); } - private function getContainer($bundles = 'YamlBundle', $vendor = null) : ContainerBuilder + private function getContainer($bundles = 'YamlBundle', $vendor = null): ContainerBuilder { $bundles = (array) $bundles; @@ -912,12 +912,12 @@ private function getContainer($bundles = 'YamlBundle', $vendor = null) : Contain return $container; } - private function assertDICConstructorArguments(Definition $definition, array $args) : void + private function assertDICConstructorArguments(Definition $definition, array $args): void { $this->assertEquals($args, $definition->getArguments(), "Expected and actual DIC Service constructor arguments of definition '" . $definition->getClass() . "' don't match."); } - private function assertDICDefinitionMethodCallAt(int $pos, Definition $definition, string $methodName, array $params = null) : void + private function assertDICDefinitionMethodCallAt(int $pos, Definition $definition, string $methodName, array $params = null): void { $calls = $definition->getMethodCalls(); if (! isset($calls[$pos][0])) { @@ -936,7 +936,7 @@ private function assertDICDefinitionMethodCallAt(int $pos, Definition $definitio /** * Assertion for the DI Container, check if the given definition contains a method call with the given parameters. */ - private function assertDICDefinitionMethodCallOnce(Definition $definition, string $methodName, array $params = null) : void + private function assertDICDefinitionMethodCallOnce(Definition $definition, string $methodName, array $params = null): void { $calls = $definition->getMethodCalls(); $called = false; @@ -954,6 +954,7 @@ private function assertDICDefinitionMethodCallOnce(Definition $definition, strin } } } + if ($called) { return; } @@ -961,7 +962,7 @@ private function assertDICDefinitionMethodCallOnce(Definition $definition, strin $this->fail("Method '" . $methodName . "' is expected to be called once, definition does not contain a call though."); } - private function compileContainer(ContainerBuilder $container) : void + private function compileContainer(ContainerBuilder $container): void { $container->getCompilerPassConfig()->setOptimizationPasses([new ResolveChildDefinitionsPass()]); $container->getCompilerPassConfig()->setRemovingPasses([]); diff --git a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Repository/TestCustomClassRepoRepository.php b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Repository/TestCustomClassRepoRepository.php index d93d696dc..23994e24f 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Repository/TestCustomClassRepoRepository.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Repository/TestCustomClassRepoRepository.php @@ -7,7 +7,7 @@ class TestCustomClassRepoRepository extends EntityRepository { - public function getEntityManager() : EntityManager + public function getEntityManager(): EntityManager { return parent::getEntityManager(); } diff --git a/Tests/DependencyInjection/Fixtures/CustomEntityListenerServiceResolver.php b/Tests/DependencyInjection/Fixtures/CustomEntityListenerServiceResolver.php index 68f908c10..33ff3dcda 100644 --- a/Tests/DependencyInjection/Fixtures/CustomEntityListenerServiceResolver.php +++ b/Tests/DependencyInjection/Fixtures/CustomEntityListenerServiceResolver.php @@ -17,7 +17,7 @@ public function __construct(EntityListenerServiceResolver $resolver) /** * {@inheritdoc} */ - public function clear($className = null) : void + public function clear($className = null): void { $this->resolver->clear($className); } @@ -33,7 +33,7 @@ public function resolve($className) /** * {@inheritdoc} */ - public function register($object) : void + public function register($object): void { $this->resolver->register($object); } @@ -41,7 +41,7 @@ public function register($object) : void /** * {@inheritdoc} */ - public function registerService($className, $serviceId) : void + public function registerService($className, $serviceId): void { $this->resolver->registerService($className, $serviceId); } diff --git a/Tests/DependencyInjection/Fixtures/InvokableEntityListener.php b/Tests/DependencyInjection/Fixtures/InvokableEntityListener.php index 5ae6743d3..2ea134d1a 100644 --- a/Tests/DependencyInjection/Fixtures/InvokableEntityListener.php +++ b/Tests/DependencyInjection/Fixtures/InvokableEntityListener.php @@ -4,11 +4,11 @@ final class InvokableEntityListener { - public function __invoke() : void + public function __invoke(): void { } - public function postPersist() : void + public function postPersist(): void { } } diff --git a/Tests/DependencyInjection/Fixtures/TestKernel.php b/Tests/DependencyInjection/Fixtures/TestKernel.php index b4ec20014..2350c3ffa 100644 --- a/Tests/DependencyInjection/Fixtures/TestKernel.php +++ b/Tests/DependencyInjection/Fixtures/TestKernel.php @@ -19,7 +19,7 @@ public function __construct() parent::__construct('test', true); } - public function registerBundles() : iterable + public function registerBundles(): iterable { return [ new FrameworkBundle(), @@ -27,9 +27,9 @@ public function registerBundles() : iterable ]; } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { - $loader->load(static function (ContainerBuilder $container) { + $loader->load(static function (ContainerBuilder $container): void { // @todo Setting the kernel.name parameter can be removed once the dependency on DoctrineCacheBundle has been dropped $container->setParameter('kernel.name', 'foo'); $container->loadFromExtension('framework', ['secret' => 'F00']); @@ -52,7 +52,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) }); } - public function getProjectDir() : string + public function getProjectDir(): string { if ($this->projectDir === null) { $this->projectDir = sys_get_temp_dir() . '/sf_kernel_' . md5(mt_rand()); @@ -61,7 +61,7 @@ public function getProjectDir() : string return $this->projectDir; } - public function getRootDir() : string + public function getRootDir(): string { return $this->getProjectDir(); } diff --git a/Tests/DependencyInjection/TestDatetimeFunction.php b/Tests/DependencyInjection/TestDatetimeFunction.php index b761ff5aa..dbdb6f5fc 100644 --- a/Tests/DependencyInjection/TestDatetimeFunction.php +++ b/Tests/DependencyInjection/TestDatetimeFunction.php @@ -8,12 +8,12 @@ class TestDatetimeFunction extends FunctionNode { - public function getSql(SqlWalker $sqlWalker) : string + public function getSql(SqlWalker $sqlWalker): string { return ''; } - public function parse(Parser $parser) : void + public function parse(Parser $parser): void { return; } diff --git a/Tests/DependencyInjection/TestFilter.php b/Tests/DependencyInjection/TestFilter.php index 7bba96b46..cb9ece329 100644 --- a/Tests/DependencyInjection/TestFilter.php +++ b/Tests/DependencyInjection/TestFilter.php @@ -10,7 +10,7 @@ class TestFilter extends SQLFilter /** * Gets the SQL query part to add to a query. */ - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) : void + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias): void { } } diff --git a/Tests/DependencyInjection/TestNumericFunction.php b/Tests/DependencyInjection/TestNumericFunction.php index 3647d852e..32e69d4e2 100644 --- a/Tests/DependencyInjection/TestNumericFunction.php +++ b/Tests/DependencyInjection/TestNumericFunction.php @@ -8,12 +8,12 @@ class TestNumericFunction extends FunctionNode { - public function getSql(SqlWalker $sqlWalker) : string + public function getSql(SqlWalker $sqlWalker): string { return ''; } - public function parse(Parser $parser) : void + public function parse(Parser $parser): void { return; } diff --git a/Tests/DependencyInjection/TestStringFunction.php b/Tests/DependencyInjection/TestStringFunction.php index 6306360c2..933f38a0c 100644 --- a/Tests/DependencyInjection/TestStringFunction.php +++ b/Tests/DependencyInjection/TestStringFunction.php @@ -8,12 +8,12 @@ class TestStringFunction extends FunctionNode { - public function getSql(SqlWalker $sqlWalker) : string + public function getSql(SqlWalker $sqlWalker): string { return ''; } - public function parse(Parser $parser) : void + public function parse(Parser $parser): void { return; } diff --git a/Tests/DependencyInjection/TestType.php b/Tests/DependencyInjection/TestType.php index 0d598e7d3..260384c4a 100644 --- a/Tests/DependencyInjection/TestType.php +++ b/Tests/DependencyInjection/TestType.php @@ -7,12 +7,12 @@ class TestType extends Type { - public function getName() : string + public function getName(): string { return 'test'; } - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string { return ''; } diff --git a/Tests/DependencyInjection/XMLSchemaTest.php b/Tests/DependencyInjection/XMLSchemaTest.php index d123a5787..f151f932f 100644 --- a/Tests/DependencyInjection/XMLSchemaTest.php +++ b/Tests/DependencyInjection/XMLSchemaTest.php @@ -26,7 +26,7 @@ public static function dataValidateSchemaFiles() /** * @dataProvider dataValidateSchemaFiles */ - public function testValidateSchema($file) : void + public function testValidateSchema($file): void { $found = false; $dom = new DOMDocument('1.0', 'UTF-8'); diff --git a/Tests/DependencyInjection/XmlDoctrineExtensionTest.php b/Tests/DependencyInjection/XmlDoctrineExtensionTest.php index 8efab7648..136237ec4 100644 --- a/Tests/DependencyInjection/XmlDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/XmlDoctrineExtensionTest.php @@ -8,7 +8,7 @@ class XmlDoctrineExtensionTest extends AbstractDoctrineExtensionTest { - protected function loadFromFile(ContainerBuilder $container, string $file) : void + protected function loadFromFile(ContainerBuilder $container, string $file): void { $loadXml = new XmlFileLoader($container, new FileLocator(__DIR__ . '/Fixtures/config/xml')); $loadXml->load($file . '.xml'); diff --git a/Tests/DependencyInjection/YamlDoctrineExtensionTest.php b/Tests/DependencyInjection/YamlDoctrineExtensionTest.php index 24c950a84..fc478928f 100644 --- a/Tests/DependencyInjection/YamlDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/YamlDoctrineExtensionTest.php @@ -8,7 +8,7 @@ class YamlDoctrineExtensionTest extends AbstractDoctrineExtensionTest { - protected function loadFromFile(ContainerBuilder $container, string $file) : void + protected function loadFromFile(ContainerBuilder $container, string $file): void { $loadYaml = new YamlFileLoader($container, new FileLocator(__DIR__ . '/Fixtures/config/yml')); $loadYaml->load($file . '.yml'); diff --git a/Tests/Mapping/ContainerEntityListenerResolverTest.php b/Tests/Mapping/ContainerEntityListenerResolverTest.php index c234bd7bd..ecc2150db 100644 --- a/Tests/Mapping/ContainerEntityListenerResolverTest.php +++ b/Tests/Mapping/ContainerEntityListenerResolverTest.php @@ -18,7 +18,7 @@ class ContainerEntityListenerResolverTest extends TestCase /** @var ContainerInterface|PHPUnit_Framework_MockObject_MockObject */ private $container; - public static function setUpBeforeClass() : void + public static function setUpBeforeClass(): void { if (interface_exists(EntityManagerInterface::class)) { return; @@ -27,7 +27,7 @@ public static function setUpBeforeClass() : void self::markTestSkipped('This test requires ORM'); } - protected function setUp() : void + protected function setUp(): void { parent::setUp(); @@ -35,7 +35,7 @@ protected function setUp() : void $this->resolver = new ContainerEntityListenerResolver($this->container); } - public function testResolveClass() : void + public function testResolveClass(): void { $className = '\Doctrine\Bundle\DoctrineBundle\Tests\Mapping\EntityListener1'; $object = $this->resolver->resolve($className); @@ -44,7 +44,7 @@ public function testResolveClass() : void $this->assertSame($object, $this->resolver->resolve($className)); } - public function testRegisterClassAndResolve() : void + public function testRegisterClassAndResolve(): void { $className = '\Doctrine\Bundle\DoctrineBundle\Tests\Mapping\EntityListener1'; $object = new $className(); @@ -54,7 +54,7 @@ public function testRegisterClassAndResolve() : void $this->assertSame($object, $this->resolver->resolve($className)); } - public function testRegisterServiceAndResolve() : void + public function testRegisterServiceAndResolve(): void { $className = '\Doctrine\Bundle\DoctrineBundle\Tests\Mapping\EntityListener1'; $serviceId = 'app.entity_listener'; @@ -76,7 +76,7 @@ public function testRegisterServiceAndResolve() : void $this->assertSame($object, $this->resolver->resolve($className)); } - public function testRegisterMissingServiceAndResolve() : void + public function testRegisterMissingServiceAndResolve(): void { $className = '\Doctrine\Bundle\DoctrineBundle\Tests\Mapping\EntityListener1'; $serviceId = 'app.entity_listener'; @@ -93,7 +93,7 @@ public function testRegisterMissingServiceAndResolve() : void $this->resolver->resolve($className); } - public function testClearOne() : void + public function testClearOne(): void { $className1 = '\Doctrine\Bundle\DoctrineBundle\Tests\Mapping\EntityListener1'; $className2 = '\Doctrine\Bundle\DoctrineBundle\Tests\Mapping\EntityListener2'; @@ -116,7 +116,7 @@ public function testClearOne() : void $this->assertSame($obj2, $this->resolver->resolve($className2)); } - public function testClearAll() : void + public function testClearAll(): void { $className1 = '\Doctrine\Bundle\DoctrineBundle\Tests\Mapping\EntityListener1'; $className2 = '\Doctrine\Bundle\DoctrineBundle\Tests\Mapping\EntityListener2'; @@ -139,7 +139,7 @@ public function testClearAll() : void $this->assertNotSame($obj2, $this->resolver->resolve($className2)); } - public function testRegisterStringException() : void + public function testRegisterStringException(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('An object was expected, but got "string".'); diff --git a/Tests/Mapping/DisconnectedMetadataFactoryTest.php b/Tests/Mapping/DisconnectedMetadataFactoryTest.php index 2d5e6bba5..a5b2e69cf 100644 --- a/Tests/Mapping/DisconnectedMetadataFactoryTest.php +++ b/Tests/Mapping/DisconnectedMetadataFactoryTest.php @@ -11,7 +11,7 @@ class DisconnectedMetadataFactoryTest extends TestCase { - public static function setUpBeforeClass() : void + public static function setUpBeforeClass(): void { if (interface_exists(EntityManagerInterface::class)) { return; @@ -20,7 +20,7 @@ public static function setUpBeforeClass() : void self::markTestSkipped('This test requires ORM'); } - public function testCannotFindNamespaceAndPathForMetadata() : void + public function testCannotFindNamespaceAndPathForMetadata(): void { $class = new ClassMetadataInfo(self::class); $collection = new ClassMetadataCollection([$class]); @@ -36,7 +36,7 @@ public function testCannotFindNamespaceAndPathForMetadata() : void $factory->findNamespaceAndPathForMetadata($collection); } - public function testFindNamespaceAndPathForMetadata() : void + public function testFindNamespaceAndPathForMetadata(): void { $class = new ClassMetadataInfo('\Vendor\Package\Class'); $collection = new ClassMetadataCollection([$class]); diff --git a/Tests/ProfilerTest.php b/Tests/ProfilerTest.php index 05f85f620..7428bb580 100644 --- a/Tests/ProfilerTest.php +++ b/Tests/ProfilerTest.php @@ -32,7 +32,7 @@ class ProfilerTest extends BaseTestCase /** @var DoctrineDataCollector */ private $collector; - public function setUp() : void + public function setUp(): void { $this->logger = new DebugStack(); $registry = $this->getMockBuilder(ManagerRegistry::class)->getMock(); @@ -63,7 +63,7 @@ public function setUp() : void $this->twig->addRuntimeLoader($loader); } - public function testRender() : void + public function testRender(): void { $this->logger->queries = [ [ diff --git a/Tests/RegistryTest.php b/Tests/RegistryTest.php index ac0f272f0..978ebe0bf 100644 --- a/Tests/RegistryTest.php +++ b/Tests/RegistryTest.php @@ -14,7 +14,7 @@ class RegistryTest extends TestCase { - public function testGetDefaultConnectionName() : void + public function testGetDefaultConnectionName(): void { $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $registry = new Registry($container, [], [], 'default', 'default'); @@ -22,7 +22,7 @@ public function testGetDefaultConnectionName() : void $this->assertEquals('default', $registry->getDefaultConnectionName()); } - public function testGetDefaultEntityManagerName() : void + public function testGetDefaultEntityManagerName(): void { $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $registry = new Registry($container, [], [], 'default', 'default'); @@ -30,7 +30,7 @@ public function testGetDefaultEntityManagerName() : void $this->assertEquals('default', $registry->getDefaultManagerName()); } - public function testGetDefaultConnection() : void + public function testGetDefaultConnection(): void { $conn = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock(); $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); @@ -44,7 +44,7 @@ public function testGetDefaultConnection() : void $this->assertSame($conn, $registry->getConnection()); } - public function testGetConnection() : void + public function testGetConnection(): void { $conn = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock(); $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); @@ -58,7 +58,7 @@ public function testGetConnection() : void $this->assertSame($conn, $registry->getConnection('default')); } - public function testGetUnknownConnection() : void + public function testGetUnknownConnection(): void { $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $registry = new Registry($container, [], [], 'default', 'default'); @@ -68,7 +68,7 @@ public function testGetUnknownConnection() : void $registry->getConnection('default'); } - public function testGetConnectionNames() : void + public function testGetConnectionNames(): void { $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $registry = new Registry($container, ['default' => 'doctrine.dbal.default_connection'], [], 'default', 'default'); @@ -76,7 +76,7 @@ public function testGetConnectionNames() : void $this->assertEquals(['default' => 'doctrine.dbal.default_connection'], $registry->getConnectionNames()); } - public function testGetDefaultEntityManager() : void + public function testGetDefaultEntityManager(): void { $em = new stdClass(); $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); @@ -90,7 +90,7 @@ public function testGetDefaultEntityManager() : void $this->assertSame($em, $registry->getManager()); } - public function testGetEntityManager() : void + public function testGetEntityManager(): void { $em = new stdClass(); $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); @@ -104,7 +104,7 @@ public function testGetEntityManager() : void $this->assertSame($em, $registry->getManager('default')); } - public function testGetUnknownEntityManager() : void + public function testGetUnknownEntityManager(): void { $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $registry = new Registry($container, [], [], 'default', 'default'); @@ -116,7 +116,7 @@ public function testGetUnknownEntityManager() : void $registry->getManager('default'); } - public function testResetUnknownEntityManager() : void + public function testResetUnknownEntityManager(): void { $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $registry = new Registry($container, [], [], 'default', 'default'); @@ -128,7 +128,7 @@ public function testResetUnknownEntityManager() : void $registry->resetManager('default'); } - public function testReset() : void + public function testReset(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -164,7 +164,7 @@ public function testReset() : void $registry->reset(); } - public function testIdentityMapsStayConsistentAfterReset() + public function testIdentityMapsStayConsistentAfterReset(): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); diff --git a/Tests/Repository/ContainerRepositoryFactoryTest.php b/Tests/Repository/ContainerRepositoryFactoryTest.php index a4673915c..ef3df1d96 100644 --- a/Tests/Repository/ContainerRepositoryFactoryTest.php +++ b/Tests/Repository/ContainerRepositoryFactoryTest.php @@ -17,7 +17,7 @@ class ContainerRepositoryFactoryTest extends TestCase { - public static function setUpBeforeClass() : void + public static function setUpBeforeClass(): void { if (interface_exists(EntityManagerInterface::class)) { return; @@ -26,7 +26,7 @@ public static function setUpBeforeClass() : void self::markTestSkipped('This test requires ORM'); } - public function testGetRepositoryReturnsService() : void + public function testGetRepositoryReturnsService(): void { $em = $this->createEntityManager(['Foo\CoolEntity' => 'my_repo']); $repo = new StubRepository(); @@ -36,7 +36,7 @@ public function testGetRepositoryReturnsService() : void $this->assertSame($repo, $factory->getRepository($em, 'Foo\CoolEntity')); } - public function testGetRepositoryReturnsEntityRepository() : void + public function testGetRepositoryReturnsEntityRepository(): void { $container = $this->createContainer([]); $em = $this->createEntityManager(['Foo\BoringEntity' => null]); @@ -48,7 +48,7 @@ public function testGetRepositoryReturnsEntityRepository() : void $this->assertSame($actualRepo, $factory->getRepository($em, 'Foo\BoringEntity')); } - public function testCustomRepositoryIsReturned() : void + public function testCustomRepositoryIsReturned(): void { $container = $this->createContainer([]); $em = $this->createEntityManager([ @@ -62,7 +62,7 @@ public function testCustomRepositoryIsReturned() : void $this->assertSame($actualRepo, $factory->getRepository($em, 'Foo\CustomNormalRepoEntity')); } - public function testServiceRepositoriesMustExtendObjectRepository() : void + public function testServiceRepositoriesMustExtendObjectRepository(): void { $repo = new stdClass(); @@ -79,7 +79,7 @@ public function testServiceRepositoriesMustExtendObjectRepository() : void $factory->getRepository($em, 'Foo\CoolEntity'); } - public function testServiceRepositoriesCanNotExtendsEntityRepository() : void + public function testServiceRepositoriesCanNotExtendsEntityRepository(): void { $repo = $this->getMockBuilder(ObjectRepository::class)->getMock(); @@ -93,7 +93,7 @@ public function testServiceRepositoriesCanNotExtendsEntityRepository() : void $this->assertSame($repo, $actualRepo); } - public function testRepositoryMatchesServiceInterfaceButServiceNotFound() : void + public function testRepositoryMatchesServiceInterfaceButServiceNotFound(): void { $container = $this->createContainer([]); @@ -110,7 +110,7 @@ public function testRepositoryMatchesServiceInterfaceButServiceNotFound() : void $factory->getRepository($em, 'Foo\CoolEntity'); } - public function testCustomRepositoryIsNotAValidClass() : void + public function testCustomRepositoryIsNotAValidClass(): void { $container = $this->createContainer([]); @@ -125,7 +125,7 @@ public function testCustomRepositoryIsNotAValidClass() : void $factory->getRepository($em, 'Foo\CoolEntity'); } - private function createContainer(array $services) : MockObject + private function createContainer(array $services): MockObject { $container = $this->getMockBuilder(ContainerInterface::class)->getMock(); $container->expects($this->any()) @@ -142,7 +142,7 @@ private function createContainer(array $services) : MockObject return $container; } - private function createEntityManager(array $entityRepositoryClasses) : MockObject + private function createEntityManager(array $entityRepositoryClasses): MockObject { $classMetadatas = []; foreach ($entityRepositoryClasses as $entityClass => $entityRepositoryClass) { @@ -181,12 +181,12 @@ public function find($id) return null; } - public function findAll() : array + public function findAll(): array { return []; } - public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null) : array + public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array { return []; } @@ -199,7 +199,7 @@ public function findOneBy(array $criteria) return null; } - public function getClassName() : string + public function getClassName(): string { return ''; } diff --git a/Tests/Repository/ServiceEntityRepositoryTest.php b/Tests/Repository/ServiceEntityRepositoryTest.php index 1fffd2a56..6174df2c5 100644 --- a/Tests/Repository/ServiceEntityRepositoryTest.php +++ b/Tests/Repository/ServiceEntityRepositoryTest.php @@ -10,7 +10,7 @@ class ServiceEntityRepositoryTest extends TestCase { - public static function setUpBeforeClass() : void + public static function setUpBeforeClass(): void { if (interface_exists(EntityManagerInterface::class)) { return; @@ -19,7 +19,7 @@ public static function setUpBeforeClass() : void self::markTestSkipped('This test requires ORM'); } - public function testConstructorThrowsExceptionWhenNoManagerFound() : void + public function testConstructorThrowsExceptionWhenNoManagerFound(): void { $registry = $this->getMockBuilder(ManagerRegistry::class)->getMock(); $this->expectException(LogicException::class); diff --git a/Tests/ServiceRepositoryTest.php b/Tests/ServiceRepositoryTest.php index 28db870d3..3e3973ac4 100644 --- a/Tests/ServiceRepositoryTest.php +++ b/Tests/ServiceRepositoryTest.php @@ -21,7 +21,7 @@ class ServiceRepositoryTest extends TestCase { - public static function setUpBeforeClass() : void + public static function setUpBeforeClass(): void { if (interface_exists(EntityManagerInterface::class)) { return; @@ -35,7 +35,7 @@ public static function setUpBeforeClass() : void * * @group legacy */ - public function testRepositoryServiceWiring() : void + public function testRepositoryServiceWiring(): void { $container = new ContainerBuilder(new ParameterBag([ 'kernel.name' => 'app', diff --git a/Tests/TestCase.php b/Tests/TestCase.php index b42f372a0..9d5aaac85 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -15,7 +15,7 @@ class TestCase extends BaseTestCase { - public function createXmlBundleTestContainer() : ContainerBuilder + public function createXmlBundleTestContainer(): ContainerBuilder { $container = new ContainerBuilder(new ParameterBag([ 'kernel.name' => 'app', @@ -85,7 +85,7 @@ public function createXmlBundleTestContainer() : ContainerBuilder class TestCaseAllPublicCompilerPass implements CompilerPassInterface { - public function process(ContainerBuilder $container) : void + public function process(ContainerBuilder $container): void { foreach ($container->getDefinitions() as $id => $definition) { if (strpos($id, 'doctrine') === false) { diff --git a/Tests/Twig/DoctrineExtensionTest.php b/Tests/Twig/DoctrineExtensionTest.php index 48e8823da..57980f423 100644 --- a/Tests/Twig/DoctrineExtensionTest.php +++ b/Tests/Twig/DoctrineExtensionTest.php @@ -7,7 +7,7 @@ class DoctrineExtensionTest extends TestCase { - public function testReplaceQueryParametersWithPostgresCasting() : void + public function testReplaceQueryParametersWithPostgresCasting(): void { $extension = new DoctrineExtension(); $query = 'a=? OR (1)::string OR b=?'; @@ -17,7 +17,7 @@ public function testReplaceQueryParametersWithPostgresCasting() : void $this->assertEquals('a=1 OR (1)::string OR b=2', $result); } - public function testReplaceQueryParametersWithStartingIndexAtOne() : void + public function testReplaceQueryParametersWithStartingIndexAtOne(): void { $extension = new DoctrineExtension(); $query = 'a=? OR b=?'; @@ -30,7 +30,7 @@ public function testReplaceQueryParametersWithStartingIndexAtOne() : void $this->assertEquals('a=1 OR b=2', $result); } - public function testReplaceQueryParameters() : void + public function testReplaceQueryParameters(): void { $extension = new DoctrineExtension(); $query = 'a=? OR b=?'; @@ -43,7 +43,7 @@ public function testReplaceQueryParameters() : void $this->assertEquals('a=1 OR b=2', $result); } - public function testReplaceQueryParametersWithNamedIndex() : void + public function testReplaceQueryParametersWithNamedIndex(): void { $extension = new DoctrineExtension(); $query = 'a=:a OR b=:b'; @@ -56,7 +56,7 @@ public function testReplaceQueryParametersWithNamedIndex() : void $this->assertEquals('a=1 OR b=2', $result); } - public function testReplaceQueryParametersWithEmptyArray() : void + public function testReplaceQueryParametersWithEmptyArray(): void { $extension = new DoctrineExtension(); $query = 'IN (?)'; @@ -68,34 +68,34 @@ public function testReplaceQueryParametersWithEmptyArray() : void $this->assertEquals('IN (NULL)', $result); } - public function testEscapeBinaryParameter() : void + public function testEscapeBinaryParameter(): void { $binaryString = pack('H*', '9d40b8c1417f42d099af4782ec4b20b6'); $this->assertEquals('0x9D40B8C1417F42D099AF4782EC4B20B6', DoctrineExtension::escapeFunction($binaryString)); } - public function testEscapeStringParameter() : void + public function testEscapeStringParameter(): void { $this->assertEquals("'test string'", DoctrineExtension::escapeFunction('test string')); } - public function testEscapeArrayParameter() : void + public function testEscapeArrayParameter(): void { $this->assertEquals("1, NULL, 'test', foo, NULL", DoctrineExtension::escapeFunction([1, null, 'test', new DummyClass('foo'), []])); } - public function testEscapeObjectParameter() : void + public function testEscapeObjectParameter(): void { $object = new DummyClass('bar'); $this->assertEquals('bar', DoctrineExtension::escapeFunction($object)); } - public function testEscapeNullParameter() : void + public function testEscapeNullParameter(): void { $this->assertEquals('NULL', DoctrineExtension::escapeFunction(null)); } - public function testEscapeBooleanParameter() : void + public function testEscapeBooleanParameter(): void { $this->assertEquals('1', DoctrineExtension::escapeFunction(true)); } @@ -103,7 +103,7 @@ public function testEscapeBooleanParameter() : void /** * @group legacy */ - public function testItHighlightsSqlQueriesUsingCssClasses() : void + public function testItHighlightsSqlQueriesUsingCssClasses(): void { $extension = new DoctrineExtension(); self::assertStringContainsString( @@ -119,7 +119,7 @@ public function testItHighlightsSqlQueriesUsingCssClasses() : void /** * @group legacy */ - public function testItDoesNotOutputDuplicatePreTags() : void + public function testItDoesNotOutputDuplicatePreTags(): void { $extension = new DoctrineExtension(); self::assertSame( @@ -135,7 +135,7 @@ public function testItDoesNotOutputDuplicatePreTags() : void /** * @group legacy */ - public function testItUsesCssOnTheDivTag() : void + public function testItUsesCssOnTheDivTag(): void { $extension = new DoctrineExtension(); self::assertSame( @@ -148,7 +148,7 @@ public function testItUsesCssOnTheDivTag() : void ); } - public function testItUsesCssOnThePreTag() : void + public function testItUsesCssOnThePreTag(): void { $extension = new DoctrineExtension(); self::assertSame( @@ -168,7 +168,7 @@ public function __construct(string $str) $this->str = $str; } - public function __toString() : string + public function __toString(): string { return $this->str; } diff --git a/Twig/DoctrineExtension.php b/Twig/DoctrineExtension.php index bfc8e0ac3..c97a1f208 100644 --- a/Twig/DoctrineExtension.php +++ b/Twig/DoctrineExtension.php @@ -32,48 +32,6 @@ public function getFilters() ]; } - /** - * Get the possible combinations of elements from the given array - */ - private function getPossibleCombinations(array $elements, int $combinationsLevel) : array - { - $baseCount = count($elements); - $result = []; - - if ($combinationsLevel === 1) { - foreach ($elements as $element) { - $result[] = [$element]; - } - - return $result; - } - - $nextLevelElements = $this->getPossibleCombinations($elements, $combinationsLevel - 1); - - foreach ($nextLevelElements as $nextLevelElement) { - $lastElement = $nextLevelElement[$combinationsLevel - 2]; - $found = false; - - foreach ($elements as $key => $element) { - if ($element === $lastElement) { - $found = true; - continue; - } - - if ($found !== true || $key >= $baseCount) { - continue; - } - - $tmp = $nextLevelElement; - $newCombination = array_slice($tmp, 0); - $newCombination[] = $element; - $result[] = array_slice($newCombination, 0); - } - } - - return $result; - } - /** * Escape parameters of a SQL query * DON'T USE THIS FUNCTION OUTSIDE ITS INTENDED SCOPE @@ -185,21 +143,21 @@ public function formatQuery($sql, $highlightOnly = false) ); } - public function prettifySql(string $sql) : string + public function prettifySql(string $sql): string { $this->setUpSqlFormatter(); return $this->sqlFormatter->highlight($sql); } - public function formatSql(string $sql, bool $highlight) : string + public function formatSql(string $sql, bool $highlight): string { $this->setUpSqlFormatter($highlight); return $this->sqlFormatter->format($sql); } - private function setUpSqlFormatter(bool $highlight = true, bool $legacy = false) : void + private function setUpSqlFormatter(bool $highlight = true, bool $legacy = false): void { $this->sqlFormatter = new SqlFormatter($highlight ? new HtmlHighlighter([ HtmlHighlighter::HIGHLIGHT_PRE => 'class="highlight highlight-sql"', diff --git a/composer.json b/composer.json index 4e99ff7e5..4febd11bb 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "symfony/service-contracts": "^1.1.1|^2.0" }, "require-dev": { - "doctrine/coding-standard": "^6.0", + "doctrine/coding-standard": "^8.0", "doctrine/orm": "^2.6", "ocramius/proxy-manager": "^2.1", "phpunit/phpunit": "^7.5 || ^9.3", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index c91a02d53..b93c32119 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -18,9 +18,10 @@ - - - + + + + @@ -35,17 +36,20 @@ Tests/DependencyInjection/Fixtures/* - + + Tests/* + + DependencyInjection/* Twig/DoctrineExtension.php Tests/* - + DependencyInjection/* Twig/DoctrineExtension.php Tests/* - + DependencyInjection/* Twig/DoctrineExtension.php Tests/*