From 9199e2ef6e04539665b0184ccb71d81bbb851322 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 27 Nov 2018 11:55:51 +0100 Subject: [PATCH 01/72] [DI] fix combinatorial explosion when analyzing the service graph --- Compiler/InlineServiceDefinitionsPass.php | 12 ++++- Dumper/PhpDumper.php | 66 ++++++++++++++++------- 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/Compiler/InlineServiceDefinitionsPass.php b/Compiler/InlineServiceDefinitionsPass.php index 05eb72d97..65da0b9ac 100644 --- a/Compiler/InlineServiceDefinitionsPass.php +++ b/Compiler/InlineServiceDefinitionsPass.php @@ -127,13 +127,19 @@ private function isInlineableDefinition($id, Definition $definition, ServiceRefe } $ids = array(); + $isReferencedByConstructor = false; foreach ($graph->getNode($id)->getInEdges() as $edge) { + $isReferencedByConstructor = $isReferencedByConstructor || $edge->isReferencedByConstructor(); if ($edge->isWeak()) { return false; } $ids[] = $edge->getSourceNode()->getId(); } + if (!$ids) { + return true; + } + if (\count(array_unique($ids)) > 1) { return false; } @@ -142,6 +148,10 @@ private function isInlineableDefinition($id, Definition $definition, ServiceRefe return false; } - return !$ids || $this->container->getDefinition($ids[0])->isShared(); + if ($isReferencedByConstructor && $this->container->getDefinition($ids[0])->isLazy() && ($definition->getProperties() || $definition->getMethodCalls() || $definition->getConfigurator())) { + return false; + } + + return $this->container->getDefinition($ids[0])->isShared(); } } diff --git a/Dumper/PhpDumper.php b/Dumper/PhpDumper.php index fd7eec057..95a98c6aa 100644 --- a/Dumper/PhpDumper.php +++ b/Dumper/PhpDumper.php @@ -155,17 +155,18 @@ public function dump(array $options = array()) } (new AnalyzeServiceReferencesPass(false, !$this->getProxyDumper() instanceof NullDumper))->process($this->container); + $checkedNodes = array(); $this->circularReferences = array(); - foreach (array(true, false) as $byConstructor) { - foreach ($this->container->getCompiler()->getServiceReferenceGraph()->getNodes() as $id => $node) { - if (!$node->getValue() instanceof Definition) { - continue; - } - $currentPath = array($id => true); - $this->analyzeCircularReferences($node->getOutEdges(), $currentPath, $id, $byConstructor); + foreach ($this->container->getCompiler()->getServiceReferenceGraph()->getNodes() as $id => $node) { + if (!$node->getValue() instanceof Definition) { + continue; + } + if (!isset($checkedNodes[$id])) { + $this->analyzeCircularReferences($id, $node->getOutEdges(), $checkedNodes); } } $this->container->getCompiler()->getServiceReferenceGraph()->clear(); + $checkedNodes = array(); $this->docStar = $options['debug'] ? '*' : ''; @@ -301,12 +302,12 @@ private function getProxyDumper() return $this->proxyDumper; } - private function analyzeCircularReferences(array $edges, &$currentPath, $sourceId, $byConstructor) + private function analyzeCircularReferences($sourceId, array $edges, &$checkedNodes, &$currentPath = array()) { + $checkedNodes[$sourceId] = true; + $currentPath[$sourceId] = $sourceId; + foreach ($edges as $edge) { - if ($byConstructor && !$edge->isReferencedByConstructor()) { - continue; - } $node = $edge->getDestNode(); $id = $node->getId(); @@ -315,20 +316,42 @@ private function analyzeCircularReferences(array $edges, &$currentPath, $sourceI } elseif (isset($currentPath[$id])) { $currentId = $id; foreach (array_reverse($currentPath) as $parentId) { - if (!isset($this->circularReferences[$parentId][$currentId])) { - $this->circularReferences[$parentId][$currentId] = $byConstructor; + $this->circularReferences[$parentId][$currentId] = $currentId; + if ($parentId === $id) { + break; } + $currentId = $parentId; + } + } elseif (!isset($checkedNodes[$id])) { + $this->analyzeCircularReferences($id, $node->getOutEdges(), $checkedNodes, $currentPath); + } elseif (isset($this->circularReferences[$id])) { + $this->connectCircularReferences($id, $currentPath); + } + } + unset($currentPath[$sourceId]); + } + + private function connectCircularReferences($sourceId, &$currentPath, &$subPath = array()) + { + $subPath[$sourceId] = $sourceId; + $currentPath[$sourceId] = $sourceId; + + foreach ($this->circularReferences[$sourceId] as $id) { + if (isset($currentPath[$id])) { + $currentId = $id; + foreach (array_reverse($currentPath) as $parentId) { + $this->circularReferences[$parentId][$currentId] = $currentId; if ($parentId === $id) { break; } $currentId = $parentId; } - } else { - $currentPath[$id] = $id; - $this->analyzeCircularReferences($node->getOutEdges(), $currentPath, $id, $byConstructor); - unset($currentPath[$id]); + } elseif (!isset($subPath[$id]) && isset($this->circularReferences[$id])) { + $this->connectCircularReferences($id, $currentPath, $subPath); } } + unset($currentPath[$sourceId]); + unset($subPath[$sourceId]); } private function collectLineage($class, array &$lineage) @@ -569,8 +592,11 @@ private function addServiceConfigurator(Definition $definition, $variableName = if (\is_array($callable)) { if ($callable[0] instanceof Reference - || ($callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0]))) { - return sprintf(" %s->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName); + || ($callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0])) + ) { + $callable[0] = $this->dumpValue($callable[0]); + + return sprintf(' '.('$' === $callable[0][0] ? '%s' : '(%s)')."->%s(\$%s);\n", $callable[0], $callable[1], $variableName); } $class = $this->dumpValue($callable[0]); @@ -724,7 +750,7 @@ private function addInlineReference($id, Definition $definition, $targetId, $for $hasSelfRef = isset($this->circularReferences[$id][$targetId]); $forConstructor = $forConstructor && !isset($this->definitionVariables[$definition]); - $code = $hasSelfRef && $this->circularReferences[$id][$targetId] && !$forConstructor ? $this->addInlineService($id, $definition, $definition) : ''; + $code = $hasSelfRef && !$forConstructor ? $this->addInlineService($id, $definition, $definition) : ''; if (isset($this->referenceVariables[$targetId]) || (2 > $callCount && (!$hasSelfRef || !$forConstructor))) { return $code; From b9846506ccf280595397f00971d1218e2c35b773 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sat, 1 Dec 2018 20:08:25 +0100 Subject: [PATCH 02/72] [DI] Fix dumping expressions accessing single-use private services --- Dumper/PhpDumper.php | 5 ++--- Tests/Dumper/PhpDumperTest.php | 2 +- Tests/Fixtures/php/services9.php | 2 +- Tests/Fixtures/php/services9_as_files.txt | 2 +- Tests/Fixtures/php/services9_compiled.php | 2 +- .../php/services_almost_circular_private.php | 4 ++-- .../php/services_almost_circular_public.php | 6 +++--- Tests/Fixtures/php/services_env_in_id.php | 4 ++-- Tests/Fixtures/php/services_inline_requires.php | 2 +- Tests/Fixtures/php/services_legacy_privates.php | 2 +- Tests/Fixtures/php/services_locator.php | 14 +++++++------- Tests/Fixtures/php/services_private_frozen.php | 4 ++-- .../php/services_private_in_expression.php | 2 +- Tests/Fixtures/php/services_rot13_env.php | 2 +- Tests/Fixtures/php/services_subscriber.php | 8 ++++---- Tests/Fixtures/php/services_uninitialized_ref.php | 2 +- 16 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Dumper/PhpDumper.php b/Dumper/PhpDumper.php index 95a98c6aa..3a3c24d04 100644 --- a/Dumper/PhpDumper.php +++ b/Dumper/PhpDumper.php @@ -594,9 +594,7 @@ private function addServiceConfigurator(Definition $definition, $variableName = if ($callable[0] instanceof Reference || ($callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0])) ) { - $callable[0] = $this->dumpValue($callable[0]); - - return sprintf(' '.('$' === $callable[0][0] ? '%s' : '(%s)')."->%s(\$%s);\n", $callable[0], $callable[1], $variableName); + return sprintf(" %s->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName); } $class = $this->dumpValue($callable[0]); @@ -1824,6 +1822,7 @@ private function getServiceCall($id, Reference $reference = null) if ($definition->isShared()) { $code = sprintf('$this->services[\'%s\'] = %s', $id, $code); } + $code = "($code)"; } elseif ($this->asFiles && $definition->isShared() && !$this->isHotPath($definition)) { $code = sprintf("\$this->load('%s.php')", $this->generateMethodName($id)); } else { diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index 51c5fd21f..60fa55c3b 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -752,7 +752,7 @@ public function testExpressionReferencingPrivateService() ->setPublic(false); $container->register('public_foo', 'stdClass') ->setPublic(true) - ->addArgument(new Expression('service("private_foo")')); + ->addArgument(new Expression('service("private_foo").bar')); $container->compile(); $dumper = new PhpDumper($container); diff --git a/Tests/Fixtures/php/services9.php b/Tests/Fixtures/php/services9.php index ad316b23c..fc04f5fae 100644 --- a/Tests/Fixtures/php/services9.php +++ b/Tests/Fixtures/php/services9.php @@ -126,7 +126,7 @@ protected function getConfiguredServiceSimpleService() { $this->services['configured_service_simple'] = $instance = new \stdClass(); - ${($_ = isset($this->services['configurator_service_simple']) ? $this->services['configurator_service_simple'] : $this->services['configurator_service_simple'] = new \ConfClass('bar')) && false ?: '_'}->configureStdClass($instance); + ${($_ = isset($this->services['configurator_service_simple']) ? $this->services['configurator_service_simple'] : ($this->services['configurator_service_simple'] = new \ConfClass('bar'))) && false ?: '_'}->configureStdClass($instance); return $instance; } diff --git a/Tests/Fixtures/php/services9_as_files.txt b/Tests/Fixtures/php/services9_as_files.txt index 4b6e2f59e..fa032cbc1 100644 --- a/Tests/Fixtures/php/services9_as_files.txt +++ b/Tests/Fixtures/php/services9_as_files.txt @@ -243,7 +243,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () { yield 0 => ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load('getFooService.php')) && false ?: '_'}; - yield 1 => ${($_ = isset($this->services['tagged_iterator_foo']) ? $this->services['tagged_iterator_foo'] : $this->services['tagged_iterator_foo'] = new \Bar()) && false ?: '_'}; + yield 1 => ${($_ = isset($this->services['tagged_iterator_foo']) ? $this->services['tagged_iterator_foo'] : ($this->services['tagged_iterator_foo'] = new \Bar())) && false ?: '_'}; }, 2)); [Container%s/getTaggedIteratorFooService.php] => services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () { yield 0 => ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->getFooService()) && false ?: '_'}; - yield 1 => ${($_ = isset($this->services['tagged_iterator_foo']) ? $this->services['tagged_iterator_foo'] : $this->services['tagged_iterator_foo'] = new \Bar()) && false ?: '_'}; + yield 1 => ${($_ = isset($this->services['tagged_iterator_foo']) ? $this->services['tagged_iterator_foo'] : ($this->services['tagged_iterator_foo'] = new \Bar())) && false ?: '_'}; }, 2)); } diff --git a/Tests/Fixtures/php/services_almost_circular_private.php b/Tests/Fixtures/php/services_almost_circular_private.php index 9c54acc6b..8aa4a2c40 100644 --- a/Tests/Fixtures/php/services_almost_circular_private.php +++ b/Tests/Fixtures/php/services_almost_circular_private.php @@ -331,7 +331,7 @@ protected function getManager2Service() */ protected function getRootService() { - return $this->services['root'] = new \stdClass(${($_ = isset($this->services['level2']) ? $this->services['level2'] : $this->getLevel2Service()) && false ?: '_'}, ${($_ = isset($this->services['multiuse1']) ? $this->services['multiuse1'] : $this->services['multiuse1'] = new \stdClass()) && false ?: '_'}); + return $this->services['root'] = new \stdClass(${($_ = isset($this->services['level2']) ? $this->services['level2'] : $this->getLevel2Service()) && false ?: '_'}, ${($_ = isset($this->services['multiuse1']) ? $this->services['multiuse1'] : ($this->services['multiuse1'] = new \stdClass())) && false ?: '_'}); } /** @@ -397,7 +397,7 @@ protected function getLevel3Service() */ protected function getLevel4Service() { - return $this->services['level4'] = new \stdClass(${($_ = isset($this->services['multiuse1']) ? $this->services['multiuse1'] : $this->services['multiuse1'] = new \stdClass()) && false ?: '_'}, ${($_ = isset($this->services['level5']) ? $this->services['level5'] : $this->getLevel5Service()) && false ?: '_'}); + return $this->services['level4'] = new \stdClass(${($_ = isset($this->services['multiuse1']) ? $this->services['multiuse1'] : ($this->services['multiuse1'] = new \stdClass())) && false ?: '_'}, ${($_ = isset($this->services['level5']) ? $this->services['level5'] : $this->getLevel5Service()) && false ?: '_'}); } /** diff --git a/Tests/Fixtures/php/services_almost_circular_public.php b/Tests/Fixtures/php/services_almost_circular_public.php index bd08c4d15..a5de37f12 100644 --- a/Tests/Fixtures/php/services_almost_circular_public.php +++ b/Tests/Fixtures/php/services_almost_circular_public.php @@ -126,7 +126,7 @@ protected function getBar3Service() { $this->services['bar3'] = $instance = new \BarCircular(); - $a = ${($_ = isset($this->services['foobar3']) ? $this->services['foobar3'] : $this->services['foobar3'] = new \FoobarCircular()) && false ?: '_'}; + $a = ${($_ = isset($this->services['foobar3']) ? $this->services['foobar3'] : ($this->services['foobar3'] = new \FoobarCircular())) && false ?: '_'}; $instance->addFoobar($a, $a); @@ -431,7 +431,7 @@ protected function getManager2Service() */ protected function getRootService() { - return $this->services['root'] = new \stdClass(${($_ = isset($this->services['level2']) ? $this->services['level2'] : $this->getLevel2Service()) && false ?: '_'}, ${($_ = isset($this->services['multiuse1']) ? $this->services['multiuse1'] : $this->services['multiuse1'] = new \stdClass()) && false ?: '_'}); + return $this->services['root'] = new \stdClass(${($_ = isset($this->services['level2']) ? $this->services['level2'] : $this->getLevel2Service()) && false ?: '_'}, ${($_ = isset($this->services['multiuse1']) ? $this->services['multiuse1'] : ($this->services['multiuse1'] = new \stdClass())) && false ?: '_'}); } /** @@ -497,7 +497,7 @@ protected function getLevel3Service() */ protected function getLevel4Service() { - return $this->services['level4'] = new \stdClass(${($_ = isset($this->services['multiuse1']) ? $this->services['multiuse1'] : $this->services['multiuse1'] = new \stdClass()) && false ?: '_'}, ${($_ = isset($this->services['level5']) ? $this->services['level5'] : $this->getLevel5Service()) && false ?: '_'}); + return $this->services['level4'] = new \stdClass(${($_ = isset($this->services['multiuse1']) ? $this->services['multiuse1'] : ($this->services['multiuse1'] = new \stdClass())) && false ?: '_'}, ${($_ = isset($this->services['level5']) ? $this->services['level5'] : $this->getLevel5Service()) && false ?: '_'}); } /** diff --git a/Tests/Fixtures/php/services_env_in_id.php b/Tests/Fixtures/php/services_env_in_id.php index 91114fd97..dab23e1db 100644 --- a/Tests/Fixtures/php/services_env_in_id.php +++ b/Tests/Fixtures/php/services_env_in_id.php @@ -73,7 +73,7 @@ public function isFrozen() */ protected function getBarService() { - return $this->services['bar'] = new \stdClass(${($_ = isset($this->services['bar_%env(BAR)%']) ? $this->services['bar_%env(BAR)%'] : $this->services['bar_%env(BAR)%'] = new \stdClass()) && false ?: '_'}); + return $this->services['bar'] = new \stdClass(${($_ = isset($this->services['bar_%env(BAR)%']) ? $this->services['bar_%env(BAR)%'] : ($this->services['bar_%env(BAR)%'] = new \stdClass())) && false ?: '_'}); } /** @@ -83,7 +83,7 @@ protected function getBarService() */ protected function getFooService() { - return $this->services['foo'] = new \stdClass(${($_ = isset($this->services['bar_%env(BAR)%']) ? $this->services['bar_%env(BAR)%'] : $this->services['bar_%env(BAR)%'] = new \stdClass()) && false ?: '_'}, array('baz_'.$this->getEnv('string:BAR') => new \stdClass())); + return $this->services['foo'] = new \stdClass(${($_ = isset($this->services['bar_%env(BAR)%']) ? $this->services['bar_%env(BAR)%'] : ($this->services['bar_%env(BAR)%'] = new \stdClass())) && false ?: '_'}, array('baz_'.$this->getEnv('string:BAR') => new \stdClass())); } /** diff --git a/Tests/Fixtures/php/services_inline_requires.php b/Tests/Fixtures/php/services_inline_requires.php index 08a474eea..c6927eb95 100644 --- a/Tests/Fixtures/php/services_inline_requires.php +++ b/Tests/Fixtures/php/services_inline_requires.php @@ -110,7 +110,7 @@ protected function getC2Service() include_once $this->targetDirs[1].'/includes/HotPath/C2.php'; include_once $this->targetDirs[1].'/includes/HotPath/C3.php'; - return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3'] : $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3()) && false ?: '_'}); + return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3())) && false ?: '_'}); } /** diff --git a/Tests/Fixtures/php/services_legacy_privates.php b/Tests/Fixtures/php/services_legacy_privates.php index 7aa1bff87..d720ae396 100644 --- a/Tests/Fixtures/php/services_legacy_privates.php +++ b/Tests/Fixtures/php/services_legacy_privates.php @@ -98,7 +98,7 @@ public function isFrozen() */ protected function getBarService() { - return $this->services['bar'] = new \stdClass(${($_ = isset($this->services['private_not_inlined']) ? $this->services['private_not_inlined'] : $this->services['private_not_inlined'] = new \stdClass()) && false ?: '_'}); + return $this->services['bar'] = new \stdClass(${($_ = isset($this->services['private_not_inlined']) ? $this->services['private_not_inlined'] : ($this->services['private_not_inlined'] = new \stdClass())) && false ?: '_'}); } /** diff --git a/Tests/Fixtures/php/services_locator.php b/Tests/Fixtures/php/services_locator.php index 496f6aa77..c436aea40 100644 --- a/Tests/Fixtures/php/services_locator.php +++ b/Tests/Fixtures/php/services_locator.php @@ -76,7 +76,7 @@ public function isFrozen() */ protected function getBarServiceService() { - return $this->services['bar_service'] = new \stdClass(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : $this->services['baz_service'] = new \stdClass()) && false ?: '_'}); + return $this->services['bar_service'] = new \stdClass(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : ($this->services['baz_service'] = new \stdClass())) && false ?: '_'}); } /** @@ -89,7 +89,7 @@ protected function getFooServiceService() return $this->services['foo_service'] = new \Symfony\Component\DependencyInjection\ServiceLocator(array('bar' => function () { return ${($_ = isset($this->services['bar_service']) ? $this->services['bar_service'] : $this->getBarServiceService()) && false ?: '_'}; }, 'baz' => function () { - $f = function (\stdClass $v) { return $v; }; return $f(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : $this->services['baz_service'] = new \stdClass()) && false ?: '_'}); + $f = function (\stdClass $v) { return $v; }; return $f(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : ($this->services['baz_service'] = new \stdClass())) && false ?: '_'}); }, 'nil' => function () { return NULL; })); @@ -133,7 +133,7 @@ protected function getTranslator_Loader3Service() protected function getTranslator1Service() { return $this->services['translator_1'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(array('translator.loader_1' => function () { - return ${($_ = isset($this->services['translator.loader_1']) ? $this->services['translator.loader_1'] : $this->services['translator.loader_1'] = new \stdClass()) && false ?: '_'}; + return ${($_ = isset($this->services['translator.loader_1']) ? $this->services['translator.loader_1'] : ($this->services['translator.loader_1'] = new \stdClass())) && false ?: '_'}; }))); } @@ -145,10 +145,10 @@ protected function getTranslator1Service() protected function getTranslator2Service() { $this->services['translator_2'] = $instance = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(array('translator.loader_2' => function () { - return ${($_ = isset($this->services['translator.loader_2']) ? $this->services['translator.loader_2'] : $this->services['translator.loader_2'] = new \stdClass()) && false ?: '_'}; + return ${($_ = isset($this->services['translator.loader_2']) ? $this->services['translator.loader_2'] : ($this->services['translator.loader_2'] = new \stdClass())) && false ?: '_'}; }))); - $instance->addResource('db', ${($_ = isset($this->services['translator.loader_2']) ? $this->services['translator.loader_2'] : $this->services['translator.loader_2'] = new \stdClass()) && false ?: '_'}, 'nl'); + $instance->addResource('db', ${($_ = isset($this->services['translator.loader_2']) ? $this->services['translator.loader_2'] : ($this->services['translator.loader_2'] = new \stdClass())) && false ?: '_'}, 'nl'); return $instance; } @@ -161,10 +161,10 @@ protected function getTranslator2Service() protected function getTranslator3Service() { $this->services['translator_3'] = $instance = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(array('translator.loader_3' => function () { - return ${($_ = isset($this->services['translator.loader_3']) ? $this->services['translator.loader_3'] : $this->services['translator.loader_3'] = new \stdClass()) && false ?: '_'}; + return ${($_ = isset($this->services['translator.loader_3']) ? $this->services['translator.loader_3'] : ($this->services['translator.loader_3'] = new \stdClass())) && false ?: '_'}; }))); - $a = ${($_ = isset($this->services['translator.loader_3']) ? $this->services['translator.loader_3'] : $this->services['translator.loader_3'] = new \stdClass()) && false ?: '_'}; + $a = ${($_ = isset($this->services['translator.loader_3']) ? $this->services['translator.loader_3'] : ($this->services['translator.loader_3'] = new \stdClass())) && false ?: '_'}; $instance->addResource('db', $a, 'nl'); $instance->addResource('db', $a, 'en'); diff --git a/Tests/Fixtures/php/services_private_frozen.php b/Tests/Fixtures/php/services_private_frozen.php index 1275e9f26..8ef589c12 100644 --- a/Tests/Fixtures/php/services_private_frozen.php +++ b/Tests/Fixtures/php/services_private_frozen.php @@ -67,7 +67,7 @@ public function isFrozen() */ protected function getBarServiceService() { - return $this->services['bar_service'] = new \stdClass(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : $this->services['baz_service'] = new \stdClass()) && false ?: '_'}); + return $this->services['bar_service'] = new \stdClass(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : ($this->services['baz_service'] = new \stdClass())) && false ?: '_'}); } /** @@ -77,7 +77,7 @@ protected function getBarServiceService() */ protected function getFooServiceService() { - return $this->services['foo_service'] = new \stdClass(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : $this->services['baz_service'] = new \stdClass()) && false ?: '_'}); + return $this->services['foo_service'] = new \stdClass(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : ($this->services['baz_service'] = new \stdClass())) && false ?: '_'}); } /** diff --git a/Tests/Fixtures/php/services_private_in_expression.php b/Tests/Fixtures/php/services_private_in_expression.php index fe84f4975..75cbc2730 100644 --- a/Tests/Fixtures/php/services_private_in_expression.php +++ b/Tests/Fixtures/php/services_private_in_expression.php @@ -67,7 +67,7 @@ public function isFrozen() */ protected function getPublicFooService() { - return $this->services['public_foo'] = new \stdClass(${($_ = isset($this->services['private_foo']) ? $this->services['private_foo'] : $this->services['private_foo'] = new \stdClass()) && false ?: '_'}); + return $this->services['public_foo'] = new \stdClass(${($_ = isset($this->services['private_foo']) ? $this->services['private_foo'] : ($this->services['private_foo'] = new \stdClass())) && false ?: '_'}->bar); } /** diff --git a/Tests/Fixtures/php/services_rot13_env.php b/Tests/Fixtures/php/services_rot13_env.php index 90836aa90..efbb00231 100644 --- a/Tests/Fixtures/php/services_rot13_env.php +++ b/Tests/Fixtures/php/services_rot13_env.php @@ -78,7 +78,7 @@ protected function getRot13EnvVarProcessorService() protected function getContainer_EnvVarProcessorsLocatorService() { return $this->services['container.env_var_processors_locator'] = new \Symfony\Component\DependencyInjection\ServiceLocator(array('rot13' => function () { - return ${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] : $this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor()) && false ?: '_'}; + return ${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor())) && false ?: '_'}; })); } diff --git a/Tests/Fixtures/php/services_subscriber.php b/Tests/Fixtures/php/services_subscriber.php index 9475c9230..8f198f0ba 100644 --- a/Tests/Fixtures/php/services_subscriber.php +++ b/Tests/Fixtures/php/services_subscriber.php @@ -84,13 +84,13 @@ protected function getTestServiceSubscriberService() protected function getFooServiceService() { return $this->services['foo_service'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber((new \Symfony\Component\DependencyInjection\ServiceLocator(array('Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => function () { - $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v = null) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] : $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition()) && false ?: '_'}); + $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v = null) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition())) && false ?: '_'}); }, 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => function () { - $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber $v) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] : $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber()) && false ?: '_'}); + $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber $v) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber())) && false ?: '_'}); }, 'bar' => function () { - $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] : $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber()) && false ?: '_'}); + $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber())) && false ?: '_'}); }, 'baz' => function () { - $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v = null) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] : $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition()) && false ?: '_'}); + $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v = null) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition())) && false ?: '_'}); })))->withContext('foo_service', $this)); } diff --git a/Tests/Fixtures/php/services_uninitialized_ref.php b/Tests/Fixtures/php/services_uninitialized_ref.php index 4d0c00b28..c53e336d2 100644 --- a/Tests/Fixtures/php/services_uninitialized_ref.php +++ b/Tests/Fixtures/php/services_uninitialized_ref.php @@ -107,7 +107,7 @@ protected function getBazService() { $this->services['baz'] = $instance = new \stdClass(); - $instance->foo3 = ${($_ = isset($this->services['foo3']) ? $this->services['foo3'] : $this->services['foo3'] = new \stdClass()) && false ?: '_'}; + $instance->foo3 = ${($_ = isset($this->services['foo3']) ? $this->services['foo3'] : ($this->services['foo3'] = new \stdClass())) && false ?: '_'}; return $instance; } From 5be2d762b51076295a972c86604a977fbcc5c12b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 2 Dec 2018 16:50:25 +0100 Subject: [PATCH 03/72] [DI] dont inline when lazy edges are found --- Compiler/InlineServiceDefinitionsPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Compiler/InlineServiceDefinitionsPass.php b/Compiler/InlineServiceDefinitionsPass.php index 65da0b9ac..a229022ed 100644 --- a/Compiler/InlineServiceDefinitionsPass.php +++ b/Compiler/InlineServiceDefinitionsPass.php @@ -130,7 +130,7 @@ private function isInlineableDefinition($id, Definition $definition, ServiceRefe $isReferencedByConstructor = false; foreach ($graph->getNode($id)->getInEdges() as $edge) { $isReferencedByConstructor = $isReferencedByConstructor || $edge->isReferencedByConstructor(); - if ($edge->isWeak()) { + if ($edge->isWeak() || $edge->isLazy()) { return false; } $ids[] = $edge->getSourceNode()->getId(); From 8fa0dd604eb3fcb9a25f6aa30165ecf4f99f81fd Mon Sep 17 00:00:00 2001 From: knuch Date: Sat, 8 Dec 2018 11:49:49 +0000 Subject: [PATCH 04/72] merge conflicts --- ServiceLocator.php | 17 +++++++++-------- Tests/ServiceLocatorTest.php | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ServiceLocator.php b/ServiceLocator.php index bdedc88e8..10c7c9eb6 100644 --- a/ServiceLocator.php +++ b/ServiceLocator.php @@ -94,39 +94,40 @@ private function createServiceNotFoundMessage($id) $class = isset($class[2]['object']) ? \get_class($class[2]['object']) : null; $externalId = $this->externalId ?: $class; - $msg = sprintf('Service "%s" not found: ', $id); + $msg = array(); + $msg[] = sprintf('Service "%s" not found:', $id); if (!$this->container) { $class = null; } elseif ($this->container->has($id) || isset($this->container->getRemovedIds()[$id])) { - $msg .= 'even though it exists in the app\'s container, '; + $msg[] = 'even though it exists in the app\'s container,'; } else { try { $this->container->get($id); $class = null; } catch (ServiceNotFoundException $e) { if ($e->getAlternatives()) { - $msg .= sprintf(' did you mean %s? Anyway, ', $this->formatAlternatives($e->getAlternatives(), 'or')); + $msg[] = sprintf('did you mean %s? Anyway,', $this->formatAlternatives($e->getAlternatives(), 'or')); } else { $class = null; } } } if ($externalId) { - $msg .= sprintf('the container inside "%s" is a smaller service locator that %s', $externalId, $this->formatAlternatives()); + $msg[] = sprintf('the container inside "%s" is a smaller service locator that %s', $externalId, $this->formatAlternatives()); } else { - $msg .= sprintf('the current service locator %s', $this->formatAlternatives()); + $msg[] = sprintf('the current service locator %s', $this->formatAlternatives()); } if (!$class) { // no-op } elseif (is_subclass_of($class, ServiceSubscriberInterface::class)) { - $msg .= sprintf(' Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "%s::getSubscribedServices()".', preg_replace('/([^\\\\]++\\\\)++/', '', $class)); + $msg[] = sprintf('Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "%s::getSubscribedServices()".', preg_replace('/([^\\\\]++\\\\)++/', '', $class)); } else { - $msg .= 'Try using dependency injection instead.'; + $msg[] = 'Try using dependency injection instead.'; } - return $msg; + return implode(' ', $msg); } private function formatAlternatives(array $alternatives = null, $separator = 'and') diff --git a/Tests/ServiceLocatorTest.php b/Tests/ServiceLocatorTest.php index 56fac643e..aa9790e83 100644 --- a/Tests/ServiceLocatorTest.php +++ b/Tests/ServiceLocatorTest.php @@ -115,6 +115,20 @@ public function testThrowsInServiceSubscriber() $subscriber->getFoo(); } + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException + * @expectedExceptionMessage Service "foo" not found: even though it exists in the app's container, the container inside "foo" is a smaller service locator that is empty... Try using dependency injection instead. + */ + public function testGetThrowsServiceNotFoundException() + { + $container = new Container(); + $container->set('foo', new \stdClass()); + + $locator = new ServiceLocator(array()); + $locator = $locator->withContext('foo', $container); + $locator->get('foo'); + } + public function testInvoke() { $locator = new ServiceLocator(array( From 158a7b3bd92bc70dd595f3ceb9293e0a30b29c31 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Wed, 12 Dec 2018 08:43:43 -0500 Subject: [PATCH 05/72] [DI] move RegisterServiceSubscribersPass before DecoratorServicePass --- Compiler/PassConfig.php | 2 +- Tests/Compiler/IntegrationTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Compiler/PassConfig.php b/Compiler/PassConfig.php index 31104fb1f..d547c3e95 100644 --- a/Compiler/PassConfig.php +++ b/Compiler/PassConfig.php @@ -51,12 +51,12 @@ public function __construct() $this->optimizationPasses = array(array( new ResolveChildDefinitionsPass(), new ServiceLocatorTagPass(), + new RegisterServiceSubscribersPass(), new DecoratorServicePass(), new ResolveParameterPlaceHoldersPass(false), new ResolveFactoryClassPass(), new FactoryReturnTypePass($resolveClassPass), new CheckDefinitionValidityPass(), - new RegisterServiceSubscribersPass(), new ResolveNamedArgumentsPass(), new AutowireRequiredMethodsPass(), new ResolveBindingsPass(), diff --git a/Tests/Compiler/IntegrationTest.php b/Tests/Compiler/IntegrationTest.php index 09ba6ab45..104b39f13 100644 --- a/Tests/Compiler/IntegrationTest.php +++ b/Tests/Compiler/IntegrationTest.php @@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; /** * This class tests the integration of the different compiler passes. @@ -117,6 +118,21 @@ public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDe $this->assertFalse($container->hasDefinition('c'), 'Service C was not inlined.'); } + public function testCanDecorateServiceSubscriber() + { + $container = new ContainerBuilder(); + $container->register(ServiceSubscriberStub::class) + ->addTag('container.service_subscriber') + ->setPublic(true); + + $container->register(DecoratedServiceSubscriber::class) + ->setDecoratedService(ServiceSubscriberStub::class); + + $container->compile(); + + $this->assertInstanceOf(DecoratedServiceSubscriber::class, $container->get(ServiceSubscriberStub::class)); + } + /** * @dataProvider getYamlCompileTests */ @@ -207,6 +223,18 @@ public function getYamlCompileTests() } } +class ServiceSubscriberStub implements ServiceSubscriberInterface +{ + public static function getSubscribedServices() + { + return array(); + } +} + +class DecoratedServiceSubscriber +{ +} + class IntegrationTestStub extends IntegrationTestStubParent { } From f993e07ae8d5f4d79ec1ea92671be08b1eeb7638 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 13 Dec 2018 17:15:21 +0100 Subject: [PATCH 06/72] [DI] fix reporting bindings on overriden services as unused --- Compiler/ResolveBindingsPass.php | 2 + ContainerBuilder.php | 46 ++++++++++++++++--- Tests/Compiler/ResolveBindingsPassTest.php | 18 ++++++++ .../ResolveChildDefinitionsPassTest.php | 2 +- Tests/ContainerBuilderTest.php | 2 +- Tests/Fixtures/config/instanceof.expected.yml | 6 +-- Tests/Fixtures/config/prototype.expected.yml | 10 ++-- 7 files changed, 69 insertions(+), 17 deletions(-) diff --git a/Compiler/ResolveBindingsPass.php b/Compiler/ResolveBindingsPass.php index bcf265ab4..166e23441 100644 --- a/Compiler/ResolveBindingsPass.php +++ b/Compiler/ResolveBindingsPass.php @@ -34,6 +34,8 @@ class ResolveBindingsPass extends AbstractRecursivePass */ public function process(ContainerBuilder $container) { + $this->usedBindings = $container->getRemovedBindingIds(); + try { parent::process($container); diff --git a/ContainerBuilder.php b/ContainerBuilder.php index 5fe6f2ae6..93239a703 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -123,6 +123,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface private $removedIds = array(); + private $removedBindingIds = array(); + private static $internalTypes = array( 'int' => true, 'float' => true, @@ -531,7 +533,8 @@ public function set($id, $service) throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id)); } - unset($this->definitions[$id], $this->aliasDefinitions[$id], $this->removedIds[$id]); + $this->removeId($id); + unset($this->removedIds[$id]); parent::set($id, $service); } @@ -544,8 +547,7 @@ public function set($id, $service) public function removeDefinition($id) { if (isset($this->definitions[$id = $this->normalizeId($id)])) { - unset($this->definitions[$id]); - $this->removedIds[$id] = true; + $this->removeId($id); } } @@ -876,7 +878,8 @@ public function setAlias($alias, $id) throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias)); } - unset($this->definitions[$alias], $this->removedIds[$alias]); + $this->removeId($alias); + unset($this->removedIds[$alias]); return $this->aliasDefinitions[$alias] = $id; } @@ -889,8 +892,7 @@ public function setAlias($alias, $id) public function removeAlias($alias) { if (isset($this->aliasDefinitions[$alias = $this->normalizeId($alias)])) { - unset($this->aliasDefinitions[$alias]); - $this->removedIds[$alias] = true; + $this->removeId($alias); } } @@ -1019,7 +1021,8 @@ public function setDefinition($id, Definition $definition) $id = $this->normalizeId($id); - unset($this->aliasDefinitions[$id], $this->removedIds[$id]); + $this->removeId($id); + unset($this->removedIds[$id]); return $this->definitions[$id] = $definition; } @@ -1552,6 +1555,18 @@ public static function getInitializedConditionals($value) return $services; } + /** + * Gets removed binding ids. + * + * @return array + * + * @internal + */ + public function getRemovedBindingIds() + { + return $this->removedBindingIds; + } + /** * Computes a reasonably unique hash of a value. * @@ -1656,4 +1671,21 @@ private function inVendors($path) return false; } + + private function removeId($id) + { + $this->removedIds[$id] = true; + unset($this->aliasDefinitions[$id]); + + if (!isset($this->definitions[$id])) { + return; + } + + foreach ($this->definitions[$id]->getBindings() as $binding) { + list(, $identifier) = $binding->getValues(); + $this->removedBindingIds[$identifier] = true; + } + + unset($this->definitions[$id]); + } } diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index d59b95af5..24909e115 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -111,4 +111,22 @@ public function testScalarSetter() $this->assertEquals(array(array('setDefaultLocale', array('fr'))), $definition->getMethodCalls()); } + + public function testOverriddenBindings() + { + $container = new ContainerBuilder(); + + $binding = new BoundArgument('bar'); + + $container->register('foo', 'stdClass') + ->setBindings(array('$foo' => clone $binding)); + $container->register('bar', 'stdClass') + ->setBindings(array('$foo' => clone $binding)); + + $container->register('foo', 'stdClass'); + + (new ResolveBindingsPass())->process($container); + + $this->assertInstanceOf('stdClass', $container->get('foo')); + } } diff --git a/Tests/Compiler/ResolveChildDefinitionsPassTest.php b/Tests/Compiler/ResolveChildDefinitionsPassTest.php index 1575bd7b0..863f2833e 100644 --- a/Tests/Compiler/ResolveChildDefinitionsPassTest.php +++ b/Tests/Compiler/ResolveChildDefinitionsPassTest.php @@ -434,7 +434,7 @@ protected function process(ContainerBuilder $container) /** * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - * @expectedExceptionMessageRegExp /^Circular reference detected for service "c", path: "c -> b -> a -> c"./ + * @expectedExceptionMessageRegExp /^Circular reference detected for service "a", path: "a -> c -> b -> a"./ */ public function testProcessDetectsChildDefinitionIndirectCircularReference() { diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index 0bf1befa3..354b44187 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -559,7 +559,7 @@ public function testMerge() $config->setDefinition('baz', new Definition('BazClass')); $config->setAlias('alias_for_foo', 'foo'); $container->merge($config); - $this->assertEquals(array('service_container', 'foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones'); + $this->assertEquals(array('foo', 'bar', 'service_container', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones'); $aliases = $container->getAliases(); $this->assertArrayHasKey('alias_for_foo', $aliases); diff --git a/Tests/Fixtures/config/instanceof.expected.yml b/Tests/Fixtures/config/instanceof.expected.yml index b12a30422..9f0bfbba7 100644 --- a/Tests/Fixtures/config/instanceof.expected.yml +++ b/Tests/Fixtures/config/instanceof.expected.yml @@ -4,6 +4,9 @@ services: class: Symfony\Component\DependencyInjection\ContainerInterface public: true synthetic: true + foo: + class: App\FooService + public: true Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo: class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo public: true @@ -16,6 +19,3 @@ services: shared: false configurator: c - foo: - class: App\FooService - public: true diff --git a/Tests/Fixtures/config/prototype.expected.yml b/Tests/Fixtures/config/prototype.expected.yml index ebfe087d7..0af4d530a 100644 --- a/Tests/Fixtures/config/prototype.expected.yml +++ b/Tests/Fixtures/config/prototype.expected.yml @@ -4,22 +4,22 @@ services: class: Symfony\Component\DependencyInjection\ContainerInterface public: true synthetic: true - Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo: - class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo + Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar: + class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar public: true tags: - { name: foo } - { name: baz } deprecated: '%service_id%' + lazy: true arguments: [1] factory: f - Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar: - class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar + Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo: + class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo public: true tags: - { name: foo } - { name: baz } deprecated: '%service_id%' - lazy: true arguments: [1] factory: f From f67049687207fbaef8006779da367ba0fea4a416 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 28 Dec 2018 12:28:01 +0100 Subject: [PATCH 07/72] Fixed minor typos --- Loader/YamlFileLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Loader/YamlFileLoader.php b/Loader/YamlFileLoader.php index 48cfde60d..27899f220 100644 --- a/Loader/YamlFileLoader.php +++ b/Loader/YamlFileLoader.php @@ -595,7 +595,7 @@ private function parseDefinition($id, $service, $file, array $defaults) * @param string $id A service identifier * @param string $file A parsed file * - * @throws InvalidArgumentException When errors are occuried + * @throws InvalidArgumentException When errors occur * * @return string|array A parsed callable */ From 8432d53580acf3434cf12921b3bd5a9742ffc46a Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 1 Jan 2019 14:42:07 +0100 Subject: [PATCH 08/72] update year in license files --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 21d7fb9e2..a677f4376 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2018 Fabien Potencier +Copyright (c) 2004-2019 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From b2b1cf561dfc66f6cff18eb2088bd748a9a9c700 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 5 Jan 2019 08:48:11 +0100 Subject: [PATCH 09/72] bug #29697 [DI] Fixed wrong factory method in exception (Wojciech Gorczyca) This PR was submitted for the 4.2 branch but it was merged into the 4.1 branch instead (closes #29697). Discussion ---------- [DI] Fixed wrong factory method in exception | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29678 | License | MIT | Doc PR | n/a When a service definition with a factory defines invalid arguments, the [resulting exception message ](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php#L70)incorrectly specifies the factory constructor instead of the factory method as not having the specified named arguments. Commits ------- 922885c892 [DI] Fixed wrong factory method in exception --- Compiler/ResolveNamedArgumentsPass.php | 1 + .../ResolveNamedArgumentsPassTest.php | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Compiler/ResolveNamedArgumentsPass.php b/Compiler/ResolveNamedArgumentsPass.php index 90cf64adb..36980df09 100644 --- a/Compiler/ResolveNamedArgumentsPass.php +++ b/Compiler/ResolveNamedArgumentsPass.php @@ -49,6 +49,7 @@ protected function processValue($value, $isRoot = false) if (null === $parameters) { $r = $this->getReflectionMethod($value, $method); $class = $r instanceof \ReflectionMethod ? $r->class : $this->currentId; + $method = $r->getName(); $parameters = $r->getParameters(); } diff --git a/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/Tests/Compiler/ResolveNamedArgumentsPassTest.php index fe681b41d..087d7ab79 100644 --- a/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -16,8 +16,10 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; +use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy; use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy; use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy; +use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1; /** * @author Kévin Dunglas @@ -102,6 +104,7 @@ public function testClassNoConstructor() /** * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "__construct()" has no argument named "$notFound". Check your service definition. */ public function testArgumentNotFound() { @@ -114,6 +117,24 @@ public function testArgumentNotFound() $pass->process($container); } + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy::create()" has no argument named "$notFound". Check your service definition. + */ + public function testCorrectMethodReportedInException() + { + $container = new ContainerBuilder(); + + $container->register(FactoryDummy::class, FactoryDummy::class); + + $definition = $container->register(TestDefinition1::class, TestDefinition1::class); + $definition->setFactory(array(FactoryDummy::class, 'create')); + $definition->setArguments(array('$notFound' => '123')); + + $pass = new ResolveNamedArgumentsPass(); + $pass->process($container); + } + public function testTypedArgument() { $container = new ContainerBuilder(); From b8ca5890a6831887d1ffa3a0970543760b8ef50b Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 5 Jan 2019 13:04:54 +0100 Subject: [PATCH 10/72] fix tests on PHP 5 --- Tests/Compiler/ResolveNamedArgumentsPassTest.php | 4 ++-- Tests/Fixtures/FactoryDummy.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/Tests/Compiler/ResolveNamedArgumentsPassTest.php index 087d7ab79..c994ff99c 100644 --- a/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -119,7 +119,7 @@ public function testArgumentNotFound() /** * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy::create()" has no argument named "$notFound". Check your service definition. + * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy::createTestDefinition1()" has no argument named "$notFound". Check your service definition. */ public function testCorrectMethodReportedInException() { @@ -128,7 +128,7 @@ public function testCorrectMethodReportedInException() $container->register(FactoryDummy::class, FactoryDummy::class); $definition = $container->register(TestDefinition1::class, TestDefinition1::class); - $definition->setFactory(array(FactoryDummy::class, 'create')); + $definition->setFactory(array(FactoryDummy::class, 'createTestDefinition1')); $definition->setArguments(array('$notFound' => '123')); $pass = new ResolveNamedArgumentsPass(); diff --git a/Tests/Fixtures/FactoryDummy.php b/Tests/Fixtures/FactoryDummy.php index da984b562..04aa5fa28 100644 --- a/Tests/Fixtures/FactoryDummy.php +++ b/Tests/Fixtures/FactoryDummy.php @@ -33,6 +33,10 @@ public static function createSelf(): self public static function createParent(): parent { } + + public function createTestDefinition1() + { + } } class FactoryParent From 928a38b18bd632d67acbca74d0b2eed09915e83e Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 5 Jan 2019 13:23:38 +0100 Subject: [PATCH 11/72] properly fix tests on PHP 5 --- .../ResolveNamedArgumentsPassTest.php | 8 ++++---- Tests/Fixtures/FactoryDummy.php | 4 ---- .../FactoryDummyWithoutReturnTypes.php | 19 +++++++++++++++++++ Tests/Fixtures/TestDefinition1.php | 18 ++++++++++++++++++ 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 Tests/Fixtures/FactoryDummyWithoutReturnTypes.php create mode 100644 Tests/Fixtures/TestDefinition1.php diff --git a/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/Tests/Compiler/ResolveNamedArgumentsPassTest.php index c994ff99c..17b8ebf31 100644 --- a/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -16,7 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; -use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy; +use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummyWithoutReturnTypes; use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy; use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy; use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1; @@ -119,16 +119,16 @@ public function testArgumentNotFound() /** * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy::createTestDefinition1()" has no argument named "$notFound". Check your service definition. + * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummyWithoutReturnTypes::createTestDefinition1()" has no argument named "$notFound". Check your service definition. */ public function testCorrectMethodReportedInException() { $container = new ContainerBuilder(); - $container->register(FactoryDummy::class, FactoryDummy::class); + $container->register(FactoryDummyWithoutReturnTypes::class, FactoryDummyWithoutReturnTypes::class); $definition = $container->register(TestDefinition1::class, TestDefinition1::class); - $definition->setFactory(array(FactoryDummy::class, 'createTestDefinition1')); + $definition->setFactory(array(FactoryDummyWithoutReturnTypes::class, 'createTestDefinition1')); $definition->setArguments(array('$notFound' => '123')); $pass = new ResolveNamedArgumentsPass(); diff --git a/Tests/Fixtures/FactoryDummy.php b/Tests/Fixtures/FactoryDummy.php index 04aa5fa28..da984b562 100644 --- a/Tests/Fixtures/FactoryDummy.php +++ b/Tests/Fixtures/FactoryDummy.php @@ -33,10 +33,6 @@ public static function createSelf(): self public static function createParent(): parent { } - - public function createTestDefinition1() - { - } } class FactoryParent diff --git a/Tests/Fixtures/FactoryDummyWithoutReturnTypes.php b/Tests/Fixtures/FactoryDummyWithoutReturnTypes.php new file mode 100644 index 000000000..f480a668b --- /dev/null +++ b/Tests/Fixtures/FactoryDummyWithoutReturnTypes.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Tests\Fixtures; + +class FactoryDummyWithoutReturnTypes +{ + public function createTestDefinition1() + { + } +} diff --git a/Tests/Fixtures/TestDefinition1.php b/Tests/Fixtures/TestDefinition1.php new file mode 100644 index 000000000..8ec76a9de --- /dev/null +++ b/Tests/Fixtures/TestDefinition1.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Tests\Fixtures; + +use Symfony\Component\DependencyInjection\Definition; + +class TestDefinition1 extends Definition +{ +} From bf7fb471311165984b8447cee52981590856ee02 Mon Sep 17 00:00:00 2001 From: Mikhail Marynich Date: Fri, 11 Jan 2019 16:53:30 +0100 Subject: [PATCH 12/72] Revert "bug #29597 [DI] fix reporting bindings on overriden services as unused (nicolas-grekas)" This reverts commit 44e9a91f306169aff0573bcb8380e3d5f9c912d0, reversing changes made to 91b28ff0817e33f7430084ef4e4b431c6648989d. --- Compiler/ResolveBindingsPass.php | 2 - ContainerBuilder.php | 46 +++---------------- Tests/Compiler/ResolveBindingsPassTest.php | 18 -------- .../ResolveChildDefinitionsPassTest.php | 2 +- Tests/ContainerBuilderTest.php | 2 +- Tests/Fixtures/config/instanceof.expected.yml | 6 +-- Tests/Fixtures/config/prototype.expected.yml | 10 ++-- 7 files changed, 17 insertions(+), 69 deletions(-) diff --git a/Compiler/ResolveBindingsPass.php b/Compiler/ResolveBindingsPass.php index 166e23441..bcf265ab4 100644 --- a/Compiler/ResolveBindingsPass.php +++ b/Compiler/ResolveBindingsPass.php @@ -34,8 +34,6 @@ class ResolveBindingsPass extends AbstractRecursivePass */ public function process(ContainerBuilder $container) { - $this->usedBindings = $container->getRemovedBindingIds(); - try { parent::process($container); diff --git a/ContainerBuilder.php b/ContainerBuilder.php index 93239a703..5fe6f2ae6 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -123,8 +123,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface private $removedIds = array(); - private $removedBindingIds = array(); - private static $internalTypes = array( 'int' => true, 'float' => true, @@ -533,8 +531,7 @@ public function set($id, $service) throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id)); } - $this->removeId($id); - unset($this->removedIds[$id]); + unset($this->definitions[$id], $this->aliasDefinitions[$id], $this->removedIds[$id]); parent::set($id, $service); } @@ -547,7 +544,8 @@ public function set($id, $service) public function removeDefinition($id) { if (isset($this->definitions[$id = $this->normalizeId($id)])) { - $this->removeId($id); + unset($this->definitions[$id]); + $this->removedIds[$id] = true; } } @@ -878,8 +876,7 @@ public function setAlias($alias, $id) throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias)); } - $this->removeId($alias); - unset($this->removedIds[$alias]); + unset($this->definitions[$alias], $this->removedIds[$alias]); return $this->aliasDefinitions[$alias] = $id; } @@ -892,7 +889,8 @@ public function setAlias($alias, $id) public function removeAlias($alias) { if (isset($this->aliasDefinitions[$alias = $this->normalizeId($alias)])) { - $this->removeId($alias); + unset($this->aliasDefinitions[$alias]); + $this->removedIds[$alias] = true; } } @@ -1021,8 +1019,7 @@ public function setDefinition($id, Definition $definition) $id = $this->normalizeId($id); - $this->removeId($id); - unset($this->removedIds[$id]); + unset($this->aliasDefinitions[$id], $this->removedIds[$id]); return $this->definitions[$id] = $definition; } @@ -1555,18 +1552,6 @@ public static function getInitializedConditionals($value) return $services; } - /** - * Gets removed binding ids. - * - * @return array - * - * @internal - */ - public function getRemovedBindingIds() - { - return $this->removedBindingIds; - } - /** * Computes a reasonably unique hash of a value. * @@ -1671,21 +1656,4 @@ private function inVendors($path) return false; } - - private function removeId($id) - { - $this->removedIds[$id] = true; - unset($this->aliasDefinitions[$id]); - - if (!isset($this->definitions[$id])) { - return; - } - - foreach ($this->definitions[$id]->getBindings() as $binding) { - list(, $identifier) = $binding->getValues(); - $this->removedBindingIds[$identifier] = true; - } - - unset($this->definitions[$id]); - } } diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index 24909e115..d59b95af5 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -111,22 +111,4 @@ public function testScalarSetter() $this->assertEquals(array(array('setDefaultLocale', array('fr'))), $definition->getMethodCalls()); } - - public function testOverriddenBindings() - { - $container = new ContainerBuilder(); - - $binding = new BoundArgument('bar'); - - $container->register('foo', 'stdClass') - ->setBindings(array('$foo' => clone $binding)); - $container->register('bar', 'stdClass') - ->setBindings(array('$foo' => clone $binding)); - - $container->register('foo', 'stdClass'); - - (new ResolveBindingsPass())->process($container); - - $this->assertInstanceOf('stdClass', $container->get('foo')); - } } diff --git a/Tests/Compiler/ResolveChildDefinitionsPassTest.php b/Tests/Compiler/ResolveChildDefinitionsPassTest.php index 863f2833e..1575bd7b0 100644 --- a/Tests/Compiler/ResolveChildDefinitionsPassTest.php +++ b/Tests/Compiler/ResolveChildDefinitionsPassTest.php @@ -434,7 +434,7 @@ protected function process(ContainerBuilder $container) /** * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - * @expectedExceptionMessageRegExp /^Circular reference detected for service "a", path: "a -> c -> b -> a"./ + * @expectedExceptionMessageRegExp /^Circular reference detected for service "c", path: "c -> b -> a -> c"./ */ public function testProcessDetectsChildDefinitionIndirectCircularReference() { diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index 354b44187..0bf1befa3 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -559,7 +559,7 @@ public function testMerge() $config->setDefinition('baz', new Definition('BazClass')); $config->setAlias('alias_for_foo', 'foo'); $container->merge($config); - $this->assertEquals(array('foo', 'bar', 'service_container', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones'); + $this->assertEquals(array('service_container', 'foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones'); $aliases = $container->getAliases(); $this->assertArrayHasKey('alias_for_foo', $aliases); diff --git a/Tests/Fixtures/config/instanceof.expected.yml b/Tests/Fixtures/config/instanceof.expected.yml index 9f0bfbba7..b12a30422 100644 --- a/Tests/Fixtures/config/instanceof.expected.yml +++ b/Tests/Fixtures/config/instanceof.expected.yml @@ -4,9 +4,6 @@ services: class: Symfony\Component\DependencyInjection\ContainerInterface public: true synthetic: true - foo: - class: App\FooService - public: true Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo: class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo public: true @@ -19,3 +16,6 @@ services: shared: false configurator: c + foo: + class: App\FooService + public: true diff --git a/Tests/Fixtures/config/prototype.expected.yml b/Tests/Fixtures/config/prototype.expected.yml index 0af4d530a..ebfe087d7 100644 --- a/Tests/Fixtures/config/prototype.expected.yml +++ b/Tests/Fixtures/config/prototype.expected.yml @@ -4,22 +4,22 @@ services: class: Symfony\Component\DependencyInjection\ContainerInterface public: true synthetic: true - Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar: - class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar + Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo: + class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo public: true tags: - { name: foo } - { name: baz } deprecated: '%service_id%' - lazy: true arguments: [1] factory: f - Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo: - class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo + Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar: + class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar public: true tags: - { name: foo } - { name: baz } deprecated: '%service_id%' + lazy: true arguments: [1] factory: f From 9150ac7ec174cc0f05632b51ae54fdef1a3f52e8 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 15 Jan 2019 14:43:24 +0100 Subject: [PATCH 13/72] the string "0" is a valid service identifier --- Loader/XmlFileLoader.php | 4 ++-- Tests/Fixtures/xml/services6.xml | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Loader/XmlFileLoader.php b/Loader/XmlFileLoader.php index 4236b72f2..4677a61ca 100644 --- a/Loader/XmlFileLoader.php +++ b/Loader/XmlFileLoader.php @@ -496,7 +496,7 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase = switch ($arg->getAttribute('type')) { case 'service': - if (!$arg->getAttribute('id')) { + if ('' === $arg->getAttribute('id')) { throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="service" has no or empty "id" attribute in "%s".', $name, $file)); } if ($arg->hasAttribute('strict')) { @@ -549,7 +549,7 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase = * @param \DOMNode $node * @param mixed $name * - * @return array + * @return \DOMElement[] */ private function getChildren(\DOMNode $node, $name) { diff --git a/Tests/Fixtures/xml/services6.xml b/Tests/Fixtures/xml/services6.xml index cffd5df60..c85b7a7c0 100644 --- a/Tests/Fixtures/xml/services6.xml +++ b/Tests/Fixtures/xml/services6.xml @@ -61,5 +61,9 @@ + + + + From ea1c2fdd87ef7178e9d2ae1c6fd989fe2a764e82 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 16 Jan 2019 10:39:14 +0100 Subject: [PATCH 14/72] switched array() to [] --- Argument/BoundArgument.php | 2 +- Argument/ServiceClosureArgument.php | 4 +- Argument/TaggedIteratorArgument.php | 2 +- Compiler/AnalyzeServiceReferencesPass.php | 2 +- Compiler/AutowirePass.php | 30 +-- Compiler/AutowireRequiredMethodsPass.php | 2 +- Compiler/CheckCircularReferencesPass.php | 4 +- Compiler/CheckDefinitionValidityPass.php | 4 +- Compiler/Compiler.php | 4 +- Compiler/DecoratorServicePass.php | 8 +- Compiler/FactoryReturnTypePass.php | 4 +- Compiler/InlineServiceDefinitionsPass.php | 6 +- Compiler/MergeExtensionConfigurationPass.php | 2 +- Compiler/PassConfig.php | 52 ++--- Compiler/PriorityTaggedServiceTrait.php | 2 +- Compiler/RegisterEnvVarProcessorsPass.php | 8 +- Compiler/RegisterServiceSubscribersPass.php | 8 +- Compiler/RemoveUnusedDefinitionsPass.php | 6 +- .../ReplaceAliasByActualDefinitionPass.php | 6 +- Compiler/ResolveBindingsPass.php | 16 +- Compiler/ResolveChildDefinitionsPass.php | 2 +- Compiler/ResolveClassPass.php | 4 +- Compiler/ResolveHotPathPass.php | 4 +- .../ResolveInstanceofConditionalsPass.php | 22 +- Compiler/ResolveNamedArgumentsPass.php | 4 +- Compiler/ResolveParameterPlaceHoldersPass.php | 2 +- Compiler/ResolveReferencesToAliasesPass.php | 4 +- Compiler/ServiceLocatorTagPass.php | 2 +- Compiler/ServiceReferenceGraph.php | 4 +- Compiler/ServiceReferenceGraphNode.php | 6 +- Config/AutowireServiceResource.php | 6 +- Container.php | 42 ++-- ContainerBuilder.php | 72 +++--- Definition.php | 38 +-- Dumper/DumperInterface.php | 2 +- Dumper/GraphvizDumper.php | 40 ++-- Dumper/PhpDumper.php | 94 ++++---- Dumper/XmlDumper.php | 6 +- Dumper/YamlDumper.php | 16 +- EnvVarProcessor.php | 4 +- Exception/ParameterNotFoundException.php | 2 +- Exception/ServiceNotFoundException.php | 2 +- ExpressionLanguage.php | 2 +- ExpressionLanguageProvider.php | 4 +- Extension/Extension.php | 4 +- Loader/Configurator/AbstractConfigurator.php | 2 +- .../AbstractServiceConfigurator.php | 6 +- Loader/Configurator/DefaultsConfigurator.php | 2 +- Loader/Configurator/PrototypeConfigurator.php | 2 +- Loader/Configurator/ServicesConfigurator.php | 6 +- Loader/Configurator/Traits/CallTrait.php | 2 +- Loader/Configurator/Traits/TagTrait.php | 2 +- Loader/FileLoader.php | 10 +- Loader/IniFileLoader.php | 2 +- Loader/XmlFileLoader.php | 44 ++-- Loader/YamlFileLoader.php | 64 ++--- ParameterBag/EnvPlaceholderParameterBag.php | 4 +- ParameterBag/FrozenParameterBag.php | 2 +- ParameterBag/ParameterBag.php | 22 +- ServiceLocator.php | 6 +- Tests/ChildDefinitionTest.php | 36 +-- .../AnalyzeServiceReferencesPassTest.php | 22 +- Tests/Compiler/AutoAliasServicePassTest.php | 10 +- Tests/Compiler/AutowireExceptionPassTest.php | 28 +-- Tests/Compiler/AutowirePassTest.php | 80 +++---- .../AutowireRequiredMethodsPassTest.php | 14 +- .../CheckArgumentsValidityPassTest.php | 34 +-- .../CheckCircularReferencesPassTest.php | 16 +- .../CheckDefinitionValidityPassTest.php | 10 +- ...tionOnInvalidReferenceBehaviorPassTest.php | 2 +- Tests/Compiler/DecoratorServicePassTest.php | 12 +- .../DefinitionErrorExceptionPassTest.php | 8 +- Tests/Compiler/FactoryReturnTypePassTest.php | 24 +- .../InlineServiceDefinitionsPassTest.php | 48 ++-- Tests/Compiler/IntegrationTest.php | 40 ++-- .../MergeExtensionConfigurationPassTest.php | 28 +-- Tests/Compiler/PassConfigTest.php | 2 +- .../PriorityTaggedServiceTraitTest.php | 46 ++-- .../RegisterEnvVarProcessorsPassTest.php | 28 +-- .../RegisterServiceSubscribersPassTest.php | 18 +- .../RemoveUnusedDefinitionsPassTest.php | 14 +- ...ReplaceAliasByActualDefinitionPassTest.php | 2 +- Tests/Compiler/ResolveBindingsPassTest.php | 22 +- .../ResolveChildDefinitionsPassTest.php | 50 ++-- Tests/Compiler/ResolveClassPassTest.php | 10 +- .../ResolveDefinitionTemplatesPassTest.php | 42 ++-- .../Compiler/ResolveFactoryClassPassTest.php | 20 +- Tests/Compiler/ResolveHotPathPassTest.php | 4 +- .../ResolveInstanceofConditionalsPassTest.php | 72 +++--- .../ResolveInvalidReferencesPassTest.php | 42 ++-- .../ResolveNamedArgumentsPassTest.php | 40 ++-- .../ResolveParameterPlaceHoldersPassTest.php | 18 +- .../ResolveReferencesToAliasesPassTest.php | 8 +- .../ResolveTaggedIteratorArgumentPassTest.php | 6 +- Tests/Config/AutowireServiceResourceTest.php | 6 +- ...ContainerParametersResourceCheckerTest.php | 28 +-- .../ContainerParametersResourceTest.php | 4 +- Tests/ContainerBuilderTest.php | 218 +++++++++--------- Tests/ContainerTest.php | 80 +++---- Tests/CrossCheckTest.php | 32 +-- Tests/DefinitionDecoratorTest.php | 32 +-- Tests/DefinitionTest.php | 112 ++++----- Tests/Dumper/GraphvizDumperTest.php | 16 +- Tests/Dumper/PhpDumperTest.php | 196 ++++++++-------- Tests/Dumper/XmlDumperTest.php | 28 +-- Tests/Dumper/YamlDumperTest.php | 2 +- Tests/EnvVarProcessorTest.php | 110 ++++----- Tests/Extension/ExtensionTest.php | 12 +- Tests/Loader/DirectoryLoaderTest.php | 8 +- Tests/Loader/FileLoaderTest.php | 36 +-- Tests/Loader/IniFileLoaderTest.php | 60 ++--- Tests/Loader/LoaderResolverTest.php | 16 +- Tests/Loader/PhpFileLoaderTest.php | 12 +- Tests/Loader/XmlFileLoaderTest.php | 110 ++++----- Tests/Loader/YamlFileLoaderTest.php | 130 +++++------ .../EnvPlaceholderParameterBagTest.php | 4 +- Tests/ParameterBag/FrozenParameterBagTest.php | 14 +- Tests/ParameterBag/ParameterBagTest.php | 106 ++++----- Tests/ServiceLocatorTest.php | 34 +-- 119 files changed, 1499 insertions(+), 1499 deletions(-) diff --git a/Argument/BoundArgument.php b/Argument/BoundArgument.php index f72f21107..a20698440 100644 --- a/Argument/BoundArgument.php +++ b/Argument/BoundArgument.php @@ -33,7 +33,7 @@ public function __construct($value) */ public function getValues() { - return array($this->value, $this->identifier, $this->used); + return [$this->value, $this->identifier, $this->used]; } /** diff --git a/Argument/ServiceClosureArgument.php b/Argument/ServiceClosureArgument.php index 2fec5d26d..6331affa4 100644 --- a/Argument/ServiceClosureArgument.php +++ b/Argument/ServiceClosureArgument.php @@ -25,7 +25,7 @@ class ServiceClosureArgument implements ArgumentInterface public function __construct(Reference $reference) { - $this->values = array($reference); + $this->values = [$reference]; } /** @@ -41,7 +41,7 @@ public function getValues() */ public function setValues(array $values) { - if (array(0) !== array_keys($values) || !($values[0] instanceof Reference || null === $values[0])) { + if ([0] !== array_keys($values) || !($values[0] instanceof Reference || null === $values[0])) { throw new InvalidArgumentException('A ServiceClosureArgument must hold one and only one Reference.'); } diff --git a/Argument/TaggedIteratorArgument.php b/Argument/TaggedIteratorArgument.php index 19e0d2b97..f00e53391 100644 --- a/Argument/TaggedIteratorArgument.php +++ b/Argument/TaggedIteratorArgument.php @@ -25,7 +25,7 @@ class TaggedIteratorArgument extends IteratorArgument */ public function __construct($tag) { - parent::__construct(array()); + parent::__construct([]); $this->tag = (string) $tag; } diff --git a/Compiler/AnalyzeServiceReferencesPass.php b/Compiler/AnalyzeServiceReferencesPass.php index 7c22d3c08..fc4047f90 100644 --- a/Compiler/AnalyzeServiceReferencesPass.php +++ b/Compiler/AnalyzeServiceReferencesPass.php @@ -87,7 +87,7 @@ protected function processValue($value, $isRoot = false) return $value; } if ($value instanceof Expression) { - $this->getExpressionLanguage()->compile((string) $value, array('this' => 'container')); + $this->getExpressionLanguage()->compile((string) $value, ['this' => 'container']); return $value; } diff --git a/Compiler/AutowirePass.php b/Compiler/AutowirePass.php index 4aabb0b29..b411b30f2 100644 --- a/Compiler/AutowirePass.php +++ b/Compiler/AutowirePass.php @@ -28,13 +28,13 @@ */ class AutowirePass extends AbstractRecursivePass { - private $definedTypes = array(); + private $definedTypes = []; private $types; private $ambiguousServiceTypes; - private $autowired = array(); + private $autowired = []; private $lastFailure; private $throwOnAutowiringException; - private $autowiringExceptions = array(); + private $autowiringExceptions = []; private $strictMode; /** @@ -63,16 +63,16 @@ public function getAutowiringExceptions() public function process(ContainerBuilder $container) { // clear out any possibly stored exceptions from before - $this->autowiringExceptions = array(); + $this->autowiringExceptions = []; $this->strictMode = $container->hasParameter('container.autowiring.strict_mode') && $container->getParameter('container.autowiring.strict_mode'); try { parent::process($container); } finally { - $this->definedTypes = array(); + $this->definedTypes = []; $this->types = null; $this->ambiguousServiceTypes = null; - $this->autowired = array(); + $this->autowired = []; } } @@ -89,7 +89,7 @@ public static function createResourceForClass(\ReflectionClass $reflectionClass) { @trigger_error('The '.__METHOD__.'() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead.', E_USER_DEPRECATED); - $metadata = array(); + $metadata = []; foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) { if (!$reflectionMethod->isStatic()) { @@ -147,7 +147,7 @@ private function doProcessValue($value, $isRoot = false) } if ($constructor) { - array_unshift($methodCalls, array($constructor, $value->getArguments())); + array_unshift($methodCalls, [$constructor, $value->getArguments()]); } $methodCalls = $this->autowireCalls($reflectionClass, $methodCalls); @@ -327,9 +327,9 @@ private function getAutowiredReference(TypedReference $reference, $deprecationMe */ private function populateAvailableTypes($onlyAutowiringTypes = false) { - $this->types = array(); + $this->types = []; if (!$onlyAutowiringTypes) { - $this->ambiguousServiceTypes = array(); + $this->ambiguousServiceTypes = []; } foreach ($this->container->getDefinitions() as $id => $definition) { @@ -401,7 +401,7 @@ private function set($type, $id) // keep an array of all services matching this type if (!isset($this->ambiguousServiceTypes[$type])) { - $this->ambiguousServiceTypes[$type] = array($this->types[$type]); + $this->ambiguousServiceTypes[$type] = [$this->types[$type]]; unset($this->types[$type]); } $this->ambiguousServiceTypes[$type][] = $id; @@ -521,7 +521,7 @@ private function createTypeAlternatives(TypedReference $reference) */ private static function getResourceMetadataForMethod(\ReflectionMethod $method) { - $methodArgumentsMetadata = array(); + $methodArgumentsMetadata = []; foreach ($method->getParameters() as $parameter) { try { $class = $parameter->getClass(); @@ -531,11 +531,11 @@ private static function getResourceMetadataForMethod(\ReflectionMethod $method) } $isVariadic = method_exists($parameter, 'isVariadic') && $parameter->isVariadic(); - $methodArgumentsMetadata[] = array( + $methodArgumentsMetadata[] = [ 'class' => $class, 'isOptional' => $parameter->isOptional(), 'defaultValue' => ($parameter->isOptional() && !$isVariadic) ? $parameter->getDefaultValue() : null, - ); + ]; } return $methodArgumentsMetadata; @@ -543,7 +543,7 @@ private static function getResourceMetadataForMethod(\ReflectionMethod $method) private function getAliasesSuggestionForType($type, $extraContext = null) { - $aliases = array(); + $aliases = []; foreach (class_parents($type) + class_implements($type) as $parent) { if ($this->container->has($parent) && !$this->container->findDefinition($parent)->isAbstract()) { $aliases[] = $parent; diff --git a/Compiler/AutowireRequiredMethodsPass.php b/Compiler/AutowireRequiredMethodsPass.php index 6c744f88f..efb9df7b9 100644 --- a/Compiler/AutowireRequiredMethodsPass.php +++ b/Compiler/AutowireRequiredMethodsPass.php @@ -34,7 +34,7 @@ protected function processValue($value, $isRoot = false) return $value; } - $alreadyCalledMethods = array(); + $alreadyCalledMethods = []; foreach ($value->getMethodCalls() as list($method)) { $alreadyCalledMethods[strtolower($method)] = true; diff --git a/Compiler/CheckCircularReferencesPass.php b/Compiler/CheckCircularReferencesPass.php index ac7866b2b..55d911c4f 100644 --- a/Compiler/CheckCircularReferencesPass.php +++ b/Compiler/CheckCircularReferencesPass.php @@ -36,9 +36,9 @@ public function process(ContainerBuilder $container) { $graph = $container->getCompiler()->getServiceReferenceGraph(); - $this->checkedNodes = array(); + $this->checkedNodes = []; foreach ($graph->getNodes() as $id => $node) { - $this->currentPath = array($id); + $this->currentPath = [$id]; $this->checkOutEdges($node->getOutEdges()); } diff --git a/Compiler/CheckDefinitionValidityPass.php b/Compiler/CheckDefinitionValidityPass.php index a1967802f..0e9005415 100644 --- a/Compiler/CheckDefinitionValidityPass.php +++ b/Compiler/CheckDefinitionValidityPass.php @@ -83,7 +83,7 @@ public function process(ContainerBuilder $container) if ($definition->isPublic() && !$definition->isPrivate()) { $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs); if (null !== $usedEnvs) { - throw new EnvParameterException(array($resolvedId), null, 'A service name ("%s") cannot contain dynamic values.'); + throw new EnvParameterException([$resolvedId], null, 'A service name ("%s") cannot contain dynamic values.'); } } } @@ -92,7 +92,7 @@ public function process(ContainerBuilder $container) if ($alias->isPublic() && !$alias->isPrivate()) { $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs); if (null !== $usedEnvs) { - throw new EnvParameterException(array($resolvedId), null, 'An alias name ("%s") cannot contain dynamic values.'); + throw new EnvParameterException([$resolvedId], null, 'An alias name ("%s") cannot contain dynamic values.'); } } } diff --git a/Compiler/Compiler.php b/Compiler/Compiler.php index d5c01a640..a6ae94d8c 100644 --- a/Compiler/Compiler.php +++ b/Compiler/Compiler.php @@ -22,7 +22,7 @@ class Compiler { private $passConfig; - private $log = array(); + private $log = []; private $loggingFormatter; private $serviceReferenceGraph; @@ -141,7 +141,7 @@ public function compile(ContainerBuilder $container) $pass->process($container); } } catch (\Exception $e) { - $usedEnvs = array(); + $usedEnvs = []; $prev = $e; do { diff --git a/Compiler/DecoratorServicePass.php b/Compiler/DecoratorServicePass.php index 263bd4cf1..bbd857e15 100644 --- a/Compiler/DecoratorServicePass.php +++ b/Compiler/DecoratorServicePass.php @@ -32,9 +32,9 @@ public function process(ContainerBuilder $container) if (!$decorated = $definition->getDecoratedService()) { continue; } - $definitions->insert(array($id, $definition), array($decorated[2], --$order)); + $definitions->insert([$id, $definition], [$decorated[2], --$order]); } - $decoratingDefinitions = array(); + $decoratingDefinitions = []; foreach ($definitions as list($id, $definition)) { list($inner, $renamedId) = $definition->getDecoratedService(); @@ -68,9 +68,9 @@ public function process(ContainerBuilder $container) if ($types = array_merge($autowiringTypes, $definition->getAutowiringTypes(false))) { $definition->setAutowiringTypes($types); } - $decoratingDefinition->setTags(array()); + $decoratingDefinition->setTags([]); if ($autowiringTypes) { - $decoratingDefinition->setAutowiringTypes(array()); + $decoratingDefinition->setAutowiringTypes([]); } $decoratingDefinitions[$inner] = $definition; } diff --git a/Compiler/FactoryReturnTypePass.php b/Compiler/FactoryReturnTypePass.php index 1279fcaa7..d688fb59f 100644 --- a/Compiler/FactoryReturnTypePass.php +++ b/Compiler/FactoryReturnTypePass.php @@ -41,14 +41,14 @@ public function process(ContainerBuilder $container) if (!method_exists(\ReflectionMethod::class, 'getReturnType')) { return; } - $resolveClassPassChanges = null !== $this->resolveClassPass ? $this->resolveClassPass->getChanges() : array(); + $resolveClassPassChanges = null !== $this->resolveClassPass ? $this->resolveClassPass->getChanges() : []; foreach ($container->getDefinitions() as $id => $definition) { $this->updateDefinition($container, $id, $definition, $resolveClassPassChanges); } } - private function updateDefinition(ContainerBuilder $container, $id, Definition $definition, array $resolveClassPassChanges, array $previous = array()) + private function updateDefinition(ContainerBuilder $container, $id, Definition $definition, array $resolveClassPassChanges, array $previous = []) { // circular reference if (isset($previous[$id])) { diff --git a/Compiler/InlineServiceDefinitionsPass.php b/Compiler/InlineServiceDefinitionsPass.php index a229022ed..ee3d7e526 100644 --- a/Compiler/InlineServiceDefinitionsPass.php +++ b/Compiler/InlineServiceDefinitionsPass.php @@ -23,8 +23,8 @@ */ class InlineServiceDefinitionsPass extends AbstractRecursivePass implements RepeatablePassInterface { - private $cloningIds = array(); - private $inlinedServiceIds = array(); + private $cloningIds = []; + private $inlinedServiceIds = []; /** * {@inheritdoc} @@ -126,7 +126,7 @@ private function isInlineableDefinition($id, Definition $definition, ServiceRefe return false; } - $ids = array(); + $ids = []; $isReferencedByConstructor = false; foreach ($graph->getNode($id)->getInEdges() as $edge) { $isReferencedByConstructor = $isReferencedByConstructor || $edge->isReferencedByConstructor(); diff --git a/Compiler/MergeExtensionConfigurationPass.php b/Compiler/MergeExtensionConfigurationPass.php index 71cfa2d51..63f8013c3 100644 --- a/Compiler/MergeExtensionConfigurationPass.php +++ b/Compiler/MergeExtensionConfigurationPass.php @@ -110,7 +110,7 @@ public function freezeAfterProcessing(Extension $extension, ContainerBuilder $co // Extension::processConfiguration() wasn't called, we cannot know how configs were merged return; } - $this->processedEnvPlaceholders = array(); + $this->processedEnvPlaceholders = []; // serialize config and container to catch env vars nested in object graphs $config = serialize($config).serialize($container->getDefinitions()).serialize($container->getAliases()).serialize($container->getParameterBag()->all()); diff --git a/Compiler/PassConfig.php b/Compiler/PassConfig.php index d547c3e95..77f4e9531 100644 --- a/Compiler/PassConfig.php +++ b/Compiler/PassConfig.php @@ -29,9 +29,9 @@ class PassConfig const TYPE_REMOVE = 'removing'; private $mergePass; - private $afterRemovingPasses = array(); - private $beforeOptimizationPasses = array(); - private $beforeRemovingPasses = array(); + private $afterRemovingPasses = []; + private $beforeOptimizationPasses = []; + private $beforeRemovingPasses = []; private $optimizationPasses; private $removingPasses; @@ -39,16 +39,16 @@ public function __construct() { $this->mergePass = new MergeExtensionConfigurationPass(); - $this->beforeOptimizationPasses = array( - 100 => array( + $this->beforeOptimizationPasses = [ + 100 => [ $resolveClassPass = new ResolveClassPass(), new ResolveInstanceofConditionalsPass(), new RegisterEnvVarProcessorsPass(), - ), - -1000 => array(new ExtensionCompilerPass()), - ); + ], + -1000 => [new ExtensionCompilerPass()], + ]; - $this->optimizationPasses = array(array( + $this->optimizationPasses = [[ new ResolveChildDefinitionsPass(), new ServiceLocatorTagPass(), new RegisterServiceSubscribersPass(), @@ -69,28 +69,28 @@ public function __construct() new CheckCircularReferencesPass(), new CheckReferenceValidityPass(), new CheckArgumentsValidityPass(false), - )); + ]]; - $this->beforeRemovingPasses = array( - -100 => array( + $this->beforeRemovingPasses = [ + -100 => [ new ResolvePrivatesPass(), - ), - ); + ], + ]; - $this->removingPasses = array(array( + $this->removingPasses = [[ new RemovePrivateAliasesPass(), new ReplaceAliasByActualDefinitionPass(), new RemoveAbstractDefinitionsPass(), - new RepeatedPass(array( + new RepeatedPass([ new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass(), new AnalyzeServiceReferencesPass(), new RemoveUnusedDefinitionsPass(), - )), + ]), new DefinitionErrorExceptionPass(), new CheckExceptionOnInvalidReferenceBehaviorPass(), new ResolveHotPathPass(), - )); + ]]; } /** @@ -101,7 +101,7 @@ public function __construct() public function getPasses() { return array_merge( - array($this->mergePass), + [$this->mergePass], $this->getBeforeOptimizationPasses(), $this->getOptimizationPasses(), $this->getBeforeRemovingPasses(), @@ -142,7 +142,7 @@ public function addPass(CompilerPassInterface $pass, $type = self::TYPE_BEFORE_O $passes = &$this->$property; if (!isset($passes[$priority])) { - $passes[$priority] = array(); + $passes[$priority] = []; } $passes[$priority][] = $pass; } @@ -219,7 +219,7 @@ public function setMergePass(CompilerPassInterface $pass) */ public function setAfterRemovingPasses(array $passes) { - $this->afterRemovingPasses = array($passes); + $this->afterRemovingPasses = [$passes]; } /** @@ -229,7 +229,7 @@ public function setAfterRemovingPasses(array $passes) */ public function setBeforeOptimizationPasses(array $passes) { - $this->beforeOptimizationPasses = array($passes); + $this->beforeOptimizationPasses = [$passes]; } /** @@ -239,7 +239,7 @@ public function setBeforeOptimizationPasses(array $passes) */ public function setBeforeRemovingPasses(array $passes) { - $this->beforeRemovingPasses = array($passes); + $this->beforeRemovingPasses = [$passes]; } /** @@ -249,7 +249,7 @@ public function setBeforeRemovingPasses(array $passes) */ public function setOptimizationPasses(array $passes) { - $this->optimizationPasses = array($passes); + $this->optimizationPasses = [$passes]; } /** @@ -259,7 +259,7 @@ public function setOptimizationPasses(array $passes) */ public function setRemovingPasses(array $passes) { - $this->removingPasses = array($passes); + $this->removingPasses = [$passes]; } /** @@ -272,7 +272,7 @@ public function setRemovingPasses(array $passes) private function sortPasses(array $passes) { if (0 === \count($passes)) { - return array(); + return []; } krsort($passes); diff --git a/Compiler/PriorityTaggedServiceTrait.php b/Compiler/PriorityTaggedServiceTrait.php index ed9b0b7f1..daff3495a 100644 --- a/Compiler/PriorityTaggedServiceTrait.php +++ b/Compiler/PriorityTaggedServiceTrait.php @@ -38,7 +38,7 @@ trait PriorityTaggedServiceTrait */ private function findAndSortTaggedServices($tagName, ContainerBuilder $container) { - $services = array(); + $services = []; foreach ($container->findTaggedServiceIds($tagName, true) as $serviceId => $attributes) { $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0; diff --git a/Compiler/RegisterEnvVarProcessorsPass.php b/Compiler/RegisterEnvVarProcessorsPass.php index e206b0ced..b4d0d0550 100644 --- a/Compiler/RegisterEnvVarProcessorsPass.php +++ b/Compiler/RegisterEnvVarProcessorsPass.php @@ -27,13 +27,13 @@ */ class RegisterEnvVarProcessorsPass implements CompilerPassInterface { - private static $allowedTypes = array('array', 'bool', 'float', 'int', 'string'); + private static $allowedTypes = ['array', 'bool', 'float', 'int', 'string']; public function process(ContainerBuilder $container) { $bag = $container->getParameterBag(); - $types = array(); - $processors = array(); + $types = []; + $processors = []; foreach ($container->findTaggedServiceIds('container.env_var_processor') as $id => $tags) { if (!$r = $container->getReflectionClass($class = $container->getDefinition($id)->getClass())) { throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); @@ -58,7 +58,7 @@ public function process(ContainerBuilder $container) if ($processors) { $container->register('container.env_var_processors_locator', ServiceLocator::class) ->setPublic(true) - ->setArguments(array($processors)) + ->setArguments([$processors]) ; } } diff --git a/Compiler/RegisterServiceSubscribersPass.php b/Compiler/RegisterServiceSubscribersPass.php index 0a7dcd7e9..8eac9f006 100644 --- a/Compiler/RegisterServiceSubscribersPass.php +++ b/Compiler/RegisterServiceSubscribersPass.php @@ -31,7 +31,7 @@ protected function processValue($value, $isRoot = false) return parent::processValue($value, $isRoot); } - $serviceMap = array(); + $serviceMap = []; $autowire = $value->isAutowired(); foreach ($value->getTag('container.service_subscriber') as $attributes) { @@ -40,7 +40,7 @@ protected function processValue($value, $isRoot = false) continue; } ksort($attributes); - if (array() !== array_diff(array_keys($attributes), array('id', 'key'))) { + if ([] !== array_diff(array_keys($attributes), ['id', 'key'])) { throw new InvalidArgumentException(sprintf('The "container.service_subscriber" tag accepts only the "key" and "id" attributes, "%s" given for service "%s".', implode('", "', array_keys($attributes)), $this->currentId)); } if (!array_key_exists('id', $attributes)) { @@ -64,7 +64,7 @@ protected function processValue($value, $isRoot = false) } $class = $r->name; - $subscriberMap = array(); + $subscriberMap = []; $declaringClass = (new \ReflectionMethod($class, 'getSubscribedServices'))->class; foreach ($class::getSubscribedServices() as $key => $type) { @@ -94,7 +94,7 @@ protected function processValue($value, $isRoot = false) throw new InvalidArgumentException(sprintf('Service %s not exist in the map returned by "%s::getSubscribedServices()" for service "%s".', $message, $class, $this->currentId)); } - $value->addTag('container.service_subscriber.locator', array('id' => (string) ServiceLocatorTagPass::register($this->container, $subscriberMap, $this->currentId))); + $value->addTag('container.service_subscriber.locator', ['id' => (string) ServiceLocatorTagPass::register($this->container, $subscriberMap, $this->currentId)]); return parent::processValue($value); } diff --git a/Compiler/RemoveUnusedDefinitionsPass.php b/Compiler/RemoveUnusedDefinitionsPass.php index 5a8548a19..a1013f66c 100644 --- a/Compiler/RemoveUnusedDefinitionsPass.php +++ b/Compiler/RemoveUnusedDefinitionsPass.php @@ -45,8 +45,8 @@ public function process(ContainerBuilder $container) if ($graph->hasNode($id)) { $edges = $graph->getNode($id)->getInEdges(); - $referencingAliases = array(); - $sourceIds = array(); + $referencingAliases = []; + $sourceIds = []; foreach ($edges as $edge) { if ($edge->isWeak()) { continue; @@ -60,7 +60,7 @@ public function process(ContainerBuilder $container) } $isReferenced = (\count(array_unique($sourceIds)) - \count($referencingAliases)) > 0; } else { - $referencingAliases = array(); + $referencingAliases = []; $isReferenced = false; } diff --git a/Compiler/ReplaceAliasByActualDefinitionPass.php b/Compiler/ReplaceAliasByActualDefinitionPass.php index 8e2067659..472bf9415 100644 --- a/Compiler/ReplaceAliasByActualDefinitionPass.php +++ b/Compiler/ReplaceAliasByActualDefinitionPass.php @@ -33,8 +33,8 @@ class ReplaceAliasByActualDefinitionPass extends AbstractRecursivePass public function process(ContainerBuilder $container) { // First collect all alias targets that need to be replaced - $seenAliasTargets = array(); - $replacements = array(); + $seenAliasTargets = []; + $replacements = []; foreach ($container->getAliases() as $definitionId => $target) { $targetId = $container->normalizeId($target); // Special case: leave this target alone @@ -69,7 +69,7 @@ public function process(ContainerBuilder $container) $this->replacements = $replacements; parent::process($container); - $this->replacements = array(); + $this->replacements = []; } /** diff --git a/Compiler/ResolveBindingsPass.php b/Compiler/ResolveBindingsPass.php index bcf265ab4..0fad285e5 100644 --- a/Compiler/ResolveBindingsPass.php +++ b/Compiler/ResolveBindingsPass.php @@ -25,9 +25,9 @@ */ class ResolveBindingsPass extends AbstractRecursivePass { - private $usedBindings = array(); - private $unusedBindings = array(); - private $errorMessages = array(); + private $usedBindings = []; + private $unusedBindings = []; + private $errorMessages = []; /** * {@inheritdoc} @@ -48,9 +48,9 @@ public function process(ContainerBuilder $container) throw new InvalidArgumentException($message); } } finally { - $this->usedBindings = array(); - $this->unusedBindings = array(); - $this->errorMessages = array(); + $this->usedBindings = []; + $this->unusedBindings = []; + $this->errorMessages = []; } } @@ -80,7 +80,7 @@ protected function processValue($value, $isRoot = false) $this->usedBindings[$bindingId] = true; unset($this->unusedBindings[$bindingId]); } elseif (!isset($this->usedBindings[$bindingId])) { - $this->unusedBindings[$bindingId] = array($key, $this->currentId); + $this->unusedBindings[$bindingId] = [$key, $this->currentId]; } if (isset($key[0]) && '$' === $key[0]) { @@ -100,7 +100,7 @@ protected function processValue($value, $isRoot = false) try { if ($constructor = $this->getConstructor($value, false)) { - $calls[] = array($constructor, $value->getArguments()); + $calls[] = [$constructor, $value->getArguments()]; } } catch (RuntimeException $e) { $this->errorMessages[] = $e->getMessage(); diff --git a/Compiler/ResolveChildDefinitionsPass.php b/Compiler/ResolveChildDefinitionsPass.php index d647eda23..539395a43 100644 --- a/Compiler/ResolveChildDefinitionsPass.php +++ b/Compiler/ResolveChildDefinitionsPass.php @@ -39,7 +39,7 @@ protected function processValue($value, $isRoot = false) $value = $this->container->getDefinition($this->currentId); } if ($value instanceof ChildDefinition) { - $this->currentPath = array(); + $this->currentPath = []; $value = $this->resolveDefinition($value); if ($isRoot) { $this->container->setDefinition($this->currentId, $value); diff --git a/Compiler/ResolveClassPass.php b/Compiler/ResolveClassPass.php index 910cb9de9..b1c1b4f88 100644 --- a/Compiler/ResolveClassPass.php +++ b/Compiler/ResolveClassPass.php @@ -20,7 +20,7 @@ */ class ResolveClassPass implements CompilerPassInterface { - private $changes = array(); + private $changes = []; /** * {@inheritdoc} @@ -49,7 +49,7 @@ public function process(ContainerBuilder $container) public function getChanges() { $changes = $this->changes; - $this->changes = array(); + $this->changes = []; return $changes; } diff --git a/Compiler/ResolveHotPathPass.php b/Compiler/ResolveHotPathPass.php index 2888cf4d3..4e025113a 100644 --- a/Compiler/ResolveHotPathPass.php +++ b/Compiler/ResolveHotPathPass.php @@ -24,7 +24,7 @@ class ResolveHotPathPass extends AbstractRecursivePass { private $tagName; - private $resolvedIds = array(); + private $resolvedIds = []; public function __construct($tagName = 'container.hot_path') { @@ -40,7 +40,7 @@ public function process(ContainerBuilder $container) parent::process($container); $container->getDefinition('service_container')->clearTag($this->tagName); } finally { - $this->resolvedIds = array(); + $this->resolvedIds = []; } } diff --git a/Compiler/ResolveInstanceofConditionalsPass.php b/Compiler/ResolveInstanceofConditionalsPass.php index 20507cfb5..69e3796df 100644 --- a/Compiler/ResolveInstanceofConditionalsPass.php +++ b/Compiler/ResolveInstanceofConditionalsPass.php @@ -50,7 +50,7 @@ public function process(ContainerBuilder $container) private function processDefinition(ContainerBuilder $container, $id, Definition $definition) { $instanceofConditionals = $definition->getInstanceofConditionals(); - $autoconfiguredInstanceof = $definition->isAutoconfigured() ? $container->getAutoconfiguredInstanceof() : array(); + $autoconfiguredInstanceof = $definition->isAutoconfigured() ? $container->getAutoconfiguredInstanceof() : []; if (!$instanceofConditionals && !$autoconfiguredInstanceof) { return $definition; } @@ -61,9 +61,9 @@ private function processDefinition(ContainerBuilder $container, $id, Definition $conditionals = $this->mergeConditionals($autoconfiguredInstanceof, $instanceofConditionals, $container); - $definition->setInstanceofConditionals(array()); + $definition->setInstanceofConditionals([]); $parent = $shared = null; - $instanceofTags = array(); + $instanceofTags = []; foreach ($conditionals as $interface => $instanceofDefs) { if ($interface !== $class && (!$container->getReflectionClass($class, false))) { @@ -81,7 +81,7 @@ private function processDefinition(ContainerBuilder $container, $id, Definition $parent = 'instanceof.'.$interface.'.'.$key.'.'.$id; $container->setDefinition($parent, $instanceofDef); $instanceofTags[] = $instanceofDef->getTags(); - $instanceofDef->setTags(array()); + $instanceofDef->setTags([]); if (isset($instanceofDef->getChanges()['shared'])) { $shared = $instanceofDef->isShared(); @@ -94,7 +94,7 @@ private function processDefinition(ContainerBuilder $container, $id, Definition $abstract = $container->setDefinition('abstract.instanceof.'.$id, $definition); // cast Definition to ChildDefinition - $definition->setBindings(array()); + $definition->setBindings([]); $definition = serialize($definition); $definition = substr_replace($definition, '53', 2, 2); $definition = substr_replace($definition, 'Child', 44, 0); @@ -121,11 +121,11 @@ private function processDefinition(ContainerBuilder $container, $id, Definition // reset fields with "merge" behavior $abstract - ->setBindings(array()) - ->setArguments(array()) - ->setMethodCalls(array()) + ->setBindings([]) + ->setArguments([]) + ->setMethodCalls([]) ->setDecoratedService(null) - ->setTags(array()) + ->setTags([]) ->setAbstract(true); } @@ -135,7 +135,7 @@ private function processDefinition(ContainerBuilder $container, $id, Definition private function mergeConditionals(array $autoconfiguredInstanceof, array $instanceofConditionals, ContainerBuilder $container) { // make each value an array of ChildDefinition - $conditionals = array_map(function ($childDef) { return array($childDef); }, $autoconfiguredInstanceof); + $conditionals = array_map(function ($childDef) { return [$childDef]; }, $autoconfiguredInstanceof); foreach ($instanceofConditionals as $interface => $instanceofDef) { // make sure the interface/class exists (but don't validate automaticInstanceofConditionals) @@ -144,7 +144,7 @@ private function mergeConditionals(array $autoconfiguredInstanceof, array $insta } if (!isset($autoconfiguredInstanceof[$interface])) { - $conditionals[$interface] = array(); + $conditionals[$interface] = []; } $conditionals[$interface][] = $instanceofDef; diff --git a/Compiler/ResolveNamedArgumentsPass.php b/Compiler/ResolveNamedArgumentsPass.php index 36980df09..ee54288ec 100644 --- a/Compiler/ResolveNamedArgumentsPass.php +++ b/Compiler/ResolveNamedArgumentsPass.php @@ -33,12 +33,12 @@ protected function processValue($value, $isRoot = false) } $calls = $value->getMethodCalls(); - $calls[] = array('__construct', $value->getArguments()); + $calls[] = ['__construct', $value->getArguments()]; foreach ($calls as $i => $call) { list($method, $arguments) = $call; $parameters = null; - $resolvedArguments = array(); + $resolvedArguments = []; foreach ($arguments as $key => $argument) { if (\is_int($key)) { diff --git a/Compiler/ResolveParameterPlaceHoldersPass.php b/Compiler/ResolveParameterPlaceHoldersPass.php index 9a59a73ec..8c942b524 100644 --- a/Compiler/ResolveParameterPlaceHoldersPass.php +++ b/Compiler/ResolveParameterPlaceHoldersPass.php @@ -42,7 +42,7 @@ public function process(ContainerBuilder $container) try { parent::process($container); - $aliases = array(); + $aliases = []; foreach ($container->getAliases() as $name => $target) { $this->currentId = $name; $aliases[$this->bag->resolveValue($name)] = $target; diff --git a/Compiler/ResolveReferencesToAliasesPass.php b/Compiler/ResolveReferencesToAliasesPass.php index 839af1ae2..b80e45256 100644 --- a/Compiler/ResolveReferencesToAliasesPass.php +++ b/Compiler/ResolveReferencesToAliasesPass.php @@ -63,10 +63,10 @@ protected function processValue($value, $isRoot = false) */ private function getDefinitionId($id, ContainerBuilder $container) { - $seen = array(); + $seen = []; while ($container->hasAlias($id)) { if (isset($seen[$id])) { - throw new ServiceCircularReferenceException($id, array_merge(array_keys($seen), array($id))); + throw new ServiceCircularReferenceException($id, array_merge(array_keys($seen), [$id])); } $seen[$id] = true; $id = $container->normalizeId($container->getAlias($id)); diff --git a/Compiler/ServiceLocatorTagPass.php b/Compiler/ServiceLocatorTagPass.php index 5a0703e83..93e489c8f 100644 --- a/Compiler/ServiceLocatorTagPass.php +++ b/Compiler/ServiceLocatorTagPass.php @@ -102,7 +102,7 @@ public static function register(ContainerBuilder $container, array $refMap, $cal // to derivate customized instances from the prototype one. $container->register($id .= '.'.$callerId, ServiceLocator::class) ->setPublic(false) - ->setFactory(array(new Reference($locatorId), 'withContext')) + ->setFactory([new Reference($locatorId), 'withContext']) ->addArgument($callerId) ->addArgument(new Reference('service_container')); } diff --git a/Compiler/ServiceReferenceGraph.php b/Compiler/ServiceReferenceGraph.php index 83486f053..23d4745ed 100644 --- a/Compiler/ServiceReferenceGraph.php +++ b/Compiler/ServiceReferenceGraph.php @@ -28,7 +28,7 @@ class ServiceReferenceGraph /** * @var ServiceReferenceGraphNode[] */ - private $nodes = array(); + private $nodes = []; /** * Checks if the graph has a specific node. @@ -78,7 +78,7 @@ public function clear() foreach ($this->nodes as $node) { $node->clear(); } - $this->nodes = array(); + $this->nodes = []; } /** diff --git a/Compiler/ServiceReferenceGraphNode.php b/Compiler/ServiceReferenceGraphNode.php index 36b99f1a8..6abd6c86a 100644 --- a/Compiler/ServiceReferenceGraphNode.php +++ b/Compiler/ServiceReferenceGraphNode.php @@ -24,8 +24,8 @@ class ServiceReferenceGraphNode { private $id; - private $inEdges = array(); - private $outEdges = array(); + private $inEdges = []; + private $outEdges = []; private $value; /** @@ -113,6 +113,6 @@ public function getValue() */ public function clear() { - $this->inEdges = $this->outEdges = array(); + $this->inEdges = $this->outEdges = []; } } diff --git a/Config/AutowireServiceResource.php b/Config/AutowireServiceResource.php index 0eac93964..6bb9bb0d1 100644 --- a/Config/AutowireServiceResource.php +++ b/Config/AutowireServiceResource.php @@ -23,7 +23,7 @@ class AutowireServiceResource implements SelfCheckingResourceInterface, \Seriali { private $class; private $filePath; - private $autowiringMetadata = array(); + private $autowiringMetadata = []; public function __construct($class, $path, array $autowiringMetadata) { @@ -60,13 +60,13 @@ public function __toString() public function serialize() { - return serialize(array($this->class, $this->filePath, $this->autowiringMetadata)); + return serialize([$this->class, $this->filePath, $this->autowiringMetadata]); } public function unserialize($serialized) { if (\PHP_VERSION_ID >= 70000) { - list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized, array('allowed_classes' => false)); + list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized, ['allowed_classes' => false]); } else { list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized); } diff --git a/Container.php b/Container.php index 4d3e3883d..ea4a6d763 100644 --- a/Container.php +++ b/Container.php @@ -40,26 +40,26 @@ class Container implements ResettableContainerInterface { protected $parameterBag; - protected $services = array(); - protected $fileMap = array(); - protected $methodMap = array(); - protected $aliases = array(); - protected $loading = array(); - protected $resolving = array(); - protected $syntheticIds = array(); + protected $services = []; + protected $fileMap = []; + protected $methodMap = []; + protected $aliases = []; + protected $loading = []; + protected $resolving = []; + protected $syntheticIds = []; /** * @internal */ - protected $privates = array(); + protected $privates = []; /** * @internal */ - protected $normalizedIds = array(); + protected $normalizedIds = []; - private $underscoreMap = array('_' => '', '.' => '_', '\\' => '_'); - private $envCache = array(); + private $underscoreMap = ['_' => '', '.' => '_', '\\' => '_']; + private $envCache = []; private $compiled = false; private $getEnv; @@ -294,7 +294,7 @@ public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERE } if (isset($this->loading[$id])) { - throw new ServiceCircularReferenceException($id, array_merge(array_keys($this->loading), array($id))); + throw new ServiceCircularReferenceException($id, array_merge(array_keys($this->loading), [$id])); } $this->loading[$id] = true; @@ -331,13 +331,13 @@ public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERE throw new ServiceNotFoundException($id); } if (isset($this->syntheticIds[$id])) { - throw new ServiceNotFoundException($id, null, null, array(), sprintf('The "%s" service is synthetic, it needs to be set at boot time before it can be used.', $id)); + throw new ServiceNotFoundException($id, null, null, [], sprintf('The "%s" service is synthetic, it needs to be set at boot time before it can be used.', $id)); } if (isset($this->getRemovedIds()[$id])) { - throw new ServiceNotFoundException($id, null, null, array(), sprintf('The "%s" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.', $id)); + throw new ServiceNotFoundException($id, null, null, [], sprintf('The "%s" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.', $id)); } - $alternatives = array(); + $alternatives = []; foreach ($this->getServiceIds() as $knownId) { $lev = levenshtein($id, $knownId); if ($lev <= \strlen($id) / 3 || false !== strpos($knownId, $id)) { @@ -380,7 +380,7 @@ public function initialized($id) */ public function reset() { - $this->services = array(); + $this->services = []; } /** @@ -390,7 +390,7 @@ public function reset() */ public function getServiceIds() { - $ids = array(); + $ids = []; if (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class) { // We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder, @@ -415,7 +415,7 @@ public function getServiceIds() */ public function getRemovedIds() { - return array(); + return []; } /** @@ -427,7 +427,7 @@ public function getRemovedIds() */ public static function camelize($id) { - return strtr(ucwords(strtr($id, array('_' => ' ', '.' => '_ ', '\\' => '_ '))), array(' ' => '')); + return strtr(ucwords(strtr($id, ['_' => ' ', '.' => '_ ', '\\' => '_ '])), [' ' => '']); } /** @@ -439,7 +439,7 @@ public static function camelize($id) */ public static function underscore($id) { - return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), str_replace('_', '.', $id))); + return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], str_replace('_', '.', $id))); } /** @@ -470,7 +470,7 @@ protected function getEnv($name) return $this->envCache[$name]; } if (!$this->has($id = 'container.env_var_processors_locator')) { - $this->set($id, new ServiceLocator(array())); + $this->set($id, new ServiceLocator([])); } if (!$this->getEnv) { $this->getEnv = new \ReflectionMethod($this, __FUNCTION__); diff --git a/ContainerBuilder.php b/ContainerBuilder.php index 5fe6f2ae6..436f45b85 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -53,29 +53,29 @@ class ContainerBuilder extends Container implements TaggedContainerInterface /** * @var ExtensionInterface[] */ - private $extensions = array(); + private $extensions = []; /** * @var ExtensionInterface[] */ - private $extensionsByNs = array(); + private $extensionsByNs = []; /** * @var Definition[] */ - private $definitions = array(); + private $definitions = []; /** * @var Alias[] */ - private $aliasDefinitions = array(); + private $aliasDefinitions = []; /** * @var ResourceInterface[] */ - private $resources = array(); + private $resources = []; - private $extensionConfigs = array(); + private $extensionConfigs = []; /** * @var Compiler @@ -97,33 +97,33 @@ class ContainerBuilder extends Container implements TaggedContainerInterface /** * @var ExpressionFunctionProviderInterface[] */ - private $expressionLanguageProviders = array(); + private $expressionLanguageProviders = []; /** * @var string[] with tag names used by findTaggedServiceIds */ - private $usedTags = array(); + private $usedTags = []; /** * @var string[][] a map of env var names to their placeholders */ - private $envPlaceholders = array(); + private $envPlaceholders = []; /** * @var int[] a map of env vars to their resolution counter */ - private $envCounters = array(); + private $envCounters = []; /** * @var string[] the list of vendor directories */ private $vendors; - private $autoconfiguredInstanceof = array(); + private $autoconfiguredInstanceof = []; - private $removedIds = array(); + private $removedIds = []; - private static $internalTypes = array( + private static $internalTypes = [ 'int' => true, 'float' => true, 'string' => true, @@ -135,7 +135,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface 'callable' => true, 'iterable' => true, 'mixed' => true, - ); + ]; public function __construct(ParameterBagInterface $parameterBag = null) { @@ -449,7 +449,7 @@ public function loadFromExtension($extension, array $values = null) } if (\func_num_args() < 2) { - $values = array(); + $values = []; } $namespace = $this->getExtension($extension)->getAlias(); @@ -596,7 +596,7 @@ private function doGet($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_ } if (null === $inlineServices) { $isConstructorArgument = true; - $inlineServices = array(); + $inlineServices = []; } try { if (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $invalidBehavior) { @@ -676,7 +676,7 @@ public function merge(self $container) foreach ($this->extensions as $name => $extension) { if (!isset($this->extensionConfigs[$name])) { - $this->extensionConfigs[$name] = array(); + $this->extensionConfigs[$name] = []; } $this->extensionConfigs[$name] = array_merge($this->extensionConfigs[$name], $container->getExtensionConfig($name)); @@ -686,7 +686,7 @@ public function merge(self $container) $envPlaceholders = $container->getParameterBag()->getEnvPlaceholders(); $this->getParameterBag()->mergeEnvPlaceholders($container->getParameterBag()); } else { - $envPlaceholders = array(); + $envPlaceholders = []; } foreach ($container->envCounters as $env => $count) { @@ -719,7 +719,7 @@ public function merge(self $container) public function getExtensionConfig($name) { if (!isset($this->extensionConfigs[$name])) { - $this->extensionConfigs[$name] = array(); + $this->extensionConfigs[$name] = []; } return $this->extensionConfigs[$name]; @@ -734,7 +734,7 @@ public function getExtensionConfig($name) public function prependExtensionConfig($name, array $config) { if (!isset($this->extensionConfigs[$name])) { - $this->extensionConfigs[$name] = array(); + $this->extensionConfigs[$name] = []; } array_unshift($this->extensionConfigs[$name], $config); @@ -793,7 +793,7 @@ public function compile(/*$resolveEnvPlaceholders = false*/) } } - $this->extensionConfigs = array(); + $this->extensionConfigs = []; if ($bag instanceof EnvPlaceholderParameterBag) { if ($resolveEnvPlaceholders) { @@ -847,7 +847,7 @@ public function addAliases(array $aliases) */ public function setAliases(array $aliases) { - $this->aliasDefinitions = array(); + $this->aliasDefinitions = []; $this->addAliases($aliases); } @@ -987,7 +987,7 @@ public function addDefinitions(array $definitions) */ public function setDefinitions(array $definitions) { - $this->definitions = array(); + $this->definitions = []; $this->addDefinitions($definitions); } @@ -1071,7 +1071,7 @@ public function findDefinition($id) { $id = $this->normalizeId($id); - $seen = array(); + $seen = []; while (isset($this->aliasDefinitions[$id])) { $id = (string) $this->aliasDefinitions[$id]; @@ -1143,7 +1143,7 @@ private function createService(Definition $definition, array &$inlineServices, $ if (null !== $factory = $definition->getFactory()) { if (\is_array($factory)) { - $factory = array($this->doResolveServices($parameterBag->resolveValue($factory[0]), $inlineServices, $isConstructorArgument), $factory[1]); + $factory = [$this->doResolveServices($parameterBag->resolveValue($factory[0]), $inlineServices, $isConstructorArgument), $factory[1]]; } elseif (!\is_string($factory)) { throw new RuntimeException(sprintf('Cannot create service "%s" because of invalid factory', $id)); } @@ -1169,7 +1169,7 @@ private function createService(Definition $definition, array &$inlineServices, $ $service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments); // don't trigger deprecations for internal uses // @deprecated since version 3.3, to be removed in 4.0 along with the deprecated class - $deprecationWhitelist = array('event_dispatcher' => ContainerAwareEventDispatcher::class); + $deprecationWhitelist = ['event_dispatcher' => ContainerAwareEventDispatcher::class]; if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment(), "\n * @deprecated ") && (!isset($deprecationWhitelist[$id]) || $deprecationWhitelist[$id] !== $class)) { @trigger_error(sprintf('The "%s" service relies on the deprecated "%s" class. It should either be deprecated or its implementation upgraded.', $id, $r->name), E_USER_DEPRECATED); @@ -1224,7 +1224,7 @@ public function resolveServices($value) return $this->doResolveServices($value); } - private function doResolveServices($value, array &$inlineServices = array(), $isConstructorArgument = false) + private function doResolveServices($value, array &$inlineServices = [], $isConstructorArgument = false) { if (\is_array($value)) { foreach ($value as $k => $v) { @@ -1277,7 +1277,7 @@ private function doResolveServices($value, array &$inlineServices = array(), $is } elseif ($value instanceof Parameter) { $value = $this->getParameter((string) $value); } elseif ($value instanceof Expression) { - $value = $this->getExpressionLanguage()->evaluate($value, array('container' => $this)); + $value = $this->getExpressionLanguage()->evaluate($value, ['container' => $this]); } return $value; @@ -1305,7 +1305,7 @@ private function doResolveServices($value, array &$inlineServices = array(), $is public function findTaggedServiceIds($name, $throwOnAbstract = false) { $this->usedTags[] = $name; - $tags = array(); + $tags = []; foreach ($this->getDefinitions() as $id => $definition) { if ($definition->hasTag($name)) { if ($throwOnAbstract && $definition->isAbstract()) { @@ -1325,7 +1325,7 @@ public function findTaggedServiceIds($name, $throwOnAbstract = false) */ public function findTags() { - $tags = array(); + $tags = []; foreach ($this->getDefinitions() as $id => $definition) { $tags = array_merge(array_keys($definition->getTags()), $tags); } @@ -1405,7 +1405,7 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs } if (\is_array($value)) { - $result = array(); + $result = []; foreach ($value as $k => $v) { $result[\is_string($k) ? $this->resolveEnvPlaceholders($k, $format, $usedEnvs) : $k] = $this->resolveEnvPlaceholders($v, $format, $usedEnvs); } @@ -1473,7 +1473,7 @@ public function getEnvCounters() */ public function getNormalizedIds() { - $normalizedIds = array(); + $normalizedIds = []; foreach ($this->normalizedIds as $k => $v) { if ($v !== (string) $k) { @@ -1515,7 +1515,7 @@ public function normalizeId($id) */ public static function getServiceConditionals($value) { - $services = array(); + $services = []; if (\is_array($value)) { foreach ($value as $v) { @@ -1539,7 +1539,7 @@ public static function getServiceConditionals($value) */ public static function getInitializedConditionals($value) { - $services = array(); + $services = []; if (\is_array($value)) { foreach ($value as $v) { @@ -1563,7 +1563,7 @@ public static function hash($value) { $hash = substr(base64_encode(hash('sha256', serialize($value), true)), 0, 7); - return str_replace(array('/', '+'), array('.', '_'), strtolower($hash)); + return str_replace(['/', '+'], ['.', '_'], strtolower($hash)); } /** @@ -1607,7 +1607,7 @@ private function callMethod($service, $call, array &$inlineServices) } } - \call_user_func_array(array($service, $call[0]), $this->doResolveServices($this->getParameterBag()->unescapeValue($this->getParameterBag()->resolveValue($call[1])), $inlineServices)); + \call_user_func_array([$service, $call[0]], $this->doResolveServices($this->getParameterBag()->unescapeValue($this->getParameterBag()->resolveValue($call[1])), $inlineServices)); } /** diff --git a/Definition.php b/Definition.php index 849d617a1..171bcaf46 100644 --- a/Definition.php +++ b/Definition.php @@ -28,12 +28,12 @@ class Definition private $shared = true; private $deprecated = false; private $deprecationTemplate; - private $properties = array(); - private $calls = array(); - private $instanceof = array(); + private $properties = []; + private $calls = []; + private $instanceof = []; private $autoconfigured = false; private $configurator; - private $tags = array(); + private $tags = []; private $public = true; private $private = true; private $synthetic = false; @@ -41,12 +41,12 @@ class Definition private $lazy = false; private $decoratedService; private $autowired = false; - private $autowiringTypes = array(); - private $changes = array(); - private $bindings = array(); - private $errors = array(); + private $autowiringTypes = []; + private $changes = []; + private $bindings = []; + private $errors = []; - protected $arguments = array(); + protected $arguments = []; private static $defaultDeprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.'; @@ -54,7 +54,7 @@ class Definition * @param string|null $class The service class * @param array $arguments An array of arguments to pass to the service constructor */ - public function __construct($class = null, array $arguments = array()) + public function __construct($class = null, array $arguments = []) { if (null !== $class) { $this->setClass($class); @@ -138,7 +138,7 @@ public function setDecoratedService($id, $renamedId = null, $priority = 0) if (null === $id) { $this->decoratedService = null; } else { - $this->decoratedService = array($id, $renamedId, (int) $priority); + $this->decoratedService = [$id, $renamedId, (int) $priority]; } return $this; @@ -320,9 +320,9 @@ public function getArgument($index) * * @return $this */ - public function setMethodCalls(array $calls = array()) + public function setMethodCalls(array $calls = []) { - $this->calls = array(); + $this->calls = []; foreach ($calls as $call) { $this->addMethodCall($call[0], $call[1]); } @@ -340,12 +340,12 @@ public function setMethodCalls(array $calls = array()) * * @throws InvalidArgumentException on empty $method param */ - public function addMethodCall($method, array $arguments = array()) + public function addMethodCall($method, array $arguments = []) { if (empty($method)) { throw new InvalidArgumentException('Method name cannot be empty.'); } - $this->calls[] = array($method, $arguments); + $this->calls[] = [$method, $arguments]; return $this; } @@ -476,7 +476,7 @@ public function getTags() */ public function getTag($name) { - return isset($this->tags[$name]) ? $this->tags[$name] : array(); + return isset($this->tags[$name]) ? $this->tags[$name] : []; } /** @@ -487,7 +487,7 @@ public function getTag($name) * * @return $this */ - public function addTag($name, array $attributes = array()) + public function addTag($name, array $attributes = []) { $this->tags[$name][] = $attributes; @@ -527,7 +527,7 @@ public function clearTag($name) */ public function clearTags() { - $this->tags = array(); + $this->tags = []; return $this; } @@ -816,7 +816,7 @@ public function setAutowiringTypes(array $types) { @trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED); - $this->autowiringTypes = array(); + $this->autowiringTypes = []; foreach ($types as $type) { $this->autowiringTypes[$type] = true; diff --git a/Dumper/DumperInterface.php b/Dumper/DumperInterface.php index dd001e4ed..1ea775ddf 100644 --- a/Dumper/DumperInterface.php +++ b/Dumper/DumperInterface.php @@ -25,5 +25,5 @@ interface DumperInterface * * @return string The representation of the service container */ - public function dump(array $options = array()); + public function dump(array $options = []); } diff --git a/Dumper/GraphvizDumper.php b/Dumper/GraphvizDumper.php index 2105d1d40..3adcef79b 100644 --- a/Dumper/GraphvizDumper.php +++ b/Dumper/GraphvizDumper.php @@ -32,14 +32,14 @@ class GraphvizDumper extends Dumper { private $nodes; private $edges; - private $options = array( - 'graph' => array('ratio' => 'compress'), - 'node' => array('fontsize' => 11, 'fontname' => 'Arial', 'shape' => 'record'), - 'edge' => array('fontsize' => 9, 'fontname' => 'Arial', 'color' => 'grey', 'arrowhead' => 'open', 'arrowsize' => 0.5), - 'node.instance' => array('fillcolor' => '#9999ff', 'style' => 'filled'), - 'node.definition' => array('fillcolor' => '#eeeeee'), - 'node.missing' => array('fillcolor' => '#ff9999', 'style' => 'filled'), - ); + private $options = [ + 'graph' => ['ratio' => 'compress'], + 'node' => ['fontsize' => 11, 'fontname' => 'Arial', 'shape' => 'record'], + 'edge' => ['fontsize' => 9, 'fontname' => 'Arial', 'color' => 'grey', 'arrowhead' => 'open', 'arrowsize' => 0.5], + 'node.instance' => ['fillcolor' => '#9999ff', 'style' => 'filled'], + 'node.definition' => ['fillcolor' => '#eeeeee'], + 'node.missing' => ['fillcolor' => '#ff9999', 'style' => 'filled'], + ]; /** * Dumps the service container as a graphviz graph. @@ -55,9 +55,9 @@ class GraphvizDumper extends Dumper * * @return string The dot representation of the service container */ - public function dump(array $options = array()) + public function dump(array $options = []) { - foreach (array('graph', 'node', 'edge', 'node.instance', 'node.definition', 'node.missing') as $key) { + foreach (['graph', 'node', 'edge', 'node.instance', 'node.definition', 'node.missing'] as $key) { if (isset($options[$key])) { $this->options[$key] = array_merge($this->options[$key], $options[$key]); } @@ -65,7 +65,7 @@ public function dump(array $options = array()) $this->nodes = $this->findNodes(); - $this->edges = array(); + $this->edges = []; foreach ($this->container->getDefinitions() as $id => $definition) { $this->edges[$id] = array_merge( $this->findEdges($id, $definition->getArguments(), true, ''), @@ -129,7 +129,7 @@ private function addEdges() */ private function findEdges($id, array $arguments, $required, $name, $lazy = false) { - $edges = array(); + $edges = []; foreach ($arguments as $argument) { if ($argument instanceof Parameter) { $argument = $this->container->hasParameter($argument) ? $this->container->getParameter($argument) : null; @@ -141,12 +141,12 @@ private function findEdges($id, array $arguments, $required, $name, $lazy = fals $lazyEdge = $lazy; if (!$this->container->has((string) $argument)) { - $this->nodes[(string) $argument] = array('name' => $name, 'required' => $required, 'class' => '', 'attributes' => $this->options['node.missing']); + $this->nodes[(string) $argument] = ['name' => $name, 'required' => $required, 'class' => '', 'attributes' => $this->options['node.missing']]; } elseif ('service_container' !== (string) $argument) { $lazyEdge = $lazy || $this->container->getDefinition((string) $argument)->isLazy(); } - $edges[] = array('name' => $name, 'required' => $required, 'to' => $argument, 'lazy' => $lazyEdge); + $edges[] = ['name' => $name, 'required' => $required, 'to' => $argument, 'lazy' => $lazyEdge]; } elseif ($argument instanceof ArgumentInterface) { $edges = array_merge($edges, $this->findEdges($id, $argument->getValues(), $required, $name, true)); } elseif ($argument instanceof Definition) { @@ -172,7 +172,7 @@ private function findEdges($id, array $arguments, $required, $name, $lazy = fals */ private function findNodes() { - $nodes = array(); + $nodes = []; $container = $this->cloneContainer(); @@ -188,7 +188,7 @@ private function findNodes() } catch (ParameterNotFoundException $e) { } - $nodes[$id] = array('class' => str_replace('\\', '\\\\', $class), 'attributes' => array_merge($this->options['node.definition'], array('style' => $definition->isShared() ? 'filled' : 'dotted'))); + $nodes[$id] = ['class' => str_replace('\\', '\\\\', $class), 'attributes' => array_merge($this->options['node.definition'], ['style' => $definition->isShared() ? 'filled' : 'dotted'])]; $container->setDefinition($id, new Definition('stdClass')); } @@ -198,7 +198,7 @@ private function findNodes() } if (!$container->hasDefinition($id)) { - $nodes[$id] = array('class' => str_replace('\\', '\\\\', \get_class($container->get($id))), 'attributes' => $this->options['node.instance']); + $nodes[$id] = ['class' => str_replace('\\', '\\\\', \get_class($container->get($id))), 'attributes' => $this->options['node.instance']]; } } @@ -253,7 +253,7 @@ private function endDot() */ private function addAttributes(array $attributes) { - $code = array(); + $code = []; foreach ($attributes as $k => $v) { $code[] = sprintf('%s="%s"', $k, $v); } @@ -270,7 +270,7 @@ private function addAttributes(array $attributes) */ private function addOptions(array $options) { - $code = array(); + $code = []; foreach ($options as $k => $v) { $code[] = sprintf('%s="%s"', $k, $v); } @@ -299,7 +299,7 @@ private function dotize($id) */ private function getAliases($id) { - $aliases = array(); + $aliases = []; foreach ($this->container->getAliases() as $alias => $origin) { if ($id == $origin) { $aliases[] = $alias; diff --git a/Dumper/PhpDumper.php b/Dumper/PhpDumper.php index 3a3c24d04..1e348b2bf 100644 --- a/Dumper/PhpDumper.php +++ b/Dumper/PhpDumper.php @@ -57,7 +57,7 @@ class PhpDumper extends Dumper private $variableCount; private $inlinedDefinitions; private $serviceCalls; - private $reservedVariables = array('instance', 'class', 'this'); + private $reservedVariables = ['instance', 'class', 'this']; private $expressionLanguage; private $targetDirRegex; private $targetDirMaxMatches; @@ -68,8 +68,8 @@ class PhpDumper extends Dumper private $asFiles; private $hotPathTag; private $inlineRequires; - private $inlinedRequires = array(); - private $circularReferences = array(); + private $inlinedRequires = []; + private $circularReferences = []; /** * @var ProxyDumper @@ -110,11 +110,11 @@ public function setProxyDumper(ProxyDumper $proxyDumper) * * @throws EnvParameterException When an env var exists but has not been dumped */ - public function dump(array $options = array()) + public function dump(array $options = []) { $this->targetDirRegex = null; - $this->inlinedRequires = array(); - $options = array_merge(array( + $this->inlinedRequires = []; + $options = array_merge([ 'class' => 'ProjectServiceContainer', 'base_class' => 'Container', 'namespace' => '', @@ -123,7 +123,7 @@ public function dump(array $options = array()) 'hot_path_tag' => 'container.hot_path', 'inline_class_loader_parameter' => 'container.dumper.inline_class_loader', 'build_time' => time(), - ), $options); + ], $options); $this->namespace = $options['namespace']; $this->asFiles = $options['as_files']; @@ -155,8 +155,8 @@ public function dump(array $options = array()) } (new AnalyzeServiceReferencesPass(false, !$this->getProxyDumper() instanceof NullDumper))->process($this->container); - $checkedNodes = array(); - $this->circularReferences = array(); + $checkedNodes = []; + $this->circularReferences = []; foreach ($this->container->getCompiler()->getServiceReferenceGraph()->getNodes() as $id => $node) { if (!$node->getValue() instanceof Definition) { continue; @@ -166,7 +166,7 @@ public function dump(array $options = array()) } } $this->container->getCompiler()->getServiceReferenceGraph()->clear(); - $checkedNodes = array(); + $checkedNodes = []; $this->docStar = $options['debug'] ? '*' : ''; @@ -211,7 +211,7 @@ public function dump(array $options = array()) // This file has been auto-generated by the Symfony Dependency Injection Component for internal use. EOF; - $files = array(); + $files = []; if ($ids = array_keys($this->container->getRemovedIds())) { sort($ids); @@ -230,7 +230,7 @@ public function dump(array $options = array()) } $files[$options['class'].'.php'] = $code; $hash = ucfirst(strtr(ContainerBuilder::hash($files), '._', 'xx')); - $code = array(); + $code = []; foreach ($files as $file => $c) { $code["Container{$hash}/{$file}"] = $c; @@ -272,10 +272,10 @@ public function dump(array $options = array()) } $this->targetDirRegex = null; - $this->inlinedRequires = array(); - $this->circularReferences = array(); + $this->inlinedRequires = []; + $this->circularReferences = []; - $unusedEnvs = array(); + $unusedEnvs = []; foreach ($this->container->getEnvCounters() as $env => $use) { if (!$use) { $unusedEnvs[] = $env; @@ -302,7 +302,7 @@ private function getProxyDumper() return $this->proxyDumper; } - private function analyzeCircularReferences($sourceId, array $edges, &$checkedNodes, &$currentPath = array()) + private function analyzeCircularReferences($sourceId, array $edges, &$checkedNodes, &$currentPath = []) { $checkedNodes[$sourceId] = true; $currentPath[$sourceId] = $sourceId; @@ -331,7 +331,7 @@ private function analyzeCircularReferences($sourceId, array $edges, &$checkedNod unset($currentPath[$sourceId]); } - private function connectCircularReferences($sourceId, &$currentPath, &$subPath = array()) + private function connectCircularReferences($sourceId, &$currentPath, &$subPath = []) { $subPath[$sourceId] = $sourceId; $currentPath[$sourceId] = $sourceId; @@ -387,7 +387,7 @@ private function collectLineage($class, array &$lineage) private function generateProxyClasses() { - $alreadyGenerated = array(); + $alreadyGenerated = []; $definitions = $this->container->getDefinitions(); $strip = '' === $this->docStar && method_exists('Symfony\Component\HttpKernel\Kernel', 'stripComments'); $proxyDumper = $this->getProxyDumper(); @@ -423,7 +423,7 @@ private function addServiceInclude($cId, Definition $definition) $code = ''; if ($this->inlineRequires && !$this->isHotPath($definition)) { - $lineage = array(); + $lineage = []; foreach ($this->inlinedDefinitions as $def) { if (!$def->isDeprecated() && \is_string($class = \is_array($factory = $def->getFactory()) && \is_string($factory[0]) ? $factory[0] : $def->getClass())) { $this->collectLineage($class, $lineage); @@ -555,7 +555,7 @@ private function addServiceMethodCalls(Definition $definition, $variableName = ' { $calls = ''; foreach ($definition->getMethodCalls() as $call) { - $arguments = array(); + $arguments = []; foreach ($call[1] as $value) { $arguments[] = $this->dumpValue($value); } @@ -625,11 +625,11 @@ private function addServiceConfigurator(Definition $definition, $variableName = private function addService($id, Definition $definition, &$file = null) { $this->definitionVariables = new \SplObjectStorage(); - $this->referenceVariables = array(); + $this->referenceVariables = []; $this->variableCount = 0; $this->referenceVariables[$id] = new Variable('instance'); - $return = array(); + $return = []; if ($class = $definition->getClass()) { $class = $class instanceof Parameter ? '%'.$class.'%' : $this->container->resolveEnvPlaceholders($class); @@ -685,8 +685,8 @@ protected function {$methodName}($lazyInitialization) EOF; } - $this->serviceCalls = array(); - $this->inlinedDefinitions = $this->getDefinitionsFromArguments(array($definition), null, $this->serviceCalls); + $this->serviceCalls = []; + $this->inlinedDefinitions = $this->getDefinitionsFromArguments([$definition], null, $this->serviceCalls); $code .= $this->addServiceInclude($id, $definition); @@ -787,11 +787,11 @@ private function addInlineService($id, Definition $definition, Definition $inlin return ''; } - $arguments = array($inlineDef->getArguments(), $inlineDef->getFactory()); + $arguments = [$inlineDef->getArguments(), $inlineDef->getFactory()]; $code = $this->addInlineVariables($id, $definition, $arguments, $forConstructor); - if ($arguments = array_filter(array($inlineDef->getProperties(), $inlineDef->getMethodCalls(), $inlineDef->getConfigurator()))) { + if ($arguments = array_filter([$inlineDef->getProperties(), $inlineDef->getMethodCalls(), $inlineDef->getConfigurator()])) { $isSimpleInstance = false; } elseif ($definition !== $inlineDef && 2 > $this->inlinedDefinitions[$inlineDef]) { return $code; @@ -869,7 +869,7 @@ private function addNewInstance(Definition $definition, $return, $instantiation, $class = $this->dumpValue($definition->getClass()); $return = ' '.$return.$instantiation; - $arguments = array(); + $arguments = []; foreach ($definition->getArguments() as $value) { $arguments[] = $this->dumpValue($value); } @@ -1247,11 +1247,11 @@ private function addInlineRequires() return ''; } - $lineage = array(); + $lineage = []; foreach ($this->container->findTaggedServiceIds($this->hotPathTag) as $id => $tags) { $definition = $this->container->getDefinition($id); - $inlinedDefinitions = $this->getDefinitionsFromArguments(array($definition)); + $inlinedDefinitions = $this->getDefinitionsFromArguments([$definition]); foreach ($inlinedDefinitions as $def) { if (\is_string($class = \is_array($factory = $def->getFactory()) && \is_string($factory[0]) ? $factory[0] : $def->getClass())) { @@ -1283,9 +1283,9 @@ private function addDefaultParametersMethod() return ''; } - $php = array(); - $dynamicPhp = array(); - $normalizedParams = array(); + $php = []; + $dynamicPhp = []; + $normalizedParams = []; foreach ($this->container->getParameterBag()->all() as $key => $value) { if ($key !== $resolvedKey = $this->container->resolveEnvPlaceholders($key)) { @@ -1294,7 +1294,7 @@ private function addDefaultParametersMethod() if ($key !== $lcKey = strtolower($key)) { $normalizedParams[] = sprintf(' %s => %s,', $this->export($lcKey), $this->export($key)); } - $export = $this->exportParameters(array($value)); + $export = $this->exportParameters([$value]); $export = explode('0 => ', substr(rtrim($export, " )\n"), 7, -1), 2); if (preg_match("/\\\$this->(?:getEnv\('(?:\w++:)*+\w++'\)|targetDirs\[\d++\])/", $export[1])) { @@ -1457,7 +1457,7 @@ protected function getDefaultParameters() */ private function exportParameters(array $parameters, $path = '', $indent = 12) { - $php = array(); + $php = []; foreach ($parameters as $key => $value) { if (\is_array($value)) { $value = $this->exportParameters($value, $path.'/'.$key, $indent + 4); @@ -1523,7 +1523,7 @@ private function wrapServiceConditionals($value, $code) */ private function getServiceConditionals($value) { - $conditions = array(); + $conditions = []; foreach (ContainerBuilder::getInitializedConditionals($value) as $service) { if (!$this->container->hasDefinition($service)) { return 'false'; @@ -1545,7 +1545,7 @@ private function getServiceConditionals($value) return implode(' && ', $conditions); } - private function getDefinitionsFromArguments(array $arguments, \SplObjectStorage $definitions = null, array &$calls = array()) + private function getDefinitionsFromArguments(array $arguments, \SplObjectStorage $definitions = null, array &$calls = []) { if (null === $definitions) { $definitions = new \SplObjectStorage(); @@ -1558,7 +1558,7 @@ private function getDefinitionsFromArguments(array $arguments, \SplObjectStorage $id = $this->container->normalizeId($argument); if (!isset($calls[$id])) { - $calls[$id] = array(0, $argument->getInvalidBehavior()); + $calls[$id] = [0, $argument->getInvalidBehavior()]; } else { $calls[$id][1] = min($calls[$id][1], $argument->getInvalidBehavior()); } @@ -1570,7 +1570,7 @@ private function getDefinitionsFromArguments(array $arguments, \SplObjectStorage $definitions[$argument] = 1 + $definitions[$argument]; } else { $definitions[$argument] = 1; - $arguments = array($argument->getArguments(), $argument->getFactory(), $argument->getProperties(), $argument->getMethodCalls(), $argument->getConfigurator()); + $arguments = [$argument->getArguments(), $argument->getFactory(), $argument->getProperties(), $argument->getMethodCalls(), $argument->getConfigurator()]; $this->getDefinitionsFromArguments($arguments, $definitions, $calls); } } @@ -1594,14 +1594,14 @@ private function dumpValue($value, $interpolate = true) if ($value && $interpolate && false !== $param = array_search($value, $this->container->getParameterBag()->all(), true)) { return $this->dumpValue("%$param%"); } - $code = array(); + $code = []; foreach ($value as $k => $v) { $code[] = sprintf('%s => %s', $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate)); } return sprintf('array(%s)', implode(', ', $code)); } elseif ($value instanceof ArgumentInterface) { - $scope = array($this->definitionVariables, $this->referenceVariables); + $scope = [$this->definitionVariables, $this->referenceVariables]; $this->definitionVariables = $this->referenceVariables = null; try { @@ -1619,14 +1619,14 @@ private function dumpValue($value, $interpolate = true) } if ($value instanceof IteratorArgument) { - $operands = array(0); - $code = array(); + $operands = [0]; + $code = []; $code[] = 'new RewindableGenerator(function () {'; if (!$values = $value->getValues()) { $code[] = ' return new \EmptyIterator();'; } else { - $countCode = array(); + $countCode = []; $countCode[] = 'function () {'; foreach ($values as $k => $v) { @@ -1664,7 +1664,7 @@ private function dumpValue($value, $interpolate = true) throw new RuntimeException('Cannot dump definitions which have a configurator.'); } - $arguments = array(); + $arguments = []; foreach ($value->getArguments() as $argument) { $arguments[] = $this->dumpValue($argument); } @@ -1718,7 +1718,7 @@ private function dumpValue($value, $interpolate = true) return $this->getServiceCall($id, $value); } elseif ($value instanceof Expression) { - return $this->getExpressionLanguage()->compile((string) $value, array('this' => 'container')); + return $this->getExpressionLanguage()->compile((string) $value, ['this' => 'container']); } elseif ($value instanceof Parameter) { return $this->dumpParameter($value); } elseif (true === $interpolate && \is_string($value)) { @@ -1848,8 +1848,8 @@ private function getServiceCall($id, Reference $reference = null) */ private function initializeMethodNamesMap($class) { - $this->serviceIdToMethodNameMap = array(); - $this->usedMethodNames = array(); + $this->serviceIdToMethodNameMap = []; + $this->usedMethodNames = []; if ($reflectionClass = $this->container->getReflectionClass($class)) { foreach ($reflectionClass->getMethods() as $method) { diff --git a/Dumper/XmlDumper.php b/Dumper/XmlDumper.php index 1dcef12da..36e3e121d 100644 --- a/Dumper/XmlDumper.php +++ b/Dumper/XmlDumper.php @@ -40,7 +40,7 @@ class XmlDumper extends Dumper * * @return string An xml string representing of the service container */ - public function dump(array $options = array()) + public function dump(array $options = []) { $this->document = new \DOMDocument('1.0', 'utf-8'); $this->document->formatOutput = true; @@ -306,7 +306,7 @@ private function convertParameters(array $parameters, $type, \DOMElement $parent $text = $this->document->createTextNode(self::phpToXml((string) $value)); $element->appendChild($text); } else { - if (\in_array($value, array('null', 'true', 'false'), true)) { + if (\in_array($value, ['null', 'true', 'false'], true)) { $element->setAttribute('type', 'string'); } $text = $this->document->createTextNode(self::phpToXml($value)); @@ -323,7 +323,7 @@ private function convertParameters(array $parameters, $type, \DOMElement $parent */ private function escape(array $arguments) { - $args = array(); + $args = []; foreach ($arguments as $k => $v) { if (\is_array($v)) { $args[$k] = $this->escape($v); diff --git a/Dumper/YamlDumper.php b/Dumper/YamlDumper.php index 35441023d..8f3fcddf3 100644 --- a/Dumper/YamlDumper.php +++ b/Dumper/YamlDumper.php @@ -41,7 +41,7 @@ class YamlDumper extends Dumper * * @return string A YAML string representing of the service container */ - public function dump(array $options = array()) + public function dump(array $options = []) { if (!class_exists('Symfony\Component\Yaml\Dumper')) { throw new RuntimeException('Unable to dump the container as the Symfony Yaml Component is not installed.'); @@ -80,7 +80,7 @@ private function addService($id, Definition $definition) $tagsCode = ''; foreach ($definition->getTags() as $name => $tags) { foreach ($tags as $attributes) { - $att = array(); + $att = []; foreach ($attributes as $key => $value) { $att[] = sprintf('%s: %s', $this->dumper->dump($key), $this->dumper->dump($value)); } @@ -224,7 +224,7 @@ private function addParameters() $parameters = $this->prepareParameters($this->container->getParameterBag()->all(), $this->container->isCompiled()); - return $this->dumper->dump(array('parameters' => $parameters), 2); + return $this->dumper->dump(['parameters' => $parameters], 2); } /** @@ -238,9 +238,9 @@ private function dumpCallable($callable) { if (\is_array($callable)) { if ($callable[0] instanceof Reference) { - $callable = array($this->getServiceCall((string) $callable[0], $callable[0]), $callable[1]); + $callable = [$this->getServiceCall((string) $callable[0], $callable[0]), $callable[1]]; } else { - $callable = array($callable[0], $callable[1]); + $callable = [$callable[0], $callable[1]]; } } @@ -275,7 +275,7 @@ private function dumpValue($value) } if (\is_array($value)) { - $code = array(); + $code = []; foreach ($value as $k => $v) { $code[$k] = $this->dumpValue($v); } @@ -344,7 +344,7 @@ private function getExpressionCall($expression) */ private function prepareParameters(array $parameters, $escape = true) { - $filtered = array(); + $filtered = []; foreach ($parameters as $key => $value) { if (\is_array($value)) { $value = $this->prepareParameters($value, $escape); @@ -365,7 +365,7 @@ private function prepareParameters(array $parameters, $escape = true) */ private function escape(array $arguments) { - $args = array(); + $args = []; foreach ($arguments as $k => $v) { if (\is_array($v)) { $args[$k] = $this->escape($v); diff --git a/EnvVarProcessor.php b/EnvVarProcessor.php index 13568079b..a23b83436 100644 --- a/EnvVarProcessor.php +++ b/EnvVarProcessor.php @@ -32,7 +32,7 @@ public function __construct(ContainerInterface $container) */ public static function getProvidedTypes() { - return array( + return [ 'base64' => 'string', 'bool' => 'bool', 'const' => 'bool|int|float|string|array', @@ -42,7 +42,7 @@ public static function getProvidedTypes() 'json' => 'array', 'resolve' => 'string', 'string' => 'string', - ); + ]; } /** diff --git a/Exception/ParameterNotFoundException.php b/Exception/ParameterNotFoundException.php index 7a30f629d..b08f2e855 100644 --- a/Exception/ParameterNotFoundException.php +++ b/Exception/ParameterNotFoundException.php @@ -32,7 +32,7 @@ class ParameterNotFoundException extends InvalidArgumentException * @param string[] $alternatives Some parameter name alternatives * @param string|null $nonNestedAlternative The alternative parameter name when the user expected dot notation for nested parameters */ - public function __construct($key, $sourceId = null, $sourceKey = null, \Exception $previous = null, array $alternatives = array(), $nonNestedAlternative = null) + public function __construct($key, $sourceId = null, $sourceKey = null, \Exception $previous = null, array $alternatives = [], $nonNestedAlternative = null) { $this->key = $key; $this->sourceId = $sourceId; diff --git a/Exception/ServiceNotFoundException.php b/Exception/ServiceNotFoundException.php index 9a0128c83..280dabf33 100644 --- a/Exception/ServiceNotFoundException.php +++ b/Exception/ServiceNotFoundException.php @@ -24,7 +24,7 @@ class ServiceNotFoundException extends InvalidArgumentException implements NotFo private $sourceId; private $alternatives; - public function __construct($id, $sourceId = null, \Exception $previous = null, array $alternatives = array(), $msg = null) + public function __construct($id, $sourceId = null, \Exception $previous = null, array $alternatives = [], $msg = null) { if (null !== $msg) { // no-op diff --git a/ExpressionLanguage.php b/ExpressionLanguage.php index 051d41b84..0c1780b8b 100644 --- a/ExpressionLanguage.php +++ b/ExpressionLanguage.php @@ -25,7 +25,7 @@ class ExpressionLanguage extends BaseExpressionLanguage /** * {@inheritdoc} */ - public function __construct($cache = null, array $providers = array(), callable $serviceCompiler = null) + public function __construct($cache = null, array $providers = [], callable $serviceCompiler = null) { // prepend the default provider to let users override it easily array_unshift($providers, new ExpressionLanguageProvider($serviceCompiler)); diff --git a/ExpressionLanguageProvider.php b/ExpressionLanguageProvider.php index e2084aa85..9198ca0a4 100644 --- a/ExpressionLanguageProvider.php +++ b/ExpressionLanguageProvider.php @@ -33,7 +33,7 @@ public function __construct(callable $serviceCompiler = null) public function getFunctions() { - return array( + return [ new ExpressionFunction('service', $this->serviceCompiler ?: function ($arg) { return sprintf('$this->get(%s)', $arg); }, function (array $variables, $value) { @@ -45,6 +45,6 @@ public function getFunctions() }, function (array $variables, $value) { return $variables['container']->getParameter($value); }), - ); + ]; } } diff --git a/Extension/Extension.php b/Extension/Extension.php index 1bafdbebd..80a9419c5 100644 --- a/Extension/Extension.php +++ b/Extension/Extension.php @@ -25,7 +25,7 @@ */ abstract class Extension implements ExtensionInterface, ConfigurationExtensionInterface { - private $processedConfigs = array(); + private $processedConfigs = []; /** * {@inheritdoc} @@ -104,7 +104,7 @@ final public function getProcessedConfigs() try { return $this->processedConfigs; } finally { - $this->processedConfigs = array(); + $this->processedConfigs = []; } } diff --git a/Loader/Configurator/AbstractConfigurator.php b/Loader/Configurator/AbstractConfigurator.php index d11347aea..f7222d0ed 100644 --- a/Loader/Configurator/AbstractConfigurator.php +++ b/Loader/Configurator/AbstractConfigurator.php @@ -28,7 +28,7 @@ abstract class AbstractConfigurator public function __call($method, $args) { if (method_exists($this, 'set'.$method)) { - return \call_user_func_array(array($this, 'set'.$method), $args); + return \call_user_func_array([$this, 'set'.$method], $args); } throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', \get_class($this), $method)); diff --git a/Loader/Configurator/AbstractServiceConfigurator.php b/Loader/Configurator/AbstractServiceConfigurator.php index 40b6c2f38..0a565787f 100644 --- a/Loader/Configurator/AbstractServiceConfigurator.php +++ b/Loader/Configurator/AbstractServiceConfigurator.php @@ -18,9 +18,9 @@ abstract class AbstractServiceConfigurator extends AbstractConfigurator { protected $parent; protected $id; - private $defaultTags = array(); + private $defaultTags = []; - public function __construct(ServicesConfigurator $parent, Definition $definition, $id = null, array $defaultTags = array()) + public function __construct(ServicesConfigurator $parent, Definition $definition, $id = null, array $defaultTags = []) { $this->parent = $parent; $this->definition = $definition; @@ -36,7 +36,7 @@ public function __destruct() $this->definition->addTag($name, $attributes); } } - $this->defaultTags = array(); + $this->defaultTags = []; } /** diff --git a/Loader/Configurator/DefaultsConfigurator.php b/Loader/Configurator/DefaultsConfigurator.php index 631c92a68..662ba95d1 100644 --- a/Loader/Configurator/DefaultsConfigurator.php +++ b/Loader/Configurator/DefaultsConfigurator.php @@ -37,7 +37,7 @@ class DefaultsConfigurator extends AbstractServiceConfigurator * * @throws InvalidArgumentException when an invalid tag name or attribute is provided */ - final public function tag($name, array $attributes = array()) + final public function tag($name, array $attributes = []) { if (!\is_string($name) || '' === $name) { throw new InvalidArgumentException('The tag name in "_defaults" must be a non-empty string.'); diff --git a/Loader/Configurator/PrototypeConfigurator.php b/Loader/Configurator/PrototypeConfigurator.php index 76e7829e8..d80c8b133 100644 --- a/Loader/Configurator/PrototypeConfigurator.php +++ b/Loader/Configurator/PrototypeConfigurator.php @@ -49,7 +49,7 @@ public function __construct(ServicesConfigurator $parent, PhpFileLoader $loader, $definition->setAutowired($defaults->isAutowired()); $definition->setAutoconfigured($defaults->isAutoconfigured()); $definition->setBindings($defaults->getBindings()); - $definition->setChanges(array()); + $definition->setChanges([]); $this->loader = $loader; $this->resource = $resource; diff --git a/Loader/Configurator/ServicesConfigurator.php b/Loader/Configurator/ServicesConfigurator.php index c9673b6c7..e7677eb5e 100644 --- a/Loader/Configurator/ServicesConfigurator.php +++ b/Loader/Configurator/ServicesConfigurator.php @@ -38,7 +38,7 @@ public function __construct(ContainerBuilder $container, PhpFileLoader $loader, $this->container = $container; $this->loader = $loader; $this->instanceof = &$instanceof; - $instanceof = array(); + $instanceof = []; } /** @@ -83,7 +83,7 @@ final public function set($id, $class = null) $definition->setAutowired($defaults->isAutowired()); $definition->setAutoconfigured($defaults->isAutoconfigured()); $definition->setBindings($defaults->getBindings()); - $definition->setChanges(array()); + $definition->setChanges([]); $configurator = new ServiceConfigurator($this->container, $this->instanceof, $allowParent, $this, $definition, $id, $defaults->getTags()); @@ -136,7 +136,7 @@ final public function get($id) $allowParent = !$this->defaults->getChanges() && empty($this->instanceof); $definition = $this->container->getDefinition($id); - return new ServiceConfigurator($this->container, $definition->getInstanceofConditionals(), $allowParent, $this, $definition, $id, array()); + return new ServiceConfigurator($this->container, $definition->getInstanceofConditionals(), $allowParent, $this, $definition, $id, []); } /** diff --git a/Loader/Configurator/Traits/CallTrait.php b/Loader/Configurator/Traits/CallTrait.php index abc14e215..8e6b17a19 100644 --- a/Loader/Configurator/Traits/CallTrait.php +++ b/Loader/Configurator/Traits/CallTrait.php @@ -25,7 +25,7 @@ trait CallTrait * * @throws InvalidArgumentException on empty $method param */ - final public function call($method, array $arguments = array()) + final public function call($method, array $arguments = []) { $this->definition->addMethodCall($method, static::processValue($arguments, true)); diff --git a/Loader/Configurator/Traits/TagTrait.php b/Loader/Configurator/Traits/TagTrait.php index c165b6503..d17339f88 100644 --- a/Loader/Configurator/Traits/TagTrait.php +++ b/Loader/Configurator/Traits/TagTrait.php @@ -23,7 +23,7 @@ trait TagTrait * * @return $this */ - final public function tag($name, array $attributes = array()) + final public function tag($name, array $attributes = []) { if (!\is_string($name) || '' === $name) { throw new InvalidArgumentException(sprintf('The tag name for service "%s" must be a non-empty string.', $this->id)); diff --git a/Loader/FileLoader.php b/Loader/FileLoader.php index d5e2327ed..a428c6e35 100644 --- a/Loader/FileLoader.php +++ b/Loader/FileLoader.php @@ -28,7 +28,7 @@ abstract class FileLoader extends BaseFileLoader { protected $container; protected $isLoadingInstanceof = false; - protected $instanceof = array(); + protected $instanceof = []; public function __construct(ContainerBuilder $container, FileLocatorInterface $locator) { @@ -57,8 +57,8 @@ public function registerClasses(Definition $prototype, $namespace, $resource, $e $classes = $this->findClasses($namespace, $resource, $exclude); // prepare for deep cloning $serializedPrototype = serialize($prototype); - $interfaces = array(); - $singlyImplemented = array(); + $interfaces = []; + $singlyImplemented = []; foreach ($classes as $class => $errorMessage) { if (interface_exists($class, false)) { @@ -105,7 +105,7 @@ private function findClasses($namespace, $pattern, $excludePattern) { $parameterBag = $this->container->getParameterBag(); - $excludePaths = array(); + $excludePaths = []; $excludePrefix = null; if ($excludePattern) { $excludePattern = $parameterBag->unescapeValue($parameterBag->resolveValue($excludePattern)); @@ -120,7 +120,7 @@ private function findClasses($namespace, $pattern, $excludePattern) } $pattern = $parameterBag->unescapeValue($parameterBag->resolveValue($pattern)); - $classes = array(); + $classes = []; $extRegexp = \defined('HHVM_VERSION') ? '/\\.(?:php|hh)$/' : '/\\.php$/'; $prefixLen = null; foreach ($this->glob($pattern, true, $resource) as $path => $info) { diff --git a/Loader/IniFileLoader.php b/Loader/IniFileLoader.php index 2ee9ea8ff..307a3eefb 100644 --- a/Loader/IniFileLoader.php +++ b/Loader/IniFileLoader.php @@ -32,7 +32,7 @@ public function load($resource, $type = null) // first pass to catch parsing errors $result = parse_ini_file($path, true); - if (false === $result || array() === $result) { + if (false === $result || [] === $result) { throw new InvalidArgumentException(sprintf('The "%s" file is not valid.', $resource)); } diff --git a/Loader/XmlFileLoader.php b/Loader/XmlFileLoader.php index 4677a61ca..1921c7157 100644 --- a/Loader/XmlFileLoader.php +++ b/Loader/XmlFileLoader.php @@ -63,7 +63,7 @@ public function load($resource, $type = null) try { $this->parseDefinitions($xml, $path, $defaults); } finally { - $this->instanceof = array(); + $this->instanceof = []; } } @@ -134,11 +134,11 @@ private function parseDefinitions(\DOMDocument $xml, $file, $defaults) } $this->setCurrentDir(\dirname($file)); - $this->instanceof = array(); + $this->instanceof = []; $this->isLoadingInstanceof = true; $instanceof = $xpath->query('//container:services/container:instanceof'); foreach ($instanceof as $service) { - $this->setDefinition((string) $service->getAttribute('id'), $this->parseDefinition($service, $file, array())); + $this->setDefinition((string) $service->getAttribute('id'), $this->parseDefinition($service, $file, [])); } $this->isLoadingInstanceof = false; @@ -164,12 +164,12 @@ private function getServiceDefaults(\DOMDocument $xml, $file) $xpath->registerNamespace('container', self::NS); if (null === $defaultsNode = $xpath->query('//container:services/container:defaults')->item(0)) { - return array(); + return []; } - $defaults = array( + $defaults = [ 'tags' => $this->getChildren($defaultsNode, 'tag'), 'bind' => array_map(function ($v) { return new BoundArgument($v); }, $this->getArgumentsAsPhp($defaultsNode, 'bind', $file)), - ); + ]; foreach ($defaults['tags'] as $tag) { if ('' === $tag->getAttribute('name')) { @@ -253,10 +253,10 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults) $definition->setAutoconfigured($defaults['autoconfigure']); } - $definition->setChanges(array()); + $definition->setChanges([]); } - foreach (array('class', 'public', 'shared', 'synthetic', 'lazy', 'abstract') as $key) { + foreach (['class', 'public', 'shared', 'synthetic', 'lazy', 'abstract'] as $key) { if ($value = $service->getAttribute($key)) { $method = 'set'.$key; $definition->$method(XmlUtils::phpize($value)); @@ -297,7 +297,7 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults) $class = $factory->hasAttribute('class') ? $factory->getAttribute('class') : null; } - $definition->setFactory(array($class, $factory->getAttribute('method'))); + $definition->setFactory([$class, $factory->getAttribute('method')]); } } @@ -312,7 +312,7 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults) $class = $configurator->getAttribute('class'); } - $definition->setConfigurator(array($class, $configurator->getAttribute('method'))); + $definition->setConfigurator([$class, $configurator->getAttribute('method')]); } } @@ -327,7 +327,7 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults) } foreach ($tags as $tag) { - $parameters = array(); + $parameters = []; foreach ($tag->attributes as $name => $node) { if ('name' === $name) { continue; @@ -381,7 +381,7 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults) private function parseFileToDOM($file) { try { - $dom = XmlUtils::loadFile($file, array($this, 'validateSchema')); + $dom = XmlUtils::loadFile($file, [$this, 'validateSchema']); } catch (\InvalidArgumentException $e) { throw new InvalidArgumentException(sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e); } @@ -400,7 +400,7 @@ private function parseFileToDOM($file) */ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults) { - $definitions = array(); + $definitions = []; $count = 0; $suffix = '~'.ContainerBuilder::hash($file); @@ -416,7 +416,7 @@ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults) $node->setAttribute('id', $id); $node->setAttribute('service', $id); - $definitions[$id] = array($services[0], $file, false); + $definitions[$id] = [$services[0], $file, false]; $services[0]->setAttribute('id', $id); // anonymous services are always private @@ -434,14 +434,14 @@ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults) // give it a unique name $id = sprintf('%d_%s', ++$count, preg_replace('/^.*\\\\/', '', $node->getAttribute('class')).$suffix); $node->setAttribute('id', $id); - $definitions[$id] = array($node, $file, true); + $definitions[$id] = [$node, $file, true]; } } // resolve definitions uksort($definitions, 'strnatcmp'); foreach (array_reverse($definitions) as $id => list($domElement, $file, $wild)) { - if (null !== $definition = $this->parseDefinition($domElement, $file, $wild ? $defaults : array())) { + if (null !== $definition = $this->parseDefinition($domElement, $file, $wild ? $defaults : [])) { $this->setDefinition($id, $definition); } @@ -465,7 +465,7 @@ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults) */ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase = true, $isChildDefinition = false) { - $arguments = array(); + $arguments = []; foreach ($this->getChildren($node, $name) as $arg) { if ($arg->hasAttribute('name')) { $arg->setAttribute('key', $arg->getAttribute('name')); @@ -553,7 +553,7 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase = */ private function getChildren(\DOMNode $node, $name) { - $children = array(); + $children = []; foreach ($node->childNodes as $child) { if ($child instanceof \DOMElement && $child->localName === $name && self::NS === $child->namespaceURI) { $children[] = $child; @@ -574,7 +574,7 @@ private function getChildren(\DOMNode $node, $name) */ public function validateSchema(\DOMDocument $dom) { - $schemaLocations = array('http://symfony.com/schema/dic/services' => str_replace('\\', '/', __DIR__.'/schema/dic/services/services-1.0.xsd')); + $schemaLocations = ['http://symfony.com/schema/dic/services' => str_replace('\\', '/', __DIR__.'/schema/dic/services/services-1.0.xsd')]; if ($element = $dom->documentElement->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation')) { $items = preg_split('/\s+/', $element); @@ -595,7 +595,7 @@ public function validateSchema(\DOMDocument $dom) } } - $tmpfiles = array(); + $tmpfiles = []; $imports = ''; foreach ($schemaLocations as $namespace => $location) { $parts = explode('/', $location); @@ -650,7 +650,7 @@ public function validateSchema(\DOMDocument $dom) private function validateAlias(\DOMElement $alias, $file) { foreach ($alias->attributes as $name => $node) { - if (!\in_array($name, array('alias', 'id', 'public'))) { + if (!\in_array($name, ['alias', 'id', 'public'])) { @trigger_error(sprintf('Using the attribute "%s" is deprecated for the service "%s" which is defined as an alias in "%s". Allowed attributes for service aliases are "alias", "id" and "public". The XmlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported attributes.', $name, $alias->getAttribute('id'), $file), E_USER_DEPRECATED); } } @@ -699,7 +699,7 @@ private function loadFromExtensions(\DOMDocument $xml) $values = static::convertDomElementToArray($node); if (!\is_array($values)) { - $values = array(); + $values = []; } $this->container->loadFromExtension($node->namespaceURI, $values); diff --git a/Loader/YamlFileLoader.php b/Loader/YamlFileLoader.php index 27899f220..dccbae9b7 100644 --- a/Loader/YamlFileLoader.php +++ b/Loader/YamlFileLoader.php @@ -36,7 +36,7 @@ */ class YamlFileLoader extends FileLoader { - private static $serviceKeywords = array( + private static $serviceKeywords = [ 'alias' => 'alias', 'parent' => 'parent', 'class' => 'class', @@ -60,9 +60,9 @@ class YamlFileLoader extends FileLoader 'autowiring_types' => 'autowiring_types', 'autoconfigure' => 'autoconfigure', 'bind' => 'bind', - ); + ]; - private static $prototypeKeywords = array( + private static $prototypeKeywords = [ 'resource' => 'resource', 'namespace' => 'namespace', 'exclude' => 'exclude', @@ -81,9 +81,9 @@ class YamlFileLoader extends FileLoader 'autowire' => 'autowire', 'autoconfigure' => 'autoconfigure', 'bind' => 'bind', - ); + ]; - private static $instanceofKeywords = array( + private static $instanceofKeywords = [ 'shared' => 'shared', 'lazy' => 'lazy', 'public' => 'public', @@ -92,15 +92,15 @@ class YamlFileLoader extends FileLoader 'calls' => 'calls', 'tags' => 'tags', 'autowire' => 'autowire', - ); + ]; - private static $defaultsKeywords = array( + private static $defaultsKeywords = [ 'public' => 'public', 'tags' => 'tags', 'autowire' => 'autowire', 'autoconfigure' => 'autoconfigure', 'bind' => 'bind', - ); + ]; private $yamlParser; @@ -147,7 +147,7 @@ public function load($resource, $type = null) try { $this->parseDefinitions($content, $path); } finally { - $this->instanceof = array(); + $this->instanceof = []; } } @@ -160,11 +160,11 @@ public function supports($resource, $type = null) return false; } - if (null === $type && \in_array(pathinfo($resource, PATHINFO_EXTENSION), array('yaml', 'yml'), true)) { + if (null === $type && \in_array(pathinfo($resource, PATHINFO_EXTENSION), ['yaml', 'yml'], true)) { return true; } - return \in_array($type, array('yaml', 'yml'), true); + return \in_array($type, ['yaml', 'yml'], true); } /** @@ -186,7 +186,7 @@ private function parseImports(array $content, $file) $defaultDirectory = \dirname($file); foreach ($content['imports'] as $import) { if (!\is_array($import)) { - $import = array('resource' => $import); + $import = ['resource' => $import]; } if (!isset($import['resource'])) { throw new InvalidArgumentException(sprintf('An import should provide a resource in %s. Check your YAML syntax.', $file)); @@ -220,7 +220,7 @@ private function parseDefinitions(array $content, $file) if (!\is_array($instanceof)) { throw new InvalidArgumentException(sprintf('Service "_instanceof" key must be an array, "%s" given in "%s".', \gettype($instanceof), $file)); } - $this->instanceof = array(); + $this->instanceof = []; $this->isLoadingInstanceof = true; foreach ($instanceof as $id => $service) { if (!$service || !\is_array($service)) { @@ -229,7 +229,7 @@ private function parseDefinitions(array $content, $file) if (\is_string($service) && 0 === strpos($service, '@')) { throw new InvalidArgumentException(sprintf('Type definition "%s" cannot be an alias within "_instanceof" in %s. Check your YAML syntax.', $id, $file)); } - $this->parseDefinition($id, $service, $file, array()); + $this->parseDefinition($id, $service, $file, []); } } @@ -251,7 +251,7 @@ private function parseDefinitions(array $content, $file) private function parseDefaults(array &$content, $file) { if (!array_key_exists('_defaults', $content['services'])) { - return array(); + return []; } $defaults = $content['services']['_defaults']; unset($content['services']['_defaults']); @@ -273,7 +273,7 @@ private function parseDefaults(array &$content, $file) foreach ($tags as $tag) { if (!\is_array($tag)) { - $tag = array('name' => $tag); + $tag = ['name' => $tag]; } if (!isset($tag['name'])) { @@ -346,11 +346,11 @@ private function parseDefinition($id, $service, $file, array $defaults) } if (\is_array($service) && $this->isUsingShortSyntax($service)) { - $service = array('arguments' => $service); + $service = ['arguments' => $service]; } if (null === $service) { - $service = array(); + $service = []; } if (!\is_array($service)) { @@ -368,7 +368,7 @@ private function parseDefinition($id, $service, $file, array $defaults) } foreach ($service as $key => $value) { - if (!\in_array($key, array('alias', 'public'))) { + if (!\in_array($key, ['alias', 'public'])) { @trigger_error(sprintf('The configuration key "%s" is unsupported for the service "%s" which is defined as an alias in "%s". Allowed configuration keys for service aliases are "alias" and "public". The YamlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported attributes.', $key, $id, $file), E_USER_DEPRECATED); } } @@ -411,7 +411,7 @@ private function parseDefinition($id, $service, $file, array $defaults) $definition->setAutoconfigured($defaults['autoconfigure']); } - $definition->setChanges(array()); + $definition->setChanges([]); } if (isset($service['class'])) { @@ -470,10 +470,10 @@ private function parseDefinition($id, $service, $file, array $defaults) foreach ($service['calls'] as $call) { if (isset($call['method'])) { $method = $call['method']; - $args = isset($call['arguments']) ? $this->resolveServices($call['arguments'], $file) : array(); + $args = isset($call['arguments']) ? $this->resolveServices($call['arguments'], $file) : []; } else { $method = $call[0]; - $args = isset($call[1]) ? $this->resolveServices($call[1], $file) : array(); + $args = isset($call[1]) ? $this->resolveServices($call[1], $file) : []; } if (!\is_array($args)) { @@ -483,7 +483,7 @@ private function parseDefinition($id, $service, $file, array $defaults) } } - $tags = isset($service['tags']) ? $service['tags'] : array(); + $tags = isset($service['tags']) ? $service['tags'] : []; if (!\is_array($tags)) { throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file)); } @@ -494,7 +494,7 @@ private function parseDefinition($id, $service, $file, array $defaults) foreach ($tags as $tag) { if (!\is_array($tag)) { - $tag = array('name' => $tag); + $tag = ['name' => $tag]; } if (!isset($tag['name'])) { @@ -550,7 +550,7 @@ private function parseDefinition($id, $service, $file, array $defaults) if (isset($defaults['bind']) || isset($service['bind'])) { // deep clone, to avoid multiple process of the same instance in the passes - $bindings = isset($defaults['bind']) ? unserialize(serialize($defaults['bind'])) : array(); + $bindings = isset($defaults['bind']) ? unserialize(serialize($defaults['bind'])) : []; if (isset($service['bind'])) { if (!\is_array($service['bind'])) { @@ -609,7 +609,7 @@ private function parseCallable($callable, $parameter, $id, $file) if (false !== strpos($callable, ':') && false === strpos($callable, '::')) { $parts = explode(':', $callable); - return array($this->resolveServices('@'.$parts[0], $file), $parts[1]); + return [$this->resolveServices('@'.$parts[0], $file), $parts[1]]; } return $callable; @@ -617,7 +617,7 @@ private function parseCallable($callable, $parameter, $id, $file) if (\is_array($callable)) { if (isset($callable[0]) && isset($callable[1])) { - return array($this->resolveServices($callable[0], $file), $callable[1]); + return [$this->resolveServices($callable[0], $file), $callable[1]]; } if ('factory' === $parameter && isset($callable[1]) && null === $callable[0]) { @@ -695,7 +695,7 @@ private function validate($content, $file) } foreach ($content as $namespace => $data) { - if (\in_array($namespace, array('imports', 'parameters', 'services'))) { + if (\in_array($namespace, ['imports', 'parameters', 'services'])) { continue; } @@ -747,10 +747,10 @@ private function resolveServices($value, $file, $isParameter = false) $isLoadingInstanceof = $this->isLoadingInstanceof; $this->isLoadingInstanceof = false; $instanceof = $this->instanceof; - $this->instanceof = array(); + $this->instanceof = []; $id = sprintf('%d_%s', ++$this->anonymousServicesCount, preg_replace('/^.*\\\\/', '', isset($argument['class']) ? $argument['class'] : '').$this->anonymousServicesSuffix); - $this->parseDefinition($id, $argument, $file, array()); + $this->parseDefinition($id, $argument, $file, []); if (!$this->container->hasDefinition($id)) { throw new InvalidArgumentException(sprintf('Creating an alias using the tag "!service" is not allowed in "%s".', $file)); @@ -811,12 +811,12 @@ private function resolveServices($value, $file, $isParameter = false) private function loadFromExtensions(array $content) { foreach ($content as $namespace => $values) { - if (\in_array($namespace, array('imports', 'parameters', 'services'))) { + if (\in_array($namespace, ['imports', 'parameters', 'services'])) { continue; } if (!\is_array($values) && null !== $values) { - $values = array(); + $values = []; } $this->container->loadFromExtension($namespace, $values); diff --git a/ParameterBag/EnvPlaceholderParameterBag.php b/ParameterBag/EnvPlaceholderParameterBag.php index 12bc7612f..e453a774e 100644 --- a/ParameterBag/EnvPlaceholderParameterBag.php +++ b/ParameterBag/EnvPlaceholderParameterBag.php @@ -19,8 +19,8 @@ */ class EnvPlaceholderParameterBag extends ParameterBag { - private $envPlaceholders = array(); - private $providedTypes = array(); + private $envPlaceholders = []; + private $providedTypes = []; /** * {@inheritdoc} diff --git a/ParameterBag/FrozenParameterBag.php b/ParameterBag/FrozenParameterBag.php index ad65ad960..a5199937e 100644 --- a/ParameterBag/FrozenParameterBag.php +++ b/ParameterBag/FrozenParameterBag.php @@ -28,7 +28,7 @@ class FrozenParameterBag extends ParameterBag * * @param array $parameters An array of parameters */ - public function __construct(array $parameters = array()) + public function __construct(array $parameters = []) { $this->parameters = $parameters; $this->resolved = true; diff --git a/ParameterBag/ParameterBag.php b/ParameterBag/ParameterBag.php index e06fd344c..8a86f9417 100644 --- a/ParameterBag/ParameterBag.php +++ b/ParameterBag/ParameterBag.php @@ -22,15 +22,15 @@ */ class ParameterBag implements ParameterBagInterface { - protected $parameters = array(); + protected $parameters = []; protected $resolved = false; - private $normalizedNames = array(); + private $normalizedNames = []; /** * @param array $parameters An array of parameters */ - public function __construct(array $parameters = array()) + public function __construct(array $parameters = []) { $this->add($parameters); } @@ -40,7 +40,7 @@ public function __construct(array $parameters = array()) */ public function clear() { - $this->parameters = array(); + $this->parameters = []; } /** @@ -75,7 +75,7 @@ public function get($name) throw new ParameterNotFoundException($name); } - $alternatives = array(); + $alternatives = []; foreach ($this->parameters as $key => $parameterValue) { $lev = levenshtein($name, $key); if ($lev <= \strlen($name) / 3 || false !== strpos($key, $name)) { @@ -143,7 +143,7 @@ public function resolve() return; } - $parameters = array(); + $parameters = []; foreach ($this->parameters as $key => $value) { try { $value = $this->resolveValue($value); @@ -171,10 +171,10 @@ public function resolve() * @throws ParameterCircularReferenceException if a circular reference if detected * @throws RuntimeException when a given parameter has a type problem */ - public function resolveValue($value, array $resolving = array()) + public function resolveValue($value, array $resolving = []) { if (\is_array($value)) { - $args = array(); + $args = []; foreach ($value as $k => $v) { $args[\is_string($k) ? $this->resolveValue($k, $resolving) : $k] = $this->resolveValue($v, $resolving); } @@ -201,7 +201,7 @@ public function resolveValue($value, array $resolving = array()) * @throws ParameterCircularReferenceException if a circular reference if detected * @throws RuntimeException when a given parameter has a type problem */ - public function resolveString($value, array $resolving = array()) + public function resolveString($value, array $resolving = []) { // we do this to deal with non string values (Boolean, integer, ...) // as the preg_replace_callback throw an exception when trying @@ -259,7 +259,7 @@ public function escapeValue($value) } if (\is_array($value)) { - $result = array(); + $result = []; foreach ($value as $k => $v) { $result[$k] = $this->escapeValue($v); } @@ -280,7 +280,7 @@ public function unescapeValue($value) } if (\is_array($value)) { - $result = array(); + $result = []; foreach ($value as $k => $v) { $result[$k] = $this->unescapeValue($v); } diff --git a/ServiceLocator.php b/ServiceLocator.php index 10c7c9eb6..a4f5bf994 100644 --- a/ServiceLocator.php +++ b/ServiceLocator.php @@ -22,7 +22,7 @@ class ServiceLocator implements PsrContainerInterface { private $factories; - private $loading = array(); + private $loading = []; private $externalId; private $container; @@ -48,7 +48,7 @@ public function has($id) public function get($id) { if (!isset($this->factories[$id])) { - throw new ServiceNotFoundException($id, end($this->loading) ?: null, null, array(), $this->createServiceNotFoundMessage($id)); + throw new ServiceNotFoundException($id, end($this->loading) ?: null, null, [], $this->createServiceNotFoundMessage($id)); } if (isset($this->loading[$id])) { @@ -94,7 +94,7 @@ private function createServiceNotFoundMessage($id) $class = isset($class[2]['object']) ? \get_class($class[2]['object']) : null; $externalId = $this->externalId ?: $class; - $msg = array(); + $msg = []; $msg[] = sprintf('Service "%s" not found:', $id); if (!$this->container) { diff --git a/Tests/ChildDefinitionTest.php b/Tests/ChildDefinitionTest.php index a941b9607..cbae0eaaa 100644 --- a/Tests/ChildDefinitionTest.php +++ b/Tests/ChildDefinitionTest.php @@ -22,7 +22,7 @@ public function testConstructor() $def = new ChildDefinition('foo'); $this->assertSame('foo', $def->getParent()); - $this->assertSame(array(), $def->getChanges()); + $this->assertSame([], $def->getChanges()); } /** @@ -38,17 +38,17 @@ public function testSetProperty($property, $changeKey) $this->assertNull($def->$getter()); $this->assertSame($def, $def->$setter('foo')); $this->assertSame('foo', $def->$getter()); - $this->assertSame(array($changeKey => true), $def->getChanges()); + $this->assertSame([$changeKey => true], $def->getChanges()); } public function getPropertyTests() { - return array( - array('class', 'class'), - array('factory', 'factory'), - array('configurator', 'configurator'), - array('file', 'file'), - ); + return [ + ['class', 'class'], + ['factory', 'factory'], + ['configurator', 'configurator'], + ['file', 'file'], + ]; } public function testSetPublic() @@ -58,7 +58,7 @@ public function testSetPublic() $this->assertTrue($def->isPublic()); $this->assertSame($def, $def->setPublic(false)); $this->assertFalse($def->isPublic()); - $this->assertSame(array('public' => true), $def->getChanges()); + $this->assertSame(['public' => true], $def->getChanges()); } public function testSetLazy() @@ -68,7 +68,7 @@ public function testSetLazy() $this->assertFalse($def->isLazy()); $this->assertSame($def, $def->setLazy(false)); $this->assertFalse($def->isLazy()); - $this->assertSame(array('lazy' => true), $def->getChanges()); + $this->assertSame(['lazy' => true], $def->getChanges()); } public function testSetAutowired() @@ -78,16 +78,16 @@ public function testSetAutowired() $this->assertFalse($def->isAutowired()); $this->assertSame($def, $def->setAutowired(true)); $this->assertTrue($def->isAutowired()); - $this->assertSame(array('autowired' => true), $def->getChanges()); + $this->assertSame(['autowired' => true], $def->getChanges()); } public function testSetArgument() { $def = new ChildDefinition('foo'); - $this->assertSame(array(), $def->getArguments()); + $this->assertSame([], $def->getArguments()); $this->assertSame($def, $def->replaceArgument(0, 'foo')); - $this->assertSame(array('index_0' => 'foo'), $def->getArguments()); + $this->assertSame(['index_0' => 'foo'], $def->getArguments()); } /** @@ -104,7 +104,7 @@ public function testReplaceArgument() { $def = new ChildDefinition('foo'); - $def->setArguments(array(0 => 'foo', 1 => 'bar')); + $def->setArguments([0 => 'foo', 1 => 'bar']); $this->assertSame('foo', $def->getArgument(0)); $this->assertSame('bar', $def->getArgument(1)); @@ -112,11 +112,11 @@ public function testReplaceArgument() $this->assertSame('foo', $def->getArgument(0)); $this->assertSame('baz', $def->getArgument(1)); - $this->assertSame(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments()); + $this->assertSame([0 => 'foo', 1 => 'bar', 'index_1' => 'baz'], $def->getArguments()); $this->assertSame($def, $def->replaceArgument('$bar', 'val')); $this->assertSame('val', $def->getArgument('$bar')); - $this->assertSame(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz', '$bar' => 'val'), $def->getArguments()); + $this->assertSame([0 => 'foo', 1 => 'bar', 'index_1' => 'baz', '$bar' => 'val'], $def->getArguments()); } /** @@ -126,7 +126,7 @@ public function testGetArgumentShouldCheckBounds() { $def = new ChildDefinition('foo'); - $def->setArguments(array(0 => 'foo')); + $def->setArguments([0 => 'foo']); $def->replaceArgument(0, 'foo'); $def->getArgument(1); @@ -152,6 +152,6 @@ public function testCannotCallSetAutoconfigured() public function testCannotCallSetInstanceofConditionals() { $def = new ChildDefinition('foo'); - $def->setInstanceofConditionals(array('Foo' => new ChildDefinition(''))); + $def->setInstanceofConditionals(['Foo' => new ChildDefinition('')]); } } diff --git a/Tests/Compiler/AnalyzeServiceReferencesPassTest.php b/Tests/Compiler/AnalyzeServiceReferencesPassTest.php index 8d44fad86..0bd94a3e6 100644 --- a/Tests/Compiler/AnalyzeServiceReferencesPassTest.php +++ b/Tests/Compiler/AnalyzeServiceReferencesPassTest.php @@ -32,7 +32,7 @@ public function testProcess() $b = $container ->register('b') - ->addMethodCall('setA', array($ref2 = new Reference('a'))) + ->addMethodCall('setA', [$ref2 = new Reference('a')]) ; $c = $container @@ -48,7 +48,7 @@ public function testProcess() $e = $container ->register('e') - ->setConfigurator(array($ref6 = new Reference('b'), 'methodName')) + ->setConfigurator([$ref6 = new Reference('b'), 'methodName']) ; $graph = $this->process($container); @@ -94,7 +94,7 @@ public function testProcessMarksEdgesLazyWhenReferencedFromIteratorArgument() $container ->register('c') ->addArgument($ref1 = new Reference('a')) - ->addArgument(new IteratorArgument(array($ref2 = new Reference('b')))) + ->addArgument(new IteratorArgument([$ref2 = new Reference('b')])) ; $graph = $this->process($container); @@ -119,7 +119,7 @@ public function testProcessDetectsReferencesFromInlinedDefinitions() $container ->register('b') - ->addArgument(new Definition(null, array($ref = new Reference('a')))) + ->addArgument(new Definition(null, [$ref = new Reference('a')])) ; $graph = $this->process($container); @@ -138,7 +138,7 @@ public function testProcessDetectsReferencesFromIteratorArguments() $container ->register('b') - ->addArgument(new IteratorArgument(array($ref = new Reference('a')))) + ->addArgument(new IteratorArgument([$ref = new Reference('a')])) ; $graph = $this->process($container); @@ -156,7 +156,7 @@ public function testProcessDetectsReferencesFromInlinedFactoryDefinitions() ; $factory = new Definition(); - $factory->setFactory(array(new Reference('a'), 'a')); + $factory->setFactory([new Reference('a'), 'a']); $container ->register('b') @@ -178,8 +178,8 @@ public function testProcessDoesNotSaveDuplicateReferences() ; $container ->register('b') - ->addArgument(new Definition(null, array($ref1 = new Reference('a')))) - ->addArgument(new Definition(null, array($ref2 = new Reference('a')))) + ->addArgument(new Definition(null, [$ref1 = new Reference('a')])) + ->addArgument(new Definition(null, [$ref2 = new Reference('a')])) ; $graph = $this->process($container); @@ -193,11 +193,11 @@ public function testProcessDetectsFactoryReferences() $container ->register('foo', 'stdClass') - ->setFactory(array('stdClass', 'getInstance')); + ->setFactory(['stdClass', 'getInstance']); $container ->register('bar', 'stdClass') - ->setFactory(array(new Reference('foo'), 'getInstance')); + ->setFactory([new Reference('foo'), 'getInstance']); $graph = $this->process($container); @@ -207,7 +207,7 @@ public function testProcessDetectsFactoryReferences() protected function process(ContainerBuilder $container) { - $pass = new RepeatedPass(array(new AnalyzeServiceReferencesPass())); + $pass = new RepeatedPass([new AnalyzeServiceReferencesPass()]); $pass->process($container); return $container->getCompiler()->getServiceReferenceGraph(); diff --git a/Tests/Compiler/AutoAliasServicePassTest.php b/Tests/Compiler/AutoAliasServicePassTest.php index f76001a11..d029636a7 100644 --- a/Tests/Compiler/AutoAliasServicePassTest.php +++ b/Tests/Compiler/AutoAliasServicePassTest.php @@ -25,7 +25,7 @@ public function testProcessWithMissingParameter() $container = new ContainerBuilder(); $container->register('example') - ->addTag('auto_alias', array('format' => '%non_existing%.example')); + ->addTag('auto_alias', ['format' => '%non_existing%.example']); $pass = new AutoAliasServicePass(); $pass->process($container); @@ -39,7 +39,7 @@ public function testProcessWithMissingFormat() $container = new ContainerBuilder(); $container->register('example') - ->addTag('auto_alias', array()); + ->addTag('auto_alias', []); $container->setParameter('existing', 'mysql'); $pass = new AutoAliasServicePass(); @@ -51,7 +51,7 @@ public function testProcessWithNonExistingAlias() $container = new ContainerBuilder(); $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault') - ->addTag('auto_alias', array('format' => '%existing%.example')); + ->addTag('auto_alias', ['format' => '%existing%.example']); $container->setParameter('existing', 'mysql'); $pass = new AutoAliasServicePass(); @@ -65,7 +65,7 @@ public function testProcessWithExistingAlias() $container = new ContainerBuilder(); $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault') - ->addTag('auto_alias', array('format' => '%existing%.example')); + ->addTag('auto_alias', ['format' => '%existing%.example']); $container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql'); $container->setParameter('existing', 'mysql'); @@ -83,7 +83,7 @@ public function testProcessWithManualAlias() $container = new ContainerBuilder(); $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault') - ->addTag('auto_alias', array('format' => '%existing%.example')); + ->addTag('auto_alias', ['format' => '%existing%.example']); $container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql'); $container->register('mariadb.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMariaDb'); diff --git a/Tests/Compiler/AutowireExceptionPassTest.php b/Tests/Compiler/AutowireExceptionPassTest.php index a9c3445ce..5bcb12342 100644 --- a/Tests/Compiler/AutowireExceptionPassTest.php +++ b/Tests/Compiler/AutowireExceptionPassTest.php @@ -31,13 +31,13 @@ public function testThrowsException() $autowireException = new AutowiringFailedException('foo_service_id', 'An autowiring exception message'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') - ->will($this->returnValue(array($autowireException))); + ->will($this->returnValue([$autowireException])); $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') - ->will($this->returnValue(array())); + ->will($this->returnValue([])); $container = new ContainerBuilder(); $container->register('foo_service_id'); @@ -60,18 +60,18 @@ public function testThrowExceptionIfServiceInlined() $autowireException = new AutowiringFailedException('a_service', 'An autowiring exception message'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') - ->will($this->returnValue(array($autowireException))); + ->will($this->returnValue([$autowireException])); $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') - ->will($this->returnValue(array( + ->will($this->returnValue([ // a_service inlined into b_service - 'a_service' => array('b_service'), + 'a_service' => ['b_service'], // b_service inlined into c_service - 'b_service' => array('c_service'), - ))); + 'b_service' => ['c_service'], + ])); $container = new ContainerBuilder(); // ONLY register c_service in the final container @@ -95,18 +95,18 @@ public function testDoNotThrowExceptionIfServiceInlinedButRemoved() $autowireException = new AutowiringFailedException('a_service', 'An autowiring exception message'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') - ->will($this->returnValue(array($autowireException))); + ->will($this->returnValue([$autowireException])); $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') - ->will($this->returnValue(array( + ->will($this->returnValue([ // a_service inlined into b_service - 'a_service' => array('b_service'), + 'a_service' => ['b_service'], // b_service inlined into c_service - 'b_service' => array('c_service'), - ))); + 'b_service' => ['c_service'], + ])); // do NOT register c_service in the container $container = new ContainerBuilder(); @@ -126,13 +126,13 @@ public function testNoExceptionIfServiceRemoved() $autowireException = new AutowiringFailedException('non_existent_service'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') - ->will($this->returnValue(array($autowireException))); + ->will($this->returnValue([$autowireException])); $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') - ->will($this->returnValue(array())); + ->will($this->returnValue([])); $container = new ContainerBuilder(); diff --git a/Tests/Compiler/AutowirePassTest.php b/Tests/Compiler/AutowirePassTest.php index a21687723..6bd49fa5c 100644 --- a/Tests/Compiler/AutowirePassTest.php +++ b/Tests/Compiler/AutowirePassTest.php @@ -434,22 +434,22 @@ public function testSomeSpecificArgumentsAreSet() ->setAutowired(true) // set the 2nd (index 1) argument only: autowire the first and third // args are: A, Foo, Dunglas - ->setArguments(array( + ->setArguments([ 1 => new Reference('foo'), - 3 => array('bar'), - )); + 3 => ['bar'], + ]); (new ResolveClassPass())->process($container); (new AutowirePass())->process($container); $definition = $container->getDefinition('multiple'); $this->assertEquals( - array( + [ new TypedReference(A::class, A::class, MultipleArguments::class), new Reference('foo'), new TypedReference(Dunglas::class, Dunglas::class, MultipleArguments::class), - array('bar'), - ), + ['bar'], + ], $definition->getArguments() ); } @@ -465,7 +465,7 @@ public function testScalarArgsCannotBeAutowired() $container->register(A::class); $container->register(Dunglas::class); $container->register('arg_no_type_hint', __NAMESPACE__.'\MultipleArguments') - ->setArguments(array(1 => 'foo')) + ->setArguments([1 => 'foo']) ->setAutowired(true); (new ResolveClassPass())->process($container); @@ -518,12 +518,12 @@ public function testOptionalScalarArgsDontMessUpOrder() $definition = $container->getDefinition('with_optional_scalar'); $this->assertEquals( - array( + [ new TypedReference(A::class, A::class, MultipleArgumentsOptionalScalar::class), // use the default value 'default_val', new TypedReference(Lille::class, Lille::class), - ), + ], $definition->getArguments() ); } @@ -542,10 +542,10 @@ public function testOptionalScalarArgsNotPassedIfLast() $definition = $container->getDefinition('with_optional_scalar_last'); $this->assertEquals( - array( + [ new TypedReference(A::class, A::class, MultipleArgumentsOptionalScalarLast::class), new TypedReference(Lille::class, Lille::class, MultipleArgumentsOptionalScalarLast::class), - ), + ], $definition->getArguments() ); } @@ -562,7 +562,7 @@ public function testOptionalArgsNoRequiredForCoreClasses() $definition = $container->getDefinition('foo'); $this->assertEquals( - array('foo.txt'), + ['foo.txt'], $definition->getArguments() ); } @@ -579,7 +579,7 @@ public function testSetterInjection() $container ->register('setter_injection', SetterInjection::class) ->setAutowired(true) - ->addMethodCall('setWithCallsConfigured', array('manual_arg1', 'manual_arg2')) + ->addMethodCall('setWithCallsConfigured', ['manual_arg1', 'manual_arg2']) ; (new ResolveClassPass())->process($container); @@ -589,18 +589,18 @@ public function testSetterInjection() $methodCalls = $container->getDefinition('setter_injection')->getMethodCalls(); $this->assertEquals( - array('setWithCallsConfigured', 'setFoo', 'setDependencies', 'setChildMethodWithoutDocBlock'), + ['setWithCallsConfigured', 'setFoo', 'setDependencies', 'setChildMethodWithoutDocBlock'], array_column($methodCalls, 0) ); // test setWithCallsConfigured args $this->assertEquals( - array('manual_arg1', 'manual_arg2'), + ['manual_arg1', 'manual_arg2'], $methodCalls[0][1] ); // test setFoo args $this->assertEquals( - array(new TypedReference(Foo::class, Foo::class, SetterInjection::class)), + [new TypedReference(Foo::class, Foo::class, SetterInjection::class)], $methodCalls[1][1] ); } @@ -616,7 +616,7 @@ public function testExplicitMethodInjection() $container ->register('setter_injection', SetterInjection::class) ->setAutowired(true) - ->addMethodCall('notASetter', array()) + ->addMethodCall('notASetter', []) ; (new ResolveClassPass())->process($container); @@ -626,11 +626,11 @@ public function testExplicitMethodInjection() $methodCalls = $container->getDefinition('setter_injection')->getMethodCalls(); $this->assertEquals( - array('notASetter', 'setFoo', 'setDependencies', 'setWithCallsConfigured', 'setChildMethodWithoutDocBlock'), + ['notASetter', 'setFoo', 'setDependencies', 'setWithCallsConfigured', 'setChildMethodWithoutDocBlock'], array_column($methodCalls, 0) ); $this->assertEquals( - array(new TypedReference(A::class, A::class, SetterInjection::class)), + [new TypedReference(A::class, A::class, SetterInjection::class)], $methodCalls[0][1] ); } @@ -645,7 +645,7 @@ public function testTypedReference() $container ->register('bar', Bar::class) - ->setProperty('a', array(new TypedReference(A::class, A::class, Bar::class))) + ->setProperty('a', [new TypedReference(A::class, A::class, Bar::class)]) ; $pass = new AutowirePass(); @@ -682,10 +682,10 @@ public function testCreateResourceForClass($className, $isEqual) public function getCreateResourceTests() { - return array( - array('IdenticalClassResource', true), - array('ClassChangedConstructorArgs', false), - ); + return [ + ['IdenticalClassResource', true], + ['ClassChangedConstructorArgs', false], + ]; } public function testIgnoreServiceWithClassNotExisting() @@ -773,12 +773,12 @@ public function testEmptyStringIsKept() $container->register(Lille::class); $container->register('foo', __NAMESPACE__.'\MultipleArgumentsOptionalScalar') ->setAutowired(true) - ->setArguments(array('', '')); + ->setArguments(['', '']); (new ResolveClassPass())->process($container); (new AutowirePass())->process($container); - $this->assertEquals(array(new TypedReference(A::class, A::class, MultipleArgumentsOptionalScalar::class), '', new TypedReference(Lille::class, Lille::class)), $container->getDefinition('foo')->getArguments()); + $this->assertEquals([new TypedReference(A::class, A::class, MultipleArgumentsOptionalScalar::class), '', new TypedReference(Lille::class, Lille::class)], $container->getDefinition('foo')->getArguments()); } public function testWithFactory() @@ -787,13 +787,13 @@ public function testWithFactory() $container->register(Foo::class); $definition = $container->register('a', A::class) - ->setFactory(array(A::class, 'create')) + ->setFactory([A::class, 'create']) ->setAutowired(true); (new ResolveClassPass())->process($container); (new AutowirePass())->process($container); - $this->assertEquals(array(new TypedReference(Foo::class, Foo::class, A::class)), $definition->getArguments()); + $this->assertEquals([new TypedReference(Foo::class, Foo::class, A::class)], $definition->getArguments()); } /** @@ -805,14 +805,14 @@ public function testNotWireableCalls($method, $expectedMsg) $container = new ContainerBuilder(); $foo = $container->register('foo', NotWireable::class)->setAutowired(true) - ->addMethodCall('setBar', array()) - ->addMethodCall('setOptionalNotAutowireable', array()) - ->addMethodCall('setOptionalNoTypeHint', array()) - ->addMethodCall('setOptionalArgNoAutowireable', array()) + ->addMethodCall('setBar', []) + ->addMethodCall('setOptionalNotAutowireable', []) + ->addMethodCall('setOptionalNoTypeHint', []) + ->addMethodCall('setOptionalArgNoAutowireable', []) ; if ($method) { - $foo->addMethodCall($method, array()); + $foo->addMethodCall($method, []); } if (method_exists($this, 'expectException')) { @@ -829,11 +829,11 @@ public function testNotWireableCalls($method, $expectedMsg) public function provideNotWireableCalls() { - return array( - array('setNotAutowireable', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.'), - array('setDifferentNamespace', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setDifferentNamespace()" references class "stdClass" but no such service exists. It cannot be auto-registered because it is from a different root namespace.'), - array(null, 'Invalid service "foo": method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod()" must be public.'), - ); + return [ + ['setNotAutowireable', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.'], + ['setDifferentNamespace', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setDifferentNamespace()" references class "stdClass" but no such service exists. It cannot be auto-registered because it is from a different root namespace.'], + [null, 'Invalid service "foo": method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod()" must be public.'], + ]; } /** @@ -867,7 +867,7 @@ public function testTypedReferenceDeprecationNotice() $container->setAlias(AInterface::class, 'aClass'); $container ->register('bar', Bar::class) - ->setProperty('a', array(new TypedReference(A::class, A::class, Bar::class))) + ->setProperty('a', [new TypedReference(A::class, A::class, Bar::class)]) ; $pass = new AutowirePass(); @@ -922,6 +922,6 @@ public function testInlineServicesAreNotCandidates() $pass = new AutowirePass(); $pass->process($container); - $this->assertSame(array(), $container->getDefinition('autowired')->getArguments()); + $this->assertSame([], $container->getDefinition('autowired')->getArguments()); } } diff --git a/Tests/Compiler/AutowireRequiredMethodsPassTest.php b/Tests/Compiler/AutowireRequiredMethodsPassTest.php index 07c9f9d77..644b32d20 100644 --- a/Tests/Compiler/AutowireRequiredMethodsPassTest.php +++ b/Tests/Compiler/AutowireRequiredMethodsPassTest.php @@ -32,7 +32,7 @@ public function testSetterInjection() $container ->register('setter_injection', SetterInjection::class) ->setAutowired(true) - ->addMethodCall('setWithCallsConfigured', array('manual_arg1', 'manual_arg2')); + ->addMethodCall('setWithCallsConfigured', ['manual_arg1', 'manual_arg2']); (new ResolveClassPass())->process($container); (new AutowireRequiredMethodsPass())->process($container); @@ -40,17 +40,17 @@ public function testSetterInjection() $methodCalls = $container->getDefinition('setter_injection')->getMethodCalls(); $this->assertEquals( - array('setWithCallsConfigured', 'setFoo', 'setDependencies', 'setChildMethodWithoutDocBlock'), + ['setWithCallsConfigured', 'setFoo', 'setDependencies', 'setChildMethodWithoutDocBlock'], array_column($methodCalls, 0) ); // test setWithCallsConfigured args $this->assertEquals( - array('manual_arg1', 'manual_arg2'), + ['manual_arg1', 'manual_arg2'], $methodCalls[0][1] ); // test setFoo args - $this->assertEquals(array(), $methodCalls[1][1]); + $this->assertEquals([], $methodCalls[1][1]); } public function testExplicitMethodInjection() @@ -64,7 +64,7 @@ public function testExplicitMethodInjection() $container ->register('setter_injection', SetterInjection::class) ->setAutowired(true) - ->addMethodCall('notASetter', array()); + ->addMethodCall('notASetter', []); (new ResolveClassPass())->process($container); (new AutowireRequiredMethodsPass())->process($container); @@ -72,9 +72,9 @@ public function testExplicitMethodInjection() $methodCalls = $container->getDefinition('setter_injection')->getMethodCalls(); $this->assertEquals( - array('notASetter', 'setFoo', 'setDependencies', 'setWithCallsConfigured', 'setChildMethodWithoutDocBlock'), + ['notASetter', 'setFoo', 'setDependencies', 'setWithCallsConfigured', 'setChildMethodWithoutDocBlock'], array_column($methodCalls, 0) ); - $this->assertEquals(array(), $methodCalls[0][1]); + $this->assertEquals([], $methodCalls[0][1]); } } diff --git a/Tests/Compiler/CheckArgumentsValidityPassTest.php b/Tests/Compiler/CheckArgumentsValidityPassTest.php index d121689ff..c1e47b308 100644 --- a/Tests/Compiler/CheckArgumentsValidityPassTest.php +++ b/Tests/Compiler/CheckArgumentsValidityPassTest.php @@ -24,20 +24,20 @@ public function testProcess() { $container = new ContainerBuilder(); $definition = $container->register('foo'); - $definition->setArguments(array(null, 1, 'a')); - $definition->setMethodCalls(array( - array('bar', array('a', 'b')), - array('baz', array('c', 'd')), - )); + $definition->setArguments([null, 1, 'a']); + $definition->setMethodCalls([ + ['bar', ['a', 'b']], + ['baz', ['c', 'd']], + ]); $pass = new CheckArgumentsValidityPass(); $pass->process($container); - $this->assertEquals(array(null, 1, 'a'), $container->getDefinition('foo')->getArguments()); - $this->assertEquals(array( - array('bar', array('a', 'b')), - array('baz', array('c', 'd')), - ), $container->getDefinition('foo')->getMethodCalls()); + $this->assertEquals([null, 1, 'a'], $container->getDefinition('foo')->getArguments()); + $this->assertEquals([ + ['bar', ['a', 'b']], + ['baz', ['c', 'd']], + ], $container->getDefinition('foo')->getMethodCalls()); } /** @@ -57,19 +57,19 @@ public function testException(array $arguments, array $methodCalls) public function definitionProvider() { - return array( - array(array(null, 'a' => 'a'), array()), - array(array(1 => 1), array()), - array(array(), array(array('baz', array(null, 'a' => 'a')))), - array(array(), array(array('baz', array(1 => 1)))), - ); + return [ + [[null, 'a' => 'a'], []], + [[1 => 1], []], + [[], [['baz', [null, 'a' => 'a']]]], + [[], [['baz', [1 => 1]]]], + ]; } public function testNoException() { $container = new ContainerBuilder(); $definition = $container->register('foo'); - $definition->setArguments(array(null, 'a' => 'a')); + $definition->setArguments([null, 'a' => 'a']); $pass = new CheckArgumentsValidityPass(false); $pass->process($container); diff --git a/Tests/Compiler/CheckCircularReferencesPassTest.php b/Tests/Compiler/CheckCircularReferencesPassTest.php index a87dc44a9..8423c5616 100644 --- a/Tests/Compiler/CheckCircularReferencesPassTest.php +++ b/Tests/Compiler/CheckCircularReferencesPassTest.php @@ -55,11 +55,11 @@ public function testProcessWithFactory() $container ->register('a', 'stdClass') - ->setFactory(array(new Reference('b'), 'getInstance')); + ->setFactory([new Reference('b'), 'getInstance']); $container ->register('b', 'stdClass') - ->setFactory(array(new Reference('a'), 'getInstance')); + ->setFactory([new Reference('a'), 'getInstance']); $this->process($container); } @@ -88,7 +88,7 @@ public function testProcessDetectsIndirectCircularReferenceWithFactory() $container ->register('b', 'stdClass') - ->setFactory(array(new Reference('c'), 'getInstance')); + ->setFactory([new Reference('c'), 'getInstance']); $container->register('c')->addArgument(new Reference('a')); @@ -112,7 +112,7 @@ public function testProcessIgnoresMethodCalls() { $container = new ContainerBuilder(); $container->register('a')->addArgument(new Reference('b')); - $container->register('b')->addMethodCall('setA', array(new Reference('a'))); + $container->register('b')->addMethodCall('setA', [new Reference('a')]); $this->process($container); @@ -135,7 +135,7 @@ public function testProcessIgnoresIteratorArguments() { $container = new ContainerBuilder(); $container->register('a')->addArgument(new Reference('b')); - $container->register('b')->addArgument(new IteratorArgument(array(new Reference('a')))); + $container->register('b')->addArgument(new IteratorArgument([new Reference('a')])); $this->process($container); @@ -147,11 +147,11 @@ protected function process(ContainerBuilder $container) { $compiler = new Compiler(); $passConfig = $compiler->getPassConfig(); - $passConfig->setOptimizationPasses(array( + $passConfig->setOptimizationPasses([ new AnalyzeServiceReferencesPass(true), new CheckCircularReferencesPass(), - )); - $passConfig->setRemovingPasses(array()); + ]); + $passConfig->setRemovingPasses([]); $compiler->compile($container); } diff --git a/Tests/Compiler/CheckDefinitionValidityPassTest.php b/Tests/Compiler/CheckDefinitionValidityPassTest.php index f698ed02d..e1dd60b66 100644 --- a/Tests/Compiler/CheckDefinitionValidityPassTest.php +++ b/Tests/Compiler/CheckDefinitionValidityPassTest.php @@ -55,10 +55,10 @@ public function testProcess() public function testValidTags() { $container = new ContainerBuilder(); - $container->register('a', 'class')->addTag('foo', array('bar' => 'baz')); - $container->register('b', 'class')->addTag('foo', array('bar' => null)); - $container->register('c', 'class')->addTag('foo', array('bar' => 1)); - $container->register('d', 'class')->addTag('foo', array('bar' => 1.1)); + $container->register('a', 'class')->addTag('foo', ['bar' => 'baz']); + $container->register('b', 'class')->addTag('foo', ['bar' => null]); + $container->register('c', 'class')->addTag('foo', ['bar' => 1]); + $container->register('d', 'class')->addTag('foo', ['bar' => 1.1]); $this->process($container); @@ -71,7 +71,7 @@ public function testValidTags() public function testInvalidTags() { $container = new ContainerBuilder(); - $container->register('a', 'class')->addTag('foo', array('bar' => array('baz' => 'baz'))); + $container->register('a', 'class')->addTag('foo', ['bar' => ['baz' => 'baz']]); $this->process($container); } diff --git a/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php b/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php index 631c344ff..38717eaf1 100644 --- a/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php +++ b/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php @@ -74,7 +74,7 @@ public function testProcessDefinitionWithBindings() $container ->register('b') - ->setBindings(array(new BoundArgument(new Reference('a')))) + ->setBindings([new BoundArgument(new Reference('a'))]) ; $this->process($container); diff --git a/Tests/Compiler/DecoratorServicePassTest.php b/Tests/Compiler/DecoratorServicePassTest.php index fe1334e91..29fc5cc57 100644 --- a/Tests/Compiler/DecoratorServicePassTest.php +++ b/Tests/Compiler/DecoratorServicePassTest.php @@ -130,18 +130,18 @@ public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinitio $container = new ContainerBuilder(); $container ->register('foo') - ->setTags(array('bar' => array('attr' => 'baz'))) + ->setTags(['bar' => ['attr' => 'baz']]) ; $container ->register('baz') - ->setTags(array('foobar' => array('attr' => 'bar'))) + ->setTags(['foobar' => ['attr' => 'bar']]) ->setDecoratedService('foo') ; $this->process($container); $this->assertEmpty($container->getDefinition('baz.inner')->getTags()); - $this->assertEquals(array('bar' => array('attr' => 'baz'), 'foobar' => array('attr' => 'bar')), $container->getDefinition('baz')->getTags()); + $this->assertEquals(['bar' => ['attr' => 'baz'], 'foobar' => ['attr' => 'bar']], $container->getDefinition('baz')->getTags()); } /** @@ -164,7 +164,7 @@ public function testProcessMergesAutowiringTypesInDecoratingDefinitionAndRemoveT $this->process($container); - $this->assertEquals(array('Bar', 'Foo'), $container->getDefinition('child')->getAutowiringTypes()); + $this->assertEquals(['Bar', 'Foo'], $container->getDefinition('child')->getAutowiringTypes()); $this->assertEmpty($container->getDefinition('child.inner')->getAutowiringTypes()); } @@ -174,7 +174,7 @@ public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinitio $container ->register('foo') ->setPublic(true) - ->setTags(array('bar' => array('attr' => 'baz'))) + ->setTags(['bar' => ['attr' => 'baz']]) ; $container ->register('deco1') @@ -188,7 +188,7 @@ public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinitio $this->process($container); $this->assertEmpty($container->getDefinition('deco1')->getTags()); - $this->assertEquals(array('bar' => array('attr' => 'baz')), $container->getDefinition('deco2')->getTags()); + $this->assertEquals(['bar' => ['attr' => 'baz']], $container->getDefinition('deco2')->getTags()); } protected function process(ContainerBuilder $container) diff --git a/Tests/Compiler/DefinitionErrorExceptionPassTest.php b/Tests/Compiler/DefinitionErrorExceptionPassTest.php index e0585e213..ce6f0496e 100644 --- a/Tests/Compiler/DefinitionErrorExceptionPassTest.php +++ b/Tests/Compiler/DefinitionErrorExceptionPassTest.php @@ -29,9 +29,9 @@ public function testThrowsException() $def->addError('Things went wrong!'); $def->addError('Now something else!'); $container->register('foo_service_id') - ->setArguments(array( + ->setArguments([ $def, - )); + ]); $pass = new DefinitionErrorExceptionPass(); $pass->process($container); @@ -42,9 +42,9 @@ public function testNoExceptionThrown() $container = new ContainerBuilder(); $def = new Definition(); $container->register('foo_service_id') - ->setArguments(array( + ->setArguments([ $def, - )); + ]); $pass = new DefinitionErrorExceptionPass(); $pass->process($container); diff --git a/Tests/Compiler/FactoryReturnTypePassTest.php b/Tests/Compiler/FactoryReturnTypePassTest.php index bfb61c373..87f07c700 100644 --- a/Tests/Compiler/FactoryReturnTypePassTest.php +++ b/Tests/Compiler/FactoryReturnTypePassTest.php @@ -31,15 +31,15 @@ public function testProcess() $container = new ContainerBuilder(); $factory = $container->register('factory'); - $factory->setFactory(array(FactoryDummy::class, 'createFactory')); + $factory->setFactory([FactoryDummy::class, 'createFactory']); $container->setAlias('alias_factory', 'factory'); $foo = $container->register('foo'); - $foo->setFactory(array(new Reference('alias_factory'), 'create')); + $foo->setFactory([new Reference('alias_factory'), 'create']); $bar = $container->register('bar', __CLASS__); - $bar->setFactory(array(new Reference('factory'), 'create')); + $bar->setFactory([new Reference('factory'), 'create']); $pass = new FactoryReturnTypePass(); $pass->process($container); @@ -80,13 +80,13 @@ public function testReturnTypes($factory, $returnType, $hhvmSupport = true) public function returnTypesProvider() { - return array( + return [ // must be loaded before the function as they are in the same file - array(array(FactoryDummy::class, 'createBuiltin'), null, false), - array(array(FactoryDummy::class, 'createParent'), FactoryParent::class), - array(array(FactoryDummy::class, 'createSelf'), FactoryDummy::class), - array(factoryFunction::class, FactoryDummy::class), - ); + [[FactoryDummy::class, 'createBuiltin'], null, false], + [[FactoryDummy::class, 'createParent'], FactoryParent::class], + [[FactoryDummy::class, 'createSelf'], FactoryDummy::class], + [factoryFunction::class, FactoryDummy::class], + ]; } public function testCircularReference() @@ -94,10 +94,10 @@ public function testCircularReference() $container = new ContainerBuilder(); $factory = $container->register('factory'); - $factory->setFactory(array(new Reference('factory2'), 'createSelf')); + $factory->setFactory([new Reference('factory2'), 'createSelf']); $factory2 = $container->register('factory2'); - $factory2->setFactory(array(new Reference('factory'), 'create')); + $factory2->setFactory([new Reference('factory'), 'create']); $pass = new FactoryReturnTypePass(); $pass->process($container); @@ -115,7 +115,7 @@ public function testCompile() $container = new ContainerBuilder(); $factory = $container->register('factory'); - $factory->setFactory(array(FactoryDummy::class, 'createFactory')); + $factory->setFactory([FactoryDummy::class, 'createFactory']); $container->compile(); $this->assertEquals(FactoryDummy::class, $container->getDefinition('factory')->getClass()); diff --git a/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/Tests/Compiler/InlineServiceDefinitionsPassTest.php index b2ad6f947..6e5c80a7d 100644 --- a/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -33,7 +33,7 @@ public function testProcess() $container ->register('service') - ->setArguments(array(new Reference('inlinable.service'))) + ->setArguments([new Reference('inlinable.service')]) ; $this->process($container); @@ -54,7 +54,7 @@ public function testProcessDoesNotInlinesWhenAliasedServiceIsShared() $container ->register('service') - ->setArguments(array($ref = new Reference('foo'))) + ->setArguments([$ref = new Reference('foo')]) ; $this->process($container); @@ -79,7 +79,7 @@ public function testProcessDoesInlineNonSharedService() $container ->register('service') - ->setArguments(array(new Reference('foo'), $ref = new Reference('moo'), new Reference('bar'))) + ->setArguments([new Reference('foo'), $ref = new Reference('moo'), new Reference('bar')]) ; $this->process($container); @@ -103,7 +103,7 @@ public function testProcessDoesNotInlineMixedServicesLoop() $container ->register('bar') ->setPublic(false) - ->addMethodCall('setFoo', array(new Reference('foo'))) + ->addMethodCall('setFoo', [new Reference('foo')]) ; $this->process($container); @@ -126,7 +126,7 @@ public function testProcessThrowsOnNonSharedLoops() $container ->register('bar') ->setShared(false) - ->addMethodCall('setFoo', array(new Reference('foo'))) + ->addMethodCall('setFoo', [new Reference('foo')]) ; $this->process($container); @@ -173,7 +173,7 @@ public function testProcessInlinesIfMultipleReferencesButAllFromTheSameDefinitio $b = $container ->register('b') ->addArgument(new Reference('a')) - ->addArgument(new Definition(null, array(new Reference('a')))) + ->addArgument(new Definition(null, [new Reference('a')])) ; $this->process($container); @@ -193,14 +193,14 @@ public function testProcessInlinesPrivateFactoryReference() $b = $container ->register('b') ->setPublic(false) - ->setFactory(array(new Reference('a'), 'a')) + ->setFactory([new Reference('a'), 'a']) ; $container ->register('foo') - ->setArguments(array( + ->setArguments([ $ref = new Reference('b'), - )); + ]); $this->process($container); @@ -217,15 +217,15 @@ public function testProcessDoesNotInlinePrivateFactoryIfReferencedMultipleTimesW $container ->register('b') ->setPublic(false) - ->setFactory(array(new Reference('a'), 'a')) + ->setFactory([new Reference('a'), 'a']) ; $container ->register('foo') - ->setArguments(array( + ->setArguments([ $ref1 = new Reference('b'), $ref2 = new Reference('b'), - )) + ]) ; $this->process($container); @@ -243,19 +243,19 @@ public function testProcessDoesNotInlineReferenceWhenUsedByInlineFactory() $container ->register('b') ->setPublic(false) - ->setFactory(array(new Reference('a'), 'a')) + ->setFactory([new Reference('a'), 'a']) ; $inlineFactory = new Definition(); $inlineFactory->setPublic(false); - $inlineFactory->setFactory(array(new Reference('b'), 'b')); + $inlineFactory->setFactory([new Reference('b'), 'b']); $container ->register('foo') - ->setArguments(array( + ->setArguments([ $ref = new Reference('b'), $inlineFactory, - )) + ]) ; $this->process($container); @@ -274,7 +274,7 @@ public function testProcessDoesNotInlineWhenServiceIsPrivateButLazy() $container ->register('service') - ->setArguments(array($ref = new Reference('foo'))) + ->setArguments([$ref = new Reference('foo')]) ; $this->process($container); @@ -289,7 +289,7 @@ public function testProcessDoesNotInlineWhenServiceReferencesItself() $container ->register('foo') ->setPublic(false) - ->addMethodCall('foo', array($ref = new Reference('foo'))) + ->addMethodCall('foo', [$ref = new Reference('foo')]) ; $this->process($container); @@ -307,11 +307,11 @@ public function testProcessDoesNotSetLazyArgumentValuesAfterInlining() ; $container ->register('service-closure') - ->setArguments(array(new ServiceClosureArgument(new Reference('inline')))) + ->setArguments([new ServiceClosureArgument(new Reference('inline'))]) ; $container ->register('iterator') - ->setArguments(array(new IteratorArgument(array(new Reference('inline'))))) + ->setArguments([new IteratorArgument([new Reference('inline')])]) ; $this->process($container); @@ -342,19 +342,19 @@ public function testGetInlinedServiceIdData() $container ->register('other_service') - ->setArguments(array(new Reference('inlinable.service'))) + ->setArguments([new Reference('inlinable.service')]) ; $inlinePass = new InlineServiceDefinitionsPass(); - $repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), $inlinePass)); + $repeatedPass = new RepeatedPass([new AnalyzeServiceReferencesPass(), $inlinePass]); $repeatedPass->process($container); - $this->assertEquals(array('inlinable.service' => array('other_service')), $inlinePass->getInlinedServiceIds()); + $this->assertEquals(['inlinable.service' => ['other_service']], $inlinePass->getInlinedServiceIds()); } protected function process(ContainerBuilder $container) { - $repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass())); + $repeatedPass = new RepeatedPass([new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()]); $repeatedPass->process($container); } } diff --git a/Tests/Compiler/IntegrationTest.php b/Tests/Compiler/IntegrationTest.php index 104b39f13..10c34aa48 100644 --- a/Tests/Compiler/IntegrationTest.php +++ b/Tests/Compiler/IntegrationTest.php @@ -97,7 +97,7 @@ public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDe $container ->register('a', '\stdClass') ->addArgument(new Reference('b')) - ->addMethodCall('setC', array(new Reference('c'))) + ->addMethodCall('setC', [new Reference('c')]) ; $container @@ -155,8 +155,8 @@ public function testYamlContainerCompiles($directory, $actualServiceId, $expecte $expectedService = $container->getDefinition($expectedServiceId); // reset changes, we don't care if these differ - $actualService->setChanges(array()); - $expectedService->setChanges(array()); + $actualService->setChanges([]); + $expectedService->setChanges([]); $this->assertEquals($expectedService, $actualService); } @@ -165,61 +165,61 @@ public function getYamlCompileTests() { $container = new ContainerBuilder(); $container->registerForAutoconfiguration(IntegrationTestStub::class); - yield array( + yield [ 'autoconfigure_child_not_applied', 'child_service', 'child_service_expected', $container, - ); + ]; $container = new ContainerBuilder(); $container->registerForAutoconfiguration(IntegrationTestStub::class); - yield array( + yield [ 'autoconfigure_parent_child', 'child_service', 'child_service_expected', $container, - ); + ]; $container = new ContainerBuilder(); $container->registerForAutoconfiguration(IntegrationTestStub::class) ->addTag('from_autoconfigure'); - yield array( + yield [ 'autoconfigure_parent_child_tags', 'child_service', 'child_service_expected', $container, - ); + ]; - yield array( + yield [ 'child_parent', 'child_service', 'child_service_expected', - ); + ]; - yield array( + yield [ 'defaults_child_tags', 'child_service', 'child_service_expected', - ); + ]; - yield array( + yield [ 'defaults_instanceof_importance', 'main_service', 'main_service_expected', - ); + ]; - yield array( + yield [ 'defaults_parent_child', 'child_service', 'child_service_expected', - ); + ]; - yield array( + yield [ 'instanceof_parent_child', 'child_service', 'child_service_expected', - ); + ]; } } @@ -227,7 +227,7 @@ class ServiceSubscriberStub implements ServiceSubscriberInterface { public static function getSubscribedServices() { - return array(); + return []; } } diff --git a/Tests/Compiler/MergeExtensionConfigurationPassTest.php b/Tests/Compiler/MergeExtensionConfigurationPassTest.php index 3ebd3f5e5..667ae3886 100644 --- a/Tests/Compiler/MergeExtensionConfigurationPassTest.php +++ b/Tests/Compiler/MergeExtensionConfigurationPassTest.php @@ -25,7 +25,7 @@ class MergeExtensionConfigurationPassTest extends TestCase { public function testExpressionLanguageProviderForwarding() { - $tmpProviders = array(); + $tmpProviders = []; $extension = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface')->getMock(); $extension->expects($this->any()) @@ -46,18 +46,18 @@ public function testExpressionLanguageProviderForwarding() $provider = $this->getMockBuilder('Symfony\\Component\\ExpressionLanguage\\ExpressionFunctionProviderInterface')->getMock(); $container = new ContainerBuilder(new ParameterBag()); $container->registerExtension($extension); - $container->prependExtensionConfig('foo', array('bar' => true)); + $container->prependExtensionConfig('foo', ['bar' => true]); $container->addExpressionLanguageProvider($provider); $pass = new MergeExtensionConfigurationPass(); $pass->process($container); - $this->assertEquals(array($provider), $tmpProviders); + $this->assertEquals([$provider], $tmpProviders); } public function testExtensionLoadGetAMergeExtensionConfigurationContainerBuilderInstance() { - $extension = $this->getMockBuilder(FooExtension::class)->setMethods(array('load'))->getMock(); + $extension = $this->getMockBuilder(FooExtension::class)->setMethods(['load'])->getMock(); $extension->expects($this->once()) ->method('load') ->with($this->isType('array'), $this->isInstanceOf(MergeExtensionConfigurationContainerBuilder::class)) @@ -65,7 +65,7 @@ public function testExtensionLoadGetAMergeExtensionConfigurationContainerBuilder $container = new ContainerBuilder(new ParameterBag()); $container->registerExtension($extension); - $container->prependExtensionConfig('foo', array()); + $container->prependExtensionConfig('foo', []); $pass = new MergeExtensionConfigurationPass(); $pass->process($container); @@ -73,14 +73,14 @@ public function testExtensionLoadGetAMergeExtensionConfigurationContainerBuilder public function testExtensionConfigurationIsTrackedByDefault() { - $extension = $this->getMockBuilder(FooExtension::class)->setMethods(array('getConfiguration'))->getMock(); + $extension = $this->getMockBuilder(FooExtension::class)->setMethods(['getConfiguration'])->getMock(); $extension->expects($this->exactly(2)) ->method('getConfiguration') ->will($this->returnValue(new FooConfiguration())); $container = new ContainerBuilder(new ParameterBag()); $container->registerExtension($extension); - $container->prependExtensionConfig('foo', array('bar' => true)); + $container->prependExtensionConfig('foo', ['bar' => true]); $pass = new MergeExtensionConfigurationPass(); $pass->process($container); @@ -92,14 +92,14 @@ public function testOverriddenEnvsAreMerged() { $container = new ContainerBuilder(); $container->registerExtension(new FooExtension()); - $container->prependExtensionConfig('foo', array('bar' => '%env(FOO)%')); - $container->prependExtensionConfig('foo', array('bar' => '%env(BAR)%', 'baz' => '%env(BAZ)%')); + $container->prependExtensionConfig('foo', ['bar' => '%env(FOO)%']); + $container->prependExtensionConfig('foo', ['bar' => '%env(BAR)%', 'baz' => '%env(BAZ)%']); $pass = new MergeExtensionConfigurationPass(); $pass->process($container); - $this->assertSame(array('BAZ', 'FOO'), array_keys($container->getParameterBag()->getEnvPlaceholders())); - $this->assertSame(array('BAZ' => 1, 'FOO' => 0), $container->getEnvCounters()); + $this->assertSame(['BAZ', 'FOO'], array_keys($container->getParameterBag()->getEnvPlaceholders())); + $this->assertSame(['BAZ' => 1, 'FOO' => 0], $container->getEnvCounters()); } /** @@ -110,7 +110,7 @@ public function testProcessedEnvsAreIncompatibleWithResolve() { $container = new ContainerBuilder(); $container->registerExtension(new BarExtension()); - $container->prependExtensionConfig('bar', array()); + $container->prependExtensionConfig('bar', []); (new MergeExtensionConfigurationPass())->process($container); } @@ -119,7 +119,7 @@ public function testThrowingExtensionsGetMergedBag() { $container = new ContainerBuilder(); $container->registerExtension(new ThrowingExtension()); - $container->prependExtensionConfig('throwing', array('bar' => '%env(FOO)%')); + $container->prependExtensionConfig('throwing', ['bar' => '%env(FOO)%']); try { $pass = new MergeExtensionConfigurationPass(); @@ -128,7 +128,7 @@ public function testThrowingExtensionsGetMergedBag() } catch (\Exception $e) { } - $this->assertSame(array('FOO'), array_keys($container->getParameterBag()->getEnvPlaceholders())); + $this->assertSame(['FOO'], array_keys($container->getParameterBag()->getEnvPlaceholders())); } } diff --git a/Tests/Compiler/PassConfigTest.php b/Tests/Compiler/PassConfigTest.php index 1fd772ee6..9470e526f 100644 --- a/Tests/Compiler/PassConfigTest.php +++ b/Tests/Compiler/PassConfigTest.php @@ -23,7 +23,7 @@ class PassConfigTest extends TestCase public function testPassOrdering() { $config = new PassConfig(); - $config->setBeforeOptimizationPasses(array()); + $config->setBeforeOptimizationPasses([]); $pass1 = $this->getMockBuilder(CompilerPassInterface::class)->getMock(); $config->addPass($pass1, PassConfig::TYPE_BEFORE_OPTIMIZATION, 10); diff --git a/Tests/Compiler/PriorityTaggedServiceTraitTest.php b/Tests/Compiler/PriorityTaggedServiceTraitTest.php index 61e3fa947..57682b5da 100644 --- a/Tests/Compiler/PriorityTaggedServiceTraitTest.php +++ b/Tests/Compiler/PriorityTaggedServiceTraitTest.php @@ -20,27 +20,27 @@ class PriorityTaggedServiceTraitTest extends TestCase { public function testThatCacheWarmersAreProcessedInPriorityOrder() { - $services = array( - 'my_service1' => array('my_custom_tag' => array('priority' => 100)), - 'my_service2' => array('my_custom_tag' => array('priority' => 200)), - 'my_service3' => array('my_custom_tag' => array('priority' => -501)), - 'my_service4' => array('my_custom_tag' => array()), - 'my_service5' => array('my_custom_tag' => array('priority' => -1)), - 'my_service6' => array('my_custom_tag' => array('priority' => -500)), - 'my_service7' => array('my_custom_tag' => array('priority' => -499)), - 'my_service8' => array('my_custom_tag' => array('priority' => 1)), - 'my_service9' => array('my_custom_tag' => array('priority' => -2)), - 'my_service10' => array('my_custom_tag' => array('priority' => -1000)), - 'my_service11' => array('my_custom_tag' => array('priority' => -1001)), - 'my_service12' => array('my_custom_tag' => array('priority' => -1002)), - 'my_service13' => array('my_custom_tag' => array('priority' => -1003)), - 'my_service14' => array('my_custom_tag' => array('priority' => -1000)), - 'my_service15' => array('my_custom_tag' => array('priority' => 1)), - 'my_service16' => array('my_custom_tag' => array('priority' => -1)), - 'my_service17' => array('my_custom_tag' => array('priority' => 200)), - 'my_service18' => array('my_custom_tag' => array('priority' => 100)), - 'my_service19' => array('my_custom_tag' => array()), - ); + $services = [ + 'my_service1' => ['my_custom_tag' => ['priority' => 100]], + 'my_service2' => ['my_custom_tag' => ['priority' => 200]], + 'my_service3' => ['my_custom_tag' => ['priority' => -501]], + 'my_service4' => ['my_custom_tag' => []], + 'my_service5' => ['my_custom_tag' => ['priority' => -1]], + 'my_service6' => ['my_custom_tag' => ['priority' => -500]], + 'my_service7' => ['my_custom_tag' => ['priority' => -499]], + 'my_service8' => ['my_custom_tag' => ['priority' => 1]], + 'my_service9' => ['my_custom_tag' => ['priority' => -2]], + 'my_service10' => ['my_custom_tag' => ['priority' => -1000]], + 'my_service11' => ['my_custom_tag' => ['priority' => -1001]], + 'my_service12' => ['my_custom_tag' => ['priority' => -1002]], + 'my_service13' => ['my_custom_tag' => ['priority' => -1003]], + 'my_service14' => ['my_custom_tag' => ['priority' => -1000]], + 'my_service15' => ['my_custom_tag' => ['priority' => 1]], + 'my_service16' => ['my_custom_tag' => ['priority' => -1]], + 'my_service17' => ['my_custom_tag' => ['priority' => 200]], + 'my_service18' => ['my_custom_tag' => ['priority' => 100]], + 'my_service19' => ['my_custom_tag' => []], + ]; $container = new ContainerBuilder(); @@ -52,7 +52,7 @@ public function testThatCacheWarmersAreProcessedInPriorityOrder() } } - $expected = array( + $expected = [ new Reference('my_service2'), new Reference('my_service17'), new Reference('my_service1'), @@ -72,7 +72,7 @@ public function testThatCacheWarmersAreProcessedInPriorityOrder() new Reference('my_service11'), new Reference('my_service12'), new Reference('my_service13'), - ); + ]; $priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation(); diff --git a/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php b/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php index cddb62dce..3d3fdf769 100644 --- a/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php +++ b/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php @@ -28,18 +28,18 @@ public function testSimpleProcessor() $this->assertTrue($container->has('container.env_var_processors_locator')); $this->assertInstanceOf(SimpleProcessor::class, $container->get('container.env_var_processors_locator')->get('foo')); - $expected = array( - 'foo' => array('string'), - 'base64' => array('string'), - 'bool' => array('bool'), - 'const' => array('bool', 'int', 'float', 'string', 'array'), - 'file' => array('string'), - 'float' => array('float'), - 'int' => array('int'), - 'json' => array('array'), - 'resolve' => array('string'), - 'string' => array('string'), - ); + $expected = [ + 'foo' => ['string'], + 'base64' => ['string'], + 'bool' => ['bool'], + 'const' => ['bool', 'int', 'float', 'string', 'array'], + 'file' => ['string'], + 'float' => ['float'], + 'int' => ['int'], + 'json' => ['array'], + 'resolve' => ['string'], + 'string' => ['string'], + ]; $this->assertSame($expected, $container->getParameterBag()->getProvidedTypes()); } @@ -75,7 +75,7 @@ public function getEnv($prefix, $name, \Closure $getEnv) public static function getProvidedTypes() { - return array('foo' => 'string'); + return ['foo' => 'string']; } } @@ -83,6 +83,6 @@ class BadProcessor extends SimpleProcessor { public static function getProvidedTypes() { - return array('foo' => 'string|foo'); + return ['foo' => 'string|foo']; } } diff --git a/Tests/Compiler/RegisterServiceSubscribersPassTest.php b/Tests/Compiler/RegisterServiceSubscribersPassTest.php index 42f994e82..0356c9713 100644 --- a/Tests/Compiler/RegisterServiceSubscribersPassTest.php +++ b/Tests/Compiler/RegisterServiceSubscribersPassTest.php @@ -53,7 +53,7 @@ public function testInvalidAttributes() $container = new ContainerBuilder(); $container->register('foo', TestServiceSubscriber::class) - ->addTag('container.service_subscriber', array('bar' => '123')) + ->addTag('container.service_subscriber', ['bar' => '123']) ; (new RegisterServiceSubscribersPass())->process($container); @@ -78,12 +78,12 @@ public function testNoAttributes() $this->assertFalse($locator->isPublic()); $this->assertSame(ServiceLocator::class, $locator->getClass()); - $expected = array( + $expected = [ TestServiceSubscriber::class => new ServiceClosureArgument(new TypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class, TestServiceSubscriber::class)), CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)), 'bar' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class)), 'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)), - ); + ]; $this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0)); } @@ -95,8 +95,8 @@ public function testWithAttributes() $container->register('foo', TestServiceSubscriber::class) ->setAutowired(true) ->addArgument(new Reference(PsrContainerInterface::class)) - ->addTag('container.service_subscriber', array('key' => 'bar', 'id' => 'bar')) - ->addTag('container.service_subscriber', array('key' => 'bar', 'id' => 'baz')) // should be ignored: the first wins + ->addTag('container.service_subscriber', ['key' => 'bar', 'id' => 'bar']) + ->addTag('container.service_subscriber', ['key' => 'bar', 'id' => 'baz']) // should be ignored: the first wins ; (new RegisterServiceSubscribersPass())->process($container); @@ -108,12 +108,12 @@ public function testWithAttributes() $this->assertFalse($locator->isPublic()); $this->assertSame(ServiceLocator::class, $locator->getClass()); - $expected = array( + $expected = [ TestServiceSubscriber::class => new ServiceClosureArgument(new TypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class, TestServiceSubscriber::class)), CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)), 'bar' => new ServiceClosureArgument(new TypedReference('bar', CustomDefinition::class, TestServiceSubscriber::class)), 'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)), - ); + ]; $this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0)); } @@ -128,10 +128,10 @@ public function testExtraServiceSubscriber() $container->register('foo_service', TestServiceSubscriber::class) ->setAutowired(true) ->addArgument(new Reference(PsrContainerInterface::class)) - ->addTag('container.service_subscriber', array( + ->addTag('container.service_subscriber', [ 'key' => 'test', 'id' => TestServiceSubscriber::class, - )) + ]) ; $container->register(TestServiceSubscriber::class, TestServiceSubscriber::class); $container->compile(); diff --git a/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php b/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php index fd26561a2..1dfdd9dde 100644 --- a/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php +++ b/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php @@ -35,7 +35,7 @@ public function testProcess() ; $container ->register('moo') - ->setArguments(array(new Reference('bar'))) + ->setArguments([new Reference('bar')]) ; $this->process($container); @@ -54,7 +54,7 @@ public function testProcessRemovesUnusedDefinitionsRecursively() ; $container ->register('bar') - ->setArguments(array(new Reference('foo'))) + ->setArguments([new Reference('foo')]) ->setPublic(false) ; @@ -73,7 +73,7 @@ public function testProcessWorksWithInlinedDefinitions() ; $container ->register('bar') - ->setArguments(array(new Definition(null, array(new Reference('foo'))))) + ->setArguments([new Definition(null, [new Reference('foo')])]) ; $this->process($container); @@ -88,12 +88,12 @@ public function testProcessWontRemovePrivateFactory() $container ->register('foo', 'stdClass') - ->setFactory(array('stdClass', 'getInstance')) + ->setFactory(['stdClass', 'getInstance']) ->setPublic(false); $container ->register('bar', 'stdClass') - ->setFactory(array(new Reference('foo'), 'getInstance')) + ->setFactory([new Reference('foo'), 'getInstance']) ->setPublic(false); $container @@ -113,7 +113,7 @@ public function testProcessConsiderEnvVariablesAsUsedEvenInPrivateServices() $container->setParameter('env(FOOBAR)', 'test'); $container ->register('foo') - ->setArguments(array('%env(FOOBAR)%')) + ->setArguments(['%env(FOOBAR)%']) ->setPublic(false) ; @@ -131,7 +131,7 @@ public function testProcessConsiderEnvVariablesAsUsedEvenInPrivateServices() protected function process(ContainerBuilder $container) { - $repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new RemoveUnusedDefinitionsPass())); + $repeatedPass = new RepeatedPass([new AnalyzeServiceReferencesPass(), new RemoveUnusedDefinitionsPass()]); $repeatedPass->process($container); } } diff --git a/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php b/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php index 7574e7943..f9c755c35 100644 --- a/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php +++ b/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php @@ -26,7 +26,7 @@ public function testProcess() $container = new ContainerBuilder(); $aDefinition = $container->register('a', '\stdClass'); - $aDefinition->setFactory(array(new Reference('b'), 'createA')); + $aDefinition->setFactory([new Reference('b'), 'createA']); $bDefinition = new Definition('\stdClass'); $bDefinition->setPublic(false); diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index d59b95af5..5118b416f 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -30,10 +30,10 @@ public function testProcess() { $container = new ContainerBuilder(); - $bindings = array(CaseSensitiveClass::class => new BoundArgument(new Reference('foo'))); + $bindings = [CaseSensitiveClass::class => new BoundArgument(new Reference('foo'))]; $definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class); - $definition->setArguments(array(1 => '123')); + $definition->setArguments([1 => '123']); $definition->addMethodCall('setSensitiveClass'); $definition->setBindings($bindings); @@ -43,8 +43,8 @@ public function testProcess() $pass = new ResolveBindingsPass(); $pass->process($container); - $this->assertEquals(array(new Reference('foo'), '123'), $definition->getArguments()); - $this->assertEquals(array(array('setSensitiveClass', array(new Reference('foo')))), $definition->getMethodCalls()); + $this->assertEquals([new Reference('foo'), '123'], $definition->getArguments()); + $this->assertEquals([['setSensitiveClass', [new Reference('foo')]]], $definition->getMethodCalls()); } /** @@ -56,7 +56,7 @@ public function testUnusedBinding() $container = new ContainerBuilder(); $definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class); - $definition->setBindings(array('$quz' => '123')); + $definition->setBindings(['$quz' => '123']); $pass = new ResolveBindingsPass(); $pass->process($container); @@ -71,7 +71,7 @@ public function testMissingParent() $container = new ContainerBuilder(); $definition = $container->register(ParentNotExists::class, ParentNotExists::class); - $definition->setBindings(array('$quz' => '123')); + $definition->setBindings(['$quz' => '123']); $pass = new ResolveBindingsPass(); $pass->process($container); @@ -81,7 +81,7 @@ public function testTypedReferenceSupport() { $container = new ContainerBuilder(); - $bindings = array(CaseSensitiveClass::class => new BoundArgument(new Reference('foo'))); + $bindings = [CaseSensitiveClass::class => new BoundArgument(new Reference('foo'))]; // Explicit service id $definition1 = $container->register('def1', NamedArgumentsDummy::class); @@ -95,8 +95,8 @@ public function testTypedReferenceSupport() $pass = new ResolveBindingsPass(); $pass->process($container); - $this->assertEquals(array($typedRef), $container->getDefinition('def1')->getArguments()); - $this->assertEquals(array(new Reference('foo')), $container->getDefinition('def2')->getArguments()); + $this->assertEquals([$typedRef], $container->getDefinition('def1')->getArguments()); + $this->assertEquals([new Reference('foo')], $container->getDefinition('def2')->getArguments()); } public function testScalarSetter() @@ -104,11 +104,11 @@ public function testScalarSetter() $container = new ContainerBuilder(); $definition = $container->autowire('foo', ScalarSetter::class); - $definition->setBindings(array('$defaultLocale' => 'fr')); + $definition->setBindings(['$defaultLocale' => 'fr']); (new AutowireRequiredMethodsPass())->process($container); (new ResolveBindingsPass())->process($container); - $this->assertEquals(array(array('setDefaultLocale', array('fr'))), $definition->getMethodCalls()); + $this->assertEquals([['setDefaultLocale', ['fr']]], $definition->getMethodCalls()); } } diff --git a/Tests/Compiler/ResolveChildDefinitionsPassTest.php b/Tests/Compiler/ResolveChildDefinitionsPassTest.php index 1575bd7b0..4eca8f707 100644 --- a/Tests/Compiler/ResolveChildDefinitionsPassTest.php +++ b/Tests/Compiler/ResolveChildDefinitionsPassTest.php @@ -22,7 +22,7 @@ class ResolveChildDefinitionsPassTest extends TestCase public function testProcess() { $container = new ContainerBuilder(); - $container->register('parent', 'foo')->setArguments(array('moo', 'b'))->setProperty('foo', 'moo'); + $container->register('parent', 'foo')->setArguments(['moo', 'b'])->setProperty('foo', 'moo'); $container->setDefinition('child', new ChildDefinition('parent')) ->replaceArgument(0, 'a') ->setProperty('foo', 'bar') @@ -34,8 +34,8 @@ public function testProcess() $def = $container->getDefinition('child'); $this->assertNotInstanceOf(ChildDefinition::class, $def); $this->assertEquals('bar', $def->getClass()); - $this->assertEquals(array('a', 'b'), $def->getArguments()); - $this->assertEquals(array('foo' => 'bar'), $def->getProperties()); + $this->assertEquals(['a', 'b'], $def->getArguments()); + $this->assertEquals(['foo' => 'bar'], $def->getProperties()); } public function testProcessAppendsMethodCallsAlways() @@ -44,21 +44,21 @@ public function testProcessAppendsMethodCallsAlways() $container ->register('parent') - ->addMethodCall('foo', array('bar')) + ->addMethodCall('foo', ['bar']) ; $container ->setDefinition('child', new ChildDefinition('parent')) - ->addMethodCall('bar', array('foo')) + ->addMethodCall('bar', ['foo']) ; $this->process($container); $def = $container->getDefinition('child'); - $this->assertEquals(array( - array('foo', array('bar')), - array('bar', array('foo')), - ), $def->getMethodCalls()); + $this->assertEquals([ + ['foo', ['bar']], + ['bar', ['foo']], + ], $def->getMethodCalls()); } public function testProcessDoesNotCopyAbstract() @@ -115,7 +115,7 @@ public function testProcessDoesNotCopyTags() $this->process($container); $def = $container->getDefinition('child'); - $this->assertEquals(array(), $def->getTags()); + $this->assertEquals([], $def->getTags()); } public function testProcessDoesNotCopyDecoratedService() @@ -162,7 +162,7 @@ public function testProcessHandlesMultipleInheritance() $container ->register('parent', 'foo') - ->setArguments(array('foo', 'bar', 'c')) + ->setArguments(['foo', 'bar', 'c']) ; $container @@ -178,7 +178,7 @@ public function testProcessHandlesMultipleInheritance() $this->process($container); $def = $container->getDefinition('child2'); - $this->assertEquals(array('a', 'b', 'c'), $def->getArguments()); + $this->assertEquals(['a', 'b', 'c'], $def->getArguments()); $this->assertEquals('foo', $def->getClass()); } @@ -251,10 +251,10 @@ public function testDeepDefinitionsResolving() $container->register('parent', 'parentClass'); $container->register('sibling', 'siblingClass') ->setConfigurator(new ChildDefinition('parent'), 'foo') - ->setFactory(array(new ChildDefinition('parent'), 'foo')) + ->setFactory([new ChildDefinition('parent'), 'foo']) ->addArgument(new ChildDefinition('parent')) ->setProperty('prop', new ChildDefinition('parent')) - ->addMethodCall('meth', array(new ChildDefinition('parent'))) + ->addMethodCall('meth', [new ChildDefinition('parent')]) ; $this->process($container); @@ -292,7 +292,7 @@ public function testSetDecoratedServiceOnServiceHasParent() $this->process($container); - $this->assertEquals(array('foo', 'foo_inner', 5), $container->getDefinition('child1')->getDecoratedService()); + $this->assertEquals(['foo', 'foo_inner', 5], $container->getDefinition('child1')->getDecoratedService()); } public function testDecoratedServiceCopiesDeprecatedStatusFromParent() @@ -345,10 +345,10 @@ public function testProcessMergeAutowiringTypes() $this->process($container); $childDef = $container->getDefinition('child'); - $this->assertEquals(array('Foo', 'Bar'), $childDef->getAutowiringTypes()); + $this->assertEquals(['Foo', 'Bar'], $childDef->getAutowiringTypes()); $parentDef = $container->getDefinition('parent'); - $this->assertSame(array('Foo'), $parentDef->getAutowiringTypes()); + $this->assertSame(['Foo'], $parentDef->getAutowiringTypes()); } public function testProcessResolvesAliases() @@ -369,17 +369,17 @@ public function testProcessSetsArguments() { $container = new ContainerBuilder(); - $container->register('parent', 'ParentClass')->setArguments(array(0)); - $container->setDefinition('child', (new ChildDefinition('parent'))->setArguments(array( + $container->register('parent', 'ParentClass')->setArguments([0]); + $container->setDefinition('child', (new ChildDefinition('parent'))->setArguments([ 1, 'index_0' => 2, 'foo' => 3, - ))); + ])); $this->process($container); $def = $container->getDefinition('child'); - $this->assertSame(array(2, 1, 'foo' => 3), $def->getArguments()); + $this->assertSame([2, 1, 'foo' => 3], $def->getArguments()); } public function testBindings() @@ -387,20 +387,20 @@ public function testBindings() $container = new ContainerBuilder(); $container->register('parent', 'stdClass') - ->setBindings(array('a' => '1', 'b' => '2')) + ->setBindings(['a' => '1', 'b' => '2']) ; $child = $container->setDefinition('child', new ChildDefinition('parent')) - ->setBindings(array('b' => 'B', 'c' => 'C')) + ->setBindings(['b' => 'B', 'c' => 'C']) ; $this->process($container); - $bindings = array(); + $bindings = []; foreach ($container->getDefinition('child')->getBindings() as $k => $v) { $bindings[$k] = $v->getValues()[0]; } - $this->assertEquals(array('b' => 'B', 'c' => 'C', 'a' => '1'), $bindings); + $this->assertEquals(['b' => 'B', 'c' => 'C', 'a' => '1'], $bindings); } public function testSetAutoconfiguredOnServiceIsParent() diff --git a/Tests/Compiler/ResolveClassPassTest.php b/Tests/Compiler/ResolveClassPassTest.php index acbcf1dda..48df3843d 100644 --- a/Tests/Compiler/ResolveClassPassTest.php +++ b/Tests/Compiler/ResolveClassPassTest.php @@ -34,8 +34,8 @@ public function testResolveClassFromId($serviceId) public function provideValidClassId() { - yield array('Acme\UnknownClass'); - yield array(CaseSensitiveClass::class); + yield ['Acme\UnknownClass']; + yield [CaseSensitiveClass::class]; } /** @@ -53,9 +53,9 @@ public function testWontResolveClassFromId($serviceId) public function provideInvalidClassId() { - yield array(\stdClass::class); - yield array('bar'); - yield array('\DateTime'); + yield [\stdClass::class]; + yield ['bar']; + yield ['\DateTime']; } public function testNonFqcnChildDefinition() diff --git a/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php b/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php index 39ae7f4f6..407c803cb 100644 --- a/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php +++ b/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php @@ -24,7 +24,7 @@ class ResolveDefinitionTemplatesPassTest extends TestCase public function testProcess() { $container = new ContainerBuilder(); - $container->register('parent', 'foo')->setArguments(array('moo', 'b'))->setProperty('foo', 'moo'); + $container->register('parent', 'foo')->setArguments(['moo', 'b'])->setProperty('foo', 'moo'); $container->setDefinition('child', new ChildDefinition('parent')) ->replaceArgument(0, 'a') ->setProperty('foo', 'bar') @@ -36,8 +36,8 @@ public function testProcess() $def = $container->getDefinition('child'); $this->assertNotInstanceOf(ChildDefinition::class, $def); $this->assertEquals('bar', $def->getClass()); - $this->assertEquals(array('a', 'b'), $def->getArguments()); - $this->assertEquals(array('foo' => 'bar'), $def->getProperties()); + $this->assertEquals(['a', 'b'], $def->getArguments()); + $this->assertEquals(['foo' => 'bar'], $def->getProperties()); } public function testProcessAppendsMethodCallsAlways() @@ -46,21 +46,21 @@ public function testProcessAppendsMethodCallsAlways() $container ->register('parent') - ->addMethodCall('foo', array('bar')) + ->addMethodCall('foo', ['bar']) ; $container ->setDefinition('child', new ChildDefinition('parent')) - ->addMethodCall('bar', array('foo')) + ->addMethodCall('bar', ['foo']) ; $this->process($container); $def = $container->getDefinition('child'); - $this->assertEquals(array( - array('foo', array('bar')), - array('bar', array('foo')), - ), $def->getMethodCalls()); + $this->assertEquals([ + ['foo', ['bar']], + ['bar', ['foo']], + ], $def->getMethodCalls()); } public function testProcessDoesNotCopyAbstract() @@ -117,7 +117,7 @@ public function testProcessDoesNotCopyTags() $this->process($container); $def = $container->getDefinition('child'); - $this->assertEquals(array(), $def->getTags()); + $this->assertEquals([], $def->getTags()); } public function testProcessDoesNotCopyDecoratedService() @@ -164,7 +164,7 @@ public function testProcessHandlesMultipleInheritance() $container ->register('parent', 'foo') - ->setArguments(array('foo', 'bar', 'c')) + ->setArguments(['foo', 'bar', 'c']) ; $container @@ -180,7 +180,7 @@ public function testProcessHandlesMultipleInheritance() $this->process($container); $def = $container->getDefinition('child2'); - $this->assertEquals(array('a', 'b', 'c'), $def->getArguments()); + $this->assertEquals(['a', 'b', 'c'], $def->getArguments()); $this->assertEquals('foo', $def->getClass()); } @@ -253,10 +253,10 @@ public function testDeepDefinitionsResolving() $container->register('parent', 'parentClass'); $container->register('sibling', 'siblingClass') ->setConfigurator(new ChildDefinition('parent'), 'foo') - ->setFactory(array(new ChildDefinition('parent'), 'foo')) + ->setFactory([new ChildDefinition('parent'), 'foo']) ->addArgument(new ChildDefinition('parent')) ->setProperty('prop', new ChildDefinition('parent')) - ->addMethodCall('meth', array(new ChildDefinition('parent'))) + ->addMethodCall('meth', [new ChildDefinition('parent')]) ; $this->process($container); @@ -294,7 +294,7 @@ public function testSetDecoratedServiceOnServiceHasParent() $this->process($container); - $this->assertEquals(array('foo', 'foo_inner', 5), $container->getDefinition('child1')->getDecoratedService()); + $this->assertEquals(['foo', 'foo_inner', 5], $container->getDefinition('child1')->getDecoratedService()); } public function testDecoratedServiceCopiesDeprecatedStatusFromParent() @@ -347,10 +347,10 @@ public function testProcessMergeAutowiringTypes() $this->process($container); $childDef = $container->getDefinition('child'); - $this->assertEquals(array('Foo', 'Bar'), $childDef->getAutowiringTypes()); + $this->assertEquals(['Foo', 'Bar'], $childDef->getAutowiringTypes()); $parentDef = $container->getDefinition('parent'); - $this->assertSame(array('Foo'), $parentDef->getAutowiringTypes()); + $this->assertSame(['Foo'], $parentDef->getAutowiringTypes()); } public function testProcessResolvesAliases() @@ -371,17 +371,17 @@ public function testProcessSetsArguments() { $container = new ContainerBuilder(); - $container->register('parent', 'ParentClass')->setArguments(array(0)); - $container->setDefinition('child', (new ChildDefinition('parent'))->setArguments(array( + $container->register('parent', 'ParentClass')->setArguments([0]); + $container->setDefinition('child', (new ChildDefinition('parent'))->setArguments([ 1, 'index_0' => 2, 'foo' => 3, - ))); + ])); $this->process($container); $def = $container->getDefinition('child'); - $this->assertSame(array(2, 1, 'foo' => 3), $def->getArguments()); + $this->assertSame([2, 1, 'foo' => 3], $def->getArguments()); } public function testSetAutoconfiguredOnServiceIsParent() diff --git a/Tests/Compiler/ResolveFactoryClassPassTest.php b/Tests/Compiler/ResolveFactoryClassPassTest.php index 96453c303..3438fad06 100644 --- a/Tests/Compiler/ResolveFactoryClassPassTest.php +++ b/Tests/Compiler/ResolveFactoryClassPassTest.php @@ -24,12 +24,12 @@ public function testProcess() $container = new ContainerBuilder(); $factory = $container->register('factory', 'Foo\Bar'); - $factory->setFactory(array(null, 'create')); + $factory->setFactory([null, 'create']); $pass = new ResolveFactoryClassPass(); $pass->process($container); - $this->assertSame(array('Foo\Bar', 'create'), $factory->getFactory()); + $this->assertSame(['Foo\Bar', 'create'], $factory->getFactory()); } public function testInlinedDefinitionFactoryIsProcessed() @@ -37,21 +37,21 @@ public function testInlinedDefinitionFactoryIsProcessed() $container = new ContainerBuilder(); $factory = $container->register('factory'); - $factory->setFactory(array((new Definition('Baz\Qux'))->setFactory(array(null, 'getInstance')), 'create')); + $factory->setFactory([(new Definition('Baz\Qux'))->setFactory([null, 'getInstance']), 'create']); $pass = new ResolveFactoryClassPass(); $pass->process($container); - $this->assertSame(array('Baz\Qux', 'getInstance'), $factory->getFactory()[0]->getFactory()); + $this->assertSame(['Baz\Qux', 'getInstance'], $factory->getFactory()[0]->getFactory()); } public function provideFulfilledFactories() { - return array( - array(array('Foo\Bar', 'create')), - array(array(new Reference('foo'), 'create')), - array(array(new Definition('Baz'), 'create')), - ); + return [ + [['Foo\Bar', 'create']], + [[new Reference('foo'), 'create']], + [[new Definition('Baz'), 'create']], + ]; } /** @@ -80,7 +80,7 @@ public function testNotAnyClassThrowsException() $container = new ContainerBuilder(); $factory = $container->register('factory'); - $factory->setFactory(array(null, 'create')); + $factory->setFactory([null, 'create']); $pass = new ResolveFactoryClassPass(); $pass->process($container); diff --git a/Tests/Compiler/ResolveHotPathPassTest.php b/Tests/Compiler/ResolveHotPathPassTest.php index d2ba59004..a2fece058 100644 --- a/Tests/Compiler/ResolveHotPathPassTest.php +++ b/Tests/Compiler/ResolveHotPathPassTest.php @@ -26,9 +26,9 @@ public function testProcess() $container->register('foo') ->addTag('container.hot_path') - ->addArgument(new IteratorArgument(array(new Reference('lazy')))) + ->addArgument(new IteratorArgument([new Reference('lazy')])) ->addArgument(new Reference('service_container')) - ->addArgument(new Definition('', array(new Reference('bar')))) + ->addArgument(new Definition('', [new Reference('bar')])) ->addArgument(new Reference('baz', ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE)) ->addArgument(new Reference('missing')) ; diff --git a/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php b/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php index ad6f79d40..26560b4ca 100644 --- a/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php +++ b/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php @@ -23,10 +23,10 @@ class ResolveInstanceofConditionalsPassTest extends TestCase public function testProcess() { $container = new ContainerBuilder(); - $def = $container->register('foo', self::class)->addTag('tag')->setAutowired(true)->setChanges(array()); - $def->setInstanceofConditionals(array( - parent::class => (new ChildDefinition(''))->setProperty('foo', 'bar')->addTag('baz', array('attr' => 123)), - )); + $def = $container->register('foo', self::class)->addTag('tag')->setAutowired(true)->setChanges([]); + $def->setInstanceofConditionals([ + parent::class => (new ChildDefinition(''))->setProperty('foo', 'bar')->addTag('baz', ['attr' => 123]), + ]); (new ResolveInstanceofConditionalsPass())->process($container); @@ -36,11 +36,11 @@ public function testProcess() $this->assertInstanceOf(ChildDefinition::class, $def); $this->assertTrue($def->isAutowired()); $this->assertSame($parent, $def->getParent()); - $this->assertSame(array('tag' => array(array()), 'baz' => array(array('attr' => 123))), $def->getTags()); + $this->assertSame(['tag' => [[]], 'baz' => [['attr' => 123]]], $def->getTags()); $parent = $container->getDefinition($parent); - $this->assertSame(array('foo' => 'bar'), $parent->getProperties()); - $this->assertSame(array(), $parent->getTags()); + $this->assertSame(['foo' => 'bar'], $parent->getProperties()); + $this->assertSame([], $parent->getTags()); } public function testProcessInheritance() @@ -49,10 +49,10 @@ public function testProcessInheritance() $def = $container ->register('parent', parent::class) - ->addMethodCall('foo', array('foo')); - $def->setInstanceofConditionals(array( - parent::class => (new ChildDefinition(''))->addMethodCall('foo', array('bar')), - )); + ->addMethodCall('foo', ['foo']); + $def->setInstanceofConditionals([ + parent::class => (new ChildDefinition(''))->addMethodCall('foo', ['bar']), + ]); $def = (new ChildDefinition('parent'))->setClass(self::class); $container->setDefinition('child', $def); @@ -60,10 +60,10 @@ public function testProcessInheritance() (new ResolveInstanceofConditionalsPass())->process($container); (new ResolveChildDefinitionsPass())->process($container); - $expected = array( - array('foo', array('bar')), - array('foo', array('foo')), - ); + $expected = [ + ['foo', ['bar']], + ['foo', ['foo']], + ]; $this->assertSame($expected, $container->getDefinition('parent')->getMethodCalls()); $this->assertSame($expected, $container->getDefinition('child')->getMethodCalls()); @@ -74,9 +74,9 @@ public function testProcessDoesReplaceShared() $container = new ContainerBuilder(); $def = $container->register('foo', 'stdClass'); - $def->setInstanceofConditionals(array( + $def->setInstanceofConditionals([ 'stdClass' => (new ChildDefinition(''))->setShared(false), - )); + ]); (new ResolveInstanceofConditionalsPass())->process($container); @@ -90,10 +90,10 @@ public function testProcessHandlesMultipleInheritance() $def = $container->register('foo', self::class)->setShared(true); - $def->setInstanceofConditionals(array( + $def->setInstanceofConditionals([ parent::class => (new ChildDefinition(''))->setLazy(true)->setShared(false), self::class => (new ChildDefinition(''))->setAutowired(true), - )); + ]); (new ResolveInstanceofConditionalsPass())->process($container); (new ResolveChildDefinitionsPass())->process($container); @@ -108,11 +108,11 @@ public function testProcessUsesAutoconfiguredInstanceof() { $container = new ContainerBuilder(); $def = $container->register('normal_service', self::class); - $def->setInstanceofConditionals(array( + $def->setInstanceofConditionals([ parent::class => (new ChildDefinition('')) ->addTag('local_instanceof_tag') ->setFactory('locally_set_factory'), - )); + ]); $def->setAutoconfigured(true); $container->registerForAutoconfiguration(parent::class) ->addTag('autoconfigured_tag') @@ -128,7 +128,7 @@ public function testProcessUsesAutoconfiguredInstanceof() // factory from the specific instanceof overrides global one $this->assertEquals('locally_set_factory', $def->getFactory()); // tags are merged, the locally set one is first - $this->assertSame(array('local_instanceof_tag' => array(array()), 'autoconfigured_tag' => array(array())), $def->getTags()); + $this->assertSame(['local_instanceof_tag' => [[]], 'autoconfigured_tag' => [[]]], $def->getTags()); } public function testAutoconfigureInstanceofDoesNotDuplicateTags() @@ -137,31 +137,31 @@ public function testAutoconfigureInstanceofDoesNotDuplicateTags() $def = $container->register('normal_service', self::class); $def ->addTag('duplicated_tag') - ->addTag('duplicated_tag', array('and_attributes' => 1)) + ->addTag('duplicated_tag', ['and_attributes' => 1]) ; - $def->setInstanceofConditionals(array( + $def->setInstanceofConditionals([ parent::class => (new ChildDefinition(''))->addTag('duplicated_tag'), - )); + ]); $def->setAutoconfigured(true); $container->registerForAutoconfiguration(parent::class) - ->addTag('duplicated_tag', array('and_attributes' => 1)) + ->addTag('duplicated_tag', ['and_attributes' => 1]) ; (new ResolveInstanceofConditionalsPass())->process($container); (new ResolveChildDefinitionsPass())->process($container); $def = $container->getDefinition('normal_service'); - $this->assertSame(array('duplicated_tag' => array(array(), array('and_attributes' => 1))), $def->getTags()); + $this->assertSame(['duplicated_tag' => [[], ['and_attributes' => 1]]], $def->getTags()); } public function testProcessDoesNotUseAutoconfiguredInstanceofIfNotEnabled() { $container = new ContainerBuilder(); $def = $container->register('normal_service', self::class); - $def->setInstanceofConditionals(array( + $def->setInstanceofConditionals([ parent::class => (new ChildDefinition('')) ->addTag('foo_tag'), - )); + ]); $container->registerForAutoconfiguration(parent::class) ->setAutowired(true); @@ -180,10 +180,10 @@ public function testBadInterfaceThrowsException() { $container = new ContainerBuilder(); $def = $container->register('normal_service', self::class); - $def->setInstanceofConditionals(array( + $def->setInstanceofConditionals([ 'App\\FakeInterface' => (new ChildDefinition('')) ->addTag('foo_tag'), - )); + ]); (new ResolveInstanceofConditionalsPass())->process($container); } @@ -236,9 +236,9 @@ public function testMergeReset() ->addMethodCall('setB') ->setDecoratedService('foo') ->addTag('t') - ->setInstanceofConditionals(array( + ->setInstanceofConditionals([ parent::class => (new ChildDefinition(''))->addTag('bar'), - )) + ]) ; (new ResolveInstanceofConditionalsPass())->process($container); @@ -255,13 +255,13 @@ public function testMergeReset() public function testBindings() { $container = new ContainerBuilder(); - $def = $container->register('foo', self::class)->setBindings(array('$toto' => 123)); - $def->setInstanceofConditionals(array(parent::class => new ChildDefinition(''))); + $def = $container->register('foo', self::class)->setBindings(['$toto' => 123]); + $def->setInstanceofConditionals([parent::class => new ChildDefinition('')]); (new ResolveInstanceofConditionalsPass())->process($container); $bindings = $container->getDefinition('foo')->getBindings(); - $this->assertSame(array('$toto'), array_keys($bindings)); + $this->assertSame(['$toto'], array_keys($bindings)); $this->assertInstanceOf(BoundArgument::class, $bindings['$toto']); $this->assertSame(123, $bindings['$toto']->getValues()[0]); } diff --git a/Tests/Compiler/ResolveInvalidReferencesPassTest.php b/Tests/Compiler/ResolveInvalidReferencesPassTest.php index 61bad48a5..817cc64ce 100644 --- a/Tests/Compiler/ResolveInvalidReferencesPassTest.php +++ b/Tests/Compiler/ResolveInvalidReferencesPassTest.php @@ -25,17 +25,17 @@ public function testProcess() $container = new ContainerBuilder(); $def = $container ->register('foo') - ->setArguments(array( + ->setArguments([ new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE), new Reference('baz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), - )) - ->addMethodCall('foo', array(new Reference('moo', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))) + ]) + ->addMethodCall('foo', [new Reference('moo', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]) ; $this->process($container); $arguments = $def->getArguments(); - $this->assertSame(array(null, null), $arguments); + $this->assertSame([null, null], $arguments); $this->assertCount(0, $def->getMethodCalls()); } @@ -45,19 +45,19 @@ public function testProcessIgnoreInvalidArgumentInCollectionArgument() $container->register('baz'); $def = $container ->register('foo') - ->setArguments(array( - array( + ->setArguments([ + [ new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), $baz = new Reference('baz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), new Reference('moo', ContainerInterface::NULL_ON_INVALID_REFERENCE), - ), - )) + ], + ]) ; $this->process($container); $arguments = $def->getArguments(); - $this->assertSame(array($baz, null), $arguments[0]); + $this->assertSame([$baz, null], $arguments[0]); } public function testProcessKeepMethodCallOnInvalidArgumentInCollectionArgument() @@ -66,20 +66,20 @@ public function testProcessKeepMethodCallOnInvalidArgumentInCollectionArgument() $container->register('baz'); $def = $container ->register('foo') - ->addMethodCall('foo', array( - array( + ->addMethodCall('foo', [ + [ new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), $baz = new Reference('baz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), new Reference('moo', ContainerInterface::NULL_ON_INVALID_REFERENCE), - ), - )) + ], + ]) ; $this->process($container); $calls = $def->getMethodCalls(); $this->assertCount(1, $def->getMethodCalls()); - $this->assertSame(array($baz, null), $calls[0][1][0]); + $this->assertSame([$baz, null], $calls[0][1][0]); } public function testProcessIgnoreNonExistentServices() @@ -87,7 +87,7 @@ public function testProcessIgnoreNonExistentServices() $container = new ContainerBuilder(); $def = $container ->register('foo') - ->setArguments(array(new Reference('bar'))) + ->setArguments([new Reference('bar')]) ; $this->process($container); @@ -106,7 +106,7 @@ public function testProcessRemovesPropertiesOnInvalid() $this->process($container); - $this->assertEquals(array(), $def->getProperties()); + $this->assertEquals([], $def->getProperties()); } public function testProcessRemovesArgumentsOnInvalid() @@ -114,17 +114,17 @@ public function testProcessRemovesArgumentsOnInvalid() $container = new ContainerBuilder(); $def = $container ->register('foo') - ->addArgument(array( - array( + ->addArgument([ + [ new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), new ServiceClosureArgument(new Reference('baz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)), - ), - )) + ], + ]) ; $this->process($container); - $this->assertSame(array(array(array())), $def->getArguments()); + $this->assertSame([[[]]], $def->getArguments()); } protected function process(ContainerBuilder $container) diff --git a/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/Tests/Compiler/ResolveNamedArgumentsPassTest.php index 17b8ebf31..e25d96f53 100644 --- a/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -31,18 +31,18 @@ public function testProcess() $container = new ContainerBuilder(); $definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class); - $definition->setArguments(array( + $definition->setArguments([ 2 => 'http://api.example.com', '$apiKey' => '123', 0 => new Reference('foo'), - )); - $definition->addMethodCall('setApiKey', array('$apiKey' => '123')); + ]); + $definition->addMethodCall('setApiKey', ['$apiKey' => '123']); $pass = new ResolveNamedArgumentsPass(); $pass->process($container); - $this->assertEquals(array(0 => new Reference('foo'), 1 => '123', 2 => 'http://api.example.com'), $definition->getArguments()); - $this->assertEquals(array(array('setApiKey', array('123'))), $definition->getMethodCalls()); + $this->assertEquals([0 => new Reference('foo'), 1 => '123', 2 => 'http://api.example.com'], $definition->getArguments()); + $this->assertEquals([['setApiKey', ['123']]], $definition->getMethodCalls()); } public function testWithFactory() @@ -51,13 +51,13 @@ public function testWithFactory() $container->register('factory', NoConstructor::class); $definition = $container->register('foo', NoConstructor::class) - ->setFactory(array(new Reference('factory'), 'create')) - ->setArguments(array('$apiKey' => '123')); + ->setFactory([new Reference('factory'), 'create']) + ->setArguments(['$apiKey' => '123']); $pass = new ResolveNamedArgumentsPass(); $pass->process($container); - $this->assertSame(array(0 => '123'), $definition->getArguments()); + $this->assertSame([0 => '123'], $definition->getArguments()); } /** @@ -68,7 +68,7 @@ public function testClassNull() $container = new ContainerBuilder(); $definition = $container->register(NamedArgumentsDummy::class); - $definition->setArguments(array('$apiKey' => '123')); + $definition->setArguments(['$apiKey' => '123']); $pass = new ResolveNamedArgumentsPass(); $pass->process($container); @@ -82,7 +82,7 @@ public function testClassNotExist() $container = new ContainerBuilder(); $definition = $container->register(NotExist::class, NotExist::class); - $definition->setArguments(array('$apiKey' => '123')); + $definition->setArguments(['$apiKey' => '123']); $pass = new ResolveNamedArgumentsPass(); $pass->process($container); @@ -96,7 +96,7 @@ public function testClassNoConstructor() $container = new ContainerBuilder(); $definition = $container->register(NoConstructor::class, NoConstructor::class); - $definition->setArguments(array('$apiKey' => '123')); + $definition->setArguments(['$apiKey' => '123']); $pass = new ResolveNamedArgumentsPass(); $pass->process($container); @@ -111,7 +111,7 @@ public function testArgumentNotFound() $container = new ContainerBuilder(); $definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class); - $definition->setArguments(array('$notFound' => '123')); + $definition->setArguments(['$notFound' => '123']); $pass = new ResolveNamedArgumentsPass(); $pass->process($container); @@ -128,8 +128,8 @@ public function testCorrectMethodReportedInException() $container->register(FactoryDummyWithoutReturnTypes::class, FactoryDummyWithoutReturnTypes::class); $definition = $container->register(TestDefinition1::class, TestDefinition1::class); - $definition->setFactory(array(FactoryDummyWithoutReturnTypes::class, 'createTestDefinition1')); - $definition->setArguments(array('$notFound' => '123')); + $definition->setFactory([FactoryDummyWithoutReturnTypes::class, 'createTestDefinition1']); + $definition->setArguments(['$notFound' => '123']); $pass = new ResolveNamedArgumentsPass(); $pass->process($container); @@ -140,12 +140,12 @@ public function testTypedArgument() $container = new ContainerBuilder(); $definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class); - $definition->setArguments(array('$apiKey' => '123', CaseSensitiveClass::class => new Reference('foo'))); + $definition->setArguments(['$apiKey' => '123', CaseSensitiveClass::class => new Reference('foo')]); $pass = new ResolveNamedArgumentsPass(); $pass->process($container); - $this->assertEquals(array(new Reference('foo'), '123'), $definition->getArguments()); + $this->assertEquals([new Reference('foo'), '123'], $definition->getArguments()); } public function testResolvesMultipleArgumentsOfTheSameType() @@ -153,12 +153,12 @@ public function testResolvesMultipleArgumentsOfTheSameType() $container = new ContainerBuilder(); $definition = $container->register(SimilarArgumentsDummy::class, SimilarArgumentsDummy::class); - $definition->setArguments(array(CaseSensitiveClass::class => new Reference('foo'), '$token' => 'qwerty')); + $definition->setArguments([CaseSensitiveClass::class => new Reference('foo'), '$token' => 'qwerty']); $pass = new ResolveNamedArgumentsPass(); $pass->process($container); - $this->assertEquals(array(new Reference('foo'), 'qwerty', new Reference('foo')), $definition->getArguments()); + $this->assertEquals([new Reference('foo'), 'qwerty', new Reference('foo')], $definition->getArguments()); } public function testResolvePrioritizeNamedOverType() @@ -166,12 +166,12 @@ public function testResolvePrioritizeNamedOverType() $container = new ContainerBuilder(); $definition = $container->register(SimilarArgumentsDummy::class, SimilarArgumentsDummy::class); - $definition->setArguments(array(CaseSensitiveClass::class => new Reference('foo'), '$token' => 'qwerty', '$class1' => new Reference('bar'))); + $definition->setArguments([CaseSensitiveClass::class => new Reference('foo'), '$token' => 'qwerty', '$class1' => new Reference('bar')]); $pass = new ResolveNamedArgumentsPass(); $pass->process($container); - $this->assertEquals(array(new Reference('bar'), 'qwerty', new Reference('foo')), $definition->getArguments()); + $this->assertEquals([new Reference('bar'), 'qwerty', new Reference('foo')], $definition->getArguments()); } } diff --git a/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php b/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php index a34e007de..5aa647175 100644 --- a/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php +++ b/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php @@ -36,22 +36,22 @@ public function testClassParametersShouldBeResolved() public function testFactoryParametersShouldBeResolved() { - $this->assertSame(array('FooFactory', 'getFoo'), $this->fooDefinition->getFactory()); + $this->assertSame(['FooFactory', 'getFoo'], $this->fooDefinition->getFactory()); } public function testArgumentParametersShouldBeResolved() { - $this->assertSame(array('bar', array('bar' => 'baz')), $this->fooDefinition->getArguments()); + $this->assertSame(['bar', ['bar' => 'baz']], $this->fooDefinition->getArguments()); } public function testMethodCallParametersShouldBeResolved() { - $this->assertSame(array(array('foobar', array('bar', array('bar' => 'baz')))), $this->fooDefinition->getMethodCalls()); + $this->assertSame([['foobar', ['bar', ['bar' => 'baz']]]], $this->fooDefinition->getMethodCalls()); } public function testPropertyParametersShouldBeResolved() { - $this->assertSame(array('bar' => 'baz'), $this->fooDefinition->getProperties()); + $this->assertSame(['bar' => 'baz'], $this->fooDefinition->getProperties()); } public function testFileParametersShouldBeResolved() @@ -78,7 +78,7 @@ private function createContainerBuilder() $containerBuilder->setParameter('foo.class', 'Foo'); $containerBuilder->setParameter('foo.factory.class', 'FooFactory'); $containerBuilder->setParameter('foo.arg1', 'bar'); - $containerBuilder->setParameter('foo.arg2', array('%foo.arg1%' => 'baz')); + $containerBuilder->setParameter('foo.arg2', ['%foo.arg1%' => 'baz']); $containerBuilder->setParameter('foo.method', 'foobar'); $containerBuilder->setParameter('foo.property.name', 'bar'); $containerBuilder->setParameter('foo.property.value', 'baz'); @@ -86,12 +86,12 @@ private function createContainerBuilder() $containerBuilder->setParameter('alias.id', 'bar'); $fooDefinition = $containerBuilder->register('foo', '%foo.class%'); - $fooDefinition->setFactory(array('%foo.factory.class%', 'getFoo')); - $fooDefinition->setArguments(array('%foo.arg1%', array('%foo.arg1%' => 'baz'))); - $fooDefinition->addMethodCall('%foo.method%', array('%foo.arg1%', '%foo.arg2%')); + $fooDefinition->setFactory(['%foo.factory.class%', 'getFoo']); + $fooDefinition->setArguments(['%foo.arg1%', ['%foo.arg1%' => 'baz']]); + $fooDefinition->addMethodCall('%foo.method%', ['%foo.arg1%', '%foo.arg2%']); $fooDefinition->setProperty('%foo.property.name%', '%foo.property.value%'); $fooDefinition->setFile('%foo.file%'); - $fooDefinition->setBindings(array('$baz' => '%env(BAZ)%')); + $fooDefinition->setBindings(['$baz' => '%env(BAZ)%']); $containerBuilder->setAlias('%alias.id%', 'foo'); diff --git a/Tests/Compiler/ResolveReferencesToAliasesPassTest.php b/Tests/Compiler/ResolveReferencesToAliasesPassTest.php index 6fb619718..55b47057b 100644 --- a/Tests/Compiler/ResolveReferencesToAliasesPassTest.php +++ b/Tests/Compiler/ResolveReferencesToAliasesPassTest.php @@ -26,7 +26,7 @@ public function testProcess() $container->setAlias('bar', 'foo'); $def = $container ->register('moo') - ->setArguments(array(new Reference('bar'))) + ->setArguments([new Reference('bar')]) ; $this->process($container); @@ -42,7 +42,7 @@ public function testProcessRecursively() $container->setAlias('moo', 'bar'); $def = $container ->register('foobar') - ->setArguments(array(new Reference('moo'))) + ->setArguments([new Reference('moo')]) ; $this->process($container); @@ -68,10 +68,10 @@ public function testResolveFactory() $container->register('factory', 'Factory'); $container->setAlias('factory_alias', new Alias('factory')); $foo = new Definition(); - $foo->setFactory(array(new Reference('factory_alias'), 'createFoo')); + $foo->setFactory([new Reference('factory_alias'), 'createFoo']); $container->setDefinition('foo', $foo); $bar = new Definition(); - $bar->setFactory(array('Factory', 'createFoo')); + $bar->setFactory(['Factory', 'createFoo']); $container->setDefinition('bar', $bar); $this->process($container); diff --git a/Tests/Compiler/ResolveTaggedIteratorArgumentPassTest.php b/Tests/Compiler/ResolveTaggedIteratorArgumentPassTest.php index a219f8600..2322817e8 100644 --- a/Tests/Compiler/ResolveTaggedIteratorArgumentPassTest.php +++ b/Tests/Compiler/ResolveTaggedIteratorArgumentPassTest.php @@ -26,15 +26,15 @@ public function testProcess() { $container = new ContainerBuilder(); $container->register('a', 'stdClass')->addTag('foo'); - $container->register('b', 'stdClass')->addTag('foo', array('priority' => 20)); - $container->register('c', 'stdClass')->addTag('foo', array('priority' => 10)); + $container->register('b', 'stdClass')->addTag('foo', ['priority' => 20]); + $container->register('c', 'stdClass')->addTag('foo', ['priority' => 10]); $container->register('d', 'stdClass')->setProperty('foos', new TaggedIteratorArgument('foo')); (new ResolveTaggedIteratorArgumentPass())->process($container); $properties = $container->getDefinition('d')->getProperties(); $expected = new TaggedIteratorArgument('foo'); - $expected->setValues(array(new Reference('b'), new Reference('c'), new Reference('a'))); + $expected->setValues([new Reference('b'), new Reference('c'), new Reference('a')]); $this->assertEquals($expected, $properties['foos']); } } diff --git a/Tests/Config/AutowireServiceResourceTest.php b/Tests/Config/AutowireServiceResourceTest.php index 64d99e637..153e0807e 100644 --- a/Tests/Config/AutowireServiceResourceTest.php +++ b/Tests/Config/AutowireServiceResourceTest.php @@ -38,7 +38,7 @@ protected function setUp() $this->resource = new AutowireServiceResource( $this->class, $this->file, - array() + [] ); } @@ -73,7 +73,7 @@ public function testIsNotFreshChangedResource() $oldResource = new AutowireServiceResource( $this->class, $this->file, - array('will_be_different') + ['will_be_different'] ); // test with a stale file *and* a resource that *will* be different than the actual @@ -95,7 +95,7 @@ public function testNotFreshIfClassNotFound() $resource = new AutowireServiceResource( 'Some\Non\Existent\Class', $this->file, - array() + [] ); $this->assertFalse($resource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the class no longer exists'); diff --git a/Tests/Config/ContainerParametersResourceCheckerTest.php b/Tests/Config/ContainerParametersResourceCheckerTest.php index a91934b3e..fc2d85ecf 100644 --- a/Tests/Config/ContainerParametersResourceCheckerTest.php +++ b/Tests/Config/ContainerParametersResourceCheckerTest.php @@ -30,7 +30,7 @@ class ContainerParametersResourceCheckerTest extends TestCase protected function setUp() { - $this->resource = new ContainerParametersResource(array('locales' => array('fr', 'en'), 'default_locale' => 'fr')); + $this->resource = new ContainerParametersResource(['locales' => ['fr', 'en'], 'default_locale' => 'fr']); $this->container = $this->getMockBuilder(ContainerInterface::class)->getMock(); $this->resourceChecker = new ContainerParametersResourceChecker($this->container); } @@ -52,26 +52,26 @@ public function testIsFresh(callable $mockContainer, $expected) public function isFreshProvider() { - yield 'not fresh on missing parameter' => array(function (\PHPUnit_Framework_MockObject_MockObject $container) { + yield 'not fresh on missing parameter' => [function (\PHPUnit_Framework_MockObject_MockObject $container) { $container->method('hasParameter')->with('locales')->willReturn(false); - }, false); + }, false]; - yield 'not fresh on different value' => array(function (\PHPUnit_Framework_MockObject_MockObject $container) { - $container->method('getParameter')->with('locales')->willReturn(array('nl', 'es')); - }, false); + yield 'not fresh on different value' => [function (\PHPUnit_Framework_MockObject_MockObject $container) { + $container->method('getParameter')->with('locales')->willReturn(['nl', 'es']); + }, false]; - yield 'fresh on every identical parameters' => array(function (\PHPUnit_Framework_MockObject_MockObject $container) { + yield 'fresh on every identical parameters' => [function (\PHPUnit_Framework_MockObject_MockObject $container) { $container->expects($this->exactly(2))->method('hasParameter')->willReturn(true); $container->expects($this->exactly(2))->method('getParameter') ->withConsecutive( - array($this->equalTo('locales')), - array($this->equalTo('default_locale')) + [$this->equalTo('locales')], + [$this->equalTo('default_locale')] ) - ->will($this->returnValueMap(array( - array('locales', array('fr', 'en')), - array('default_locale', 'fr'), - ))) + ->will($this->returnValueMap([ + ['locales', ['fr', 'en']], + ['default_locale', 'fr'], + ])) ; - }, true); + }, true]; } } diff --git a/Tests/Config/ContainerParametersResourceTest.php b/Tests/Config/ContainerParametersResourceTest.php index 4da4766f2..e177ac16b 100644 --- a/Tests/Config/ContainerParametersResourceTest.php +++ b/Tests/Config/ContainerParametersResourceTest.php @@ -21,7 +21,7 @@ class ContainerParametersResourceTest extends TestCase protected function setUp() { - $this->resource = new ContainerParametersResource(array('locales' => array('fr', 'en'), 'default_locale' => 'fr')); + $this->resource = new ContainerParametersResource(['locales' => ['fr', 'en'], 'default_locale' => 'fr']); } public function testToString() @@ -38,6 +38,6 @@ public function testSerializeUnserialize() public function testGetParameters() { - $this->assertSame(array('locales' => array('fr', 'en'), 'default_locale' => 'fr'), $this->resource->getParameters()); + $this->assertSame(['locales' => ['fr', 'en'], 'default_locale' => 'fr'], $this->resource->getParameters()); } } diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index 0bf1befa3..40afaa169 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -62,10 +62,10 @@ public function testDefaultRegisteredDefinitions() public function testDefinitions() { $builder = new ContainerBuilder(); - $definitions = array( + $definitions = [ 'foo' => new Definition('Bar\FooClass'), 'bar' => new Definition('BarClass'), - ); + ]; $builder->setDefinitions($definitions); $this->assertEquals($definitions, $builder->getDefinitions(), '->setDefinitions() sets the service definitions'); $this->assertTrue($builder->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists'); @@ -75,7 +75,7 @@ public function testDefinitions() $this->assertEquals($foo, $builder->getDefinition('foobar'), '->getDefinition() returns a service definition if defined'); $this->assertSame($builder->setDefinition('foobar', $foo = new Definition('FooBarClass')), $foo, '->setDefinition() implements a fluid interface by returning the service reference'); - $builder->addDefinitions($defs = array('foobar' => new Definition('FooBarClass'))); + $builder->addDefinitions($defs = ['foobar' => new Definition('FooBarClass')]); $this->assertEquals(array_merge($definitions, $defs), $builder->getDefinitions(), '->addDefinitions() adds the service definitions'); try { @@ -150,7 +150,7 @@ public function testGetReturnsNullIfServiceDoesNotExistAndInvalidReferenceIsUsed public function testGetThrowsCircularReferenceExceptionIfServiceHasReferenceToItself() { $builder = new ContainerBuilder(); - $builder->register('baz', 'stdClass')->setArguments(array(new Reference('baz'))); + $builder->register('baz', 'stdClass')->setArguments([new Reference('baz')]); $builder->get('baz'); } @@ -221,13 +221,13 @@ public function testGetServiceIds() $builder->bar = $bar = new \stdClass(); $builder->register('bar', 'stdClass'); $this->assertEquals( - array( + [ 'service_container', 'foo', 'bar', 'Psr\Container\ContainerInterface', 'Symfony\Component\DependencyInjection\ContainerInterface', - ), + ], $builder->getServiceIds(), '->getServiceIds() returns all defined service ids' ); @@ -284,7 +284,7 @@ public function testGetAliases() public function testSetAliases() { $builder = new ContainerBuilder(); - $builder->setAliases(array('bar' => 'foo', 'foobar' => 'foo')); + $builder->setAliases(['bar' => 'foo', 'foobar' => 'foo']); $aliases = $builder->getAliases(); $this->assertArrayHasKey('bar', $aliases); @@ -294,8 +294,8 @@ public function testSetAliases() public function testAddAliases() { $builder = new ContainerBuilder(); - $builder->setAliases(array('bar' => 'foo')); - $builder->addAliases(array('foobar' => 'foo')); + $builder->setAliases(['bar' => 'foo']); + $builder->addAliases(['foobar' => 'foo']); $aliases = $builder->getAliases(); $this->assertArrayHasKey('bar', $aliases); @@ -317,7 +317,7 @@ public function testAliasesKeepInvalidBehavior() $builder = new ContainerBuilder(); $aliased = new Definition('stdClass'); - $aliased->addMethodCall('setBar', array(new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))); + $aliased->addMethodCall('setBar', [new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]); $builder->setDefinition('aliased', $aliased); $builder->setAlias('alias', 'aliased'); @@ -373,18 +373,18 @@ public function testCreateServiceArguments() { $builder = new ContainerBuilder(); $builder->register('bar', 'stdClass'); - $builder->register('foo1', 'Bar\FooClass')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar'), '%%unescape_it%%')); + $builder->register('foo1', 'Bar\FooClass')->addArgument(['foo' => '%value%', '%value%' => 'foo', new Reference('bar'), '%%unescape_it%%']); $builder->setParameter('value', 'bar'); - $this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', $builder->get('bar'), '%unescape_it%'), $builder->get('foo1')->arguments, '->createService() replaces parameters and service references in the arguments provided by the service definition'); + $this->assertEquals(['foo' => 'bar', 'bar' => 'foo', $builder->get('bar'), '%unescape_it%'], $builder->get('foo1')->arguments, '->createService() replaces parameters and service references in the arguments provided by the service definition'); } public function testCreateServiceFactory() { $builder = new ContainerBuilder(); $builder->register('foo', 'Bar\FooClass')->setFactory('Bar\FooClass::getInstance'); - $builder->register('qux', 'Bar\FooClass')->setFactory(array('Bar\FooClass', 'getInstance')); - $builder->register('bar', 'Bar\FooClass')->setFactory(array(new Definition('Bar\FooClass'), 'getInstance')); - $builder->register('baz', 'Bar\FooClass')->setFactory(array(new Reference('bar'), 'getInstance')); + $builder->register('qux', 'Bar\FooClass')->setFactory(['Bar\FooClass', 'getInstance']); + $builder->register('bar', 'Bar\FooClass')->setFactory([new Definition('Bar\FooClass'), 'getInstance']); + $builder->register('baz', 'Bar\FooClass')->setFactory([new Reference('bar'), 'getInstance']); $this->assertTrue($builder->get('foo')->called, '->createService() calls the factory method to create the service instance'); $this->assertTrue($builder->get('qux')->called, '->createService() calls the factory method to create the service instance'); @@ -396,38 +396,38 @@ public function testCreateServiceMethodCalls() { $builder = new ContainerBuilder(); $builder->register('bar', 'stdClass'); - $builder->register('foo1', 'Bar\FooClass')->addMethodCall('setBar', array(array('%value%', new Reference('bar')))); + $builder->register('foo1', 'Bar\FooClass')->addMethodCall('setBar', [['%value%', new Reference('bar')]]); $builder->setParameter('value', 'bar'); - $this->assertEquals(array('bar', $builder->get('bar')), $builder->get('foo1')->bar, '->createService() replaces the values in the method calls arguments'); + $this->assertEquals(['bar', $builder->get('bar')], $builder->get('foo1')->bar, '->createService() replaces the values in the method calls arguments'); } public function testCreateServiceMethodCallsWithEscapedParam() { $builder = new ContainerBuilder(); $builder->register('bar', 'stdClass'); - $builder->register('foo1', 'Bar\FooClass')->addMethodCall('setBar', array(array('%%unescape_it%%'))); + $builder->register('foo1', 'Bar\FooClass')->addMethodCall('setBar', [['%%unescape_it%%']]); $builder->setParameter('value', 'bar'); - $this->assertEquals(array('%unescape_it%'), $builder->get('foo1')->bar, '->createService() replaces the values in the method calls arguments'); + $this->assertEquals(['%unescape_it%'], $builder->get('foo1')->bar, '->createService() replaces the values in the method calls arguments'); } public function testCreateServiceProperties() { $builder = new ContainerBuilder(); $builder->register('bar', 'stdClass'); - $builder->register('foo1', 'Bar\FooClass')->setProperty('bar', array('%value%', new Reference('bar'), '%%unescape_it%%')); + $builder->register('foo1', 'Bar\FooClass')->setProperty('bar', ['%value%', new Reference('bar'), '%%unescape_it%%']); $builder->setParameter('value', 'bar'); - $this->assertEquals(array('bar', $builder->get('bar'), '%unescape_it%'), $builder->get('foo1')->bar, '->createService() replaces the values in the properties'); + $this->assertEquals(['bar', $builder->get('bar'), '%unescape_it%'], $builder->get('foo1')->bar, '->createService() replaces the values in the properties'); } public function testCreateServiceConfigurator() { $builder = new ContainerBuilder(); $builder->register('foo1', 'Bar\FooClass')->setConfigurator('sc_configure'); - $builder->register('foo2', 'Bar\FooClass')->setConfigurator(array('%class%', 'configureStatic')); + $builder->register('foo2', 'Bar\FooClass')->setConfigurator(['%class%', 'configureStatic']); $builder->setParameter('class', 'BazClass'); $builder->register('baz', 'BazClass'); - $builder->register('foo3', 'Bar\FooClass')->setConfigurator(array(new Reference('baz'), 'configure')); - $builder->register('foo4', 'Bar\FooClass')->setConfigurator(array($builder->getDefinition('baz'), 'configure')); + $builder->register('foo3', 'Bar\FooClass')->setConfigurator([new Reference('baz'), 'configure']); + $builder->register('foo4', 'Bar\FooClass')->setConfigurator([$builder->getDefinition('baz'), 'configure']); $builder->register('foo5', 'Bar\FooClass')->setConfigurator('foo'); $this->assertTrue($builder->get('foo1')->configured, '->createService() calls the configurator'); @@ -449,10 +449,10 @@ public function testCreateServiceWithIteratorArgument() $builder->register('bar', 'stdClass'); $builder ->register('lazy_context', 'LazyContext') - ->setArguments(array( - new IteratorArgument(array('k1' => new Reference('bar'), new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))), - new IteratorArgument(array()), - )) + ->setArguments([ + new IteratorArgument(['k1' => new Reference('bar'), new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]), + new IteratorArgument([]), + ]) ; $lazyContext = $builder->get('lazy_context'); @@ -494,7 +494,7 @@ public function testCreateServiceWithExpression() $builder = new ContainerBuilder(); $builder->setParameter('bar', 'bar'); $builder->register('bar', 'BarClass'); - $builder->register('foo', 'Bar\FooClass')->addArgument(array('foo' => new Expression('service("bar").foo ~ parameter("bar")'))); + $builder->register('foo', 'Bar\FooClass')->addArgument(['foo' => new Expression('service("bar").foo ~ parameter("bar")')]); $this->assertEquals('foobar', $builder->get('foo')->arguments['foo']); } @@ -503,7 +503,7 @@ public function testResolveServices() $builder = new ContainerBuilder(); $builder->register('foo', 'Bar\FooClass'); $this->assertEquals($builder->get('foo'), $builder->resolveServices(new Reference('foo')), '->resolveServices() resolves service references to service instances'); - $this->assertEquals(array('foo' => array('foo', $builder->get('foo'))), $builder->resolveServices(array('foo' => array('foo', new Reference('foo')))), '->resolveServices() resolves service references to service instances in nested arrays'); + $this->assertEquals(['foo' => ['foo', $builder->get('foo')]], $builder->resolveServices(['foo' => ['foo', new Reference('foo')]]), '->resolveServices() resolves service references to service instances in nested arrays'); $this->assertEquals($builder->get('foo'), $builder->resolveServices(new Expression('service("foo")')), '->resolveServices() resolves expressions'); } @@ -531,25 +531,25 @@ public function testResolveServicesWithCustomDefinitionClass() public function testMerge() { - $container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo'))); + $container = new ContainerBuilder(new ParameterBag(['bar' => 'foo'])); $container->setResourceTracking(false); - $config = new ContainerBuilder(new ParameterBag(array('foo' => 'bar'))); + $config = new ContainerBuilder(new ParameterBag(['foo' => 'bar'])); $container->merge($config); - $this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $container->getParameterBag()->all(), '->merge() merges current parameters with the loaded ones'); + $this->assertEquals(['bar' => 'foo', 'foo' => 'bar'], $container->getParameterBag()->all(), '->merge() merges current parameters with the loaded ones'); - $container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo'))); + $container = new ContainerBuilder(new ParameterBag(['bar' => 'foo'])); $container->setResourceTracking(false); - $config = new ContainerBuilder(new ParameterBag(array('foo' => '%bar%'))); + $config = new ContainerBuilder(new ParameterBag(['foo' => '%bar%'])); $container->merge($config); $container->compile(); - $this->assertEquals(array('bar' => 'foo', 'foo' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones'); + $this->assertEquals(['bar' => 'foo', 'foo' => 'foo'], $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones'); - $container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo'))); + $container = new ContainerBuilder(new ParameterBag(['bar' => 'foo'])); $container->setResourceTracking(false); - $config = new ContainerBuilder(new ParameterBag(array('foo' => '%bar%', 'baz' => '%foo%'))); + $config = new ContainerBuilder(new ParameterBag(['foo' => '%bar%', 'baz' => '%foo%'])); $container->merge($config); $container->compile(); - $this->assertEquals(array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones'); + $this->assertEquals(['bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'], $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones'); $container = new ContainerBuilder(); $container->setResourceTracking(false); @@ -559,7 +559,7 @@ public function testMerge() $config->setDefinition('baz', new Definition('BazClass')); $config->setAlias('alias_for_foo', 'foo'); $container->merge($config); - $this->assertEquals(array('service_container', 'foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones'); + $this->assertEquals(['service_container', 'foo', 'bar', 'baz'], array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones'); $aliases = $container->getAliases(); $this->assertArrayHasKey('alias_for_foo', $aliases); @@ -576,16 +576,16 @@ public function testMerge() $bag = new EnvPlaceholderParameterBag(); $bag->get('env(Foo)'); $config = new ContainerBuilder($bag); - $this->assertSame(array('%env(Bar)%'), $config->resolveEnvPlaceholders(array($bag->get('env(Bar)')))); + $this->assertSame(['%env(Bar)%'], $config->resolveEnvPlaceholders([$bag->get('env(Bar)')])); $container->merge($config); - $this->assertEquals(array('Foo' => 0, 'Bar' => 1), $container->getEnvCounters()); + $this->assertEquals(['Foo' => 0, 'Bar' => 1], $container->getEnvCounters()); $container = new ContainerBuilder(); $config = new ContainerBuilder(); $childDefA = $container->registerForAutoconfiguration('AInterface'); $childDefB = $config->registerForAutoconfiguration('BInterface'); $container->merge($config); - $this->assertSame(array('AInterface' => $childDefA, 'BInterface' => $childDefB), $container->getAutoconfiguredInstanceof()); + $this->assertSame(['AInterface' => $childDefA, 'BInterface' => $childDefB], $container->getAutoconfiguredInstanceof()); } /** @@ -620,7 +620,7 @@ public function testResolveEnvValuesWithArray() { $_ENV['ANOTHER_DUMMY_ENV_VAR'] = 'dummy'; - $dummyArray = array('1' => 'one', '2' => 'two'); + $dummyArray = ['1' => 'one', '2' => 'two']; $container = new ContainerBuilder(); $container->setParameter('dummy', '%env(ANOTHER_DUMMY_ENV_VAR)%'); @@ -673,7 +673,7 @@ public function testCompileWithArrayResolveEnv() $container->setParameter('foo', '%env(json:ARRAY)%'); $container->compile(true); - $this->assertSame(array('foo' => 'bar'), $container->getParameter('foo')); + $this->assertSame(['foo' => 'bar'], $container->getParameter('foo')); putenv('ARRAY'); } @@ -688,7 +688,7 @@ public function testCompileWithArrayAndAnotherResolveEnv() $container->setParameter('bar', '%env(DUMMY_ENV_VAR)%'); $container->compile(true); - $this->assertSame(array('foo' => 'bar'), $container->getParameter('foo')); + $this->assertSame(['foo' => 'bar'], $container->getParameter('foo')); $this->assertSame('abc', $container->getParameter('bar')); putenv('DUMMY_ENV_VAR'); @@ -745,9 +745,9 @@ public function testCastEnv() $container->register('foo', 'stdClass') ->setPublic(true) - ->setProperties(array( + ->setProperties([ 'fake' => '%env(int:FAKE)%', - )); + ]); $container->compile(true); @@ -761,9 +761,9 @@ public function testEnvAreNullable() $container->register('foo', 'stdClass') ->setPublic(true) - ->setProperties(array( + ->setProperties([ 'fake' => '%env(int:FAKE)%', - )); + ]); $container->compile(true); @@ -775,23 +775,23 @@ public function testEnvInId() $container = include __DIR__.'/Fixtures/containers/container_env_in_id.php'; $container->compile(true); - $expected = array( + $expected = [ 'service_container', 'foo', 'bar', 'bar_%env(BAR)%', - ); + ]; $this->assertSame($expected, array_keys($container->getDefinitions())); - $expected = array( + $expected = [ PsrContainerInterface::class => true, ContainerInterface::class => true, 'baz_%env(BAR)%' => true, 'bar_%env(BAR)%' => true, - ); + ]; $this->assertSame($expected, $container->getRemovedIds()); - $this->assertSame(array('baz_bar'), array_keys($container->getDefinition('foo')->getArgument(1))); + $this->assertSame(['baz_bar'], array_keys($container->getDefinition('foo')->getArgument(1))); } /** @@ -829,17 +829,17 @@ public function testfindTaggedServiceIds() $builder = new ContainerBuilder(); $builder ->register('foo', 'Bar\FooClass') - ->addTag('foo', array('foo' => 'foo')) - ->addTag('bar', array('bar' => 'bar')) - ->addTag('foo', array('foofoo' => 'foofoo')) + ->addTag('foo', ['foo' => 'foo']) + ->addTag('bar', ['bar' => 'bar']) + ->addTag('foo', ['foofoo' => 'foofoo']) ; - $this->assertEquals($builder->findTaggedServiceIds('foo'), array( - 'foo' => array( - array('foo' => 'foo'), - array('foofoo' => 'foofoo'), - ), - ), '->findTaggedServiceIds() returns an array of service ids and its tag attributes'); - $this->assertEquals(array(), $builder->findTaggedServiceIds('foobar'), '->findTaggedServiceIds() returns an empty array if there is annotated services'); + $this->assertEquals($builder->findTaggedServiceIds('foo'), [ + 'foo' => [ + ['foo' => 'foo'], + ['foofoo' => 'foofoo'], + ], + ], '->findTaggedServiceIds() returns an array of service ids and its tag attributes'); + $this->assertEquals([], $builder->findTaggedServiceIds('foobar'), '->findTaggedServiceIds() returns an empty array if there is annotated services'); } public function testFindUnusedTags() @@ -847,11 +847,11 @@ public function testFindUnusedTags() $builder = new ContainerBuilder(); $builder ->register('foo', 'Bar\FooClass') - ->addTag('kernel.event_listener', array('foo' => 'foo')) - ->addTag('kenrel.event_listener', array('bar' => 'bar')) + ->addTag('kernel.event_listener', ['foo' => 'foo']) + ->addTag('kenrel.event_listener', ['bar' => 'bar']) ; $builder->findTaggedServiceIds('kernel.event_listener'); - $this->assertEquals(array('kenrel.event_listener'), $builder->findUnusedTags(), '->findUnusedTags() returns an array with unused tags'); + $this->assertEquals(['kenrel.event_listener'], $builder->findUnusedTags(), '->findUnusedTags() returns an array with unused tags'); } public function testFindDefinition() @@ -981,15 +981,15 @@ public function testResources() $container = new ContainerBuilder(); $container->addResource($a = new FileResource(__DIR__.'/Fixtures/xml/services1.xml')); $container->addResource($b = new FileResource(__DIR__.'/Fixtures/xml/services2.xml')); - $resources = array(); + $resources = []; foreach ($container->getResources() as $resource) { if (false === strpos($resource, '.php')) { $resources[] = $resource; } } - $this->assertEquals(array($a, $b), $resources, '->getResources() returns an array of resources read for the current configuration'); - $this->assertSame($container, $container->setResources(array())); - $this->assertEquals(array(), $container->getResources()); + $this->assertEquals([$a, $b], $resources, '->getResources() returns an array of resources read for the current configuration'); + $this->assertSame($container, $container->setResources([])); + $this->assertEquals([], $container->getResources()); } public function testFileExists() @@ -1002,14 +1002,14 @@ public function testFileExists() $this->assertTrue($container->fileExists((string) $a) && $container->fileExists((string) $b) && $container->fileExists($dir)); - $resources = array(); + $resources = []; foreach ($container->getResources() as $resource) { if (false === strpos($resource, '.php')) { $resources[] = $resource; } } - $this->assertEquals(array($A, $a, $b, $c), $resources, '->getResources() returns an array of resources read for the current configuration'); + $this->assertEquals([$A, $a, $b, $c], $resources, '->getResources() returns an array of resources read for the current configuration'); } public function testExtension() @@ -1040,28 +1040,28 @@ public function testRegisteredAndLoadedExtension() { $extension = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface')->getMock(); $extension->expects($this->exactly(2))->method('getAlias')->will($this->returnValue('project')); - $extension->expects($this->once())->method('load')->with(array(array('foo' => 'bar'))); + $extension->expects($this->once())->method('load')->with([['foo' => 'bar']]); $container = new ContainerBuilder(); $container->setResourceTracking(false); $container->registerExtension($extension); - $container->loadFromExtension('project', array('foo' => 'bar')); + $container->loadFromExtension('project', ['foo' => 'bar']); $container->compile(); } public function testPrivateServiceUser() { $fooDefinition = new Definition('BarClass'); - $fooUserDefinition = new Definition('BarUserClass', array(new Reference('bar'))); + $fooUserDefinition = new Definition('BarUserClass', [new Reference('bar')]); $container = new ContainerBuilder(); $container->setResourceTracking(false); $fooDefinition->setPublic(false); - $container->addDefinitions(array( + $container->addDefinitions([ 'bar' => $fooDefinition, 'bar_user' => $fooUserDefinition->setPublic(true), - )); + ]); $container->compile(); $this->assertInstanceOf('BarClass', $container->get('bar_user')->bar); @@ -1116,15 +1116,15 @@ public function testExtensionConfig() $configs = $container->getExtensionConfig('foo'); $this->assertEmpty($configs); - $first = array('foo' => 'bar'); + $first = ['foo' => 'bar']; $container->prependExtensionConfig('foo', $first); $configs = $container->getExtensionConfig('foo'); - $this->assertEquals(array($first), $configs); + $this->assertEquals([$first], $configs); - $second = array('ding' => 'dong'); + $second = ['ding' => 'dong']; $container->prependExtensionConfig('foo', $second); $configs = $container->getExtensionConfig('foo'); - $this->assertEquals(array($second, $first), $configs); + $this->assertEquals([$second, $first], $configs); } public function testAbstractAlias() @@ -1184,7 +1184,7 @@ public function testInlinedDefinitions() $container->register('bar', 'BarClass') ->setProperty('foo', $definition) - ->addMethodCall('setBaz', array($definition)); + ->addMethodCall('setBaz', [$definition]); $barUser = $container->get('bar_user'); $bar = $container->get('bar'); @@ -1202,11 +1202,11 @@ public function testThrowsCircularExceptionForCircularAliases() { $builder = new ContainerBuilder(); - $builder->setAliases(array( + $builder->setAliases([ 'foo' => new Alias('app.test_class'), 'app.test_class' => new Alias('App\\TestClass'), 'App\\TestClass' => new Alias('app.test_class'), - )); + ]); $builder->findDefinition('foo'); } @@ -1317,12 +1317,12 @@ public function testServiceLocator() $container = new ContainerBuilder(); $container->register('foo_service', ServiceLocator::class) ->setPublic(true) - ->addArgument(array( + ->addArgument([ 'bar' => new ServiceClosureArgument(new Reference('bar_service')), 'baz' => new ServiceClosureArgument(new TypedReference('baz_service', 'stdClass')), - )) + ]) ; - $container->register('bar_service', 'stdClass')->setArguments(array(new Reference('baz_service')))->setPublic(true); + $container->register('bar_service', 'stdClass')->setArguments([new Reference('baz_service')])->setPublic(true); $container->register('baz_service', 'stdClass')->setPublic(false); $container->compile(); @@ -1343,7 +1343,7 @@ public function testUninitializedReference() $this->assertNull($bar->closures[0]()); $this->assertNull($bar->closures[1]()); $this->assertNull($bar->closures[2]()); - $this->assertSame(array(), iterator_to_array($bar->iter)); + $this->assertSame([], iterator_to_array($bar->iter)); $container = include __DIR__.'/Fixtures/containers/container_uninitialized_ref.php'; $container->compile(); @@ -1359,7 +1359,7 @@ public function testUninitializedReference() $this->assertEquals(new \stdClass(), $bar->closures[0]()); $this->assertNull($bar->closures[1]()); $this->assertEquals(new \stdClass(), $bar->closures[2]()); - $this->assertEquals(array('foo1' => new \stdClass(), 'foo3' => new \stdClass()), iterator_to_array($bar->iter)); + $this->assertEquals(['foo1' => new \stdClass(), 'foo3' => new \stdClass()], iterator_to_array($bar->iter)); } /** @@ -1375,7 +1375,7 @@ public function testAlmostCircular($visibility) $foo2 = $container->get('foo2'); $this->assertSame($foo2, $foo2->bar->foobar->foo); - $this->assertSame(array(), (array) $container->get('foobar4')); + $this->assertSame([], (array) $container->get('foobar4')); $foo5 = $container->get('foo5'); $this->assertSame($foo5, $foo5->bar->foo); @@ -1387,15 +1387,15 @@ public function testAlmostCircular($visibility) $this->assertEquals(new \stdClass(), $manager); $foo6 = $container->get('foo6'); - $this->assertEquals((object) array('bar6' => (object) array()), $foo6); + $this->assertEquals((object) ['bar6' => (object) []], $foo6); $this->assertInstanceOf(\stdClass::class, $container->get('root')); } public function provideAlmostCircular() { - yield array('public'); - yield array('private'); + yield ['public']; + yield ['private']; } public function testRegisterForAutoconfiguration() @@ -1403,7 +1403,7 @@ public function testRegisterForAutoconfiguration() $container = new ContainerBuilder(); $childDefA = $container->registerForAutoconfiguration('AInterface'); $childDefB = $container->registerForAutoconfiguration('BInterface'); - $this->assertSame(array('AInterface' => $childDefA, 'BInterface' => $childDefB), $container->getAutoconfiguredInstanceof()); + $this->assertSame(['AInterface' => $childDefA, 'BInterface' => $childDefB], $container->getAutoconfiguredInstanceof()); // when called multiple times, the same instance is returned $this->assertSame($childDefA, $container->registerForAutoconfiguration('AInterface')); @@ -1436,7 +1436,7 @@ public function testPrivateServiceTriggersDeprecation() */ public function testParameterWithMixedCase() { - $container = new ContainerBuilder(new ParameterBag(array('foo' => 'bar'))); + $container = new ContainerBuilder(new ParameterBag(['foo' => 'bar'])); $container->register('foo', 'stdClass') ->setPublic(true) ->setProperty('foo', '%FOO%'); @@ -1449,20 +1449,20 @@ public function testParameterWithMixedCase() public function testArgumentsHaveHigherPriorityThanBindings() { $container = new ContainerBuilder(); - $container->register('class.via.bindings', CaseSensitiveClass::class)->setArguments(array( + $container->register('class.via.bindings', CaseSensitiveClass::class)->setArguments([ 'via-bindings', - )); - $container->register('class.via.argument', CaseSensitiveClass::class)->setArguments(array( + ]); + $container->register('class.via.argument', CaseSensitiveClass::class)->setArguments([ 'via-argument', - )); - $container->register('foo', SimilarArgumentsDummy::class)->setPublic(true)->setBindings(array( + ]); + $container->register('foo', SimilarArgumentsDummy::class)->setPublic(true)->setBindings([ CaseSensitiveClass::class => new Reference('class.via.bindings'), '$token' => '1234', - ))->setArguments(array( + ])->setArguments([ '$class1' => new Reference('class.via.argument'), - )); + ]); - $this->assertSame(array('service_container', 'class.via.bindings', 'class.via.argument', 'foo', 'Psr\Container\ContainerInterface', 'Symfony\Component\DependencyInjection\ContainerInterface'), $container->getServiceIds()); + $this->assertSame(['service_container', 'class.via.bindings', 'class.via.argument', 'foo', 'Psr\Container\ContainerInterface', 'Symfony\Component\DependencyInjection\ContainerInterface'], $container->getServiceIds()); $container->compile(); @@ -1479,10 +1479,10 @@ public function testUninitializedSyntheticReference() $container->compile(); - $this->assertEquals((object) array('foo' => null), $container->get('bar')); + $this->assertEquals((object) ['foo' => null], $container->get('bar')); - $container->set('foo', (object) array(123)); - $this->assertEquals((object) array('foo' => (object) array(123)), $container->get('bar')); + $container->set('foo', (object) [123]); + $this->assertEquals((object) ['foo' => (object) [123]], $container->get('bar')); } public function testDecoratedSelfReferenceInvolvingPrivateServices() @@ -1498,7 +1498,7 @@ public function testDecoratedSelfReferenceInvolvingPrivateServices() $container->compile(); - $this->assertSame(array('service_container'), array_keys($container->getDefinitions())); + $this->assertSame(['service_container'], array_keys($container->getDefinitions())); } } diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index a57f78797..d2616a34b 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -25,8 +25,8 @@ public function testConstructor() $sc = new Container(); $this->assertSame($sc, $sc->get('service_container'), '__construct() automatically registers itself as a service'); - $sc = new Container(new ParameterBag(array('foo' => 'bar'))); - $this->assertEquals(array('foo' => 'bar'), $sc->getParameterBag()->all(), '__construct() takes an array of parameters as its first argument'); + $sc = new Container(new ParameterBag(['foo' => 'bar'])); + $this->assertEquals(['foo' => 'bar'], $sc->getParameterBag()->all(), '__construct() takes an array of parameters as its first argument'); } /** @@ -39,18 +39,18 @@ public function testCamelize($id, $expected) public function dataForTestCamelize() { - return array( - array('foo_bar', 'FooBar'), - array('foo.bar', 'Foo_Bar'), - array('foo.bar_baz', 'Foo_BarBaz'), - array('foo._bar', 'Foo_Bar'), - array('foo_.bar', 'Foo_Bar'), - array('_foo', 'Foo'), - array('.foo', '_Foo'), - array('foo_', 'Foo'), - array('foo.', 'Foo_'), - array('foo\bar', 'Foo_Bar'), - ); + return [ + ['foo_bar', 'FooBar'], + ['foo.bar', 'Foo_Bar'], + ['foo.bar_baz', 'Foo_BarBaz'], + ['foo._bar', 'Foo_Bar'], + ['foo_.bar', 'Foo_Bar'], + ['_foo', 'Foo'], + ['.foo', '_Foo'], + ['foo_', 'Foo'], + ['foo.', 'Foo_'], + ['foo\bar', 'Foo_Bar'], + ]; } /** @@ -63,24 +63,24 @@ public function testUnderscore($id, $expected) public function dataForTestUnderscore() { - return array( - array('FooBar', 'foo_bar'), - array('Foo_Bar', 'foo.bar'), - array('Foo_BarBaz', 'foo.bar_baz'), - array('FooBar_BazQux', 'foo_bar.baz_qux'), - array('_Foo', '.foo'), - array('Foo_', 'foo.'), - ); + return [ + ['FooBar', 'foo_bar'], + ['Foo_Bar', 'foo.bar'], + ['Foo_BarBaz', 'foo.bar_baz'], + ['FooBar_BazQux', 'foo_bar.baz_qux'], + ['_Foo', '.foo'], + ['Foo_', 'foo.'], + ]; } public function testCompile() { - $sc = new Container(new ParameterBag(array('foo' => 'bar'))); + $sc = new Container(new ParameterBag(['foo' => 'bar'])); $this->assertFalse($sc->getParameterBag()->isResolved(), '->compile() resolves the parameter bag'); $sc->compile(); $this->assertTrue($sc->getParameterBag()->isResolved(), '->compile() resolves the parameter bag'); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag', $sc->getParameterBag(), '->compile() changes the parameter bag to a FrozenParameterBag instance'); - $this->assertEquals(array('foo' => 'bar'), $sc->getParameterBag()->all(), '->compile() copies the current parameters to the new parameter bag'); + $this->assertEquals(['foo' => 'bar'], $sc->getParameterBag()->all(), '->compile() copies the current parameters to the new parameter bag'); } /** @@ -90,7 +90,7 @@ public function testCompile() */ public function testIsFrozen() { - $sc = new Container(new ParameterBag(array('foo' => 'bar'))); + $sc = new Container(new ParameterBag(['foo' => 'bar'])); $this->assertFalse($sc->isFrozen(), '->isFrozen() returns false if the parameters are not frozen'); $sc->compile(); $this->assertTrue($sc->isFrozen(), '->isFrozen() returns true if the parameters are frozen'); @@ -98,7 +98,7 @@ public function testIsFrozen() public function testIsCompiled() { - $sc = new Container(new ParameterBag(array('foo' => 'bar'))); + $sc = new Container(new ParameterBag(['foo' => 'bar'])); $this->assertFalse($sc->isCompiled(), '->isCompiled() returns false if the container is not compiled'); $sc->compile(); $this->assertTrue($sc->isCompiled(), '->isCompiled() returns true if the container is compiled'); @@ -106,19 +106,19 @@ public function testIsCompiled() public function testIsCompiledWithFrozenParameters() { - $sc = new Container(new FrozenParameterBag(array('foo' => 'bar'))); + $sc = new Container(new FrozenParameterBag(['foo' => 'bar'])); $this->assertFalse($sc->isCompiled(), '->isCompiled() returns false if the container is not compiled but the parameter bag is already frozen'); } public function testGetParameterBag() { $sc = new Container(); - $this->assertEquals(array(), $sc->getParameterBag()->all(), '->getParameterBag() returns an empty array if no parameter has been defined'); + $this->assertEquals([], $sc->getParameterBag()->all(), '->getParameterBag() returns an empty array if no parameter has been defined'); } public function testGetSetParameter() { - $sc = new Container(new ParameterBag(array('foo' => 'bar'))); + $sc = new Container(new ParameterBag(['foo' => 'bar'])); $sc->setParameter('bar', 'foo'); $this->assertEquals('foo', $sc->getParameter('bar'), '->setParameter() sets the value of a new parameter'); @@ -141,7 +141,7 @@ public function testGetSetParameter() */ public function testGetSetParameterWithMixedCase() { - $sc = new Container(new ParameterBag(array('foo' => 'bar'))); + $sc = new Container(new ParameterBag(['foo' => 'bar'])); $sc->setParameter('Foo', 'baz1'); $this->assertEquals('baz1', $sc->getParameter('foo'), '->setParameter() converts the key to lowercase'); @@ -153,11 +153,11 @@ public function testGetServiceIds() $sc = new Container(); $sc->set('foo', $obj = new \stdClass()); $sc->set('bar', $obj = new \stdClass()); - $this->assertEquals(array('service_container', 'foo', 'bar'), $sc->getServiceIds(), '->getServiceIds() returns all defined service ids'); + $this->assertEquals(['service_container', 'foo', 'bar'], $sc->getServiceIds(), '->getServiceIds() returns all defined service ids'); $sc = new ProjectServiceContainer(); $sc->set('foo', $obj = new \stdClass()); - $this->assertEquals(array('service_container', 'internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'internal_dependency', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by factory methods in the method map, followed by service ids defined by set()'); + $this->assertEquals(['service_container', 'internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'internal_dependency', 'foo'], $sc->getServiceIds(), '->getServiceIds() returns defined service ids by factory methods in the method map, followed by service ids defined by set()'); } /** @@ -169,7 +169,7 @@ public function testGetLegacyServiceIds() $sc = new LegacyProjectServiceContainer(); $sc->set('foo', $obj = new \stdClass()); - $this->assertEquals(array('internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()'); + $this->assertEquals(['internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'foo'], $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()'); } public function testSet() @@ -557,7 +557,7 @@ class ProjectServiceContainer extends Container public $__foo_baz; public $__internal; protected $privates; - protected $methodMap = array( + protected $methodMap = [ 'internal' => 'getInternalService', 'bar' => 'getBarService', 'foo_bar' => 'getFooBarService', @@ -566,7 +566,7 @@ class ProjectServiceContainer extends Container 'throw_exception' => 'getThrowExceptionService', 'throws_exception_on_service_configuration' => 'getThrowsExceptionOnServiceConfigurationService', 'internal_dependency' => 'getInternalDependencyService', - ); + ]; public function __construct() { @@ -576,11 +576,11 @@ public function __construct() $this->__foo_bar = new \stdClass(); $this->__foo_baz = new \stdClass(); $this->__internal = new \stdClass(); - $this->privates = array( + $this->privates = [ 'internal' => true, 'synthetic' => true, - ); - $this->aliases = array('alias' => 'bar'); + ]; + $this->aliases = ['alias' => 'bar']; $this->syntheticIds['synthetic'] = true; } @@ -646,8 +646,8 @@ public function __construct() $this->__foo_bar = new \stdClass(); $this->__foo_baz = new \stdClass(); $this->__internal = new \stdClass(); - $this->privates = array('internal' => true); - $this->aliases = array('alias' => 'bar'); + $this->privates = ['internal' => true]; + $this->aliases = ['alias' => 'bar']; } protected function getInternalService() diff --git a/Tests/CrossCheckTest.php b/Tests/CrossCheckTest.php index 6ec9d33f5..fe132af48 100644 --- a/Tests/CrossCheckTest.php +++ b/Tests/CrossCheckTest.php @@ -58,16 +58,16 @@ public function testCrossCheck($fixture, $type) $r = new \ReflectionProperty(ContainerBuilder::class, 'normalizedIds'); $r->setAccessible(true); - $r->setValue($container2, array()); - $r->setValue($container1, array()); + $r->setValue($container2, []); + $r->setValue($container1, []); $this->assertEquals(serialize($container2), serialize($container1), 'loading a dump from a previously loaded container returns the same container'); - $services1 = array(); + $services1 = []; foreach ($container1 as $id => $service) { $services1[$id] = serialize($service); } - $services2 = array(); + $services2 = []; foreach ($container2 as $id => $service) { $services2[$id] = serialize($service); } @@ -79,17 +79,17 @@ public function testCrossCheck($fixture, $type) public function crossCheckLoadersDumpers() { - return array( - array('services1.xml', 'xml'), - array('services2.xml', 'xml'), - array('services6.xml', 'xml'), - array('services8.xml', 'xml'), - array('services9.xml', 'xml'), - array('services1.yml', 'yaml'), - array('services2.yml', 'yaml'), - array('services6.yml', 'yaml'), - array('services8.yml', 'yaml'), - array('services9.yml', 'yaml'), - ); + return [ + ['services1.xml', 'xml'], + ['services2.xml', 'xml'], + ['services6.xml', 'xml'], + ['services8.xml', 'xml'], + ['services9.xml', 'xml'], + ['services1.yml', 'yaml'], + ['services2.yml', 'yaml'], + ['services6.yml', 'yaml'], + ['services8.yml', 'yaml'], + ['services9.yml', 'yaml'], + ]; } } diff --git a/Tests/DefinitionDecoratorTest.php b/Tests/DefinitionDecoratorTest.php index 92a212ec4..ac58d3455 100644 --- a/Tests/DefinitionDecoratorTest.php +++ b/Tests/DefinitionDecoratorTest.php @@ -24,7 +24,7 @@ public function testConstructor() $def = new DefinitionDecorator('foo'); $this->assertEquals('foo', $def->getParent()); - $this->assertEquals(array(), $def->getChanges()); + $this->assertEquals([], $def->getChanges()); } /** @@ -40,17 +40,17 @@ public function testSetProperty($property, $changeKey) $this->assertNull($def->$getter()); $this->assertSame($def, $def->$setter('foo')); $this->assertEquals('foo', $def->$getter()); - $this->assertEquals(array($changeKey => true), $def->getChanges()); + $this->assertEquals([$changeKey => true], $def->getChanges()); } public function getPropertyTests() { - return array( - array('class', 'class'), - array('factory', 'factory'), - array('configurator', 'configurator'), - array('file', 'file'), - ); + return [ + ['class', 'class'], + ['factory', 'factory'], + ['configurator', 'configurator'], + ['file', 'file'], + ]; } public function testSetPublic() @@ -60,7 +60,7 @@ public function testSetPublic() $this->assertTrue($def->isPublic()); $this->assertSame($def, $def->setPublic(false)); $this->assertFalse($def->isPublic()); - $this->assertEquals(array('public' => true), $def->getChanges()); + $this->assertEquals(['public' => true], $def->getChanges()); } public function testSetLazy() @@ -70,7 +70,7 @@ public function testSetLazy() $this->assertFalse($def->isLazy()); $this->assertSame($def, $def->setLazy(false)); $this->assertFalse($def->isLazy()); - $this->assertEquals(array('lazy' => true), $def->getChanges()); + $this->assertEquals(['lazy' => true], $def->getChanges()); } public function testSetAutowired() @@ -80,16 +80,16 @@ public function testSetAutowired() $this->assertFalse($def->isAutowired()); $this->assertSame($def, $def->setAutowired(true)); $this->assertTrue($def->isAutowired()); - $this->assertSame(array('autowired' => true), $def->getChanges()); + $this->assertSame(['autowired' => true], $def->getChanges()); } public function testSetArgument() { $def = new DefinitionDecorator('foo'); - $this->assertEquals(array(), $def->getArguments()); + $this->assertEquals([], $def->getArguments()); $this->assertSame($def, $def->replaceArgument(0, 'foo')); - $this->assertEquals(array('index_0' => 'foo'), $def->getArguments()); + $this->assertEquals(['index_0' => 'foo'], $def->getArguments()); } /** @@ -106,7 +106,7 @@ public function testReplaceArgument() { $def = new DefinitionDecorator('foo'); - $def->setArguments(array(0 => 'foo', 1 => 'bar')); + $def->setArguments([0 => 'foo', 1 => 'bar']); $this->assertEquals('foo', $def->getArgument(0)); $this->assertEquals('bar', $def->getArgument(1)); @@ -114,7 +114,7 @@ public function testReplaceArgument() $this->assertEquals('foo', $def->getArgument(0)); $this->assertEquals('baz', $def->getArgument(1)); - $this->assertEquals(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments()); + $this->assertEquals([0 => 'foo', 1 => 'bar', 'index_1' => 'baz'], $def->getArguments()); } /** @@ -124,7 +124,7 @@ public function testGetArgumentShouldCheckBounds() { $def = new DefinitionDecorator('foo'); - $def->setArguments(array(0 => 'foo')); + $def->setArguments([0 => 'foo']); $def->replaceArgument(0, 'foo'); $def->getArgument(1); diff --git a/Tests/DefinitionTest.php b/Tests/DefinitionTest.php index 5fe4236ad..3581fe855 100644 --- a/Tests/DefinitionTest.php +++ b/Tests/DefinitionTest.php @@ -20,10 +20,10 @@ public function testConstructor() { $def = new Definition('stdClass'); $this->assertEquals('stdClass', $def->getClass(), '__construct() takes the class name as its first argument'); - $this->assertSame(array('class' => true), $def->getChanges()); + $this->assertSame(['class' => true], $def->getChanges()); - $def = new Definition('stdClass', array('foo')); - $this->assertEquals(array('foo'), $def->getArguments(), '__construct() takes an optional array of arguments as its second argument'); + $def = new Definition('stdClass', ['foo']); + $this->assertEquals(['foo'], $def->getArguments(), '__construct() takes an optional array of arguments as its second argument'); } public function testSetGetFactory() @@ -34,8 +34,8 @@ public function testSetGetFactory() $this->assertEquals('foo', $def->getFactory(), '->getFactory() returns the factory'); $def->setFactory('Foo::bar'); - $this->assertEquals(array('Foo', 'bar'), $def->getFactory(), '->setFactory() converts string static method call to the array'); - $this->assertSame(array('factory' => true), $def->getChanges()); + $this->assertEquals(['Foo', 'bar'], $def->getFactory(), '->setFactory() converts string static method call to the array'); + $this->assertSame(['factory' => true], $def->getChanges()); } public function testSetGetClass() @@ -50,20 +50,20 @@ public function testSetGetDecoratedService() $def = new Definition('stdClass'); $this->assertNull($def->getDecoratedService()); $def->setDecoratedService('foo', 'foo.renamed', 5); - $this->assertEquals(array('foo', 'foo.renamed', 5), $def->getDecoratedService()); + $this->assertEquals(['foo', 'foo.renamed', 5], $def->getDecoratedService()); $def->setDecoratedService(null); $this->assertNull($def->getDecoratedService()); $def = new Definition('stdClass'); $this->assertNull($def->getDecoratedService()); $def->setDecoratedService('foo', 'foo.renamed'); - $this->assertEquals(array('foo', 'foo.renamed', 0), $def->getDecoratedService()); + $this->assertEquals(['foo', 'foo.renamed', 0], $def->getDecoratedService()); $def->setDecoratedService(null); $this->assertNull($def->getDecoratedService()); $def = new Definition('stdClass'); $def->setDecoratedService('foo'); - $this->assertEquals(array('foo', null, 0), $def->getDecoratedService()); + $this->assertEquals(['foo', null, 0], $def->getDecoratedService()); $def->setDecoratedService(null); $this->assertNull($def->getDecoratedService()); @@ -82,23 +82,23 @@ public function testSetGetDecoratedService() public function testArguments() { $def = new Definition('stdClass'); - $this->assertSame($def, $def->setArguments(array('foo')), '->setArguments() implements a fluent interface'); - $this->assertEquals(array('foo'), $def->getArguments(), '->getArguments() returns the arguments'); + $this->assertSame($def, $def->setArguments(['foo']), '->setArguments() implements a fluent interface'); + $this->assertEquals(['foo'], $def->getArguments(), '->getArguments() returns the arguments'); $this->assertSame($def, $def->addArgument('bar'), '->addArgument() implements a fluent interface'); - $this->assertEquals(array('foo', 'bar'), $def->getArguments(), '->addArgument() adds an argument'); + $this->assertEquals(['foo', 'bar'], $def->getArguments(), '->addArgument() adds an argument'); } public function testMethodCalls() { $def = new Definition('stdClass'); - $this->assertSame($def, $def->setMethodCalls(array(array('foo', array('foo')))), '->setMethodCalls() implements a fluent interface'); - $this->assertEquals(array(array('foo', array('foo'))), $def->getMethodCalls(), '->getMethodCalls() returns the methods to call'); - $this->assertSame($def, $def->addMethodCall('bar', array('bar')), '->addMethodCall() implements a fluent interface'); - $this->assertEquals(array(array('foo', array('foo')), array('bar', array('bar'))), $def->getMethodCalls(), '->addMethodCall() adds a method to call'); + $this->assertSame($def, $def->setMethodCalls([['foo', ['foo']]]), '->setMethodCalls() implements a fluent interface'); + $this->assertEquals([['foo', ['foo']]], $def->getMethodCalls(), '->getMethodCalls() returns the methods to call'); + $this->assertSame($def, $def->addMethodCall('bar', ['bar']), '->addMethodCall() implements a fluent interface'); + $this->assertEquals([['foo', ['foo']], ['bar', ['bar']]], $def->getMethodCalls(), '->addMethodCall() adds a method to call'); $this->assertTrue($def->hasMethodCall('bar'), '->hasMethodCall() returns true if first argument is a method to call registered'); $this->assertFalse($def->hasMethodCall('no_registered'), '->hasMethodCall() returns false if first argument is not a method to call registered'); $this->assertSame($def, $def->removeMethodCall('bar'), '->removeMethodCall() implements a fluent interface'); - $this->assertEquals(array(array('foo', array('foo'))), $def->getMethodCalls(), '->removeMethodCall() removes a method to call'); + $this->assertEquals([['foo', ['foo']]], $def->getMethodCalls(), '->removeMethodCall() removes a method to call'); } /** @@ -179,12 +179,12 @@ public function testSetDeprecatedWithInvalidDeprecationTemplate($message) public function invalidDeprecationMessageProvider() { - return array( - "With \rs" => array("invalid \r message %service_id%"), - "With \ns" => array("invalid \n message %service_id%"), - 'With */s' => array('invalid */ message %service_id%'), - 'message not containing require %service_id% variable' => array('this is deprecated'), - ); + return [ + "With \rs" => ["invalid \r message %service_id%"], + "With \ns" => ["invalid \n message %service_id%"], + 'With */s' => ['invalid */ message %service_id%'], + 'message not containing require %service_id% variable' => ['this is deprecated'], + ]; } public function testSetGetConfigurator() @@ -198,18 +198,18 @@ public function testClearTags() { $def = new Definition('stdClass'); $this->assertSame($def, $def->clearTags(), '->clearTags() implements a fluent interface'); - $def->addTag('foo', array('foo' => 'bar')); + $def->addTag('foo', ['foo' => 'bar']); $def->clearTags(); - $this->assertEquals(array(), $def->getTags(), '->clearTags() removes all current tags'); + $this->assertEquals([], $def->getTags(), '->clearTags() removes all current tags'); } public function testClearTag() { $def = new Definition('stdClass'); $this->assertSame($def, $def->clearTags(), '->clearTags() implements a fluent interface'); - $def->addTag('1foo1', array('foo1' => 'bar1')); - $def->addTag('2foo2', array('foo2' => 'bar2')); - $def->addTag('3foo3', array('foo3' => 'bar3')); + $def->addTag('1foo1', ['foo1' => 'bar1']); + $def->addTag('2foo2', ['foo2' => 'bar2']); + $def->addTag('3foo3', ['foo3' => 'bar3']); $def->clearTag('2foo2'); $this->assertTrue($def->hasTag('1foo1')); $this->assertFalse($def->hasTag('2foo2')); @@ -222,18 +222,18 @@ public function testClearTag() public function testTags() { $def = new Definition('stdClass'); - $this->assertEquals(array(), $def->getTag('foo'), '->getTag() returns an empty array if the tag is not defined'); + $this->assertEquals([], $def->getTag('foo'), '->getTag() returns an empty array if the tag is not defined'); $this->assertFalse($def->hasTag('foo')); $this->assertSame($def, $def->addTag('foo'), '->addTag() implements a fluent interface'); $this->assertTrue($def->hasTag('foo')); - $this->assertEquals(array(array()), $def->getTag('foo'), '->getTag() returns attributes for a tag name'); - $def->addTag('foo', array('foo' => 'bar')); - $this->assertEquals(array(array(), array('foo' => 'bar')), $def->getTag('foo'), '->addTag() can adds the same tag several times'); - $def->addTag('bar', array('bar' => 'bar')); - $this->assertEquals($def->getTags(), array( - 'foo' => array(array(), array('foo' => 'bar')), - 'bar' => array(array('bar' => 'bar')), - ), '->getTags() returns all tags'); + $this->assertEquals([[]], $def->getTag('foo'), '->getTag() returns attributes for a tag name'); + $def->addTag('foo', ['foo' => 'bar']); + $this->assertEquals([[], ['foo' => 'bar']], $def->getTag('foo'), '->addTag() can adds the same tag several times'); + $def->addTag('bar', ['bar' => 'bar']); + $this->assertEquals($def->getTags(), [ + 'foo' => [[], ['foo' => 'bar']], + 'bar' => [['bar' => 'bar']], + ], '->getTags() returns all tags'); } public function testSetArgument() @@ -241,17 +241,17 @@ public function testSetArgument() $def = new Definition('stdClass'); $def->addArgument('foo'); - $this->assertSame(array('foo'), $def->getArguments()); + $this->assertSame(['foo'], $def->getArguments()); $this->assertSame($def, $def->replaceArgument(0, 'moo')); - $this->assertSame(array('moo'), $def->getArguments()); + $this->assertSame(['moo'], $def->getArguments()); $def->addArgument('moo'); $def ->replaceArgument(0, 'foo') ->replaceArgument(1, 'bar') ; - $this->assertSame(array('foo', 'bar'), $def->getArguments()); + $this->assertSame(['foo', 'bar'], $def->getArguments()); } /** @@ -291,18 +291,18 @@ public function testSetGetProperties() { $def = new Definition('stdClass'); - $this->assertEquals(array(), $def->getProperties()); - $this->assertSame($def, $def->setProperties(array('foo' => 'bar'))); - $this->assertEquals(array('foo' => 'bar'), $def->getProperties()); + $this->assertEquals([], $def->getProperties()); + $this->assertSame($def, $def->setProperties(['foo' => 'bar'])); + $this->assertEquals(['foo' => 'bar'], $def->getProperties()); } public function testSetProperty() { $def = new Definition('stdClass'); - $this->assertEquals(array(), $def->getProperties()); + $this->assertEquals([], $def->getProperties()); $this->assertSame($def, $def->setProperty('foo', 'bar')); - $this->assertEquals(array('foo' => 'bar'), $def->getProperties()); + $this->assertEquals(['foo' => 'bar'], $def->getProperties()); } public function testAutowired() @@ -321,12 +321,12 @@ public function testChangesNoChanges() { $def = new Definition(); - $this->assertSame(array(), $def->getChanges()); + $this->assertSame([], $def->getChanges()); } public function testGetChangesWithChanges() { - $def = new Definition('stdClass', array('fooarg')); + $def = new Definition('stdClass', ['fooarg']); $def->setAbstract(true); $def->setAutowired(true); @@ -340,13 +340,13 @@ public function testGetChangesWithChanges() $def->setShared(true); $def->setSynthetic(true); // changes aren't tracked for these, class or arguments - $def->setInstanceofConditionals(array()); + $def->setInstanceofConditionals([]); $def->addTag('foo_tag'); $def->addMethodCall('methodCall'); $def->setProperty('fooprop', true); $def->setAutoconfigured(true); - $this->assertSame(array( + $this->assertSame([ 'class' => true, 'autowired' => true, 'configurator' => true, @@ -358,10 +358,10 @@ public function testGetChangesWithChanges() 'public' => true, 'shared' => true, 'autoconfigured' => true, - ), $def->getChanges()); + ], $def->getChanges()); - $def->setChanges(array()); - $this->assertSame(array(), $def->getChanges()); + $def->setChanges([]); + $this->assertSame([], $def->getChanges()); } /** @@ -371,13 +371,13 @@ public function testTypes() { $def = new Definition('stdClass'); - $this->assertEquals(array(), $def->getAutowiringTypes()); - $this->assertSame($def, $def->setAutowiringTypes(array('Foo'))); - $this->assertEquals(array('Foo'), $def->getAutowiringTypes()); + $this->assertEquals([], $def->getAutowiringTypes()); + $this->assertSame($def, $def->setAutowiringTypes(['Foo'])); + $this->assertEquals(['Foo'], $def->getAutowiringTypes()); $this->assertSame($def, $def->addAutowiringType('Bar')); $this->assertTrue($def->hasAutowiringType('Bar')); $this->assertSame($def, $def->removeAutowiringType('Foo')); - $this->assertEquals(array('Bar'), $def->getAutowiringTypes()); + $this->assertEquals(['Bar'], $def->getAutowiringTypes()); } public function testShouldAutoconfigure() @@ -394,6 +394,6 @@ public function testAddError() $this->assertEmpty($def->getErrors()); $def->addError('First error'); $def->addError('Second error'); - $this->assertSame(array('First error', 'Second error'), $def->getErrors()); + $this->assertSame(['First error', 'Second error'], $def->getErrors()); } } diff --git a/Tests/Dumper/GraphvizDumperTest.php b/Tests/Dumper/GraphvizDumperTest.php index 3c40bb550..ea11c7c53 100644 --- a/Tests/Dumper/GraphvizDumperTest.php +++ b/Tests/Dumper/GraphvizDumperTest.php @@ -42,14 +42,14 @@ public function testDump() $container = include self::$fixturesPath.'/containers/container10.php'; $dumper = new GraphvizDumper($container); - $this->assertEquals($dumper->dump(array( - 'graph' => array('ratio' => 'normal'), - 'node' => array('fontsize' => 13, 'fontname' => 'Verdana', 'shape' => 'square'), - 'edge' => array('fontsize' => 12, 'fontname' => 'Verdana', 'color' => 'white', 'arrowhead' => 'closed', 'arrowsize' => 1), - 'node.instance' => array('fillcolor' => 'green', 'style' => 'empty'), - 'node.definition' => array('fillcolor' => 'grey'), - 'node.missing' => array('fillcolor' => 'red', 'style' => 'empty'), - )), file_get_contents(self::$fixturesPath.'/graphviz/services10-1.dot'), '->dump() dumps services'); + $this->assertEquals($dumper->dump([ + 'graph' => ['ratio' => 'normal'], + 'node' => ['fontsize' => 13, 'fontname' => 'Verdana', 'shape' => 'square'], + 'edge' => ['fontsize' => 12, 'fontname' => 'Verdana', 'color' => 'white', 'arrowhead' => 'closed', 'arrowsize' => 1], + 'node.instance' => ['fillcolor' => 'green', 'style' => 'empty'], + 'node.definition' => ['fillcolor' => 'grey'], + 'node.missing' => ['fillcolor' => 'red', 'style' => 'empty'], + ]), file_get_contents(self::$fixturesPath.'/graphviz/services10-1.dot'), '->dump() dumps services'); } public function testDumpWithFrozenContainer() diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index 60fa55c3b..6d985eaca 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -54,14 +54,14 @@ public function testDump() $dumper = new PhpDumper($container); $this->assertStringEqualsFile(self::$fixturesPath.'/php/services1.php', $dumper->dump(), '->dump() dumps an empty container as an empty PHP class'); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services1-1.php', $dumper->dump(array('class' => 'Container', 'base_class' => 'AbstractContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Dump')), '->dump() takes a class and a base_class options'); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services1-1.php', $dumper->dump(['class' => 'Container', 'base_class' => 'AbstractContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Dump']), '->dump() takes a class and a base_class options'); } public function testDumpOptimizationString() { $definition = new Definition(); $definition->setClass('stdClass'); - $definition->addArgument(array( + $definition->addArgument([ 'only dot' => '.', 'concatenation as value' => '.\'\'.', 'concatenation from the start value' => '\'\'.', @@ -73,7 +73,7 @@ public function testDumpOptimizationString() 'optimize concatenation from the start' => '%empty_value%start', 'optimize concatenation at the end' => 'end%empty_value%', 'new line' => "string with \nnew line", - )); + ]); $definition->setPublic(true); $container = new ContainerBuilder(); @@ -92,7 +92,7 @@ public function testDumpRelativeDir() $definition = new Definition(); $definition->setClass('stdClass'); $definition->addArgument('%foo%'); - $definition->addArgument(array('%foo%' => '%buz%/')); + $definition->addArgument(['%foo%' => '%buz%/']); $definition->setPublic(true); $container = new ContainerBuilder(); @@ -104,7 +104,7 @@ public function testDumpRelativeDir() $container->compile(); $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services12.php', $dumper->dump(array('file' => __FILE__)), '->dump() dumps __DIR__ relative strings'); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services12.php', $dumper->dump(['file' => __FILE__]), '->dump() dumps __DIR__ relative strings'); } public function testDumpCustomContainerClassWithoutConstructor() @@ -114,7 +114,7 @@ public function testDumpCustomContainerClassWithoutConstructor() $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_without_constructor.php', $dumper->dump(array('base_class' => 'NoConstructorContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container'))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_without_constructor.php', $dumper->dump(['base_class' => 'NoConstructorContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container'])); } public function testDumpCustomContainerClassConstructorWithoutArguments() @@ -124,7 +124,7 @@ public function testDumpCustomContainerClassConstructorWithoutArguments() $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_constructor_without_arguments.php', $dumper->dump(array('base_class' => 'ConstructorWithoutArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container'))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_constructor_without_arguments.php', $dumper->dump(['base_class' => 'ConstructorWithoutArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container'])); } public function testDumpCustomContainerClassWithOptionalArgumentLessConstructor() @@ -134,7 +134,7 @@ public function testDumpCustomContainerClassWithOptionalArgumentLessConstructor( $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_with_optional_constructor_arguments.php', $dumper->dump(array('base_class' => 'ConstructorWithOptionalArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container'))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_with_optional_constructor_arguments.php', $dumper->dump(['base_class' => 'ConstructorWithOptionalArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container'])); } public function testDumpCustomContainerClassWithMandatoryArgumentLessConstructor() @@ -144,7 +144,7 @@ public function testDumpCustomContainerClassWithMandatoryArgumentLessConstructor $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_with_mandatory_constructor_arguments.php', $dumper->dump(array('base_class' => 'ConstructorWithMandatoryArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container'))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_with_mandatory_constructor_arguments.php', $dumper->dump(['base_class' => 'ConstructorWithMandatoryArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container'])); } /** @@ -161,12 +161,12 @@ public function testExportParameters($parameters) public function provideInvalidParameters() { - return array( - array(array('foo' => new Definition('stdClass'))), - array(array('foo' => new Expression('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")'))), - array(array('foo' => new Reference('foo'))), - array(array('foo' => new Variable('foo'))), - ); + return [ + [['foo' => new Definition('stdClass')]], + [['foo' => new Expression('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")')]], + [['foo' => new Reference('foo')]], + [['foo' => new Variable('foo')]], + ]; } public function testAddParameters() @@ -214,7 +214,7 @@ public function testDumpAsFiles() $container->getDefinition('bar')->addTag('hot'); $container->compile(); $dumper = new PhpDumper($container); - $dump = print_r($dumper->dump(array('as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot')), true); + $dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot']), true); if ('\\' === \DIRECTORY_SEPARATOR) { $dump = str_replace('\\\\Fixtures\\\\includes\\\\foo.php', '/Fixtures/includes/foo.php', $dump); } @@ -238,7 +238,7 @@ public function testAddServiceIdWithUnsupportedCharacters() $container->register('bar$!', 'FooClass')->setPublic(true); $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array('class' => $class))); + eval('?>'.$dumper->dump(['class' => $class])); $this->assertTrue(method_exists($class, 'getBarService')); $this->assertTrue(method_exists($class, 'getBar2Service')); @@ -252,7 +252,7 @@ public function testConflictingServiceIds() $container->register('foobar', 'FooClass')->setPublic(true); $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array('class' => $class))); + eval('?>'.$dumper->dump(['class' => $class])); $this->assertTrue(method_exists($class, 'getFooBarService')); $this->assertTrue(method_exists($class, 'getFoobar2Service')); @@ -266,10 +266,10 @@ public function testConflictingMethodsWithParent() $container->register('foo_bar', 'FooClass')->setPublic(true); $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array( + eval('?>'.$dumper->dump([ 'class' => $class, 'base_class' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\containers\CustomContainer', - ))); + ])); $this->assertTrue(method_exists($class, 'getBar2Service')); $this->assertTrue(method_exists($class, 'getFoobar2Service')); @@ -294,12 +294,12 @@ public function testInvalidFactories($factory) public function provideInvalidFactories() { - return array( - array(array('', 'method')), - array(array('class', '')), - array(array('...', 'method')), - array(array('class', '...')), - ); + return [ + [['', 'method']], + [['class', '']], + [['...', 'method']], + [['class', '...']], + ]; } public function testAliases() @@ -308,7 +308,7 @@ public function testAliases() $container->setParameter('foo_bar', 'foo_bar'); $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Aliases'))); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Aliases'])); $container = new \Symfony_DI_PhpDumper_Test_Aliases(); $foo = $container->get('foo'); @@ -322,7 +322,7 @@ public function testFrozenContainerWithoutAliases() $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Frozen_No_Aliases'))); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Frozen_No_Aliases'])); $container = new \Symfony_DI_PhpDumper_Test_Frozen_No_Aliases(); $this->assertFalse($container->has('foo')); @@ -372,12 +372,12 @@ public function testEnvParameter() $container->compile(); $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services26.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_EnvParameters', 'file' => self::$fixturesPath.'/php/services26.php'))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services26.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_EnvParameters', 'file' => self::$fixturesPath.'/php/services26.php'])); require self::$fixturesPath.'/php/services26.php'; $container = new \Symfony_DI_PhpDumper_Test_EnvParameters(); $this->assertSame($rand, $container->getParameter('baz')); - $this->assertSame(array(123, 'abc'), $container->getParameter('json')); + $this->assertSame([123, 'abc'], $container->getParameter('json')); $this->assertSame('sqlite:///foo/bar/var/data.db', $container->getParameter('db_dsn')); putenv('Baz'); } @@ -389,10 +389,10 @@ public function testResolvedBase64EnvParameters() $container->setParameter('hello', '%env(base64:foo)%'); $container->compile(true); - $expected = array( + $expected = [ 'env(foo)' => 'd29ybGQ=', 'hello' => 'world', - ); + ]; $this->assertSame($expected, $container->getParameterBag()->all()); } @@ -406,7 +406,7 @@ public function testDumpedBase64EnvParameters() $dumper = new PhpDumper($container); $dumper->dump(); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_base64_env.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Base64Parameters'))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_base64_env.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Base64Parameters'])); require self::$fixturesPath.'/php/services_base64_env.php'; $container = new \Symfony_DI_PhpDumper_Test_Base64Parameters(); @@ -424,7 +424,7 @@ public function testCustomEnvParameters() $dumper = new PhpDumper($container); $dumper->dump(); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_rot13_env.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Rot13Parameters'))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_rot13_env.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Rot13Parameters'])); require self::$fixturesPath.'/php/services_rot13_env.php'; $container = new \Symfony_DI_PhpDumper_Test_Rot13Parameters(); @@ -466,7 +466,7 @@ public function testCircularDynamicEnv() $container->compile(); $dumper = new PhpDumper($container); - $dump = $dumper->dump(array('class' => $class = __FUNCTION__)); + $dump = $dumper->dump(['class' => $class = __FUNCTION__]); eval('?>'.$dump); $container = new $class(); @@ -482,7 +482,7 @@ public function testCircularDynamicEnv() public function testInlinedDefinitionReferencingServiceContainer() { $container = new ContainerBuilder(); - $container->register('foo', 'stdClass')->addMethodCall('add', array(new Reference('service_container')))->setPublic(false); + $container->register('foo', 'stdClass')->addMethodCall('add', [new Reference('service_container')])->setPublic(false); $container->register('bar', 'stdClass')->addArgument(new Reference('foo'))->setPublic(true); $container->compile(); @@ -517,7 +517,7 @@ public function testInitializePropertiesBeforeMethodCalls() $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Properties_Before_Method_Calls'))); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Properties_Before_Method_Calls'])); $container = new \Symfony_DI_PhpDumper_Test_Properties_Before_Method_Calls(); $this->assertTrue($container->get('bar')->callPassed(), '->dump() initializes properties before method calls'); @@ -571,15 +571,15 @@ public function testLazyArgumentProvideGenerator() $container ->register('lazy_context', 'LazyContext') ->setPublic(true) - ->setArguments(array( - new IteratorArgument(array('k1' => new Reference('lazy_referenced'), 'k2' => new Reference('service_container'))), - new IteratorArgument(array()), - )) + ->setArguments([ + new IteratorArgument(['k1' => new Reference('lazy_referenced'), 'k2' => new Reference('service_container')]), + new IteratorArgument([]), + ]) ; $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Lazy_Argument_Provide_Generator'))); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Lazy_Argument_Provide_Generator'])); $container = new \Symfony_DI_PhpDumper_Test_Lazy_Argument_Provide_Generator(); $lazyContext = $container->get('lazy_context'); @@ -618,8 +618,8 @@ public function testNormalizedId() public function testDumpContainerBuilderWithFrozenConstructorIncludingPrivateServices() { $container = new ContainerBuilder(); - $container->register('foo_service', 'stdClass')->setArguments(array(new Reference('baz_service')))->setPublic(true); - $container->register('bar_service', 'stdClass')->setArguments(array(new Reference('baz_service')))->setPublic(true); + $container->register('foo_service', 'stdClass')->setArguments([new Reference('baz_service')])->setPublic(true); + $container->register('bar_service', 'stdClass')->setArguments([new Reference('baz_service')])->setPublic(true); $container->register('baz_service', 'stdClass')->setPublic(false); $container->compile(); @@ -633,20 +633,20 @@ public function testServiceLocator() $container = new ContainerBuilder(); $container->register('foo_service', ServiceLocator::class) ->setPublic(true) - ->addArgument(array( + ->addArgument([ 'bar' => new ServiceClosureArgument(new Reference('bar_service')), 'baz' => new ServiceClosureArgument(new TypedReference('baz_service', 'stdClass')), 'nil' => $nil = new ServiceClosureArgument(new Reference('nil')), - )) + ]) ; // no method calls $container->register('translator.loader_1', 'stdClass')->setPublic(true); $container->register('translator.loader_1_locator', ServiceLocator::class) ->setPublic(false) - ->addArgument(array( + ->addArgument([ 'translator.loader_1' => new ServiceClosureArgument(new Reference('translator.loader_1')), - )); + ]); $container->register('translator_1', StubbedTranslator::class) ->setPublic(true) ->addArgument(new Reference('translator.loader_1_locator')); @@ -655,29 +655,29 @@ public function testServiceLocator() $container->register('translator.loader_2', 'stdClass')->setPublic(true); $container->register('translator.loader_2_locator', ServiceLocator::class) ->setPublic(false) - ->addArgument(array( + ->addArgument([ 'translator.loader_2' => new ServiceClosureArgument(new Reference('translator.loader_2')), - )); + ]); $container->register('translator_2', StubbedTranslator::class) ->setPublic(true) ->addArgument(new Reference('translator.loader_2_locator')) - ->addMethodCall('addResource', array('db', new Reference('translator.loader_2'), 'nl')); + ->addMethodCall('addResource', ['db', new Reference('translator.loader_2'), 'nl']); // two method calls $container->register('translator.loader_3', 'stdClass')->setPublic(true); $container->register('translator.loader_3_locator', ServiceLocator::class) ->setPublic(false) - ->addArgument(array( + ->addArgument([ 'translator.loader_3' => new ServiceClosureArgument(new Reference('translator.loader_3')), - )); + ]); $container->register('translator_3', StubbedTranslator::class) ->setPublic(true) ->addArgument(new Reference('translator.loader_3_locator')) - ->addMethodCall('addResource', array('db', new Reference('translator.loader_3'), 'nl')) - ->addMethodCall('addResource', array('db', new Reference('translator.loader_3'), 'en')); + ->addMethodCall('addResource', ['db', new Reference('translator.loader_3'), 'nl']) + ->addMethodCall('addResource', ['db', new Reference('translator.loader_3'), 'en']); - $nil->setValues(array(null)); - $container->register('bar_service', 'stdClass')->setArguments(array(new Reference('baz_service')))->setPublic(true); + $nil->setValues([null]); + $container->register('bar_service', 'stdClass')->setArguments([new Reference('baz_service')])->setPublic(true); $container->register('baz_service', 'stdClass')->setPublic(false); $container->compile(); @@ -693,10 +693,10 @@ public function testServiceSubscriber() ->setPublic(true) ->setAutowired(true) ->addArgument(new Reference(ContainerInterface::class)) - ->addTag('container.service_subscriber', array( + ->addTag('container.service_subscriber', [ 'key' => 'bar', 'id' => TestServiceSubscriber::class, - )) + ]) ; $container->register(TestServiceSubscriber::class, TestServiceSubscriber::class)->setPublic(true); @@ -718,11 +718,11 @@ public function testPrivateWithIgnoreOnInvalidReference() ->setPublic(false); $container->register('bar', 'BarClass') ->setPublic(true) - ->addMethodCall('setBaz', array(new Reference('not_invalid', SymfonyContainerInterface::IGNORE_ON_INVALID_REFERENCE))); + ->addMethodCall('setBaz', [new Reference('not_invalid', SymfonyContainerInterface::IGNORE_ON_INVALID_REFERENCE)]); $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Private_With_Ignore_On_Invalid_Reference'))); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Private_With_Ignore_On_Invalid_Reference'])); $container = new \Symfony_DI_PhpDumper_Test_Private_With_Ignore_On_Invalid_Reference(); $this->assertInstanceOf('BazClass', $container->get('bar')->getBaz()); @@ -731,16 +731,16 @@ public function testPrivateWithIgnoreOnInvalidReference() public function testArrayParameters() { $container = new ContainerBuilder(); - $container->setParameter('array_1', array(123)); - $container->setParameter('array_2', array(__DIR__)); + $container->setParameter('array_1', [123]); + $container->setParameter('array_2', [__DIR__]); $container->register('bar', 'BarClass') ->setPublic(true) - ->addMethodCall('setBaz', array('%array_1%', '%array_2%', '%%array_1%%', array(123))); + ->addMethodCall('setBaz', ['%array_1%', '%array_2%', '%%array_1%%', [123]]); $container->compile(); $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_array_params.php', str_replace('\\\\Dumper', '/Dumper', $dumper->dump(array('file' => self::$fixturesPath.'/php/services_array_params.php')))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_array_params.php', str_replace('\\\\Dumper', '/Dumper', $dumper->dump(['file' => self::$fixturesPath.'/php/services_array_params.php']))); } public function testExpressionReferencingPrivateService() @@ -766,7 +766,7 @@ public function testUninitializedReference() $container->compile(); $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_uninitialized_ref.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Uninitialized_Reference'))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_uninitialized_ref.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Uninitialized_Reference'])); require self::$fixturesPath.'/php/services_uninitialized_ref.php'; @@ -780,7 +780,7 @@ public function testUninitializedReference() $this->assertNull($bar->closures[0]()); $this->assertNull($bar->closures[1]()); $this->assertNull($bar->closures[2]()); - $this->assertSame(array(), iterator_to_array($bar->iter)); + $this->assertSame([], iterator_to_array($bar->iter)); $container = new \Symfony_DI_PhpDumper_Test_Uninitialized_Reference(); @@ -795,7 +795,7 @@ public function testUninitializedReference() $this->assertEquals(new \stdClass(), $bar->closures[0]()); $this->assertNull($bar->closures[1]()); $this->assertEquals(new \stdClass(), $bar->closures[2]()); - $this->assertEquals(array('foo1' => new \stdClass(), 'foo3' => new \stdClass()), iterator_to_array($bar->iter)); + $this->assertEquals(['foo1' => new \stdClass(), 'foo3' => new \stdClass()], iterator_to_array($bar->iter)); } /** @@ -808,7 +808,7 @@ public function testAlmostCircular($visibility) $dumper = new PhpDumper($container); $container = 'Symfony_DI_PhpDumper_Test_Almost_Circular_'.ucfirst($visibility); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_almost_circular_'.$visibility.'.php', $dumper->dump(array('class' => $container))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_almost_circular_'.$visibility.'.php', $dumper->dump(['class' => $container])); require self::$fixturesPath.'/php/services_almost_circular_'.$visibility.'.php'; @@ -820,7 +820,7 @@ public function testAlmostCircular($visibility) $foo2 = $container->get('foo2'); $this->assertSame($foo2, $foo2->bar->foobar->foo); - $this->assertSame(array(), (array) $container->get('foobar4')); + $this->assertSame([], (array) $container->get('foobar4')); $foo5 = $container->get('foo5'); $this->assertSame($foo5, $foo5->bar->foo); @@ -832,15 +832,15 @@ public function testAlmostCircular($visibility) $this->assertEquals(new \stdClass(), $manager); $foo6 = $container->get('foo6'); - $this->assertEquals((object) array('bar6' => (object) array()), $foo6); + $this->assertEquals((object) ['bar6' => (object) []], $foo6); $this->assertInstanceOf(\stdClass::class, $container->get('root')); } public function provideAlmostCircular() { - yield array('public'); - yield array('private'); + yield ['public']; + yield ['private']; } public function testDeepServiceGraph() @@ -855,14 +855,14 @@ public function testDeepServiceGraph() $dumper = new PhpDumper($container); $dumper->dump(); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_deep_graph.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Deep_Graph'))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_deep_graph.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Deep_Graph'])); require self::$fixturesPath.'/php/services_deep_graph.php'; $container = new \Symfony_DI_PhpDumper_Test_Deep_Graph(); $this->assertInstanceOf(FooForDeepGraph::class, $container->get('foo')); - $this->assertEquals((object) array('p2' => (object) array('p3' => (object) array())), $container->get('foo')->bClone); + $this->assertEquals((object) ['p2' => (object) ['p3' => (object) []]], $container->get('foo')->bClone); } public function testInlineSelfRef() @@ -884,7 +884,7 @@ public function testInlineSelfRef() $container->compile(); $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_inline_self_ref.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Inline_Self_Ref'))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_inline_self_ref.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Inline_Self_Ref'])); } public function testHotPathOptimizations() @@ -894,7 +894,7 @@ public function testHotPathOptimizations() $container->compile(); $dumper = new PhpDumper($container); - $dump = $dumper->dump(array('hot_path_tag' => 'container.hot_path', 'inline_class_loader_parameter' => 'inline_requires', 'file' => self::$fixturesPath.'/php/services_inline_requires.php')); + $dump = $dumper->dump(['hot_path_tag' => 'container.hot_path', 'inline_class_loader_parameter' => 'inline_requires', 'file' => self::$fixturesPath.'/php/services_inline_requires.php']); if ('\\' === \DIRECTORY_SEPARATOR) { $dump = str_replace("'\\\\includes\\\\HotPath\\\\", "'/includes/HotPath/", $dump); } @@ -909,7 +909,7 @@ public function testDumpHandlesLiteralClassWithRootNamespace() $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace'))); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace'])); $container = new \Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace(); @@ -918,23 +918,23 @@ public function testDumpHandlesLiteralClassWithRootNamespace() public function testDumpHandlesObjectClassNames() { - $container = new ContainerBuilder(new ParameterBag(array( + $container = new ContainerBuilder(new ParameterBag([ 'class' => 'stdClass', - ))); + ])); $container->setDefinition('foo', new Definition(new Parameter('class'))); - $container->setDefinition('bar', new Definition('stdClass', array( + $container->setDefinition('bar', new Definition('stdClass', [ new Reference('foo'), - )))->setPublic(true); + ]))->setPublic(true); $container->setParameter('inline_requires', true); $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array( + eval('?>'.$dumper->dump([ 'class' => 'Symfony_DI_PhpDumper_Test_Object_Class_Name', 'inline_class_loader_parameter' => 'inline_requires', - ))); + ])); $container = new \Symfony_DI_PhpDumper_Test_Object_Class_Name(); @@ -951,17 +951,17 @@ public function testUninitializedSyntheticReference() $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array( + eval('?>'.$dumper->dump([ 'class' => 'Symfony_DI_PhpDumper_Test_UninitializedSyntheticReference', 'inline_class_loader_parameter' => 'inline_requires', - ))); + ])); $container = new \Symfony_DI_PhpDumper_Test_UninitializedSyntheticReference(); - $this->assertEquals((object) array('foo' => null), $container->get('bar')); + $this->assertEquals((object) ['foo' => null], $container->get('bar')); - $container->set('foo', (object) array(123)); - $this->assertEquals((object) array('foo' => (object) array(123)), $container->get('bar')); + $container->set('foo', (object) [123]); + $this->assertEquals((object) ['foo' => (object) [123]], $container->get('bar')); } public function testAdawsonContainer() @@ -1007,7 +1007,7 @@ public function testLegacyPrivateServices() $container->compile(); $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_legacy_privates.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Legacy_Privates', 'file' => self::$fixturesPath.'/php/services_legacy_privates.php'))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_legacy_privates.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Legacy_Privates', 'file' => self::$fixturesPath.'/php/services_legacy_privates.php'])); require self::$fixturesPath.'/php/services_legacy_privates.php'; @@ -1044,7 +1044,7 @@ public function testPrivateServiceTriggersDeprecation() $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Private_Service_Triggers_Deprecation'))); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Private_Service_Triggers_Deprecation'])); $container = new \Symfony_DI_PhpDumper_Test_Private_Service_Triggers_Deprecation(); @@ -1059,11 +1059,11 @@ public function testPrivateServiceTriggersDeprecation() */ public function testParameterWithMixedCase() { - $container = new ContainerBuilder(new ParameterBag(array('Foo' => 'bar', 'BAR' => 'foo'))); + $container = new ContainerBuilder(new ParameterBag(['Foo' => 'bar', 'BAR' => 'foo'])); $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Parameter_With_Mixed_Case'))); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Parameter_With_Mixed_Case'])); $container = new \Symfony_DI_PhpDumper_Test_Parameter_With_Mixed_Case(); @@ -1079,11 +1079,11 @@ public function testParameterWithMixedCase() */ public function testParameterWithLowerCase() { - $container = new ContainerBuilder(new ParameterBag(array('foo' => 'bar'))); + $container = new ContainerBuilder(new ParameterBag(['foo' => 'bar'])); $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Parameter_With_Lower_Case'))); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Parameter_With_Lower_Case'])); $container = new \Symfony_DI_PhpDumper_Test_Parameter_With_Lower_Case(); @@ -1103,11 +1103,11 @@ public function testReferenceWithLowerCaseId() $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Reference_With_Lower_Case_Id'))); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Reference_With_Lower_Case_Id'])); $container = new \Symfony_DI_PhpDumper_Test_Reference_With_Lower_Case_Id(); - $this->assertEquals((object) array('foo' => (object) array()), $container->get('Bar')); + $this->assertEquals((object) ['foo' => (object) []], $container->get('Bar')); } } @@ -1120,7 +1120,7 @@ public function getEnv($prefix, $name, \Closure $getEnv) public static function getProvidedTypes() { - return array('rot13' => 'string'); + return ['rot13' => 'string']; } } diff --git a/Tests/Dumper/XmlDumperTest.php b/Tests/Dumper/XmlDumperTest.php index f33b3b8d7..ac274c6f2 100644 --- a/Tests/Dumper/XmlDumperTest.php +++ b/Tests/Dumper/XmlDumperTest.php @@ -123,8 +123,8 @@ public function provideDecoratedServicesData() { $fixturesPath = realpath(__DIR__.'/../Fixtures/'); - return array( - array(" + return [ + [" @@ -133,8 +133,8 @@ public function provideDecoratedServicesData() -", include $fixturesPath.'/containers/container15.php'), - array(" +", include $fixturesPath.'/containers/container15.php'], + [" @@ -143,8 +143,8 @@ public function provideDecoratedServicesData() -", include $fixturesPath.'/containers/container16.php'), - ); +", include $fixturesPath.'/containers/container16.php'], + ]; } /** @@ -163,13 +163,13 @@ public function testCompiledContainerCanBeDumped($containerFile) public function provideCompiledContainerData() { - return array( - array('container8'), - array('container9'), - array('container11'), - array('container12'), - array('container14'), - ); + return [ + ['container8'], + ['container9'], + ['container11'], + ['container12'], + ['container14'], + ]; } public function testDumpInlinedServices() @@ -194,7 +194,7 @@ public function testDumpLoad() $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('services_dump_load.xml'); - $this->assertEquals(array(new Reference('bar', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE)), $container->getDefinition('foo')->getArguments()); + $this->assertEquals([new Reference('bar', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE)], $container->getDefinition('foo')->getArguments()); $dumper = new XmlDumper($container); $this->assertStringEqualsFile(self::$fixturesPath.'/xml/services_dump_load.xml', $dumper->dump()); diff --git a/Tests/Dumper/YamlDumperTest.php b/Tests/Dumper/YamlDumperTest.php index ff2239fb6..49ee8e6f3 100644 --- a/Tests/Dumper/YamlDumperTest.php +++ b/Tests/Dumper/YamlDumperTest.php @@ -75,7 +75,7 @@ public function testDumpLoad() $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('services_dump_load.yml'); - $this->assertEquals(array(new Reference('bar', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE)), $container->getDefinition('foo')->getArguments()); + $this->assertEquals([new Reference('bar', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE)], $container->getDefinition('foo')->getArguments()); $dumper = new YamlDumper($container); $this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services_dump_load.yml', $dumper->dump()); diff --git a/Tests/EnvVarProcessorTest.php b/Tests/EnvVarProcessorTest.php index b1ee044e9..972350467 100644 --- a/Tests/EnvVarProcessorTest.php +++ b/Tests/EnvVarProcessorTest.php @@ -31,16 +31,16 @@ public function testGetEnvString($value, $processed) public function validStrings() { - return array( - array('hello', 'hello'), - array('true', 'true'), - array('false', 'false'), - array('null', 'null'), - array('1', '1'), - array('0', '0'), - array('1.1', '1.1'), - array('1e1', '1e1'), - ); + return [ + ['hello', 'hello'], + ['true', 'true'], + ['false', 'false'], + ['null', 'null'], + ['1', '1'], + ['0', '0'], + ['1.1', '1.1'], + ['1e1', '1e1'], + ]; } /** @@ -61,15 +61,15 @@ public function testGetEnvBool($value, $processed) public function validBools() { - return array( - array('true', true), - array('false', false), - array('null', false), - array('1', true), - array('0', false), - array('1.1', true), - array('1e1', true), - ); + return [ + ['true', true], + ['false', false], + ['null', false], + ['1', true], + ['0', false], + ['1.1', true], + ['1e1', true], + ]; } /** @@ -90,11 +90,11 @@ public function testGetEnvInt($value, $processed) public function validInts() { - return array( - array('1', 1), - array('1.1', 1), - array('1e1', 10), - ); + return [ + ['1', 1], + ['1.1', 1], + ['1e1', 10], + ]; } /** @@ -115,11 +115,11 @@ public function testGetEnvIntInvalid($value) public function invalidInts() { - return array( - array('foo'), - array('true'), - array('null'), - ); + return [ + ['foo'], + ['true'], + ['null'], + ]; } /** @@ -140,11 +140,11 @@ public function testGetEnvFloat($value, $processed) public function validFloats() { - return array( - array('1', 1.0), - array('1.1', 1.1), - array('1e1', 10.0), - ); + return [ + ['1', 1.0], + ['1.1', 1.1], + ['1e1', 10.0], + ]; } /** @@ -165,11 +165,11 @@ public function testGetEnvFloatInvalid($value) public function invalidFloats() { - return array( - array('foo'), - array('true'), - array('null'), - ); + return [ + ['foo'], + ['true'], + ['null'], + ]; } /** @@ -190,10 +190,10 @@ public function testGetEnvConst($value, $processed) public function validConsts() { - return array( - array('Symfony\Component\DependencyInjection\Tests\EnvVarProcessorTest::TEST_CONST', self::TEST_CONST), - array('E_ERROR', E_ERROR), - ); + return [ + ['Symfony\Component\DependencyInjection\Tests\EnvVarProcessorTest::TEST_CONST', self::TEST_CONST], + ['E_ERROR', E_ERROR], + ]; } /** @@ -214,10 +214,10 @@ public function testGetEnvConstInvalid($value) public function invalidConsts() { - return array( - array('Symfony\Component\DependencyInjection\Tests\EnvVarProcessorTest::UNDEFINED_CONST'), - array('UNDEFINED_CONST'), - ); + return [ + ['Symfony\Component\DependencyInjection\Tests\EnvVarProcessorTest::UNDEFINED_CONST'], + ['UNDEFINED_CONST'], + ]; } public function testGetEnvBase64() @@ -240,10 +240,10 @@ public function testGetEnvJson() $result = $processor->getEnv('json', 'foo', function ($name) { $this->assertSame('foo', $name); - return json_encode(array(1)); + return json_encode([1]); }); - $this->assertSame(array(1), $result); + $this->assertSame([1], $result); } /** @@ -279,12 +279,12 @@ public function testGetEnvJsonOther($value) public function otherJsonValues() { - return array( - array(1), - array(1.1), - array(true), - array(false), - ); + return [ + [1], + [1.1], + [true], + [false], + ]; } /** diff --git a/Tests/Extension/ExtensionTest.php b/Tests/Extension/ExtensionTest.php index 9f66bfd7c..3c912f2a1 100644 --- a/Tests/Extension/ExtensionTest.php +++ b/Tests/Extension/ExtensionTest.php @@ -23,15 +23,15 @@ class ExtensionTest extends TestCase public function testIsConfigEnabledReturnsTheResolvedValue($enabled) { $extension = new EnableableExtension(); - $this->assertSame($enabled, $extension->isConfigEnabled(new ContainerBuilder(), array('enabled' => $enabled))); + $this->assertSame($enabled, $extension->isConfigEnabled(new ContainerBuilder(), ['enabled' => $enabled])); } public function getResolvedEnabledFixtures() { - return array( - array(true), - array(false), - ); + return [ + [true], + [false], + ]; } /** @@ -42,7 +42,7 @@ public function testIsConfigEnabledOnNonEnableableConfig() { $extension = new EnableableExtension(); - $extension->isConfigEnabled(new ContainerBuilder(), array()); + $extension->isConfigEnabled(new ContainerBuilder(), []); } } diff --git a/Tests/Loader/DirectoryLoaderTest.php b/Tests/Loader/DirectoryLoaderTest.php index 559abbe25..c7c303b68 100644 --- a/Tests/Loader/DirectoryLoaderTest.php +++ b/Tests/Loader/DirectoryLoaderTest.php @@ -37,25 +37,25 @@ protected function setUp() $locator = new FileLocator(self::$fixturesPath); $this->container = new ContainerBuilder(); $this->loader = new DirectoryLoader($this->container, $locator); - $resolver = new LoaderResolver(array( + $resolver = new LoaderResolver([ new PhpFileLoader($this->container, $locator), new IniFileLoader($this->container, $locator), new YamlFileLoader($this->container, $locator), $this->loader, - )); + ]); $this->loader->setResolver($resolver); } public function testDirectoryCanBeLoadedRecursively() { $this->loader->load('directory/'); - $this->assertEquals(array('ini' => 'ini', 'yaml' => 'yaml', 'php' => 'php'), $this->container->getParameterBag()->all(), '->load() takes a single directory'); + $this->assertEquals(['ini' => 'ini', 'yaml' => 'yaml', 'php' => 'php'], $this->container->getParameterBag()->all(), '->load() takes a single directory'); } public function testImports() { $this->loader->resolve('directory/import/import.yml')->load('directory/import/import.yml'); - $this->assertEquals(array('ini' => 'ini', 'yaml' => 'yaml'), $this->container->getParameterBag()->all(), '->load() takes a single file that imports a directory'); + $this->assertEquals(['ini' => 'ini', 'yaml' => 'yaml'], $this->container->getParameterBag()->all(), '->load() takes a single file that imports a directory'); } /** diff --git a/Tests/Loader/FileLoaderTest.php b/Tests/Loader/FileLoaderTest.php index 73015084a..065acdf1b 100644 --- a/Tests/Loader/FileLoaderTest.php +++ b/Tests/Loader/FileLoaderTest.php @@ -47,21 +47,21 @@ public function testImportWithGlobPattern() $container = new ContainerBuilder(); $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath)); - $resolver = new LoaderResolver(array( + $resolver = new LoaderResolver([ new IniFileLoader($container, new FileLocator(self::$fixturesPath.'/ini')), new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')), new PhpFileLoader($container, new FileLocator(self::$fixturesPath.'/php')), new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')), - )); + ]); $loader->setResolver($resolver); $loader->import('{F}ixtures/{xml,yaml}/services2.{yml,xml}'); $actual = $container->getParameterBag()->all(); - $expected = array( + $expected = [ 'a string', 'foo' => 'bar', - 'values' => array( + 'values' => [ 0, 'integer' => 4, 100 => null, @@ -73,14 +73,14 @@ public function testImportWithGlobPattern() 'float' => 1.3, 1000.3, 'a string', - array('foo', 'bar'), - ), - 'mixedcase' => array('MixedCaseKey' => 'value'), + ['foo', 'bar'], + ], + 'mixedcase' => ['MixedCaseKey' => 'value'], 'constant' => PHP_EOL, 'bar' => '%foo%', 'escape' => '@escapeme', 'foo_bar' => new Reference('foo_bar'), - ); + ]; $this->assertEquals(array_keys($expected), array_keys($actual), '->load() imports and merges imported files'); } @@ -94,15 +94,15 @@ public function testRegisterClasses() $loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\\', 'Prototype/%sub_dir%/*'); $this->assertEquals( - array('service_container', Bar::class), + ['service_container', Bar::class], array_keys($container->getDefinitions()) ); $this->assertEquals( - array( + [ PsrContainerInterface::class, ContainerInterface::class, BarInterface::class, - ), + ], array_keys($container->getAliases()) ); } @@ -127,11 +127,11 @@ public function testRegisterClassesWithExclude() $this->assertFalse($container->has(DeeperBaz::class)); $this->assertEquals( - array( + [ PsrContainerInterface::class, ContainerInterface::class, BarInterface::class, - ), + ], array_keys($container->getAliases()) ); } @@ -150,11 +150,11 @@ public function testNestedRegisterClasses() $this->assertTrue($container->has(Foo::class)); $this->assertEquals( - array( + [ PsrContainerInterface::class, ContainerInterface::class, FooInterface::class, - ), + ], array_keys($container->getAliases()) ); @@ -179,7 +179,7 @@ public function testMissingParentClass() $this->assertTrue($container->has(MissingParent::class)); $this->assertSame( - array('While discovering services from namespace "Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\", an error was thrown when processing the class "Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\MissingParent": "Class Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\MissingClass not found".'), + ['While discovering services from namespace "Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\", an error was thrown when processing the class "Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\MissingParent": "Class Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\MissingClass not found".'], $container->getDefinition(MissingParent::class)->getErrors() ); } @@ -222,8 +222,8 @@ public function testRegisterClassesWithIncompatibleExclude($resourcePattern, $ex public function getIncompatibleExcludeTests() { - yield array('Prototype/*', 'yaml/*', false); - yield array('Prototype/OtherDir/*', 'Prototype/*', false); + yield ['Prototype/*', 'yaml/*', false]; + yield ['Prototype/OtherDir/*', 'Prototype/*', false]; } } diff --git a/Tests/Loader/IniFileLoaderTest.php b/Tests/Loader/IniFileLoaderTest.php index c2332f822..1d7d3a93e 100644 --- a/Tests/Loader/IniFileLoaderTest.php +++ b/Tests/Loader/IniFileLoaderTest.php @@ -30,7 +30,7 @@ protected function setUp() public function testIniFileCanBeLoaded() { $this->loader->load('parameters.ini'); - $this->assertEquals(array('foo' => 'bar', 'bar' => '%foo%'), $this->container->getParameterBag()->all(), '->load() takes a single file name as its first argument'); + $this->assertEquals(['foo' => 'bar', 'bar' => '%foo%'], $this->container->getParameterBag()->all(), '->load() takes a single file name as its first argument'); } /** @@ -64,35 +64,35 @@ public function testTypeConversionsWithNativePhp($key, $value, $supported) public function getTypeConversions() { - return array( - array('true_comment', true, true), - array('true', true, true), - array('false', false, true), - array('on', true, true), - array('off', false, true), - array('yes', true, true), - array('no', false, true), - array('none', false, true), - array('null', null, true), - array('constant', PHP_VERSION, true), - array('12', 12, true), - array('12_string', '12', true), - array('12_quoted_number', 12, false), // INI_SCANNER_RAW removes the double quotes - array('12_comment', 12, true), - array('12_string_comment', '12', true), - array('12_quoted_number_comment', 12, false), // INI_SCANNER_RAW removes the double quotes - array('-12', -12, true), - array('1', 1, true), - array('0', 0, true), - array('0b0110', bindec('0b0110'), false), // not supported by INI_SCANNER_TYPED - array('11112222333344445555', '1111,2222,3333,4444,5555', true), - array('0777', 0777, false), // not supported by INI_SCANNER_TYPED - array('255', 0xFF, false), // not supported by INI_SCANNER_TYPED - array('100.0', 1e2, false), // not supported by INI_SCANNER_TYPED - array('-120.0', -1.2E2, false), // not supported by INI_SCANNER_TYPED - array('-10100.1', -10100.1, false), // not supported by INI_SCANNER_TYPED - array('-10,100.1', '-10,100.1', true), - ); + return [ + ['true_comment', true, true], + ['true', true, true], + ['false', false, true], + ['on', true, true], + ['off', false, true], + ['yes', true, true], + ['no', false, true], + ['none', false, true], + ['null', null, true], + ['constant', PHP_VERSION, true], + ['12', 12, true], + ['12_string', '12', true], + ['12_quoted_number', 12, false], // INI_SCANNER_RAW removes the double quotes + ['12_comment', 12, true], + ['12_string_comment', '12', true], + ['12_quoted_number_comment', 12, false], // INI_SCANNER_RAW removes the double quotes + ['-12', -12, true], + ['1', 1, true], + ['0', 0, true], + ['0b0110', bindec('0b0110'), false], // not supported by INI_SCANNER_TYPED + ['11112222333344445555', '1111,2222,3333,4444,5555', true], + ['0777', 0777, false], // not supported by INI_SCANNER_TYPED + ['255', 0xFF, false], // not supported by INI_SCANNER_TYPED + ['100.0', 1e2, false], // not supported by INI_SCANNER_TYPED + ['-120.0', -1.2E2, false], // not supported by INI_SCANNER_TYPED + ['-10100.1', -10100.1, false], // not supported by INI_SCANNER_TYPED + ['-10,100.1', '-10,100.1', true], + ]; } /** diff --git a/Tests/Loader/LoaderResolverTest.php b/Tests/Loader/LoaderResolverTest.php index cb2d6ddcc..9167e18ce 100644 --- a/Tests/Loader/LoaderResolverTest.php +++ b/Tests/Loader/LoaderResolverTest.php @@ -33,23 +33,23 @@ protected function setUp() self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); $container = new ContainerBuilder(); - $this->resolver = new LoaderResolver(array( + $this->resolver = new LoaderResolver([ new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')), new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')), new IniFileLoader($container, new FileLocator(self::$fixturesPath.'/ini')), new PhpFileLoader($container, new FileLocator(self::$fixturesPath.'/php')), new ClosureLoader($container), - )); + ]); } public function provideResourcesToLoad() { - return array( - array('ini_with_wrong_ext.xml', 'ini', IniFileLoader::class), - array('xml_with_wrong_ext.php', 'xml', XmlFileLoader::class), - array('php_with_wrong_ext.yml', 'php', PhpFileLoader::class), - array('yaml_with_wrong_ext.ini', 'yaml', YamlFileLoader::class), - ); + return [ + ['ini_with_wrong_ext.xml', 'ini', IniFileLoader::class], + ['xml_with_wrong_ext.php', 'xml', XmlFileLoader::class], + ['php_with_wrong_ext.yml', 'php', PhpFileLoader::class], + ['yaml_with_wrong_ext.ini', 'yaml', YamlFileLoader::class], + ]; } /** diff --git a/Tests/Loader/PhpFileLoaderTest.php b/Tests/Loader/PhpFileLoaderTest.php index e0a21e880..4f7c16890 100644 --- a/Tests/Loader/PhpFileLoaderTest.php +++ b/Tests/Loader/PhpFileLoaderTest.php @@ -66,14 +66,14 @@ public function testConfig($file) public function provideConfig() { - yield array('basic'); - yield array('defaults'); - yield array('instanceof'); - yield array('prototype'); - yield array('child'); + yield ['basic']; + yield ['defaults']; + yield ['instanceof']; + yield ['prototype']; + yield ['child']; if (\PHP_VERSION_ID >= 70000) { - yield array('php7'); + yield ['php7']; } } diff --git a/Tests/Loader/XmlFileLoaderTest.php b/Tests/Loader/XmlFileLoaderTest.php index 2a9ac68e9..c265c00e8 100644 --- a/Tests/Loader/XmlFileLoaderTest.php +++ b/Tests/Loader/XmlFileLoaderTest.php @@ -112,10 +112,10 @@ public function testLoadParameters() $loader->load('services2.xml'); $actual = $container->getParameterBag()->all(); - $expected = array( + $expected = [ 'a string', 'foo' => 'bar', - 'values' => array( + 'values' => [ 0, 'integer' => 4, 100 => null, @@ -127,11 +127,11 @@ public function testLoadParameters() 'float' => 1.3, 1000.3, 'a string', - array('foo', 'bar'), - ), - 'mixedcase' => array('MixedCaseKey' => 'value'), + ['foo', 'bar'], + ], + 'mixedcase' => ['MixedCaseKey' => 'value'], 'constant' => PHP_EOL, - ); + ]; $this->assertEquals($expected, $actual, '->load() converts XML values to PHP ones'); } @@ -139,19 +139,19 @@ public function testLoadParameters() public function testLoadImports() { $container = new ContainerBuilder(); - $resolver = new LoaderResolver(array( + $resolver = new LoaderResolver([ new IniFileLoader($container, new FileLocator(self::$fixturesPath.'/ini')), new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yml')), $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')), - )); + ]); $loader->setResolver($resolver); $loader->load('services4.xml'); $actual = $container->getParameterBag()->all(); - $expected = array( + $expected = [ 'a string', 'foo' => 'bar', - 'values' => array( + 'values' => [ 0, 'integer' => 4, 100 => null, @@ -163,15 +163,15 @@ public function testLoadImports() 'float' => 1.3, 1000.3, 'a string', - array('foo', 'bar'), - ), - 'mixedcase' => array('MixedCaseKey' => 'value'), + ['foo', 'bar'], + ], + 'mixedcase' => ['MixedCaseKey' => 'value'], 'constant' => PHP_EOL, 'bar' => '%foo%', 'imported_from_ini' => true, 'imported_from_yaml' => true, 'with_wrong_ext' => 'from yaml', - ); + ]; $this->assertEquals(array_keys($expected), array_keys($actual), '->load() imports and merges imported files'); $this->assertTrue($actual['imported_from_ini']); @@ -266,16 +266,16 @@ public function testLoadServices() $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts element to Definition instances'); $this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute'); $this->assertEquals('%path%/foo.php', $services['file']->getFile(), '->load() parses the file tag'); - $this->assertEquals(array('foo', new Reference('foo'), array(true, false)), $services['arguments']->getArguments(), '->load() parses the argument tags'); + $this->assertEquals(['foo', new Reference('foo'), [true, false]], $services['arguments']->getArguments(), '->load() parses the argument tags'); $this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag'); - $this->assertEquals(array(new Reference('baz'), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag'); - $this->assertEquals(array('BazClass', 'configureStatic'), $services['configurator3']->getConfigurator(), '->load() parses the configurator tag'); - $this->assertEquals(array(array('setBar', array()), array('setBar', array(new Expression('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")')))), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag'); - $this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag'); + $this->assertEquals([new Reference('baz'), 'configure'], $services['configurator2']->getConfigurator(), '->load() parses the configurator tag'); + $this->assertEquals(['BazClass', 'configureStatic'], $services['configurator3']->getConfigurator(), '->load() parses the configurator tag'); + $this->assertEquals([['setBar', []], ['setBar', [new Expression('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")')]]], $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag'); + $this->assertEquals([['setBar', ['foo', new Reference('foo'), [true, false]]]], $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag'); $this->assertEquals('factory', $services['new_factory1']->getFactory(), '->load() parses the factory tag'); - $this->assertEquals(array(new Reference('baz'), 'getClass'), $services['new_factory2']->getFactory(), '->load() parses the factory tag'); - $this->assertEquals(array('BazClass', 'getInstance'), $services['new_factory3']->getFactory(), '->load() parses the factory tag'); - $this->assertSame(array(null, 'getInstance'), $services['new_factory4']->getFactory(), '->load() accepts factory tag without class'); + $this->assertEquals([new Reference('baz'), 'getClass'], $services['new_factory2']->getFactory(), '->load() parses the factory tag'); + $this->assertEquals(['BazClass', 'getInstance'], $services['new_factory3']->getFactory(), '->load() parses the factory tag'); + $this->assertSame([null, 'getInstance'], $services['new_factory4']->getFactory(), '->load() accepts factory tag without class'); $aliases = $container->getAliases(); $this->assertArrayHasKey('alias_for_foo', $aliases, '->load() parses elements'); @@ -285,9 +285,9 @@ public function testLoadServices() $this->assertEquals('foo', (string) $aliases['another_alias_for_foo']); $this->assertFalse($aliases['another_alias_for_foo']->isPublic()); - $this->assertEquals(array('decorated', null, 0), $services['decorator_service']->getDecoratedService()); - $this->assertEquals(array('decorated', 'decorated.pif-pouf', 0), $services['decorator_service_with_name']->getDecoratedService()); - $this->assertEquals(array('decorated', 'decorated.pif-pouf', 5), $services['decorator_service_with_name_and_priority']->getDecoratedService()); + $this->assertEquals(['decorated', null, 0], $services['decorator_service']->getDecoratedService()); + $this->assertEquals(['decorated', 'decorated.pif-pouf', 0], $services['decorator_service_with_name']->getDecoratedService()); + $this->assertEquals(['decorated', 'decorated.pif-pouf', 5], $services['decorator_service_with_name_and_priority']->getDecoratedService()); } public function testParsesIteratorArgument() @@ -298,7 +298,7 @@ public function testParsesIteratorArgument() $lazyDefinition = $container->getDefinition('lazy_context'); - $this->assertEquals(array(new IteratorArgument(array('k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container'))), new IteratorArgument(array())), $lazyDefinition->getArguments(), '->load() parses lazy arguments'); + $this->assertEquals([new IteratorArgument(['k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container')]), new IteratorArgument([])], $lazyDefinition->getArguments(), '->load() parses lazy arguments'); } public function testParsesTags() @@ -368,27 +368,27 @@ public function testConvertDomElementToArray() $doc = new \DOMDocument('1.0'); $doc->loadXML(''); - $this->assertEquals(array('foo' => 'bar'), XmlFileLoader::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); + $this->assertEquals(['foo' => 'bar'], XmlFileLoader::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); $doc = new \DOMDocument('1.0'); $doc->loadXML('bar'); - $this->assertEquals(array('foo' => 'bar'), XmlFileLoader::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); + $this->assertEquals(['foo' => 'bar'], XmlFileLoader::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); $doc = new \DOMDocument('1.0'); $doc->loadXML('barbar'); - $this->assertEquals(array('foo' => array('value' => 'bar', 'foo' => 'bar')), XmlFileLoader::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); + $this->assertEquals(['foo' => ['value' => 'bar', 'foo' => 'bar']], XmlFileLoader::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); $doc = new \DOMDocument('1.0'); $doc->loadXML(''); - $this->assertEquals(array('foo' => null), XmlFileLoader::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); + $this->assertEquals(['foo' => null], XmlFileLoader::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); $doc = new \DOMDocument('1.0'); $doc->loadXML(''); - $this->assertEquals(array('foo' => null), XmlFileLoader::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); + $this->assertEquals(['foo' => null], XmlFileLoader::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); $doc = new \DOMDocument('1.0'); $doc->loadXML(''); - $this->assertEquals(array('foo' => array(array('foo' => 'bar'), array('foo' => 'bar'))), XmlFileLoader::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); + $this->assertEquals(['foo' => [['foo' => 'bar'], ['foo' => 'bar']]], XmlFileLoader::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); } public function testExtensions() @@ -545,7 +545,7 @@ public function testXmlNamespaces() $this->assertArrayHasKey('foo', $services, '->load() parses elements'); $this->assertCount(1, $services['foo']->getTag('foo.tag'), '->load parses elements'); - $this->assertEquals(array(array('setBar', array('foo'))), $services['foo']->getMethodCalls(), '->load() parses the tag'); + $this->assertEquals([['setBar', ['foo']]], $services['foo']->getMethodCalls(), '->load() parses the tag'); } public function testLoadIndexedArguments() @@ -554,7 +554,7 @@ public function testLoadIndexedArguments() $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('services14.xml'); - $this->assertEquals(array('index_0' => 'app'), $container->findDefinition('logger')->getArguments()); + $this->assertEquals(['index_0' => 'app'], $container->findDefinition('logger')->getArguments()); } public function testLoadInlinedServices() @@ -600,7 +600,7 @@ public function testType() $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('services22.xml'); - $this->assertEquals(array('Bar', 'Baz'), $container->getDefinition('foo')->getAutowiringTypes()); + $this->assertEquals(['Bar', 'Baz'], $container->getDefinition('foo')->getAutowiringTypes()); } public function testAutowire() @@ -630,7 +630,7 @@ public function testPrototype() $ids = array_keys($container->getDefinitions()); sort($ids); - $this->assertSame(array(Prototype\Foo::class, Prototype\Sub\Bar::class, 'service_container'), $ids); + $this->assertSame([Prototype\Foo::class, Prototype\Sub\Bar::class, 'service_container'], $ids); $resources = $container->getResources(); @@ -664,7 +664,7 @@ public function testArgumentWithKeyOutsideCollection() $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('with_key_outside_collection.xml'); - $this->assertSame(array('type' => 'foo', 'bar'), $container->getDefinition('foo')->getArguments()); + $this->assertSame(['type' => 'foo', 'bar'], $container->getDefinition('foo')->getArguments()); } public function testDefaults() @@ -674,7 +674,7 @@ public function testDefaults() $loader->load('services28.xml'); $this->assertFalse($container->getDefinition('with_defaults')->isPublic()); - $this->assertSame(array('foo' => array(array())), $container->getDefinition('with_defaults')->getTags()); + $this->assertSame(['foo' => [[]]], $container->getDefinition('with_defaults')->getTags()); $this->assertTrue($container->getDefinition('with_defaults')->isAutowired()); $this->assertArrayNotHasKey('public', $container->getDefinition('with_defaults')->getChanges()); $this->assertArrayNotHasKey('autowire', $container->getDefinition('with_defaults')->getChanges()); @@ -683,12 +683,12 @@ public function testDefaults() $this->assertTrue($container->getDefinition('no_defaults')->isPublic()); - $this->assertSame(array('foo' => array(array())), $container->getDefinition('no_defaults')->getTags()); + $this->assertSame(['foo' => [[]]], $container->getDefinition('no_defaults')->getTags()); $this->assertFalse($container->getDefinition('no_defaults')->isAutowired()); $this->assertTrue($container->getDefinition('child_def')->isPublic()); - $this->assertSame(array('foo' => array(array())), $container->getDefinition('child_def')->getTags()); + $this->assertSame(['foo' => [[]]], $container->getDefinition('child_def')->getTags()); $this->assertFalse($container->getDefinition('child_def')->isAutowired()); $definitions = $container->getDefinitions(); @@ -699,7 +699,7 @@ public function testDefaults() $this->assertSame('bar', key($definitions)); $this->assertTrue($anonymous->isPublic()); $this->assertTrue($anonymous->isAutowired()); - $this->assertSame(array('foo' => array(array())), $anonymous->getTags()); + $this->assertSame(['foo' => [[]]], $anonymous->getTags()); } public function testNamedArguments() @@ -708,12 +708,12 @@ public function testNamedArguments() $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('services_named_args.xml'); - $this->assertEquals(array('$apiKey' => 'ABCD', CaseSensitiveClass::class => null), $container->getDefinition(NamedArgumentsDummy::class)->getArguments()); + $this->assertEquals(['$apiKey' => 'ABCD', CaseSensitiveClass::class => null], $container->getDefinition(NamedArgumentsDummy::class)->getArguments()); $container->compile(); - $this->assertEquals(array(null, 'ABCD'), $container->getDefinition(NamedArgumentsDummy::class)->getArguments()); - $this->assertEquals(array(array('setApiKey', array('123'))), $container->getDefinition(NamedArgumentsDummy::class)->getMethodCalls()); + $this->assertEquals([null, 'ABCD'], $container->getDefinition(NamedArgumentsDummy::class)->getArguments()); + $this->assertEquals([['setApiKey', ['123']]], $container->getDefinition(NamedArgumentsDummy::class)->getMethodCalls()); } public function testInstanceof() @@ -726,7 +726,7 @@ public function testInstanceof() $definition = $container->getDefinition(Bar::class); $this->assertTrue($definition->isAutowired()); $this->assertTrue($definition->isLazy()); - $this->assertSame(array('foo' => array(array()), 'bar' => array(array())), $definition->getTags()); + $this->assertSame(['foo' => [[]], 'bar' => [[]]], $definition->getTags()); } /** @@ -783,30 +783,30 @@ public function testBindings() $container->compile(); $definition = $container->getDefinition('bar'); - $this->assertEquals(array( + $this->assertEquals([ 'NonExistent' => null, BarInterface::class => new Reference(Bar::class), - '$foo' => array(null), + '$foo' => [null], '$quz' => 'quz', '$factory' => 'factory', - ), array_map(function ($v) { return $v->getValues()[0]; }, $definition->getBindings())); - $this->assertEquals(array( + ], array_map(function ($v) { return $v->getValues()[0]; }, $definition->getBindings())); + $this->assertEquals([ 'quz', null, new Reference(Bar::class), - array(null), - ), $definition->getArguments()); + [null], + ], $definition->getArguments()); $definition = $container->getDefinition(Bar::class); - $this->assertEquals(array( + $this->assertEquals([ null, 'factory', - ), $definition->getArguments()); - $this->assertEquals(array( + ], $definition->getArguments()); + $this->assertEquals([ 'NonExistent' => null, '$quz' => 'quz', '$factory' => 'factory', - ), array_map(function ($v) { return $v->getValues()[0]; }, $definition->getBindings())); + ], array_map(function ($v) { return $v->getValues()[0]; }, $definition->getBindings())); } public function testTsantosContainer() diff --git a/Tests/Loader/YamlFileLoaderTest.php b/Tests/Loader/YamlFileLoaderTest.php index d8b329a56..7bcf0ec05 100644 --- a/Tests/Loader/YamlFileLoaderTest.php +++ b/Tests/Loader/YamlFileLoaderTest.php @@ -83,17 +83,17 @@ public function testLoadInvalidFile($file) public function provideInvalidFiles() { - return array( - array('bad_parameters'), - array('bad_imports'), - array('bad_import'), - array('bad_services'), - array('bad_service'), - array('bad_calls'), - array('bad_format'), - array('nonvalid1'), - array('nonvalid2'), - ); + return [ + ['bad_parameters'], + ['bad_imports'], + ['bad_import'], + ['bad_services'], + ['bad_service'], + ['bad_calls'], + ['bad_format'], + ['nonvalid1'], + ['nonvalid2'], + ]; } public function testLoadParameters() @@ -101,33 +101,33 @@ public function testLoadParameters() $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('services2.yml'); - $this->assertEquals(array('foo' => 'bar', 'mixedcase' => array('MixedCaseKey' => 'value'), 'values' => array(true, false, 0, 1000.3, PHP_INT_MAX), 'bar' => 'foo', 'escape' => '@escapeme', 'foo_bar' => new Reference('foo_bar')), $container->getParameterBag()->all(), '->load() converts YAML keys to lowercase'); + $this->assertEquals(['foo' => 'bar', 'mixedcase' => ['MixedCaseKey' => 'value'], 'values' => [true, false, 0, 1000.3, PHP_INT_MAX], 'bar' => 'foo', 'escape' => '@escapeme', 'foo_bar' => new Reference('foo_bar')], $container->getParameterBag()->all(), '->load() converts YAML keys to lowercase'); } public function testLoadImports() { $container = new ContainerBuilder(); - $resolver = new LoaderResolver(array( + $resolver = new LoaderResolver([ new IniFileLoader($container, new FileLocator(self::$fixturesPath.'/ini')), new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')), new PhpFileLoader($container, new FileLocator(self::$fixturesPath.'/php')), $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')), - )); + ]); $loader->setResolver($resolver); $loader->load('services4.yml'); $actual = $container->getParameterBag()->all(); - $expected = array( + $expected = [ 'foo' => 'bar', - 'values' => array(true, false, PHP_INT_MAX), + 'values' => [true, false, PHP_INT_MAX], 'bar' => '%foo%', 'escape' => '@escapeme', 'foo_bar' => new Reference('foo_bar'), - 'mixedcase' => array('MixedCaseKey' => 'value'), + 'mixedcase' => ['MixedCaseKey' => 'value'], 'imported_from_ini' => true, 'imported_from_xml' => true, 'with_wrong_ext' => 'from yaml', - ); + ]; $this->assertEquals(array_keys($expected), array_keys($actual), '->load() imports and merges imported files'); $this->assertTrue($actual['imported_from_ini']); @@ -146,17 +146,17 @@ public function testLoadServices() $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts service element to Definition instances'); $this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute'); $this->assertEquals('%path%/foo.php', $services['file']->getFile(), '->load() parses the file tag'); - $this->assertEquals(array('foo', new Reference('foo'), array(true, false)), $services['arguments']->getArguments(), '->load() parses the argument tags'); + $this->assertEquals(['foo', new Reference('foo'), [true, false]], $services['arguments']->getArguments(), '->load() parses the argument tags'); $this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag'); - $this->assertEquals(array(new Reference('baz'), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag'); - $this->assertEquals(array('BazClass', 'configureStatic'), $services['configurator3']->getConfigurator(), '->load() parses the configurator tag'); - $this->assertEquals(array(array('setBar', array()), array('setBar', array()), array('setBar', array(new Expression('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")')))), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag'); - $this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag'); + $this->assertEquals([new Reference('baz'), 'configure'], $services['configurator2']->getConfigurator(), '->load() parses the configurator tag'); + $this->assertEquals(['BazClass', 'configureStatic'], $services['configurator3']->getConfigurator(), '->load() parses the configurator tag'); + $this->assertEquals([['setBar', []], ['setBar', []], ['setBar', [new Expression('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")')]]], $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag'); + $this->assertEquals([['setBar', ['foo', new Reference('foo'), [true, false]]]], $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag'); $this->assertEquals('factory', $services['new_factory1']->getFactory(), '->load() parses the factory tag'); - $this->assertEquals(array(new Reference('baz'), 'getClass'), $services['new_factory2']->getFactory(), '->load() parses the factory tag'); - $this->assertEquals(array('BazClass', 'getInstance'), $services['new_factory3']->getFactory(), '->load() parses the factory tag'); - $this->assertSame(array(null, 'getInstance'), $services['new_factory4']->getFactory(), '->load() accepts factory tag without class'); - $this->assertEquals(array('foo', new Reference('baz')), $services['Acme\WithShortCutArgs']->getArguments(), '->load() parses short service definition'); + $this->assertEquals([new Reference('baz'), 'getClass'], $services['new_factory2']->getFactory(), '->load() parses the factory tag'); + $this->assertEquals(['BazClass', 'getInstance'], $services['new_factory3']->getFactory(), '->load() parses the factory tag'); + $this->assertSame([null, 'getInstance'], $services['new_factory4']->getFactory(), '->load() accepts factory tag without class'); + $this->assertEquals(['foo', new Reference('baz')], $services['Acme\WithShortCutArgs']->getArguments(), '->load() parses short service definition'); $aliases = $container->getAliases(); $this->assertArrayHasKey('alias_for_foo', $aliases, '->load() parses aliases'); @@ -169,9 +169,9 @@ public function testLoadServices() $this->assertEquals('foo', (string) $aliases['another_third_alias_for_foo']); $this->assertTrue($aliases['another_third_alias_for_foo']->isPublic()); - $this->assertEquals(array('decorated', null, 0), $services['decorator_service']->getDecoratedService()); - $this->assertEquals(array('decorated', 'decorated.pif-pouf', 0), $services['decorator_service_with_name']->getDecoratedService()); - $this->assertEquals(array('decorated', 'decorated.pif-pouf', 5), $services['decorator_service_with_name_and_priority']->getDecoratedService()); + $this->assertEquals(['decorated', null, 0], $services['decorator_service']->getDecoratedService()); + $this->assertEquals(['decorated', 'decorated.pif-pouf', 0], $services['decorator_service_with_name']->getDecoratedService()); + $this->assertEquals(['decorated', 'decorated.pif-pouf', 5], $services['decorator_service_with_name_and_priority']->getDecoratedService()); } public function testLoadFactoryShortSyntax() @@ -181,8 +181,8 @@ public function testLoadFactoryShortSyntax() $loader->load('services14.yml'); $services = $container->getDefinitions(); - $this->assertEquals(array(new Reference('baz'), 'getClass'), $services['factory']->getFactory(), '->load() parses the factory tag with service:method'); - $this->assertEquals(array('FooBacFactory', 'createFooBar'), $services['factory_with_static_call']->getFactory(), '->load() parses the factory tag with Class::method'); + $this->assertEquals([new Reference('baz'), 'getClass'], $services['factory']->getFactory(), '->load() parses the factory tag with service:method'); + $this->assertEquals(['FooBacFactory', 'createFooBar'], $services['factory_with_static_call']->getFactory(), '->load() parses the factory tag with Class::method'); } public function testLoadConfiguratorShortSyntax() @@ -192,8 +192,8 @@ public function testLoadConfiguratorShortSyntax() $loader->load('services_configurator_short_syntax.yml'); $services = $container->getDefinitions(); - $this->assertEquals(array(new Reference('foo_bar_configurator'), 'configure'), $services['foo_bar']->getConfigurator(), '->load() parses the configurator tag with service:method'); - $this->assertEquals(array('FooBarConfigurator', 'configureFooBar'), $services['foo_bar_with_static_call']->getConfigurator(), '->load() parses the configurator tag with Class::method'); + $this->assertEquals([new Reference('foo_bar_configurator'), 'configure'], $services['foo_bar']->getConfigurator(), '->load() parses the configurator tag with service:method'); + $this->assertEquals(['FooBarConfigurator', 'configureFooBar'], $services['foo_bar_with_static_call']->getConfigurator(), '->load() parses the configurator tag with Class::method'); } public function testExtensions() @@ -229,7 +229,7 @@ public function testExtensionWithNullConfig() $loader->load('null_config.yml'); $container->compile(); - $this->assertSame(array(null), $container->getParameter('project.configs')); + $this->assertSame([null], $container->getParameter('project.configs')); } public function testSupports() @@ -295,9 +295,9 @@ public function testLoadYamlOnlyWithKeys() $loader->load('services21.yml'); $definition = $container->getDefinition('manager'); - $this->assertEquals(array(array('setLogger', array(new Reference('logger'))), array('setClass', array('User'))), $definition->getMethodCalls()); - $this->assertEquals(array(true), $definition->getArguments()); - $this->assertEquals(array('manager' => array(array('alias' => 'user'))), $definition->getTags()); + $this->assertEquals([['setLogger', [new Reference('logger')]], ['setClass', ['User']]], $definition->getMethodCalls()); + $this->assertEquals([true], $definition->getArguments()); + $this->assertEquals(['manager' => [['alias' => 'user']]], $definition->getTags()); } /** @@ -347,8 +347,8 @@ public function testTypes() $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('services22.yml'); - $this->assertEquals(array('Foo', 'Bar'), $container->getDefinition('foo_service')->getAutowiringTypes()); - $this->assertEquals(array('Foo'), $container->getDefinition('baz_service')->getAutowiringTypes()); + $this->assertEquals(['Foo', 'Bar'], $container->getDefinition('foo_service')->getAutowiringTypes()); + $this->assertEquals(['Foo'], $container->getDefinition('baz_service')->getAutowiringTypes()); } public function testParsesIteratorArgument() @@ -359,7 +359,7 @@ public function testParsesIteratorArgument() $lazyDefinition = $container->getDefinition('lazy_context'); - $this->assertEquals(array(new IteratorArgument(array('k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container'))), new IteratorArgument(array())), $lazyDefinition->getArguments(), '->load() parses lazy arguments'); + $this->assertEquals([new IteratorArgument(['k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container')]), new IteratorArgument([])], $lazyDefinition->getArguments(), '->load() parses lazy arguments'); } public function testAutowire() @@ -389,7 +389,7 @@ public function testPrototype() $ids = array_keys($container->getDefinitions()); sort($ids); - $this->assertSame(array(Prototype\Foo::class, Prototype\Sub\Bar::class, 'service_container'), $ids); + $this->assertSame([Prototype\Foo::class, Prototype\Sub\Bar::class, 'service_container'], $ids); $resources = $container->getResources(); @@ -410,13 +410,13 @@ public function testPrototypeWithNamespace() $ids = array_keys($container->getDefinitions()); sort($ids); - $this->assertSame(array( + $this->assertSame([ Prototype\OtherDir\Component1\Dir1\Service1::class, Prototype\OtherDir\Component1\Dir2\Service2::class, Prototype\OtherDir\Component2\Dir1\Service4::class, Prototype\OtherDir\Component2\Dir2\Service5::class, 'service_container', - ), $ids); + ], $ids); $this->assertTrue($container->getDefinition(Prototype\OtherDir\Component1\Dir1\Service1::class)->hasTag('foo')); $this->assertTrue($container->getDefinition(Prototype\OtherDir\Component2\Dir1\Service4::class)->hasTag('foo')); @@ -447,7 +447,7 @@ public function testDefaults() $loader->load('services28.yml'); $this->assertFalse($container->getDefinition('with_defaults')->isPublic()); - $this->assertSame(array('foo' => array(array())), $container->getDefinition('with_defaults')->getTags()); + $this->assertSame(['foo' => [[]]], $container->getDefinition('with_defaults')->getTags()); $this->assertTrue($container->getDefinition('with_defaults')->isAutowired()); $this->assertArrayNotHasKey('public', $container->getDefinition('with_defaults')->getChanges()); $this->assertArrayNotHasKey('autowire', $container->getDefinition('with_defaults')->getChanges()); @@ -456,7 +456,7 @@ public function testDefaults() $this->assertFalse($container->getAlias('with_defaults_aliased_short')->isPublic()); $this->assertFalse($container->getDefinition('Acme\WithShortCutArgs')->isPublic()); - $this->assertSame(array('foo' => array(array())), $container->getDefinition('Acme\WithShortCutArgs')->getTags()); + $this->assertSame(['foo' => [[]]], $container->getDefinition('Acme\WithShortCutArgs')->getTags()); $this->assertTrue($container->getDefinition('Acme\WithShortCutArgs')->isAutowired()); $container->compile(); @@ -465,14 +465,14 @@ public function testDefaults() $this->assertTrue($container->getDefinition('no_defaults')->isPublic()); // foo tag is inherited from defaults - $this->assertSame(array('foo' => array(array())), $container->getDefinition('with_null')->getTags()); - $this->assertSame(array('foo' => array(array())), $container->getDefinition('no_defaults')->getTags()); + $this->assertSame(['foo' => [[]]], $container->getDefinition('with_null')->getTags()); + $this->assertSame(['foo' => [[]]], $container->getDefinition('no_defaults')->getTags()); $this->assertTrue($container->getDefinition('with_null')->isAutowired()); $this->assertFalse($container->getDefinition('no_defaults')->isAutowired()); $this->assertTrue($container->getDefinition('child_def')->isPublic()); - $this->assertSame(array('foo' => array(array())), $container->getDefinition('child_def')->getTags()); + $this->assertSame(['foo' => [[]]], $container->getDefinition('child_def')->getTags()); $this->assertFalse($container->getDefinition('child_def')->isAutowired()); } @@ -482,14 +482,14 @@ public function testNamedArguments() $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('services_named_args.yml'); - $this->assertEquals(array(null, '$apiKey' => 'ABCD'), $container->getDefinition(NamedArgumentsDummy::class)->getArguments()); - $this->assertEquals(array('$apiKey' => 'ABCD', CaseSensitiveClass::class => null), $container->getDefinition('another_one')->getArguments()); + $this->assertEquals([null, '$apiKey' => 'ABCD'], $container->getDefinition(NamedArgumentsDummy::class)->getArguments()); + $this->assertEquals(['$apiKey' => 'ABCD', CaseSensitiveClass::class => null], $container->getDefinition('another_one')->getArguments()); $container->compile(); - $this->assertEquals(array(null, 'ABCD'), $container->getDefinition(NamedArgumentsDummy::class)->getArguments()); - $this->assertEquals(array(null, 'ABCD'), $container->getDefinition('another_one')->getArguments()); - $this->assertEquals(array(array('setApiKey', array('123'))), $container->getDefinition('another_one')->getMethodCalls()); + $this->assertEquals([null, 'ABCD'], $container->getDefinition(NamedArgumentsDummy::class)->getArguments()); + $this->assertEquals([null, 'ABCD'], $container->getDefinition('another_one')->getArguments()); + $this->assertEquals([['setApiKey', ['123']]], $container->getDefinition('another_one')->getMethodCalls()); } public function testInstanceof() @@ -502,7 +502,7 @@ public function testInstanceof() $definition = $container->getDefinition(Bar::class); $this->assertTrue($definition->isAutowired()); $this->assertTrue($definition->isLazy()); - $this->assertSame(array('foo' => array(array()), 'bar' => array(array())), $definition->getTags()); + $this->assertSame(['foo' => [[]], 'bar' => [[]]], $definition->getTags()); } /** @@ -707,29 +707,29 @@ public function testBindings() $container->compile(); $definition = $container->getDefinition('bar'); - $this->assertEquals(array( + $this->assertEquals([ 'NonExistent' => null, BarInterface::class => new Reference(Bar::class), - '$foo' => array(null), + '$foo' => [null], '$quz' => 'quz', '$factory' => 'factory', - ), array_map(function ($v) { return $v->getValues()[0]; }, $definition->getBindings())); - $this->assertEquals(array( + ], array_map(function ($v) { return $v->getValues()[0]; }, $definition->getBindings())); + $this->assertEquals([ 'quz', null, new Reference(Bar::class), - array(null), - ), $definition->getArguments()); + [null], + ], $definition->getArguments()); $definition = $container->getDefinition(Bar::class); - $this->assertEquals(array( + $this->assertEquals([ null, 'factory', - ), $definition->getArguments()); - $this->assertEquals(array( + ], $definition->getArguments()); + $this->assertEquals([ 'NonExistent' => null, '$quz' => 'quz', '$factory' => 'factory', - ), array_map(function ($v) { return $v->getValues()[0]; }, $definition->getBindings())); + ], array_map(function ($v) { return $v->getValues()[0]; }, $definition->getBindings())); } } diff --git a/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php b/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php index 9abfb45d6..e7c88d2bb 100644 --- a/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php +++ b/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php @@ -137,7 +137,7 @@ public function testResolveThrowsOnBadDefaultValue() { $bag = new EnvPlaceholderParameterBag(); $bag->get('env(ARRAY_VAR)'); - $bag->set('env(ARRAY_VAR)', array()); + $bag->set('env(ARRAY_VAR)', []); $bag->resolve(); } @@ -158,7 +158,7 @@ public function testGetEnvAllowsNull() public function testGetThrowsOnBadDefaultValue() { $bag = new EnvPlaceholderParameterBag(); - $bag->set('env(ARRAY_VAR)', array()); + $bag->set('env(ARRAY_VAR)', []); $bag->get('env(ARRAY_VAR)'); $bag->resolve(); } diff --git a/Tests/ParameterBag/FrozenParameterBagTest.php b/Tests/ParameterBag/FrozenParameterBagTest.php index ef9a66f6c..b168e0c20 100644 --- a/Tests/ParameterBag/FrozenParameterBagTest.php +++ b/Tests/ParameterBag/FrozenParameterBagTest.php @@ -18,10 +18,10 @@ class FrozenParameterBagTest extends TestCase { public function testConstructor() { - $parameters = array( + $parameters = [ 'foo' => 'foo', 'bar' => 'bar', - ); + ]; $bag = new FrozenParameterBag($parameters); $this->assertEquals($parameters, $bag->all(), '__construct() takes an array of parameters as its first argument'); } @@ -31,7 +31,7 @@ public function testConstructor() */ public function testClear() { - $bag = new FrozenParameterBag(array()); + $bag = new FrozenParameterBag([]); $bag->clear(); } @@ -40,7 +40,7 @@ public function testClear() */ public function testSet() { - $bag = new FrozenParameterBag(array()); + $bag = new FrozenParameterBag([]); $bag->set('foo', 'bar'); } @@ -49,8 +49,8 @@ public function testSet() */ public function testAdd() { - $bag = new FrozenParameterBag(array()); - $bag->add(array()); + $bag = new FrozenParameterBag([]); + $bag->add([]); } /** @@ -58,7 +58,7 @@ public function testAdd() */ public function testRemove() { - $bag = new FrozenParameterBag(array('foo' => 'bar')); + $bag = new FrozenParameterBag(['foo' => 'bar']); $bag->remove('foo'); } } diff --git a/Tests/ParameterBag/ParameterBagTest.php b/Tests/ParameterBag/ParameterBagTest.php index a04cc15c1..e67e393df 100644 --- a/Tests/ParameterBag/ParameterBagTest.php +++ b/Tests/ParameterBag/ParameterBagTest.php @@ -21,36 +21,36 @@ class ParameterBagTest extends TestCase { public function testConstructor() { - $bag = new ParameterBag($parameters = array( + $bag = new ParameterBag($parameters = [ 'foo' => 'foo', 'bar' => 'bar', - )); + ]); $this->assertEquals($parameters, $bag->all(), '__construct() takes an array of parameters as its first argument'); } public function testClear() { - $bag = new ParameterBag($parameters = array( + $bag = new ParameterBag($parameters = [ 'foo' => 'foo', 'bar' => 'bar', - )); + ]); $bag->clear(); - $this->assertEquals(array(), $bag->all(), '->clear() removes all parameters'); + $this->assertEquals([], $bag->all(), '->clear() removes all parameters'); } public function testRemove() { - $bag = new ParameterBag(array( + $bag = new ParameterBag([ 'foo' => 'foo', 'bar' => 'bar', - )); + ]); $bag->remove('foo'); - $this->assertEquals(array('bar' => 'bar'), $bag->all(), '->remove() removes a parameter'); + $this->assertEquals(['bar' => 'bar'], $bag->all(), '->remove() removes a parameter'); } public function testGetSet() { - $bag = new ParameterBag(array('foo' => 'bar')); + $bag = new ParameterBag(['foo' => 'bar']); $bag->set('bar', 'foo'); $this->assertEquals('foo', $bag->get('bar'), '->set() sets the value of a new parameter'); @@ -71,12 +71,12 @@ public function testGetSet() */ public function testGetThrowParameterNotFoundException($parameterKey, $exceptionMessage) { - $bag = new ParameterBag(array( + $bag = new ParameterBag([ 'foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz', - 'fiz' => array('bar' => array('boo' => 12)), - )); + 'fiz' => ['bar' => ['boo' => 12]], + ]); if (method_exists($this, 'expectException')) { $this->expectException(ParameterNotFoundException::class); @@ -90,18 +90,18 @@ public function testGetThrowParameterNotFoundException($parameterKey, $exception public function provideGetThrowParameterNotFoundExceptionData() { - return array( - array('foo1', 'You have requested a non-existent parameter "foo1". Did you mean this: "foo"?'), - array('bag', 'You have requested a non-existent parameter "bag". Did you mean one of these: "bar", "baz"?'), - array('', 'You have requested a non-existent parameter "".'), + return [ + ['foo1', 'You have requested a non-existent parameter "foo1". Did you mean this: "foo"?'], + ['bag', 'You have requested a non-existent parameter "bag". Did you mean one of these: "bar", "baz"?'], + ['', 'You have requested a non-existent parameter "".'], - array('fiz.bar.boo', 'You have requested a non-existent parameter "fiz.bar.boo". You cannot access nested array items, do you want to inject "fiz" instead?'), - ); + ['fiz.bar.boo', 'You have requested a non-existent parameter "fiz.bar.boo". You cannot access nested array items, do you want to inject "fiz" instead?'], + ]; } public function testHas() { - $bag = new ParameterBag(array('foo' => 'bar')); + $bag = new ParameterBag(['foo' => 'bar']); $this->assertTrue($bag->has('foo'), '->has() returns true if a parameter is defined'); $this->assertFalse($bag->has('bar'), '->has() returns false if a parameter is not defined'); } @@ -115,13 +115,13 @@ public function testHas() */ public function testMixedCase() { - $bag = new ParameterBag(array( + $bag = new ParameterBag([ 'foo' => 'foo', 'bar' => 'bar', - )); + ]); $bag->remove('BAR'); - $this->assertEquals(array('foo' => 'foo'), $bag->all(), '->remove() converts key to lowercase before removing'); + $this->assertEquals(['foo' => 'foo'], $bag->all(), '->remove() converts key to lowercase before removing'); $bag->set('Foo', 'baz1'); $this->assertEquals('baz1', $bag->get('foo'), '->set() converts the key to lowercase'); @@ -132,29 +132,29 @@ public function testMixedCase() public function testResolveValue() { - $bag = new ParameterBag(array()); + $bag = new ParameterBag([]); $this->assertEquals('foo', $bag->resolveValue('foo'), '->resolveValue() returns its argument unmodified if no placeholders are found'); - $bag = new ParameterBag(array('foo' => 'bar')); + $bag = new ParameterBag(['foo' => 'bar']); $this->assertEquals('I\'m a bar', $bag->resolveValue('I\'m a %foo%'), '->resolveValue() replaces placeholders by their values'); - $this->assertEquals(array('bar' => 'bar'), $bag->resolveValue(array('%foo%' => '%foo%')), '->resolveValue() replaces placeholders in keys and values of arrays'); - $this->assertEquals(array('bar' => array('bar' => array('bar' => 'bar'))), $bag->resolveValue(array('%foo%' => array('%foo%' => array('%foo%' => '%foo%')))), '->resolveValue() replaces placeholders in nested arrays'); + $this->assertEquals(['bar' => 'bar'], $bag->resolveValue(['%foo%' => '%foo%']), '->resolveValue() replaces placeholders in keys and values of arrays'); + $this->assertEquals(['bar' => ['bar' => ['bar' => 'bar']]], $bag->resolveValue(['%foo%' => ['%foo%' => ['%foo%' => '%foo%']]]), '->resolveValue() replaces placeholders in nested arrays'); $this->assertEquals('I\'m a %%foo%%', $bag->resolveValue('I\'m a %%foo%%'), '->resolveValue() supports % escaping by doubling it'); $this->assertEquals('I\'m a bar %%foo bar', $bag->resolveValue('I\'m a %foo% %%foo %foo%'), '->resolveValue() supports % escaping by doubling it'); - $this->assertEquals(array('foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar'))), $bag->resolveValue(array('foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar')))), '->resolveValue() supports % escaping by doubling it'); + $this->assertEquals(['foo' => ['bar' => ['ding' => 'I\'m a bar %%foo %%bar']]], $bag->resolveValue(['foo' => ['bar' => ['ding' => 'I\'m a bar %%foo %%bar']]]), '->resolveValue() supports % escaping by doubling it'); - $bag = new ParameterBag(array('foo' => true)); + $bag = new ParameterBag(['foo' => true]); $this->assertTrue($bag->resolveValue('%foo%'), '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings'); - $bag = new ParameterBag(array('foo' => null)); + $bag = new ParameterBag(['foo' => null]); $this->assertNull($bag->resolveValue('%foo%'), '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings'); - $bag = new ParameterBag(array('foo' => 'bar', 'baz' => '%%%foo% %foo%%% %%foo%% %%%foo%%%')); + $bag = new ParameterBag(['foo' => 'bar', 'baz' => '%%%foo% %foo%%% %%foo%% %%%foo%%%']); $this->assertEquals('%%bar bar%% %%foo%% %%bar%%', $bag->resolveValue('%baz%'), '->resolveValue() replaces params placed besides escaped %'); - $bag = new ParameterBag(array('baz' => '%%s?%%s')); + $bag = new ParameterBag(['baz' => '%%s?%%s']); $this->assertEquals('%%s?%%s', $bag->resolveValue('%baz%'), '->resolveValue() is not replacing greedily'); - $bag = new ParameterBag(array()); + $bag = new ParameterBag([]); try { $bag->resolveValue('%foobar%'); $this->fail('->resolveValue() throws an InvalidArgumentException if a placeholder references a non-existent parameter'); @@ -169,7 +169,7 @@ public function testResolveValue() $this->assertEquals('You have requested a non-existent parameter "foobar".', $e->getMessage(), '->resolveValue() throws a ParameterNotFoundException if a placeholder references a non-existent parameter'); } - $bag = new ParameterBag(array('foo' => 'a %bar%', 'bar' => array())); + $bag = new ParameterBag(['foo' => 'a %bar%', 'bar' => []]); try { $bag->resolveValue('%foo%'); $this->fail('->resolveValue() throws a RuntimeException when a parameter embeds another non-string parameter'); @@ -177,7 +177,7 @@ public function testResolveValue() $this->assertEquals('A string value must be composed of strings and/or numbers, but found parameter "bar" of type array inside string value "a %bar%".', $e->getMessage(), '->resolveValue() throws a RuntimeException when a parameter embeds another non-string parameter'); } - $bag = new ParameterBag(array('foo' => '%bar%', 'bar' => '%foobar%', 'foobar' => '%foo%')); + $bag = new ParameterBag(['foo' => '%bar%', 'bar' => '%foobar%', 'foobar' => '%foo%']); try { $bag->resolveValue('%foo%'); $this->fail('->resolveValue() throws a ParameterCircularReferenceException when a parameter has a circular reference'); @@ -185,7 +185,7 @@ public function testResolveValue() $this->assertEquals('Circular reference detected for parameter "foo" ("foo" > "bar" > "foobar" > "foo").', $e->getMessage(), '->resolveValue() throws a ParameterCircularReferenceException when a parameter has a circular reference'); } - $bag = new ParameterBag(array('foo' => 'a %bar%', 'bar' => 'a %foobar%', 'foobar' => 'a %foo%')); + $bag = new ParameterBag(['foo' => 'a %bar%', 'bar' => 'a %foobar%', 'foobar' => 'a %foo%']); try { $bag->resolveValue('%foo%'); $this->fail('->resolveValue() throws a ParameterCircularReferenceException when a parameter has a circular reference'); @@ -193,13 +193,13 @@ public function testResolveValue() $this->assertEquals('Circular reference detected for parameter "foo" ("foo" > "bar" > "foobar" > "foo").', $e->getMessage(), '->resolveValue() throws a ParameterCircularReferenceException when a parameter has a circular reference'); } - $bag = new ParameterBag(array('host' => 'foo.bar', 'port' => 1337)); + $bag = new ParameterBag(['host' => 'foo.bar', 'port' => 1337]); $this->assertEquals('foo.bar:1337', $bag->resolveValue('%host%:%port%')); } public function testResolveIndicatesWhyAParameterIsNeeded() { - $bag = new ParameterBag(array('foo' => '%bar%')); + $bag = new ParameterBag(['foo' => '%bar%']); try { $bag->resolve(); @@ -207,7 +207,7 @@ public function testResolveIndicatesWhyAParameterIsNeeded() $this->assertEquals('The parameter "foo" has a dependency on a non-existent parameter "bar".', $e->getMessage()); } - $bag = new ParameterBag(array('foo' => '%bar%')); + $bag = new ParameterBag(['foo' => '%bar%']); try { $bag->resolve(); @@ -218,28 +218,28 @@ public function testResolveIndicatesWhyAParameterIsNeeded() public function testResolveUnescapesValue() { - $bag = new ParameterBag(array( - 'foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar')), + $bag = new ParameterBag([ + 'foo' => ['bar' => ['ding' => 'I\'m a bar %%foo %%bar']], 'bar' => 'I\'m a %%foo%%', - )); + ]); $bag->resolve(); $this->assertEquals('I\'m a %foo%', $bag->get('bar'), '->resolveValue() supports % escaping by doubling it'); - $this->assertEquals(array('bar' => array('ding' => 'I\'m a bar %foo %bar')), $bag->get('foo'), '->resolveValue() supports % escaping by doubling it'); + $this->assertEquals(['bar' => ['ding' => 'I\'m a bar %foo %bar']], $bag->get('foo'), '->resolveValue() supports % escaping by doubling it'); } public function testEscapeValue() { $bag = new ParameterBag(); - $bag->add(array( - 'foo' => $bag->escapeValue(array('bar' => array('ding' => 'I\'m a bar %foo %bar', 'zero' => null))), + $bag->add([ + 'foo' => $bag->escapeValue(['bar' => ['ding' => 'I\'m a bar %foo %bar', 'zero' => null]]), 'bar' => $bag->escapeValue('I\'m a %foo%'), - )); + ]); $this->assertEquals('I\'m a %%foo%%', $bag->get('bar'), '->escapeValue() escapes % by doubling it'); - $this->assertEquals(array('bar' => array('ding' => 'I\'m a bar %%foo %%bar', 'zero' => null)), $bag->get('foo'), '->escapeValue() escapes % by doubling it'); + $this->assertEquals(['bar' => ['ding' => 'I\'m a bar %%foo %%bar', 'zero' => null]], $bag->get('foo'), '->escapeValue() escapes % by doubling it'); } /** @@ -247,7 +247,7 @@ public function testEscapeValue() */ public function testResolveStringWithSpacesReturnsString($expected, $test, $description) { - $bag = new ParameterBag(array('foo' => 'bar')); + $bag = new ParameterBag(['foo' => 'bar']); try { $this->assertEquals($expected, $bag->resolveString($test), $description); @@ -258,11 +258,11 @@ public function testResolveStringWithSpacesReturnsString($expected, $test, $desc public function stringsWithSpacesProvider() { - return array( - array('bar', '%foo%', 'Parameters must be wrapped by %.'), - array('% foo %', '% foo %', 'Parameters should not have spaces.'), - array('{% set my_template = "foo" %}', '{% set my_template = "foo" %}', 'Twig-like strings are not parameters.'), - array('50% is less than 100%', '50% is less than 100%', 'Text between % signs is allowed, if there are spaces.'), - ); + return [ + ['bar', '%foo%', 'Parameters must be wrapped by %.'], + ['% foo %', '% foo %', 'Parameters should not have spaces.'], + ['{% set my_template = "foo" %}', '{% set my_template = "foo" %}', 'Twig-like strings are not parameters.'], + ['50% is less than 100%', '50% is less than 100%', 'Text between % signs is allowed, if there are spaces.'], + ]; } } diff --git a/Tests/ServiceLocatorTest.php b/Tests/ServiceLocatorTest.php index aa9790e83..aa9ebab68 100644 --- a/Tests/ServiceLocatorTest.php +++ b/Tests/ServiceLocatorTest.php @@ -20,11 +20,11 @@ class ServiceLocatorTest extends TestCase { public function testHas() { - $locator = new ServiceLocator(array( + $locator = new ServiceLocator([ 'foo' => function () { return 'bar'; }, 'bar' => function () { return 'baz'; }, function () { return 'dummy'; }, - )); + ]); $this->assertTrue($locator->has('foo')); $this->assertTrue($locator->has('bar')); @@ -33,10 +33,10 @@ function () { return 'dummy'; }, public function testGet() { - $locator = new ServiceLocator(array( + $locator = new ServiceLocator([ 'foo' => function () { return 'bar'; }, 'bar' => function () { return 'baz'; }, - )); + ]); $this->assertSame('bar', $locator->get('foo')); $this->assertSame('baz', $locator->get('bar')); @@ -45,13 +45,13 @@ public function testGet() public function testGetDoesNotMemoize() { $i = 0; - $locator = new ServiceLocator(array( + $locator = new ServiceLocator([ 'foo' => function () use (&$i) { ++$i; return 'bar'; }, - )); + ]); $this->assertSame('bar', $locator->get('foo')); $this->assertSame('bar', $locator->get('foo')); @@ -64,10 +64,10 @@ public function testGetDoesNotMemoize() */ public function testGetThrowsOnUndefinedService() { - $locator = new ServiceLocator(array( + $locator = new ServiceLocator([ 'foo' => function () { return 'bar'; }, 'bar' => function () { return 'baz'; }, - )); + ]); $locator->get('dummy'); } @@ -78,9 +78,9 @@ public function testGetThrowsOnUndefinedService() */ public function testThrowsOnUndefinedInternalService() { - $locator = new ServiceLocator(array( + $locator = new ServiceLocator([ 'foo' => function () use (&$locator) { return $locator->get('bar'); }, - )); + ]); $locator->get('foo'); } @@ -91,11 +91,11 @@ public function testThrowsOnUndefinedInternalService() */ public function testThrowsOnCircularReference() { - $locator = new ServiceLocator(array( + $locator = new ServiceLocator([ 'foo' => function () use (&$locator) { return $locator->get('bar'); }, 'bar' => function () use (&$locator) { return $locator->get('baz'); }, 'baz' => function () use (&$locator) { return $locator->get('bar'); }, - )); + ]); $locator->get('foo'); } @@ -109,7 +109,7 @@ public function testThrowsInServiceSubscriber() $container = new Container(); $container->set('foo', new \stdClass()); $subscriber = new SomeServiceSubscriber(); - $subscriber->container = new ServiceLocator(array('bar' => function () {})); + $subscriber->container = new ServiceLocator(['bar' => function () {}]); $subscriber->container = $subscriber->container->withContext('caller', $container); $subscriber->getFoo(); @@ -124,17 +124,17 @@ public function testGetThrowsServiceNotFoundException() $container = new Container(); $container->set('foo', new \stdClass()); - $locator = new ServiceLocator(array()); + $locator = new ServiceLocator([]); $locator = $locator->withContext('foo', $container); $locator->get('foo'); } public function testInvoke() { - $locator = new ServiceLocator(array( + $locator = new ServiceLocator([ 'foo' => function () { return 'bar'; }, 'bar' => function () { return 'baz'; }, - )); + ]); $this->assertSame('bar', $locator('foo')); $this->assertSame('baz', $locator('bar')); @@ -153,6 +153,6 @@ public function getFoo() public static function getSubscribedServices() { - return array('bar' => 'stdClass'); + return ['bar' => 'stdClass']; } } From fc292f9ffb5c6e191b4d62718406746bbc504da5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 16 Jan 2019 12:42:57 +0100 Subject: [PATCH 15/72] fixed CS on generated container files --- Dumper/PhpDumper.php | 55 ++++++++-------- Tests/Fixtures/Bar.php | 2 +- Tests/Fixtures/TestServiceSubscriber.php | 4 +- Tests/Fixtures/config/basic.php | 2 +- Tests/Fixtures/config/child.php | 2 +- Tests/Fixtures/config/defaults.php | 4 +- Tests/Fixtures/config/instanceof.php | 4 +- Tests/Fixtures/config/prototype.php | 4 +- Tests/Fixtures/config/services9.php | 62 +++++++++---------- Tests/Fixtures/containers/container11.php | 2 +- Tests/Fixtures/containers/container12.php | 2 +- Tests/Fixtures/containers/container19.php | 4 +- Tests/Fixtures/containers/container21.php | 8 +-- Tests/Fixtures/containers/container8.php | 6 +- Tests/Fixtures/containers/container9.php | 58 ++++++++--------- .../containers/container_almost_circular.php | 6 +- .../containers/container_env_in_id.php | 2 +- .../container_uninitialized_ref.php | 8 +-- Tests/Fixtures/includes/ProjectExtension.php | 2 +- Tests/Fixtures/includes/foo.php | 6 +- ...er_class_constructor_without_arguments.php | 10 +-- ...s_with_mandatory_constructor_arguments.php | 10 +-- ...ss_with_optional_constructor_arguments.php | 10 +-- ...om_container_class_without_constructor.php | 10 +-- Tests/Fixtures/php/services1-1.php | 10 +-- Tests/Fixtures/php/services1.php | 10 +-- Tests/Fixtures/php/services10.php | 26 ++++---- Tests/Fixtures/php/services12.php | 28 ++++----- Tests/Fixtures/php/services13.php | 14 ++--- Tests/Fixtures/php/services19.php | 28 ++++----- Tests/Fixtures/php/services24.php | 14 ++--- Tests/Fixtures/php/services26.php | 28 ++++----- Tests/Fixtures/php/services33.php | 18 +++--- Tests/Fixtures/php/services8.php | 24 +++---- Tests/Fixtures/php/services9.php | 34 +++++----- Tests/Fixtures/php/services9_as_files.txt | 48 +++++++------- Tests/Fixtures/php/services9_compiled.php | 38 ++++++------ Tests/Fixtures/php/services_adawson.php | 24 +++---- .../php/services_almost_circular_private.php | 18 +++--- .../php/services_almost_circular_public.php | 18 +++--- Tests/Fixtures/php/services_array_params.php | 34 +++++----- Tests/Fixtures/php/services_base64_env.php | 22 +++---- .../php/services_dedup_lazy_proxy.php | 14 ++--- Tests/Fixtures/php/services_deep_graph.php | 14 ++--- Tests/Fixtures/php/services_env_in_id.php | 36 +++++------ .../Fixtures/php/services_inline_requires.php | 32 +++++----- .../Fixtures/php/services_inline_self_ref.php | 18 +++--- .../Fixtures/php/services_legacy_privates.php | 20 +++--- Tests/Fixtures/php/services_locator.php | 34 +++++----- .../Fixtures/php/services_non_shared_lazy.php | 18 +++--- .../Fixtures/php/services_private_frozen.php | 18 +++--- .../php/services_private_in_expression.php | 18 +++--- Tests/Fixtures/php/services_rot13_env.php | 34 +++++----- Tests/Fixtures/php/services_subscriber.php | 26 ++++---- Tests/Fixtures/php/services_tsantos.php | 20 +++--- .../php/services_uninitialized_ref.php | 22 +++---- 56 files changed, 522 insertions(+), 521 deletions(-) diff --git a/Dumper/PhpDumper.php b/Dumper/PhpDumper.php index 1e348b2bf..dc14f967f 100644 --- a/Dumper/PhpDumper.php +++ b/Dumper/PhpDumper.php @@ -215,11 +215,11 @@ public function dump(array $options = []) if ($ids = array_keys($this->container->getRemovedIds())) { sort($ids); - $c = "doExport($id)." => true,\n"; } - $files['removed-ids.php'] = $c .= ");\n"; + $files['removed-ids.php'] = $c .= "];\n"; } foreach ($this->generateServiceFiles() as $file => $c) { @@ -258,11 +258,11 @@ public function dump(array $options = []) \\class_alias(\\Container{$hash}\\{$options['class']}::class, {$options['class']}::class, false); } -return new \\Container{$hash}\\{$options['class']}(array( +return new \\Container{$hash}\\{$options['class']}([ 'container.build_hash' => '$hash', 'container.build_id' => '$id', 'container.build_time' => $time, -), __DIR__.\\DIRECTORY_SEPARATOR.'Container{$hash}'); +], __DIR__.\\DIRECTORY_SEPARATOR.'Container{$hash}'); EOF; } else { @@ -607,7 +607,7 @@ private function addServiceConfigurator(Definition $definition, $variableName = return sprintf(" (%s)->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName); } - return sprintf(" \\call_user_func(array(%s, '%s'), \$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName); + return sprintf(" \\call_user_func([%s, '%s'], \$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName); } return sprintf(" %s(\$%s);\n", $callable, $variableName); @@ -900,7 +900,7 @@ private function addNewInstance(Definition $definition, $return, $instantiation, return $return.sprintf("(%s)->%s(%s);\n", $class, $callable[1], $arguments ? implode(', ', $arguments) : ''); } - return $return.sprintf("\\call_user_func(array(%s, '%s')%s);\n", $class, $callable[1], $arguments ? ', '.implode(', ', $arguments) : ''); + return $return.sprintf("\\call_user_func([%s, '%s']%s);\n", $class, $callable[1], $arguments ? ', '.implode(', ', $arguments) : ''); } return $return.sprintf("%s(%s);\n", $this->dumpLiteralClass($this->dumpValue($callable)), $arguments ? implode(', ', $arguments) : ''); @@ -947,7 +947,7 @@ private function startClass($class, $baseClass, $baseClassWithNamespace) class $class extends $baseClass { private \$parameters; - private \$targetDirs = array(); + private \$targetDirs = []; public function __construct() { @@ -965,7 +965,7 @@ public function __construct() } if ($this->asFiles) { $code = str_replace('$parameters', "\$buildParameters;\n private \$containerDir;\n private \$parameters", $code); - $code = str_replace('__construct()', '__construct(array $buildParameters = array(), $containerDir = __DIR__)', $code); + $code = str_replace('__construct()', '__construct(array $buildParameters = [], $containerDir = __DIR__)', $code); $code .= " \$this->buildParameters = \$buildParameters;\n"; $code .= " \$this->containerDir = \$containerDir;\n"; } @@ -987,7 +987,7 @@ public function __construct() $code .= " \$this->parameters = \$this->getDefaultParameters();\n\n"; } - $code .= " \$this->services = array();\n"; + $code .= " \$this->services = [];\n"; } else { $arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null; $code .= " parent::__construct($arguments);\n"; @@ -1085,7 +1085,7 @@ private function addNormalizedIds() } } - return $code ? " \$this->normalizedIds = array(\n".$code." );\n" : ''; + return $code ? " \$this->normalizedIds = [\n".$code." ];\n" : ''; } /** @@ -1104,7 +1104,7 @@ private function addSyntheticIds() } } - return $code ? " \$this->syntheticIds = array(\n{$code} );\n" : ''; + return $code ? " \$this->syntheticIds = [\n{$code} ];\n" : ''; } /** @@ -1130,7 +1130,7 @@ private function addRemovedIds() $code .= ' '.$this->doExport($id)." => true,\n"; } - $code = "array(\n{$code} )"; + $code = "[\n{$code} ]"; } return <<methodMap = array(\n{$code} );\n" : ''; + return $code ? " \$this->methodMap = [\n{$code} ];\n" : ''; } /** @@ -1178,7 +1178,7 @@ private function addFileMap() } } - return $code ? " \$this->fileMap = array(\n{$code} );\n" : ''; + return $code ? " \$this->fileMap = [\n{$code} ];\n" : ''; } /** @@ -1210,9 +1210,9 @@ private function addPrivateServices() return ''; } - $out = " \$this->privates = array(\n"; + $out = " \$this->privates = [\n"; $out .= $code; - $out .= " );\n"; + $out .= " ];\n"; return $out; } @@ -1225,10 +1225,10 @@ private function addPrivateServices() private function addAliases() { if (!$aliases = $this->container->getAliases()) { - return $this->container->isCompiled() ? "\n \$this->aliases = array();\n" : ''; + return $this->container->isCompiled() ? "\n \$this->aliases = [];\n" : ''; } - $code = " \$this->aliases = array(\n"; + $code = " \$this->aliases = [\n"; ksort($aliases); foreach ($aliases as $alias => $id) { $id = $this->container->normalizeId($id); @@ -1238,7 +1238,7 @@ private function addAliases() $code .= ' '.$this->doExport($alias).' => '.$this->doExport($id).",\n"; } - return $code." );\n"; + return $code." ];\n"; } private function addInlineRequires() @@ -1295,7 +1295,7 @@ private function addDefaultParametersMethod() $normalizedParams[] = sprintf(' %s => %s,', $this->export($lcKey), $this->export($key)); } $export = $this->exportParameters([$value]); - $export = explode('0 => ', substr(rtrim($export, " )\n"), 7, -1), 2); + $export = explode('0 => ', substr(rtrim($export, " ]\n"), 2, -1), 2); if (preg_match("/\\\$this->(?:getEnv\('(?:\w++:)*+\w++'\)|targetDirs\[\d++\])/", $export[1])) { $dynamicPhp[$key] = sprintf('%scase %s: $value = %s; break;', $export[0], $this->export($key), $export[1]); @@ -1303,7 +1303,8 @@ private function addDefaultParametersMethod() $php[] = sprintf('%s%s => %s,', $export[0], $this->export($key), $export[1]); } } - $parameters = sprintf("array(\n%s\n%s)", implode("\n", $php), str_repeat(' ', 8)); + + $parameters = sprintf("[\n%s\n%s]", implode("\n", $php), str_repeat(' ', 8)); $code = ''; if ($this->container->isCompiled()) { @@ -1379,14 +1380,14 @@ public function getParameterBag() EOF; $getDynamicParameter = sprintf($getDynamicParameter, implode("\n", $dynamicPhp)); } else { - $loadedDynamicParameters = 'array()'; + $loadedDynamicParameters = '[]'; $getDynamicParameter = str_repeat(' ', 8).'throw new InvalidArgumentException(sprintf(\'The dynamic parameter "%s" must be defined.\', $name));'; } $code .= <<docStar} * Computes a dynamic parameter. @@ -1405,7 +1406,7 @@ private function getDynamicParameter(\$name) EOF; - $code .= ' private $normalizedParameterNames = '.($normalizedParams ? sprintf("array(\n%s\n );", implode("\n", $normalizedParams)) : 'array();')."\n"; + $code .= ' private $normalizedParameterNames = '.($normalizedParams ? sprintf("[\n%s\n ];", implode("\n", $normalizedParams)) : '[];')."\n"; $code .= <<<'EOF' private function normalizeParameterName($name) @@ -1478,7 +1479,7 @@ private function exportParameters(array $parameters, $path = '', $indent = 12) $php[] = sprintf('%s%s => %s,', str_repeat(' ', $indent), $this->export($key), $value); } - return sprintf("array(\n%s\n%s)", implode("\n", $php), str_repeat(' ', $indent - 4)); + return sprintf("[\n%s\n%s]", implode("\n", $php), str_repeat(' ', $indent - 4)); } /** @@ -1599,7 +1600,7 @@ private function dumpValue($value, $interpolate = true) $code[] = sprintf('%s => %s', $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate)); } - return sprintf('array(%s)', implode(', ', $code)); + return sprintf('[%s]', implode(', ', $code)); } elseif ($value instanceof ArgumentInterface) { $scope = [$this->definitionVariables, $this->referenceVariables]; $this->definitionVariables = $this->referenceVariables = null; @@ -1691,7 +1692,7 @@ private function dumpValue($value, $interpolate = true) return sprintf('(%s)->%s(%s)', $class, $factory[1], implode(', ', $arguments)); } - return sprintf("\\call_user_func(array(%s, '%s')%s)", $class, $factory[1], \count($arguments) > 0 ? ', '.implode(', ', $arguments) : ''); + return sprintf("\\call_user_func([%s, '%s']%s)", $class, $factory[1], \count($arguments) > 0 ? ', '.implode(', ', $arguments) : ''); } if ($factory[0] instanceof Reference) { diff --git a/Tests/Fixtures/Bar.php b/Tests/Fixtures/Bar.php index d243866d3..83f2da12a 100644 --- a/Tests/Fixtures/Bar.php +++ b/Tests/Fixtures/Bar.php @@ -13,7 +13,7 @@ class Bar implements BarInterface { - public function __construct($quz = null, \NonExistent $nonExistent = null, BarInterface $decorated = null, array $foo = array()) + public function __construct($quz = null, \NonExistent $nonExistent = null, BarInterface $decorated = null, array $foo = []) { } diff --git a/Tests/Fixtures/TestServiceSubscriber.php b/Tests/Fixtures/TestServiceSubscriber.php index 875abe9e0..a3b042b8f 100644 --- a/Tests/Fixtures/TestServiceSubscriber.php +++ b/Tests/Fixtures/TestServiceSubscriber.php @@ -12,11 +12,11 @@ public function __construct($container) public static function getSubscribedServices() { - return array( + return [ __CLASS__, '?'.CustomDefinition::class, 'bar' => CustomDefinition::class, 'baz' => '?'.CustomDefinition::class, - ); + ]; } } diff --git a/Tests/Fixtures/config/basic.php b/Tests/Fixtures/config/basic.php index b98e894c3..a9e250b92 100644 --- a/Tests/Fixtures/config/basic.php +++ b/Tests/Fixtures/config/basic.php @@ -7,5 +7,5 @@ return function (ContainerConfigurator $c) { $s = $c->services(); $s->set(BarService::class) - ->args(array(inline('FooClass'))); + ->args([inline('FooClass')]); }; diff --git a/Tests/Fixtures/config/child.php b/Tests/Fixtures/config/child.php index 6fd84485e..8a5f2431d 100644 --- a/Tests/Fixtures/config/child.php +++ b/Tests/Fixtures/config/child.php @@ -13,7 +13,7 @@ ->set('foo') ->parent(BarService::class) ->decorate('bar', 'b', 1) - ->args(array(ref('b'))) + ->args([ref('b')]) ->class('Class2') ->file('file.php') ->parent('bar') diff --git a/Tests/Fixtures/config/defaults.php b/Tests/Fixtures/config/defaults.php index de3b99d74..2889d3fbb 100644 --- a/Tests/Fixtures/config/defaults.php +++ b/Tests/Fixtures/config/defaults.php @@ -12,10 +12,10 @@ ->private() ->autoconfigure() ->autowire() - ->tag('t', array('a' => 'b')) + ->tag('t', ['a' => 'b']) ->bind(Foo::class, ref('bar')) ->private(); - $s->set(Foo::class)->args(array(ref('bar')))->public(); + $s->set(Foo::class)->args([ref('bar')])->public(); $s->set('bar', Foo::class)->call('setFoo')->autoconfigure(false); }; diff --git a/Tests/Fixtures/config/instanceof.php b/Tests/Fixtures/config/instanceof.php index 062e8c00a..0d6aac7a0 100644 --- a/Tests/Fixtures/config/instanceof.php +++ b/Tests/Fixtures/config/instanceof.php @@ -9,8 +9,8 @@ $s = $c->services(); $s->instanceof(Prototype\Foo::class) ->property('p', 0) - ->call('setFoo', array(ref('foo'))) - ->tag('tag', array('k' => 'v')) + ->call('setFoo', [ref('foo')]) + ->tag('tag', ['k' => 'v']) ->share(false) ->lazy() ->configurator('c') diff --git a/Tests/Fixtures/config/prototype.php b/Tests/Fixtures/config/prototype.php index 622c51af5..e2884aa20 100644 --- a/Tests/Fixtures/config/prototype.php +++ b/Tests/Fixtures/config/prototype.php @@ -12,8 +12,8 @@ ->exclude('../Prototype/{OtherDir,BadClasses}') ->factory('f') ->deprecate('%service_id%') - ->args(array(0)) - ->args(array(1)) + ->args([0]) + ->args([1]) ->autoconfigure(false) ->tag('foo') ->parent('foo'); diff --git a/Tests/Fixtures/config/services9.php b/Tests/Fixtures/config/services9.php index b013e5126..d9373a2a6 100644 --- a/Tests/Fixtures/config/services9.php +++ b/Tests/Fixtures/config/services9.php @@ -16,65 +16,65 @@ $s = $c->services(); $s->set('foo') - ->args(array('foo', ref('foo.baz'), array('%foo%' => 'foo is %foo%', 'foobar' => '%foo%'), true, ref('service_container'))) + ->args(['foo', ref('foo.baz'), ['%foo%' => 'foo is %foo%', 'foobar' => '%foo%'], true, ref('service_container')]) ->class(FooClass::class) - ->tag('foo', array('foo' => 'foo')) - ->tag('foo', array('bar' => 'bar', 'baz' => 'baz')) - ->factory(array(FooClass::class, 'getInstance')) + ->tag('foo', ['foo' => 'foo']) + ->tag('foo', ['bar' => 'bar', 'baz' => 'baz']) + ->factory([FooClass::class, 'getInstance']) ->property('foo', 'bar') ->property('moo', ref('foo.baz')) - ->property('qux', array('%foo%' => 'foo is %foo%', 'foobar' => '%foo%')) - ->call('setBar', array(ref('bar'))) + ->property('qux', ['%foo%' => 'foo is %foo%', 'foobar' => '%foo%']) + ->call('setBar', [ref('bar')]) ->call('initialize') ->configurator('sc_configure'); $s->set('foo.baz', '%baz_class%') - ->factory(array('%baz_class%', 'getInstance')) - ->configurator(array('%baz_class%', 'configureStatic1')); + ->factory(['%baz_class%', 'getInstance']) + ->configurator(['%baz_class%', 'configureStatic1']); $s->set('bar', FooClass::class) - ->args(array('foo', ref('foo.baz'), new Parameter('foo_bar'))) - ->configurator(array(ref('foo.baz'), 'configure')); + ->args(['foo', ref('foo.baz'), new Parameter('foo_bar')]) + ->configurator([ref('foo.baz'), 'configure']); $s->set('foo_bar', '%foo_class%') - ->args(array(ref('deprecated_service'))) + ->args([ref('deprecated_service')]) ->share(false); $s->set('method_call1', 'Bar\FooClass') ->file(realpath(__DIR__.'/../includes/foo.php')) - ->call('setBar', array(ref('foo'))) - ->call('setBar', array(ref('foo2')->nullOnInvalid())) - ->call('setBar', array(ref('foo3')->ignoreOnInvalid())) - ->call('setBar', array(ref('foobaz')->ignoreOnInvalid())) - ->call('setBar', array(expr('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")'))); + ->call('setBar', [ref('foo')]) + ->call('setBar', [ref('foo2')->nullOnInvalid()]) + ->call('setBar', [ref('foo3')->ignoreOnInvalid()]) + ->call('setBar', [ref('foobaz')->ignoreOnInvalid()]) + ->call('setBar', [expr('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")')]); $s->set('foo_with_inline', 'Foo') - ->call('setBar', array(ref('inlined'))); + ->call('setBar', [ref('inlined')]); $s->set('inlined', 'Bar') ->property('pub', 'pub') - ->call('setBaz', array(ref('baz'))) + ->call('setBaz', [ref('baz')]) ->private(); $s->set('baz', 'Baz') - ->call('setFoo', array(ref('foo_with_inline'))); + ->call('setFoo', [ref('foo_with_inline')]); $s->set('request', 'Request') ->synthetic(); $s->set('configurator_service', 'ConfClass') ->private() - ->call('setFoo', array(ref('baz'))); + ->call('setFoo', [ref('baz')]); $s->set('configured_service', 'stdClass') - ->configurator(array(ref('configurator_service'), 'configureStdClass')); + ->configurator([ref('configurator_service'), 'configureStdClass']); $s->set('configurator_service_simple', 'ConfClass') - ->args(array('bar')) + ->args(['bar']) ->private(); $s->set('configured_service_simple', 'stdClass') - ->configurator(array(ref('configurator_service_simple'), 'configureStdClass')); + ->configurator([ref('configurator_service_simple'), 'configureStdClass']); $s->set('decorated', 'stdClass'); @@ -92,28 +92,28 @@ ->private(); $s->set('factory_service', 'Bar') - ->factory(array(ref('foo.baz'), 'getInstance')); + ->factory([ref('foo.baz'), 'getInstance']); $s->set('new_factory_service', 'FooBarBaz') ->property('foo', 'bar') - ->factory(array(ref('new_factory'), 'getInstance')); + ->factory([ref('new_factory'), 'getInstance']); $s->set('service_from_static_method', 'Bar\FooClass') - ->factory(array('Bar\FooClass', 'getInstance')); + ->factory(['Bar\FooClass', 'getInstance']); $s->set('factory_simple', 'SimpleFactoryClass') ->deprecate() - ->args(array('foo')) + ->args(['foo']) ->private(); $s->set('factory_service_simple', 'Bar') - ->factory(array(ref('factory_simple'), 'getInstance')); + ->factory([ref('factory_simple'), 'getInstance']); $s->set('lazy_context', 'LazyContext') - ->args(array(iterator(array('k1' => ref('foo.baz'), 'k2' => ref('service_container'))), iterator(array()))); + ->args([iterator(['k1' => ref('foo.baz'), 'k2' => ref('service_container')]), iterator([])]); $s->set('lazy_context_ignore_invalid_ref', 'LazyContext') - ->args(array(iterator(array(ref('foo.baz'), ref('invalid')->ignoreOnInvalid())), iterator(array()))); + ->args([iterator([ref('foo.baz'), ref('invalid')->ignoreOnInvalid()]), iterator([])]); $s->set('tagged_iterator_foo', 'Bar') ->private() @@ -121,7 +121,7 @@ $s->set('tagged_iterator', 'Bar') ->public() - ->args(array(tagged('foo'))); + ->args([tagged('foo')]); $s->alias('alias_for_foo', 'foo')->private()->public(); $s->alias('alias_for_alias', ref('alias_for_foo')); diff --git a/Tests/Fixtures/containers/container11.php b/Tests/Fixtures/containers/container11.php index 150cd7921..91e5c2633 100644 --- a/Tests/Fixtures/containers/container11.php +++ b/Tests/Fixtures/containers/container11.php @@ -6,7 +6,7 @@ $container = new ContainerBuilder(); $container-> register('foo', 'FooClass')-> - addArgument(new Definition('BarClass', array(new Definition('BazClass')))) + addArgument(new Definition('BarClass', [new Definition('BazClass')])) ->setPublic(true) ; diff --git a/Tests/Fixtures/containers/container12.php b/Tests/Fixtures/containers/container12.php index bc527eb79..ef0770302 100644 --- a/Tests/Fixtures/containers/container12.php +++ b/Tests/Fixtures/containers/container12.php @@ -6,7 +6,7 @@ $container-> register('foo', 'FooClass\\Foo')-> addArgument('foo<>&bar')-> - addTag('foo"bar\\bar', array('foo' => 'foo"barřž€')) + addTag('foo"bar\\bar', ['foo' => 'foo"barřž€']) ->setPublic(true) ; diff --git a/Tests/Fixtures/containers/container19.php b/Tests/Fixtures/containers/container19.php index 300a5cc76..c3af5c960 100644 --- a/Tests/Fixtures/containers/container19.php +++ b/Tests/Fixtures/containers/container19.php @@ -12,7 +12,7 @@ $container ->register('service_from_anonymous_factory', '%foo%') - ->setFactory(array(new Definition('%foo%'), 'getInstance')) + ->setFactory([new Definition('%foo%'), 'getInstance']) ->setPublic(true) ; @@ -20,7 +20,7 @@ $anonymousServiceWithFactory->setFactory('Bar\FooClass::getInstance'); $container ->register('service_with_method_call_and_factory', 'Bar\FooClass') - ->addMethodCall('setBar', array($anonymousServiceWithFactory)) + ->addMethodCall('setBar', [$anonymousServiceWithFactory]) ->setPublic(true) ; diff --git a/Tests/Fixtures/containers/container21.php b/Tests/Fixtures/containers/container21.php index 298c9266a..d82cf3853 100644 --- a/Tests/Fixtures/containers/container21.php +++ b/Tests/Fixtures/containers/container21.php @@ -6,15 +6,15 @@ $container = new ContainerBuilder(); $bar = new Definition('Bar'); -$bar->setConfigurator(array(new Definition('Baz'), 'configureBar')); +$bar->setConfigurator([new Definition('Baz'), 'configureBar']); $fooFactory = new Definition('FooFactory'); -$fooFactory->setFactory(array(new Definition('Foobar'), 'createFooFactory')); +$fooFactory->setFactory([new Definition('Foobar'), 'createFooFactory']); $container ->register('foo', 'Foo') - ->setFactory(array($fooFactory, 'createFoo')) - ->setConfigurator(array($bar, 'configureFoo')) + ->setFactory([$fooFactory, 'createFoo']) + ->setConfigurator([$bar, 'configureFoo']) ->setPublic(true) ; diff --git a/Tests/Fixtures/containers/container8.php b/Tests/Fixtures/containers/container8.php index 1a4e5ab5c..5b3c01c23 100644 --- a/Tests/Fixtures/containers/container8.php +++ b/Tests/Fixtures/containers/container8.php @@ -3,12 +3,12 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -$container = new ContainerBuilder(new ParameterBag(array( +$container = new ContainerBuilder(new ParameterBag([ 'foo' => '%baz%', 'baz' => 'bar', 'bar' => 'foo is %%foo bar', 'escape' => '@escapeme', - 'values' => array(true, false, null, 0, 1000.3, 'true', 'false', 'null'), -))); + 'values' => [true, false, null, 0, 1000.3, 'true', 'false', 'null'], +])); return $container; diff --git a/Tests/Fixtures/containers/container9.php b/Tests/Fixtures/containers/container9.php index 21d35611c..691a7fa69 100644 --- a/Tests/Fixtures/containers/container9.php +++ b/Tests/Fixtures/containers/container9.php @@ -14,26 +14,26 @@ $container = new ContainerBuilder(); $container ->register('foo', '\Bar\FooClass') - ->addTag('foo', array('foo' => 'foo')) - ->addTag('foo', array('bar' => 'bar', 'baz' => 'baz')) - ->setFactory(array('Bar\\FooClass', 'getInstance')) - ->setArguments(array('foo', new Reference('foo.baz'), array('%foo%' => 'foo is %foo%', 'foobar' => '%foo%'), true, new Reference('service_container'))) - ->setProperties(array('foo' => 'bar', 'moo' => new Reference('foo.baz'), 'qux' => array('%foo%' => 'foo is %foo%', 'foobar' => '%foo%'))) - ->addMethodCall('setBar', array(new Reference('bar'))) + ->addTag('foo', ['foo' => 'foo']) + ->addTag('foo', ['bar' => 'bar', 'baz' => 'baz']) + ->setFactory(['Bar\\FooClass', 'getInstance']) + ->setArguments(['foo', new Reference('foo.baz'), ['%foo%' => 'foo is %foo%', 'foobar' => '%foo%'], true, new Reference('service_container')]) + ->setProperties(['foo' => 'bar', 'moo' => new Reference('foo.baz'), 'qux' => ['%foo%' => 'foo is %foo%', 'foobar' => '%foo%']]) + ->addMethodCall('setBar', [new Reference('bar')]) ->addMethodCall('initialize') ->setConfigurator('sc_configure') ->setPublic(true) ; $container ->register('foo.baz', '%baz_class%') - ->setFactory(array('%baz_class%', 'getInstance')) - ->setConfigurator(array('%baz_class%', 'configureStatic1')) + ->setFactory(['%baz_class%', 'getInstance']) + ->setConfigurator(['%baz_class%', 'configureStatic1']) ->setPublic(true) ; $container ->register('bar', 'Bar\FooClass') - ->setArguments(array('foo', new Reference('foo.baz'), new Parameter('foo_bar'))) - ->setConfigurator(array(new Reference('foo.baz'), 'configure')) + ->setArguments(['foo', new Reference('foo.baz'), new Parameter('foo_bar')]) + ->setConfigurator([new Reference('foo.baz'), 'configure']) ->setPublic(true) ; $container @@ -43,35 +43,35 @@ ->setPublic(true) ; $container->getParameterBag()->clear(); -$container->getParameterBag()->add(array( +$container->getParameterBag()->add([ 'baz_class' => 'BazClass', 'foo_class' => 'Bar\FooClass', 'foo' => 'bar', -)); +]); $container ->register('method_call1', 'Bar\FooClass') ->setFile(realpath(__DIR__.'/../includes/foo.php')) - ->addMethodCall('setBar', array(new Reference('foo'))) - ->addMethodCall('setBar', array(new Reference('foo2', ContainerInterface::NULL_ON_INVALID_REFERENCE))) - ->addMethodCall('setBar', array(new Reference('foo3', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))) - ->addMethodCall('setBar', array(new Reference('foobaz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))) - ->addMethodCall('setBar', array(new Expression('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")'))) + ->addMethodCall('setBar', [new Reference('foo')]) + ->addMethodCall('setBar', [new Reference('foo2', ContainerInterface::NULL_ON_INVALID_REFERENCE)]) + ->addMethodCall('setBar', [new Reference('foo3', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]) + ->addMethodCall('setBar', [new Reference('foobaz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]) + ->addMethodCall('setBar', [new Expression('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")')]) ->setPublic(true) ; $container ->register('foo_with_inline', 'Foo') - ->addMethodCall('setBar', array(new Reference('inlined'))) + ->addMethodCall('setBar', [new Reference('inlined')]) ->setPublic(true) ; $container ->register('inlined', 'Bar') ->setProperty('pub', 'pub') - ->addMethodCall('setBaz', array(new Reference('baz'))) + ->addMethodCall('setBaz', [new Reference('baz')]) ->setPublic(false) ; $container ->register('baz', 'Baz') - ->addMethodCall('setFoo', array(new Reference('foo_with_inline'))) + ->addMethodCall('setFoo', [new Reference('foo_with_inline')]) ->setPublic(true) ; $container @@ -82,11 +82,11 @@ $container ->register('configurator_service', 'ConfClass') ->setPublic(false) - ->addMethodCall('setFoo', array(new Reference('baz'))) + ->addMethodCall('setFoo', [new Reference('baz')]) ; $container ->register('configured_service', 'stdClass') - ->setConfigurator(array(new Reference('configurator_service'), 'configureStdClass')) + ->setConfigurator([new Reference('configurator_service'), 'configureStdClass']) ->setPublic(true) ; $container @@ -96,7 +96,7 @@ ; $container ->register('configured_service_simple', 'stdClass') - ->setConfigurator(array(new Reference('configurator_service_simple'), 'configureStdClass')) + ->setConfigurator([new Reference('configurator_service_simple'), 'configureStdClass']) ->setPublic(true) ; $container @@ -125,18 +125,18 @@ ; $container ->register('factory_service', 'Bar') - ->setFactory(array(new Reference('foo.baz'), 'getInstance')) + ->setFactory([new Reference('foo.baz'), 'getInstance']) ->setPublic(true) ; $container ->register('new_factory_service', 'FooBarBaz') ->setProperty('foo', 'bar') - ->setFactory(array(new Reference('new_factory'), 'getInstance')) + ->setFactory([new Reference('new_factory'), 'getInstance']) ->setPublic(true) ; $container ->register('service_from_static_method', 'Bar\FooClass') - ->setFactory(array('Bar\FooClass', 'getInstance')) + ->setFactory(['Bar\FooClass', 'getInstance']) ->setPublic(true) ; $container @@ -147,17 +147,17 @@ ; $container ->register('factory_service_simple', 'Bar') - ->setFactory(array(new Reference('factory_simple'), 'getInstance')) + ->setFactory([new Reference('factory_simple'), 'getInstance']) ->setPublic(true) ; $container ->register('lazy_context', 'LazyContext') - ->setArguments(array(new IteratorArgument(array('k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container'))), new IteratorArgument(array()))) + ->setArguments([new IteratorArgument(['k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container')]), new IteratorArgument([])]) ->setPublic(true) ; $container ->register('lazy_context_ignore_invalid_ref', 'LazyContext') - ->setArguments(array(new IteratorArgument(array(new Reference('foo.baz'), new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))), new IteratorArgument(array()))) + ->setArguments([new IteratorArgument([new Reference('foo.baz'), new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]), new IteratorArgument([])]) ->setPublic(true) ; $container diff --git a/Tests/Fixtures/containers/container_almost_circular.php b/Tests/Fixtures/containers/container_almost_circular.php index 4c9906f7a..df136cfa5 100644 --- a/Tests/Fixtures/containers/container_almost_circular.php +++ b/Tests/Fixtures/containers/container_almost_circular.php @@ -15,7 +15,7 @@ ->addArgument(new Reference('bar')); $container->register('bar', BarCircular::class)->setPublic($public) - ->addMethodCall('addFoobar', array(new Reference('foobar'))); + ->addMethodCall('addFoobar', [new Reference('foobar')]); $container->register('foobar', FoobarCircular::class)->setPublic($public) ->addArgument(new Reference('foo')); @@ -26,7 +26,7 @@ ->addArgument(new Reference('bar2')); $container->register('bar2', BarCircular::class)->setPublic(!$public) - ->addMethodCall('addFoobar', array(new Reference('foobar2'))); + ->addMethodCall('addFoobar', [new Reference('foobar2')]); $container->register('foobar2', FoobarCircular::class)->setPublic($public) ->addArgument(new Reference('foo2')); @@ -34,7 +34,7 @@ // simple inline setter with internal reference $container->register('bar3', BarCircular::class)->setPublic(true) - ->addMethodCall('addFoobar', array(new Reference('foobar3'), new Reference('foobar3'))); + ->addMethodCall('addFoobar', [new Reference('foobar3'), new Reference('foobar3')]); $container->register('foobar3', FoobarCircular::class)->setPublic($public); diff --git a/Tests/Fixtures/containers/container_env_in_id.php b/Tests/Fixtures/containers/container_env_in_id.php index 4699f4101..1e851cf01 100644 --- a/Tests/Fixtures/containers/container_env_in_id.php +++ b/Tests/Fixtures/containers/container_env_in_id.php @@ -11,7 +11,7 @@ $container->register('foo', 'stdClass')->setPublic(true) ->addArgument(new Reference('bar_%env(BAR)%')) - ->addArgument(array('baz_%env(BAR)%' => new Reference('baz_%env(BAR)%'))); + ->addArgument(['baz_%env(BAR)%' => new Reference('baz_%env(BAR)%')]); $container->register('bar', 'stdClass')->setPublic(true) ->addArgument(new Reference('bar_%env(BAR)%')); diff --git a/Tests/Fixtures/containers/container_uninitialized_ref.php b/Tests/Fixtures/containers/container_uninitialized_ref.php index 7aeefb4d5..36c05c3fa 100644 --- a/Tests/Fixtures/containers/container_uninitialized_ref.php +++ b/Tests/Fixtures/containers/container_uninitialized_ref.php @@ -33,16 +33,16 @@ ->setProperty('foo1', new Reference('foo1', $container::IGNORE_ON_UNINITIALIZED_REFERENCE)) ->setProperty('foo2', new Reference('foo2', $container::IGNORE_ON_UNINITIALIZED_REFERENCE)) ->setProperty('foo3', new Reference('foo3', $container::IGNORE_ON_UNINITIALIZED_REFERENCE)) - ->setProperty('closures', array( + ->setProperty('closures', [ new ServiceClosureArgument(new Reference('foo1', $container::IGNORE_ON_UNINITIALIZED_REFERENCE)), new ServiceClosureArgument(new Reference('foo2', $container::IGNORE_ON_UNINITIALIZED_REFERENCE)), new ServiceClosureArgument(new Reference('foo3', $container::IGNORE_ON_UNINITIALIZED_REFERENCE)), - )) - ->setProperty('iter', new IteratorArgument(array( + ]) + ->setProperty('iter', new IteratorArgument([ 'foo1' => new Reference('foo1', $container::IGNORE_ON_UNINITIALIZED_REFERENCE), 'foo2' => new Reference('foo2', $container::IGNORE_ON_UNINITIALIZED_REFERENCE), 'foo3' => new Reference('foo3', $container::IGNORE_ON_UNINITIALIZED_REFERENCE), - ))) + ])) ->setPublic(true) ; diff --git a/Tests/Fixtures/includes/ProjectExtension.php b/Tests/Fixtures/includes/ProjectExtension.php index ba07d7c44..2198b19c4 100644 --- a/Tests/Fixtures/includes/ProjectExtension.php +++ b/Tests/Fixtures/includes/ProjectExtension.php @@ -14,7 +14,7 @@ public function load(array $configs, ContainerBuilder $configuration) if ($configs) { $config = call_user_func_array('array_merge', $configs); } else { - $config = array(); + $config = []; } $configuration->setDefinition('project.service.bar', new Definition('FooClass')); diff --git a/Tests/Fixtures/includes/foo.php b/Tests/Fixtures/includes/foo.php index bcb4e20a9..20bc928b9 100644 --- a/Tests/Fixtures/includes/foo.php +++ b/Tests/Fixtures/includes/foo.php @@ -11,14 +11,14 @@ class FooClass public $initialized = false; public $configured = false; public $called = false; - public $arguments = array(); + public $arguments = []; - public function __construct($arguments = array()) + public function __construct($arguments = []) { $this->arguments = $arguments; } - public static function getInstance($arguments = array()) + public static function getInstance($arguments = []) { $obj = new self($arguments); $obj->called = true; diff --git a/Tests/Fixtures/php/custom_container_class_constructor_without_arguments.php b/Tests/Fixtures/php/custom_container_class_constructor_without_arguments.php index 0a443f3a7..7495110dd 100644 --- a/Tests/Fixtures/php/custom_container_class_constructor_without_arguments.php +++ b/Tests/Fixtures/php/custom_container_class_constructor_without_arguments.php @@ -19,24 +19,24 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tests\Fixtures\Container\ConstructorWithoutArgumentsContainer { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { parent::__construct(); $this->parameterBag = null; - $this->services = array(); + $this->services = []; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/custom_container_class_with_mandatory_constructor_arguments.php b/Tests/Fixtures/php/custom_container_class_with_mandatory_constructor_arguments.php index dd9ed9cbb..eb573f9ba 100644 --- a/Tests/Fixtures/php/custom_container_class_with_mandatory_constructor_arguments.php +++ b/Tests/Fixtures/php/custom_container_class_with_mandatory_constructor_arguments.php @@ -19,21 +19,21 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tests\Fixtures\Container\ConstructorWithMandatoryArgumentsContainer { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); + $this->services = []; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php b/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php index 6bf3c9061..d322f80a0 100644 --- a/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php +++ b/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php @@ -19,24 +19,24 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tests\Fixtures\Container\ConstructorWithOptionalArgumentsContainer { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { parent::__construct(); $this->parameterBag = null; - $this->services = array(); + $this->services = []; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/custom_container_class_without_constructor.php b/Tests/Fixtures/php/custom_container_class_without_constructor.php index 4cf1ae40b..68bc1ef8b 100644 --- a/Tests/Fixtures/php/custom_container_class_without_constructor.php +++ b/Tests/Fixtures/php/custom_container_class_without_constructor.php @@ -19,21 +19,21 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tests\Fixtures\Container\NoConstructorContainer { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); + $this->services = []; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services1-1.php b/Tests/Fixtures/php/services1-1.php index bdd0d101a..ed085a5ef 100644 --- a/Tests/Fixtures/php/services1-1.php +++ b/Tests/Fixtures/php/services1-1.php @@ -19,21 +19,21 @@ class Container extends \Symfony\Component\DependencyInjection\Dump\AbstractContainer { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); + $this->services = []; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services1.php b/Tests/Fixtures/php/services1.php index 85830af78..9733ba9c6 100644 --- a/Tests/Fixtures/php/services1.php +++ b/Tests/Fixtures/php/services1.php @@ -17,21 +17,21 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); + $this->services = []; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services10.php b/Tests/Fixtures/php/services10.php index aa078ab85..1b7443352 100644 --- a/Tests/Fixtures/php/services10.php +++ b/Tests/Fixtures/php/services10.php @@ -17,26 +17,26 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { $this->parameters = $this->getDefaultParameters(); - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'test' => 'getTestService', - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() @@ -63,7 +63,7 @@ public function isFrozen() */ protected function getTestService() { - return $this->services['test'] = new \stdClass(array('only dot' => '.', 'concatenation as value' => '.\'\'.', 'concatenation from the start value' => '\'\'.', '.' => 'dot as a key', '.\'\'.' => 'concatenation as a key', '\'\'.' => 'concatenation from the start key', 'optimize concatenation' => 'string1-string2', 'optimize concatenation with empty string' => 'string1string2', 'optimize concatenation from the start' => 'start', 'optimize concatenation at the end' => 'end', 'new line' => 'string with '."\n".'new line')); + return $this->services['test'] = new \stdClass(['only dot' => '.', 'concatenation as value' => '.\'\'.', 'concatenation from the start value' => '\'\'.', '.' => 'dot as a key', '.\'\'.' => 'concatenation as a key', '\'\'.' => 'concatenation from the start key', 'optimize concatenation' => 'string1-string2', 'optimize concatenation with empty string' => 'string1string2', 'optimize concatenation from the start' => 'start', 'optimize concatenation at the end' => 'end', 'new line' => 'string with '."\n".'new line']); } public function getParameter($name) @@ -109,8 +109,8 @@ public function getParameterBag() return $this->parameterBag; } - private $loadedDynamicParameters = array(); - private $dynamicParameters = array(); + private $loadedDynamicParameters = []; + private $dynamicParameters = []; /** * Computes a dynamic parameter. @@ -126,7 +126,7 @@ private function getDynamicParameter($name) throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name)); } - private $normalizedParameterNames = array(); + private $normalizedParameterNames = []; private function normalizeParameterName($name) { @@ -149,9 +149,9 @@ private function normalizeParameterName($name) */ protected function getDefaultParameters() { - return array( + return [ 'empty_value' => '', 'some_string' => '-', - ); + ]; } } diff --git a/Tests/Fixtures/php/services12.php b/Tests/Fixtures/php/services12.php index 4266ad8e5..ba564b82f 100644 --- a/Tests/Fixtures/php/services12.php +++ b/Tests/Fixtures/php/services12.php @@ -17,7 +17,7 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { @@ -27,20 +27,20 @@ public function __construct() } $this->parameters = $this->getDefaultParameters(); - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'test' => 'getTestService', - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() @@ -67,7 +67,7 @@ public function isFrozen() */ protected function getTestService() { - return $this->services['test'] = new \stdClass(('wiz'.$this->targetDirs[1]), array(('wiz'.$this->targetDirs[1]) => ($this->targetDirs[2].'/'))); + return $this->services['test'] = new \stdClass(('wiz'.$this->targetDirs[1]), [('wiz'.$this->targetDirs[1]) => ($this->targetDirs[2].'/')]); } public function getParameter($name) @@ -113,11 +113,11 @@ public function getParameterBag() return $this->parameterBag; } - private $loadedDynamicParameters = array( + private $loadedDynamicParameters = [ 'foo' => false, 'buz' => false, - ); - private $dynamicParameters = array(); + ]; + private $dynamicParameters = []; /** * Computes a dynamic parameter. @@ -140,7 +140,7 @@ private function getDynamicParameter($name) return $this->dynamicParameters[$name] = $value; } - private $normalizedParameterNames = array(); + private $normalizedParameterNames = []; private function normalizeParameterName($name) { @@ -163,9 +163,9 @@ private function normalizeParameterName($name) */ protected function getDefaultParameters() { - return array( + return [ 'bar' => __DIR__, 'baz' => (__DIR__.'/PhpDumperTest.php'), - ); + ]; } } diff --git a/Tests/Fixtures/php/services13.php b/Tests/Fixtures/php/services13.php index 04705a29e..40ce06dec 100644 --- a/Tests/Fixtures/php/services13.php +++ b/Tests/Fixtures/php/services13.php @@ -17,25 +17,25 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'bar' => 'getBarService', - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'foo' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services19.php b/Tests/Fixtures/php/services19.php index c8b57a7cc..664f4dd90 100644 --- a/Tests/Fixtures/php/services19.php +++ b/Tests/Fixtures/php/services19.php @@ -17,27 +17,27 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { $this->parameters = $this->getDefaultParameters(); - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'service_from_anonymous_factory' => 'getServiceFromAnonymousFactoryService', 'service_with_method_call_and_factory' => 'getServiceWithMethodCallAndFactoryService', - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() @@ -124,10 +124,10 @@ public function getParameterBag() return $this->parameterBag; } - private $loadedDynamicParameters = array( + private $loadedDynamicParameters = [ 'foo' => false, - ); - private $dynamicParameters = array(); + ]; + private $dynamicParameters = []; /** * Computes a dynamic parameter. @@ -149,9 +149,9 @@ private function getDynamicParameter($name) return $this->dynamicParameters[$name] = $value; } - private $normalizedParameterNames = array( + private $normalizedParameterNames = [ 'env(foo)' => 'env(FOO)', - ); + ]; private function normalizeParameterName($name) { @@ -174,8 +174,8 @@ private function normalizeParameterName($name) */ protected function getDefaultParameters() { - return array( + return [ 'env(FOO)' => 'Bar\\FaooClass', - ); + ]; } } diff --git a/Tests/Fixtures/php/services24.php b/Tests/Fixtures/php/services24.php index 1be6319ee..b277ddd1c 100644 --- a/Tests/Fixtures/php/services24.php +++ b/Tests/Fixtures/php/services24.php @@ -17,24 +17,24 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'foo' => 'getFooService', - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services26.php b/Tests/Fixtures/php/services26.php index d6256008f..595d12ba6 100644 --- a/Tests/Fixtures/php/services26.php +++ b/Tests/Fixtures/php/services26.php @@ -17,7 +17,7 @@ class Symfony_DI_PhpDumper_Test_EnvParameters extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { @@ -27,21 +27,21 @@ public function __construct() } $this->parameters = $this->getDefaultParameters(); - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'bar' => 'getBarService', 'test' => 'getTestService', - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() @@ -126,14 +126,14 @@ public function getParameterBag() return $this->parameterBag; } - private $loadedDynamicParameters = array( + private $loadedDynamicParameters = [ 'bar' => false, 'baz' => false, 'json' => false, 'db_dsn' => false, 'env(json_file)' => false, - ); - private $dynamicParameters = array(); + ]; + private $dynamicParameters = []; /** * Computes a dynamic parameter. @@ -159,10 +159,10 @@ private function getDynamicParameter($name) return $this->dynamicParameters[$name] = $value; } - private $normalizedParameterNames = array( + private $normalizedParameterNames = [ 'env(foo)' => 'env(FOO)', 'env(db)' => 'env(DB)', - ); + ]; private function normalizeParameterName($name) { @@ -185,10 +185,10 @@ private function normalizeParameterName($name) */ protected function getDefaultParameters() { - return array( + return [ 'project_dir' => '/foo/bar', 'env(FOO)' => 'foo', 'env(DB)' => 'sqlite://%project_dir%/var/data.db', - ); + ]; } } diff --git a/Tests/Fixtures/php/services33.php b/Tests/Fixtures/php/services33.php index 3e308c1d4..98e34bc9b 100644 --- a/Tests/Fixtures/php/services33.php +++ b/Tests/Fixtures/php/services33.php @@ -17,29 +17,29 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->normalizedIds = array( + $this->services = []; + $this->normalizedIds = [ 'bar\\foo' => 'Bar\\Foo', 'foo\\foo' => 'Foo\\Foo', - ); - $this->methodMap = array( + ]; + $this->methodMap = [ 'Bar\\Foo' => 'getFooService', 'Foo\\Foo' => 'getFoo2Service', - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services8.php b/Tests/Fixtures/php/services8.php index 285942eb1..cc78c196a 100644 --- a/Tests/Fixtures/php/services8.php +++ b/Tests/Fixtures/php/services8.php @@ -17,23 +17,23 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { $this->parameters = $this->getDefaultParameters(); - $this->services = array(); + $this->services = []; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() @@ -96,8 +96,8 @@ public function getParameterBag() return $this->parameterBag; } - private $loadedDynamicParameters = array(); - private $dynamicParameters = array(); + private $loadedDynamicParameters = []; + private $dynamicParameters = []; /** * Computes a dynamic parameter. @@ -113,7 +113,7 @@ private function getDynamicParameter($name) throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name)); } - private $normalizedParameterNames = array(); + private $normalizedParameterNames = []; private function normalizeParameterName($name) { @@ -136,12 +136,12 @@ private function normalizeParameterName($name) */ protected function getDefaultParameters() { - return array( + return [ 'foo' => 'bar', 'baz' => 'bar', 'bar' => 'foo is %foo bar', 'escape' => '@escapeme', - 'values' => array( + 'values' => [ 0 => true, 1 => false, 2 => NULL, @@ -150,7 +150,7 @@ protected function getDefaultParameters() 5 => 'true', 6 => 'false', 7 => 'null', - ), - ); + ], + ]; } } diff --git a/Tests/Fixtures/php/services9.php b/Tests/Fixtures/php/services9.php index fc04f5fae..0e09ec624 100644 --- a/Tests/Fixtures/php/services9.php +++ b/Tests/Fixtures/php/services9.php @@ -17,19 +17,19 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { parent::__construct(new ParameterBag($this->getDefaultParameters())); - $this->normalizedIds = array( + $this->normalizedIds = [ 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); - $this->syntheticIds = array( + ]; + $this->syntheticIds = [ 'request' => true, - ); - $this->methodMap = array( + ]; + $this->methodMap = [ 'bar' => 'getBarService', 'baz' => 'getBazService', 'configurator_service' => 'getConfiguratorServiceService', @@ -56,21 +56,21 @@ public function __construct() 'service_from_static_method' => 'getServiceFromStaticMethodService', 'tagged_iterator' => 'getTaggedIteratorService', 'tagged_iterator_foo' => 'getTaggedIteratorFooService', - ); - $this->privates = array( + ]; + $this->privates = [ 'configurator_service' => true, 'configurator_service_simple' => true, 'factory_simple' => true, 'inlined' => true, 'new_factory' => true, 'tagged_iterator_foo' => true, - ); - $this->aliases = array( + ]; + $this->aliases = [ 'Psr\\Container\\ContainerInterface' => 'service_container', 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => 'service_container', 'alias_for_alias' => 'foo', 'alias_for_foo' => 'foo', - ); + ]; } /** @@ -204,11 +204,11 @@ protected function getFooService() { $a = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->getFoo_BazService()) && false ?: '_'}; - $this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo').'', 'foobar' => $this->getParameter('foo')), true, $this); + $this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, [$this->getParameter('foo') => 'foo is '.$this->getParameter('foo').'', 'foobar' => $this->getParameter('foo')], true, $this); $instance->foo = 'bar'; $instance->moo = $a; - $instance->qux = array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo').'', 'foobar' => $this->getParameter('foo')); + $instance->qux = [$this->getParameter('foo') => 'foo is '.$this->getParameter('foo').'', 'foobar' => $this->getParameter('foo')]; $instance->setBar(${($_ = isset($this->services['bar']) ? $this->services['bar'] : $this->getBarService()) && false ?: '_'}); $instance->initialize(); sc_configure($instance); @@ -223,9 +223,9 @@ protected function getFooService() */ protected function getFoo_BazService() { - $this->services['foo.baz'] = $instance = \call_user_func(array($this->getParameter('baz_class'), 'getInstance')); + $this->services['foo.baz'] = $instance = \call_user_func([$this->getParameter('baz_class'), 'getInstance']); - \call_user_func(array($this->getParameter('baz_class'), 'configureStatic1'), $instance); + \call_user_func([$this->getParameter('baz_class'), 'configureStatic1'], $instance); return $instance; } @@ -434,10 +434,10 @@ protected function getTaggedIteratorFooService() */ protected function getDefaultParameters() { - return array( + return [ 'baz_class' => 'BazClass', 'foo_class' => 'Bar\\FooClass', 'foo' => 'bar', - ); + ]; } } diff --git a/Tests/Fixtures/php/services9_as_files.txt b/Tests/Fixtures/php/services9_as_files.txt index fa032cbc1..2dc415ced 100644 --- a/Tests/Fixtures/php/services9_as_files.txt +++ b/Tests/Fixtures/php/services9_as_files.txt @@ -2,7 +2,7 @@ Array ( [Container%s/removed-ids.php] => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'configurator_service' => true, @@ -13,7 +13,7 @@ return array( 'inlined' => true, 'new_factory' => true, 'tagged_iterator_foo' => true, -); +]; [Container%s/getBazService.php] => services['foo.baz']) ? $this->services['foo.baz'] : $this->load('getFoo_BazService.php')) && false ?: '_'}; -$this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, array('bar' => 'foo is bar', 'foobar' => 'bar'), true, $this); +$this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, ['bar' => 'foo is bar', 'foobar' => 'bar'], true, $this); $instance->foo = 'bar'; $instance->moo = $a; -$instance->qux = array('bar' => 'foo is bar', 'foobar' => 'bar'); +$instance->qux = ['bar' => 'foo is bar', 'foobar' => 'bar']; $instance->setBar(${($_ = isset($this->services['bar']) ? $this->services['bar'] : $this->getBarService()) && false ?: '_'}); $instance->initialize(); sc_configure($instance); @@ -278,9 +278,9 @@ class ProjectServiceContainer extends Container private $buildParameters; private $containerDir; private $parameters; - private $targetDirs = array(); + private $targetDirs = []; - public function __construct(array $buildParameters = array(), $containerDir = __DIR__) + public function __construct(array $buildParameters = [], $containerDir = __DIR__) { $dir = $this->targetDirs[0] = \dirname($containerDir); for ($i = 1; $i <= 5; ++$i) { @@ -290,15 +290,15 @@ class ProjectServiceContainer extends Container $this->containerDir = $containerDir; $this->parameters = $this->getDefaultParameters(); - $this->services = array(); - $this->syntheticIds = array( + $this->services = []; + $this->syntheticIds = [ 'request' => true, - ); - $this->methodMap = array( + ]; + $this->methodMap = [ 'bar' => 'getBarService', 'foo_bar' => 'getFooBarService', - ); - $this->fileMap = array( + ]; + $this->fileMap = [ 'baz' => 'getBazService.php', 'configured_service' => 'getConfiguredServiceService.php', 'configured_service_simple' => 'getConfiguredServiceSimpleService.php', @@ -318,16 +318,16 @@ class ProjectServiceContainer extends Container 'service_from_static_method' => 'getServiceFromStaticMethodService.php', 'tagged_iterator' => 'getTaggedIteratorService.php', 'tagged_iterator_foo' => 'getTaggedIteratorFooService.php', - ); - $this->privates = array( + ]; + $this->privates = [ 'factory_simple' => true, 'tagged_iterator_foo' => true, - ); - $this->aliases = array( + ]; + $this->aliases = [ 'alias_for_alias' => 'foo', 'alias_for_foo' => 'foo', 'decorated' => 'decorator_service_with_name', - ); + ]; } public function getRemovedIds() @@ -435,8 +435,8 @@ class ProjectServiceContainer extends Container return $this->parameterBag; } - private $loadedDynamicParameters = array(); - private $dynamicParameters = array(); + private $loadedDynamicParameters = []; + private $dynamicParameters = []; /** * Computes a dynamic parameter. @@ -452,7 +452,7 @@ class ProjectServiceContainer extends Container throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name)); } - private $normalizedParameterNames = array(); + private $normalizedParameterNames = []; private function normalizeParameterName($name) { @@ -475,11 +475,11 @@ class ProjectServiceContainer extends Container */ protected function getDefaultParameters() { - return array( + return [ 'baz_class' => 'BazClass', 'foo_class' => 'Bar\\FooClass', 'foo' => 'bar', - ); + ]; } } @@ -499,10 +499,10 @@ if (!\class_exists(ProjectServiceContainer::class, false)) { \class_alias(\Container%s\ProjectServiceContainer::class, ProjectServiceContainer::class, false); } -return new \Container%s\ProjectServiceContainer(array( +return new \Container%s\ProjectServiceContainer([ 'container.build_hash' => '%s', 'container.build_id' => '%s', 'container.build_time' => %d, -), __DIR__.\DIRECTORY_SEPARATOR.'Container%s'); +], __DIR__.\DIRECTORY_SEPARATOR.'Container%s'); ) diff --git a/Tests/Fixtures/php/services9_compiled.php b/Tests/Fixtures/php/services9_compiled.php index b741950fa..02e0680da 100644 --- a/Tests/Fixtures/php/services9_compiled.php +++ b/Tests/Fixtures/php/services9_compiled.php @@ -17,17 +17,17 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { $this->parameters = $this->getDefaultParameters(); - $this->services = array(); - $this->syntheticIds = array( + $this->services = []; + $this->syntheticIds = [ 'request' => true, - ); - $this->methodMap = array( + ]; + $this->methodMap = [ 'bar' => 'getBarService', 'baz' => 'getBazService', 'configured_service' => 'getConfiguredServiceService', @@ -49,21 +49,21 @@ public function __construct() 'service_from_static_method' => 'getServiceFromStaticMethodService', 'tagged_iterator' => 'getTaggedIteratorService', 'tagged_iterator_foo' => 'getTaggedIteratorFooService', - ); - $this->privates = array( + ]; + $this->privates = [ 'factory_simple' => true, 'tagged_iterator_foo' => true, - ); - $this->aliases = array( + ]; + $this->aliases = [ 'alias_for_alias' => 'foo', 'alias_for_foo' => 'foo', 'decorated' => 'decorator_service_with_name', - ); + ]; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'configurator_service' => true, @@ -74,7 +74,7 @@ public function getRemovedIds() 'inlined' => true, 'new_factory' => true, 'tagged_iterator_foo' => true, - ); + ]; } public function compile() @@ -218,11 +218,11 @@ protected function getFooService() { $a = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->getFoo_BazService()) && false ?: '_'}; - $this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, array('bar' => 'foo is bar', 'foobar' => 'bar'), true, $this); + $this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, ['bar' => 'foo is bar', 'foobar' => 'bar'], true, $this); $instance->foo = 'bar'; $instance->moo = $a; - $instance->qux = array('bar' => 'foo is bar', 'foobar' => 'bar'); + $instance->qux = ['bar' => 'foo is bar', 'foobar' => 'bar']; $instance->setBar(${($_ = isset($this->services['bar']) ? $this->services['bar'] : $this->getBarService()) && false ?: '_'}); $instance->initialize(); sc_configure($instance); @@ -426,8 +426,8 @@ public function getParameterBag() return $this->parameterBag; } - private $loadedDynamicParameters = array(); - private $dynamicParameters = array(); + private $loadedDynamicParameters = []; + private $dynamicParameters = []; /** * Computes a dynamic parameter. @@ -443,7 +443,7 @@ private function getDynamicParameter($name) throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name)); } - private $normalizedParameterNames = array(); + private $normalizedParameterNames = []; private function normalizeParameterName($name) { @@ -466,10 +466,10 @@ private function normalizeParameterName($name) */ protected function getDefaultParameters() { - return array( + return [ 'baz_class' => 'BazClass', 'foo_class' => 'Bar\\FooClass', 'foo' => 'bar', - ); + ]; } } diff --git a/Tests/Fixtures/php/services_adawson.php b/Tests/Fixtures/php/services_adawson.php index 37b95567c..f222fc6e6 100644 --- a/Tests/Fixtures/php/services_adawson.php +++ b/Tests/Fixtures/php/services_adawson.php @@ -17,12 +17,12 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->normalizedIds = array( + $this->services = []; + $this->normalizedIds = [ 'app\\bus' => 'App\\Bus', 'app\\db' => 'App\\Db', 'app\\handler1' => 'App\\Handler1', @@ -30,8 +30,8 @@ public function __construct() 'app\\processor' => 'App\\Processor', 'app\\registry' => 'App\\Registry', 'app\\schema' => 'App\\Schema', - ); - $this->methodMap = array( + ]; + $this->methodMap = [ 'App\\Bus' => 'getBusService', 'App\\Db' => 'getDbService', 'App\\Handler1' => 'getHandler1Service', @@ -39,21 +39,21 @@ public function __construct() 'App\\Processor' => 'getProcessorService', 'App\\Registry' => 'getRegistryService', 'App\\Schema' => 'getSchemaService', - ); - $this->privates = array( + ]; + $this->privates = [ 'App\\Handler1' => true, 'App\\Handler2' => true, 'App\\Processor' => true, 'App\\Registry' => true, 'App\\Schema' => true, - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'App\\Handler1' => true, 'App\\Handler2' => true, 'App\\Processor' => true, @@ -61,7 +61,7 @@ public function getRemovedIds() 'App\\Schema' => true, 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() @@ -167,7 +167,7 @@ protected function getRegistryService() { $this->services['App\Registry'] = $instance = new \App\Registry(); - $instance->processor = array(0 => ${($_ = isset($this->services['App\Db']) ? $this->services['App\Db'] : $this->getDbService()) && false ?: '_'}, 1 => ${($_ = isset($this->services['App\Bus']) ? $this->services['App\Bus'] : $this->getBusService()) && false ?: '_'}); + $instance->processor = [0 => ${($_ = isset($this->services['App\Db']) ? $this->services['App\Db'] : $this->getDbService()) && false ?: '_'}, 1 => ${($_ = isset($this->services['App\Bus']) ? $this->services['App\Bus'] : $this->getBusService()) && false ?: '_'}]; return $instance; } diff --git a/Tests/Fixtures/php/services_almost_circular_private.php b/Tests/Fixtures/php/services_almost_circular_private.php index 8aa4a2c40..5345aa3b3 100644 --- a/Tests/Fixtures/php/services_almost_circular_private.php +++ b/Tests/Fixtures/php/services_almost_circular_private.php @@ -17,12 +17,12 @@ class Symfony_DI_PhpDumper_Test_Almost_Circular_Private extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'bar2' => 'getBar2Service', 'bar3' => 'getBar3Service', 'bar6' => 'getBar6Service', @@ -45,8 +45,8 @@ public function __construct() 'multiuse1' => 'getMultiuse1Service', 'root' => 'getRootService', 'subscriber' => 'getSubscriberService', - ); - $this->privates = array( + ]; + $this->privates = [ 'bar6' => true, 'level2' => true, 'level3' => true, @@ -54,14 +54,14 @@ public function __construct() 'level5' => true, 'level6' => true, 'multiuse1' => true, - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'bar' => true, @@ -83,7 +83,7 @@ public function getRemovedIds() 'logger2' => true, 'multiuse1' => true, 'subscriber2' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services_almost_circular_public.php b/Tests/Fixtures/php/services_almost_circular_public.php index a5de37f12..b569b335f 100644 --- a/Tests/Fixtures/php/services_almost_circular_public.php +++ b/Tests/Fixtures/php/services_almost_circular_public.php @@ -17,12 +17,12 @@ class Symfony_DI_PhpDumper_Test_Almost_Circular_Public extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'bar' => 'getBarService', 'bar3' => 'getBar3Service', 'bar5' => 'getBar5Service', @@ -52,8 +52,8 @@ public function __construct() 'multiuse1' => 'getMultiuse1Service', 'root' => 'getRootService', 'subscriber' => 'getSubscriberService', - ); - $this->privates = array( + ]; + $this->privates = [ 'bar6' => true, 'level2' => true, 'level3' => true, @@ -61,14 +61,14 @@ public function __construct() 'level5' => true, 'level6' => true, 'multiuse1' => true, - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'bar2' => true, @@ -83,7 +83,7 @@ public function getRemovedIds() 'logger2' => true, 'multiuse1' => true, 'subscriber2' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services_array_params.php b/Tests/Fixtures/php/services_array_params.php index 5ef6cb688..be59456b0 100644 --- a/Tests/Fixtures/php/services_array_params.php +++ b/Tests/Fixtures/php/services_array_params.php @@ -17,7 +17,7 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { @@ -27,20 +27,20 @@ public function __construct() } $this->parameters = $this->getDefaultParameters(); - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'bar' => 'getBarService', - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() @@ -117,10 +117,10 @@ public function getParameterBag() return $this->parameterBag; } - private $loadedDynamicParameters = array( + private $loadedDynamicParameters = [ 'array_2' => false, - ); - private $dynamicParameters = array(); + ]; + private $dynamicParameters = []; /** * Computes a dynamic parameter. @@ -134,9 +134,9 @@ public function getParameterBag() private function getDynamicParameter($name) { switch ($name) { - case 'array_2': $value = array( + case 'array_2': $value = [ 0 => ($this->targetDirs[2].'/Dumper'), - ); break; + ]; break; default: throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name)); } $this->loadedDynamicParameters[$name] = true; @@ -144,7 +144,7 @@ private function getDynamicParameter($name) return $this->dynamicParameters[$name] = $value; } - private $normalizedParameterNames = array(); + private $normalizedParameterNames = []; private function normalizeParameterName($name) { @@ -167,10 +167,10 @@ private function normalizeParameterName($name) */ protected function getDefaultParameters() { - return array( - 'array_1' => array( + return [ + 'array_1' => [ 0 => 123, - ), - ); + ], + ]; } } diff --git a/Tests/Fixtures/php/services_base64_env.php b/Tests/Fixtures/php/services_base64_env.php index 6b6be9569..8582c3e2d 100644 --- a/Tests/Fixtures/php/services_base64_env.php +++ b/Tests/Fixtures/php/services_base64_env.php @@ -17,23 +17,23 @@ class Symfony_DI_PhpDumper_Test_Base64Parameters extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { $this->parameters = $this->getDefaultParameters(); - $this->services = array(); + $this->services = []; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() @@ -96,10 +96,10 @@ public function getParameterBag() return $this->parameterBag; } - private $loadedDynamicParameters = array( + private $loadedDynamicParameters = [ 'hello' => false, - ); - private $dynamicParameters = array(); + ]; + private $dynamicParameters = []; /** * Computes a dynamic parameter. @@ -121,7 +121,7 @@ private function getDynamicParameter($name) return $this->dynamicParameters[$name] = $value; } - private $normalizedParameterNames = array(); + private $normalizedParameterNames = []; private function normalizeParameterName($name) { @@ -144,8 +144,8 @@ private function normalizeParameterName($name) */ protected function getDefaultParameters() { - return array( + return [ 'env(foo)' => 'd29ybGQ=', - ); + ]; } } diff --git a/Tests/Fixtures/php/services_dedup_lazy_proxy.php b/Tests/Fixtures/php/services_dedup_lazy_proxy.php index 73a7f259f..ec3c8028b 100644 --- a/Tests/Fixtures/php/services_dedup_lazy_proxy.php +++ b/Tests/Fixtures/php/services_dedup_lazy_proxy.php @@ -17,25 +17,25 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'bar' => 'getBarService', 'foo' => 'getFooService', - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services_deep_graph.php b/Tests/Fixtures/php/services_deep_graph.php index 9a1d1ab8c..4158fc628 100644 --- a/Tests/Fixtures/php/services_deep_graph.php +++ b/Tests/Fixtures/php/services_deep_graph.php @@ -17,25 +17,25 @@ class Symfony_DI_PhpDumper_Test_Deep_Graph extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'bar' => 'getBarService', 'foo' => 'getFooService', - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services_env_in_id.php b/Tests/Fixtures/php/services_env_in_id.php index dab23e1db..ad76566b1 100644 --- a/Tests/Fixtures/php/services_env_in_id.php +++ b/Tests/Fixtures/php/services_env_in_id.php @@ -17,36 +17,36 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { $this->parameters = $this->getDefaultParameters(); - $this->services = array(); - $this->normalizedIds = array( + $this->services = []; + $this->normalizedIds = [ 'bar_%env(bar)%' => 'bar_%env(BAR)%', - ); - $this->methodMap = array( + ]; + $this->methodMap = [ 'bar' => 'getBarService', 'bar_%env(BAR)%' => 'getBarenvBARService', 'foo' => 'getFooService', - ); - $this->privates = array( + ]; + $this->privates = [ 'bar_%env(BAR)%' => true, - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'bar_%env(BAR)%' => true, 'baz_%env(BAR)%' => true, - ); + ]; } public function compile() @@ -83,7 +83,7 @@ protected function getBarService() */ protected function getFooService() { - return $this->services['foo'] = new \stdClass(${($_ = isset($this->services['bar_%env(BAR)%']) ? $this->services['bar_%env(BAR)%'] : ($this->services['bar_%env(BAR)%'] = new \stdClass())) && false ?: '_'}, array('baz_'.$this->getEnv('string:BAR') => new \stdClass())); + return $this->services['foo'] = new \stdClass(${($_ = isset($this->services['bar_%env(BAR)%']) ? $this->services['bar_%env(BAR)%'] : ($this->services['bar_%env(BAR)%'] = new \stdClass())) && false ?: '_'}, ['baz_'.$this->getEnv('string:BAR') => new \stdClass()]); } /** @@ -139,8 +139,8 @@ public function getParameterBag() return $this->parameterBag; } - private $loadedDynamicParameters = array(); - private $dynamicParameters = array(); + private $loadedDynamicParameters = []; + private $dynamicParameters = []; /** * Computes a dynamic parameter. @@ -156,9 +156,9 @@ private function getDynamicParameter($name) throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name)); } - private $normalizedParameterNames = array( + private $normalizedParameterNames = [ 'env(bar)' => 'env(BAR)', - ); + ]; private function normalizeParameterName($name) { @@ -181,8 +181,8 @@ private function normalizeParameterName($name) */ protected function getDefaultParameters() { - return array( + return [ 'env(BAR)' => 'bar', - ); + ]; } } diff --git a/Tests/Fixtures/php/services_inline_requires.php b/Tests/Fixtures/php/services_inline_requires.php index c6927eb95..a23a69367 100644 --- a/Tests/Fixtures/php/services_inline_requires.php +++ b/Tests/Fixtures/php/services_inline_requires.php @@ -17,7 +17,7 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { @@ -27,24 +27,24 @@ public function __construct() } $this->parameters = $this->getDefaultParameters(); - $this->services = array(); - $this->normalizedIds = array( + $this->services = []; + $this->normalizedIds = [ 'symfony\\component\\dependencyinjection\\tests\\fixtures\\includes\\hotpath\\c1' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C1', 'symfony\\component\\dependencyinjection\\tests\\fixtures\\includes\\hotpath\\c2' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C2', 'symfony\\component\\dependencyinjection\\tests\\fixtures\\includes\\hotpath\\c3' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C3', 'symfony\\component\\dependencyinjection\\tests\\fixtures\\parentnotexists' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\ParentNotExists', - ); - $this->methodMap = array( + ]; + $this->methodMap = [ 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\ParentNotExists' => 'getParentNotExistsService', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C1' => 'getC1Service', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C2' => 'getC2Service', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C3' => 'getC3Service', - ); - $this->privates = array( + ]; + $this->privates = [ 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C3' => true, - ); + ]; - $this->aliases = array(); + $this->aliases = []; $this->privates['service_container'] = function () { include_once $this->targetDirs[1].'/includes/HotPath/I1.php'; @@ -56,11 +56,11 @@ public function __construct() public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C3' => true, - ); + ]; } public function compile() @@ -168,8 +168,8 @@ public function getParameterBag() return $this->parameterBag; } - private $loadedDynamicParameters = array(); - private $dynamicParameters = array(); + private $loadedDynamicParameters = []; + private $dynamicParameters = []; /** * Computes a dynamic parameter. @@ -185,7 +185,7 @@ private function getDynamicParameter($name) throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name)); } - private $normalizedParameterNames = array(); + private $normalizedParameterNames = []; private function normalizeParameterName($name) { @@ -208,8 +208,8 @@ private function normalizeParameterName($name) */ protected function getDefaultParameters() { - return array( + return [ 'inline_requires' => true, - ); + ]; } } diff --git a/Tests/Fixtures/php/services_inline_self_ref.php b/Tests/Fixtures/php/services_inline_self_ref.php index fa8a4e690..a2573eae6 100644 --- a/Tests/Fixtures/php/services_inline_self_ref.php +++ b/Tests/Fixtures/php/services_inline_self_ref.php @@ -17,27 +17,27 @@ class Symfony_DI_PhpDumper_Test_Inline_Self_Ref extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->normalizedIds = array( + $this->services = []; + $this->normalizedIds = [ 'app\\foo' => 'App\\Foo', - ); - $this->methodMap = array( + ]; + $this->methodMap = [ 'App\\Foo' => 'getFooService', - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services_legacy_privates.php b/Tests/Fixtures/php/services_legacy_privates.php index d720ae396..30dd2c9ba 100644 --- a/Tests/Fixtures/php/services_legacy_privates.php +++ b/Tests/Fixtures/php/services_legacy_privates.php @@ -17,7 +17,7 @@ class Symfony_DI_PhpDumper_Test_Legacy_Privates extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { @@ -25,8 +25,8 @@ public function __construct() for ($i = 1; $i <= 5; ++$i) { $this->targetDirs[$i] = $dir = \dirname($dir); } - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'bar' => 'getBarService', 'private' => 'getPrivateService', 'private_alias' => 'getPrivateAliasService', @@ -37,8 +37,8 @@ public function __construct() 'private_not_removed' => 'getPrivateNotRemovedService', 'private_parent' => 'getPrivateParentService', 'public_child' => 'getPublicChildService', - ); - $this->privates = array( + ]; + $this->privates = [ 'decorated_private' => true, 'decorated_private_alias' => true, 'private' => true, @@ -47,17 +47,17 @@ public function __construct() 'private_not_inlined' => true, 'private_not_removed' => true, 'private_parent' => true, - ); - $this->aliases = array( + ]; + $this->aliases = [ 'alias_to_private' => 'private', 'decorated_private' => 'private_decorator', 'decorated_private_alias' => 'private_alias_decorator', - ); + ]; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'decorated_private' => true, @@ -71,7 +71,7 @@ public function getRemovedIds() 'private_not_inlined' => true, 'private_not_removed' => true, 'private_parent' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services_locator.php b/Tests/Fixtures/php/services_locator.php index c436aea40..4969b2db0 100644 --- a/Tests/Fixtures/php/services_locator.php +++ b/Tests/Fixtures/php/services_locator.php @@ -17,12 +17,12 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'bar_service' => 'getBarServiceService', 'baz_service' => 'getBazServiceService', 'foo_service' => 'getFooServiceService', @@ -32,24 +32,24 @@ public function __construct() 'translator_1' => 'getTranslator1Service', 'translator_2' => 'getTranslator2Service', 'translator_3' => 'getTranslator3Service', - ); - $this->privates = array( + ]; + $this->privates = [ 'baz_service' => true, - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'baz_service' => true, 'translator.loader_1_locator' => true, 'translator.loader_2_locator' => true, 'translator.loader_3_locator' => true, - ); + ]; } public function compile() @@ -86,13 +86,13 @@ protected function getBarServiceService() */ protected function getFooServiceService() { - return $this->services['foo_service'] = new \Symfony\Component\DependencyInjection\ServiceLocator(array('bar' => function () { + return $this->services['foo_service'] = new \Symfony\Component\DependencyInjection\ServiceLocator(['bar' => function () { return ${($_ = isset($this->services['bar_service']) ? $this->services['bar_service'] : $this->getBarServiceService()) && false ?: '_'}; }, 'baz' => function () { $f = function (\stdClass $v) { return $v; }; return $f(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : ($this->services['baz_service'] = new \stdClass())) && false ?: '_'}); }, 'nil' => function () { return NULL; - })); + }]); } /** @@ -132,9 +132,9 @@ protected function getTranslator_Loader3Service() */ protected function getTranslator1Service() { - return $this->services['translator_1'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(array('translator.loader_1' => function () { + return $this->services['translator_1'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(['translator.loader_1' => function () { return ${($_ = isset($this->services['translator.loader_1']) ? $this->services['translator.loader_1'] : ($this->services['translator.loader_1'] = new \stdClass())) && false ?: '_'}; - }))); + }])); } /** @@ -144,9 +144,9 @@ protected function getTranslator1Service() */ protected function getTranslator2Service() { - $this->services['translator_2'] = $instance = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(array('translator.loader_2' => function () { + $this->services['translator_2'] = $instance = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(['translator.loader_2' => function () { return ${($_ = isset($this->services['translator.loader_2']) ? $this->services['translator.loader_2'] : ($this->services['translator.loader_2'] = new \stdClass())) && false ?: '_'}; - }))); + }])); $instance->addResource('db', ${($_ = isset($this->services['translator.loader_2']) ? $this->services['translator.loader_2'] : ($this->services['translator.loader_2'] = new \stdClass())) && false ?: '_'}, 'nl'); @@ -160,9 +160,9 @@ protected function getTranslator2Service() */ protected function getTranslator3Service() { - $this->services['translator_3'] = $instance = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(array('translator.loader_3' => function () { + $this->services['translator_3'] = $instance = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(['translator.loader_3' => function () { return ${($_ = isset($this->services['translator.loader_3']) ? $this->services['translator.loader_3'] : ($this->services['translator.loader_3'] = new \stdClass())) && false ?: '_'}; - }))); + }])); $a = ${($_ = isset($this->services['translator.loader_3']) ? $this->services['translator.loader_3'] : ($this->services['translator.loader_3'] = new \stdClass())) && false ?: '_'}; diff --git a/Tests/Fixtures/php/services_non_shared_lazy.php b/Tests/Fixtures/php/services_non_shared_lazy.php index 6c3b14050..b56063a18 100644 --- a/Tests/Fixtures/php/services_non_shared_lazy.php +++ b/Tests/Fixtures/php/services_non_shared_lazy.php @@ -17,31 +17,31 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'bar' => 'getBarService', 'foo' => 'getFooService', - ); - $this->privates = array( + ]; + $this->privates = [ 'bar' => true, 'foo' => true, - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'bar' => true, 'foo' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services_private_frozen.php b/Tests/Fixtures/php/services_private_frozen.php index 8ef589c12..da1d716c5 100644 --- a/Tests/Fixtures/php/services_private_frozen.php +++ b/Tests/Fixtures/php/services_private_frozen.php @@ -17,30 +17,30 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'bar_service' => 'getBarServiceService', 'baz_service' => 'getBazServiceService', 'foo_service' => 'getFooServiceService', - ); - $this->privates = array( + ]; + $this->privates = [ 'baz_service' => true, - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'baz_service' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services_private_in_expression.php b/Tests/Fixtures/php/services_private_in_expression.php index 75cbc2730..c7fb579b0 100644 --- a/Tests/Fixtures/php/services_private_in_expression.php +++ b/Tests/Fixtures/php/services_private_in_expression.php @@ -17,30 +17,30 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'private_foo' => 'getPrivateFooService', 'public_foo' => 'getPublicFooService', - ); - $this->privates = array( + ]; + $this->privates = [ 'private_foo' => true, - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'private_bar' => true, 'private_foo' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services_rot13_env.php b/Tests/Fixtures/php/services_rot13_env.php index efbb00231..7c903b11d 100644 --- a/Tests/Fixtures/php/services_rot13_env.php +++ b/Tests/Fixtures/php/services_rot13_env.php @@ -17,30 +17,30 @@ class Symfony_DI_PhpDumper_Test_Rot13Parameters extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { $this->parameters = $this->getDefaultParameters(); - $this->services = array(); - $this->normalizedIds = array( + $this->services = []; + $this->normalizedIds = [ 'symfony\\component\\dependencyinjection\\tests\\dumper\\rot13envvarprocessor' => 'Symfony\\Component\\DependencyInjection\\Tests\\Dumper\\Rot13EnvVarProcessor', - ); - $this->methodMap = array( + ]; + $this->methodMap = [ 'Symfony\\Component\\DependencyInjection\\Tests\\Dumper\\Rot13EnvVarProcessor' => 'getRot13EnvVarProcessorService', 'container.env_var_processors_locator' => 'getContainer_EnvVarProcessorsLocatorService', - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() @@ -77,9 +77,9 @@ protected function getRot13EnvVarProcessorService() */ protected function getContainer_EnvVarProcessorsLocatorService() { - return $this->services['container.env_var_processors_locator'] = new \Symfony\Component\DependencyInjection\ServiceLocator(array('rot13' => function () { + return $this->services['container.env_var_processors_locator'] = new \Symfony\Component\DependencyInjection\ServiceLocator(['rot13' => function () { return ${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor())) && false ?: '_'}; - })); + }]); } public function getParameter($name) @@ -125,10 +125,10 @@ public function getParameterBag() return $this->parameterBag; } - private $loadedDynamicParameters = array( + private $loadedDynamicParameters = [ 'hello' => false, - ); - private $dynamicParameters = array(); + ]; + private $dynamicParameters = []; /** * Computes a dynamic parameter. @@ -150,7 +150,7 @@ private function getDynamicParameter($name) return $this->dynamicParameters[$name] = $value; } - private $normalizedParameterNames = array(); + private $normalizedParameterNames = []; private function normalizeParameterName($name) { @@ -173,8 +173,8 @@ private function normalizeParameterName($name) */ protected function getDefaultParameters() { - return array( + return [ 'env(foo)' => 'jbeyq', - ); + ]; } } diff --git a/Tests/Fixtures/php/services_subscriber.php b/Tests/Fixtures/php/services_subscriber.php index 8f198f0ba..9424a7611 100644 --- a/Tests/Fixtures/php/services_subscriber.php +++ b/Tests/Fixtures/php/services_subscriber.php @@ -17,36 +17,36 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->normalizedIds = array( + $this->services = []; + $this->normalizedIds = [ 'symfony\\component\\dependencyinjection\\tests\\fixtures\\customdefinition' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition', 'symfony\\component\\dependencyinjection\\tests\\fixtures\\testservicesubscriber' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber', - ); - $this->methodMap = array( + ]; + $this->methodMap = [ 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => 'getCustomDefinitionService', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => 'getTestServiceSubscriberService', 'foo_service' => 'getFooServiceService', - ); - $this->privates = array( + ]; + $this->privates = [ 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => true, - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => true, 'service_locator.jmktfsv' => true, 'service_locator.jmktfsv.foo_service' => true, - ); + ]; } public function compile() @@ -83,7 +83,7 @@ protected function getTestServiceSubscriberService() */ protected function getFooServiceService() { - return $this->services['foo_service'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber((new \Symfony\Component\DependencyInjection\ServiceLocator(array('Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => function () { + return $this->services['foo_service'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber((new \Symfony\Component\DependencyInjection\ServiceLocator(['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => function () { $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v = null) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition())) && false ?: '_'}); }, 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => function () { $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber $v) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber())) && false ?: '_'}); @@ -91,7 +91,7 @@ protected function getFooServiceService() $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber())) && false ?: '_'}); }, 'baz' => function () { $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v = null) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition())) && false ?: '_'}); - })))->withContext('foo_service', $this)); + }]))->withContext('foo_service', $this)); } /** diff --git a/Tests/Fixtures/php/services_tsantos.php b/Tests/Fixtures/php/services_tsantos.php index dbaa70956..b14cdebb9 100644 --- a/Tests/Fixtures/php/services_tsantos.php +++ b/Tests/Fixtures/php/services_tsantos.php @@ -17,28 +17,28 @@ class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->normalizedIds = array( + $this->services = []; + $this->normalizedIds = [ 'tsantos\\serializer\\serializerinterface' => 'TSantos\\Serializer\\SerializerInterface', - ); - $this->methodMap = array( + ]; + $this->methodMap = [ 'tsantos_serializer' => 'getTsantosSerializerService', - ); - $this->aliases = array( + ]; + $this->aliases = [ 'TSantos\\Serializer\\SerializerInterface' => 'tsantos_serializer', - ); + ]; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, - ); + ]; } public function compile() diff --git a/Tests/Fixtures/php/services_uninitialized_ref.php b/Tests/Fixtures/php/services_uninitialized_ref.php index c53e336d2..7a24f72c5 100644 --- a/Tests/Fixtures/php/services_uninitialized_ref.php +++ b/Tests/Fixtures/php/services_uninitialized_ref.php @@ -17,32 +17,32 @@ class Symfony_DI_PhpDumper_Test_Uninitialized_Reference extends Container { private $parameters; - private $targetDirs = array(); + private $targetDirs = []; public function __construct() { - $this->services = array(); - $this->methodMap = array( + $this->services = []; + $this->methodMap = [ 'bar' => 'getBarService', 'baz' => 'getBazService', 'foo1' => 'getFoo1Service', 'foo3' => 'getFoo3Service', - ); - $this->privates = array( + ]; + $this->privates = [ 'foo3' => true, - ); + ]; - $this->aliases = array(); + $this->aliases = []; } public function getRemovedIds() { - return array( + return [ 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'foo2' => true, 'foo3' => true, - ); + ]; } public function compile() @@ -74,13 +74,13 @@ protected function getBarService() $instance->foo1 = ${($_ = isset($this->services['foo1']) ? $this->services['foo1'] : null) && false ?: '_'}; $instance->foo2 = null; $instance->foo3 = ${($_ = isset($this->services['foo3']) ? $this->services['foo3'] : null) && false ?: '_'}; - $instance->closures = array(0 => function () { + $instance->closures = [0 => function () { return ${($_ = isset($this->services['foo1']) ? $this->services['foo1'] : null) && false ?: '_'}; }, 1 => function () { return null; }, 2 => function () { return ${($_ = isset($this->services['foo3']) ? $this->services['foo3'] : null) && false ?: '_'}; - }); + }]; $instance->iter = new RewindableGenerator(function () { if (isset($this->services['foo1'])) { yield 'foo1' => ${($_ = isset($this->services['foo1']) ? $this->services['foo1'] : null) && false ?: '_'}; From 8f54459775b38ccc8865a4de4f2a343e1e51e2e2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 16 Jan 2019 14:03:22 +0100 Subject: [PATCH 16/72] fixed short array CS in comments --- ContainerBuilder.php | 4 ++-- ServiceSubscriberInterface.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ContainerBuilder.php b/ContainerBuilder.php index 436f45b85..0c1966a42 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -647,7 +647,7 @@ private function doGet($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_ * the parameters passed to the container constructor to have precedence * over the loaded ones. * - * $container = new ContainerBuilder(new ParameterBag(array('foo' => 'bar'))); + * $container = new ContainerBuilder(new ParameterBag(['foo' => 'bar'])); * $loader = new LoaderXXX($container); * $loader->load('resource_name'); * $container->register('foo', 'stdClass'); @@ -1288,7 +1288,7 @@ private function doResolveServices($value, array &$inlineServices = [], $isConst * * Example: * - * $container->register('foo')->addTag('my.tag', array('hello' => 'world')); + * $container->register('foo')->addTag('my.tag', ['hello' => 'world']); * * $serviceIds = $container->findTaggedServiceIds('my.tag'); * foreach ($serviceIds as $serviceId => $tags) { diff --git a/ServiceSubscriberInterface.php b/ServiceSubscriberInterface.php index 7024484bd..10c238754 100644 --- a/ServiceSubscriberInterface.php +++ b/ServiceSubscriberInterface.php @@ -33,16 +33,16 @@ interface ServiceSubscriberInterface * * For mandatory dependencies: * - * * array('logger' => 'Psr\Log\LoggerInterface') means the objects use the "logger" name + * * ['logger' => 'Psr\Log\LoggerInterface'] means the objects use the "logger" name * internally to fetch a service which must implement Psr\Log\LoggerInterface. - * * array('Psr\Log\LoggerInterface') is a shortcut for - * * array('Psr\Log\LoggerInterface' => 'Psr\Log\LoggerInterface') + * * ['Psr\Log\LoggerInterface'] is a shortcut for + * * ['Psr\Log\LoggerInterface' => 'Psr\Log\LoggerInterface'] * * otherwise: * - * * array('logger' => '?Psr\Log\LoggerInterface') denotes an optional dependency - * * array('?Psr\Log\LoggerInterface') is a shortcut for - * * array('Psr\Log\LoggerInterface' => '?Psr\Log\LoggerInterface') + * * ['logger' => '?Psr\Log\LoggerInterface'] denotes an optional dependency + * * ['?Psr\Log\LoggerInterface'] is a shortcut for + * * ['Psr\Log\LoggerInterface' => '?Psr\Log\LoggerInterface'] * * @return array The required service types, optionally keyed by service names */ From 5c8c902dce70907f90d9f6bc45095ad8b41748c4 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 18 Jan 2019 12:20:22 +0100 Subject: [PATCH 17/72] forward the parse error to the calling code --- Loader/XmlFileLoader.php | 2 +- Loader/YamlFileLoader.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Loader/XmlFileLoader.php b/Loader/XmlFileLoader.php index 1921c7157..a02a6c8ea 100644 --- a/Loader/XmlFileLoader.php +++ b/Loader/XmlFileLoader.php @@ -383,7 +383,7 @@ private function parseFileToDOM($file) try { $dom = XmlUtils::loadFile($file, [$this, 'validateSchema']); } catch (\InvalidArgumentException $e) { - throw new InvalidArgumentException(sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e); + throw new InvalidArgumentException(sprintf('Unable to parse file "%s": %s', $file, $e->getMessage()), $e->getCode(), $e); } $this->validateExtensions($dom, $file); diff --git a/Loader/YamlFileLoader.php b/Loader/YamlFileLoader.php index dccbae9b7..5dc41e034 100644 --- a/Loader/YamlFileLoader.php +++ b/Loader/YamlFileLoader.php @@ -666,7 +666,7 @@ protected function loadFile($file) try { $configuration = $this->yamlParser->parseFile($file, Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS); } catch (ParseException $e) { - throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e); + throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: %s', $file, $e->getMessage()), 0, $e); } finally { restore_error_handler(); } From 990ea0dd6ce21cc2d751c4ced873dc39d0a41a1b Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 20 Jan 2019 09:34:00 +0100 Subject: [PATCH 18/72] fix tests --- Tests/Loader/XmlFileLoaderTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Loader/XmlFileLoaderTest.php b/Tests/Loader/XmlFileLoaderTest.php index c265c00e8..d89887acc 100644 --- a/Tests/Loader/XmlFileLoaderTest.php +++ b/Tests/Loader/XmlFileLoaderTest.php @@ -67,7 +67,7 @@ public function testParseFile() $this->fail('->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); } catch (\Exception $e) { $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); - $this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'parameters.ini'), $e->getMessage(), '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); + $this->assertRegExp(sprintf('#^Unable to parse file ".+%s": .+.$#', 'parameters.ini'), $e->getMessage(), '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); $e = $e->getPrevious(); $this->assertInstanceOf('InvalidArgumentException', $e, '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); @@ -81,7 +81,7 @@ public function testParseFile() $this->fail('->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD'); } catch (\Exception $e) { $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD'); - $this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'nonvalid.xml'), $e->getMessage(), '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); + $this->assertRegExp(sprintf('#^Unable to parse file ".+%s": .+.$#', 'nonvalid.xml'), $e->getMessage(), '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); $e = $e->getPrevious(); $this->assertInstanceOf('InvalidArgumentException', $e, '->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD'); @@ -437,7 +437,7 @@ public function testExtensions() $this->fail('->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); } catch (\Exception $e) { $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); - $this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'services3.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); + $this->assertRegExp(sprintf('#^Unable to parse file ".+%s": .+.$#', 'services3.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); $e = $e->getPrevious(); $this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); @@ -477,7 +477,7 @@ public function testExtensionInPhar() $this->fail('->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); } catch (\Exception $e) { $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); - $this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'services7.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); + $this->assertRegExp(sprintf('#^Unable to parse file ".+%s": .+.$#', 'services7.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); $e = $e->getPrevious(); $this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); @@ -528,7 +528,7 @@ public function testDocTypeIsNotAllowed() $this->fail('->load() throws an InvalidArgumentException if the configuration contains a document type'); } catch (\Exception $e) { $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration contains a document type'); - $this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'withdoctype.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration contains a document type'); + $this->assertRegExp(sprintf('#^Unable to parse file ".+%s": .+.$#', 'withdoctype.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration contains a document type'); $e = $e->getPrevious(); $this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration contains a document type'); From 3c1d6dac1e214d9b1ffc07b9c0622917dc9b79bf Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 30 Jan 2019 10:03:33 +0100 Subject: [PATCH 19/72] Mark some/most implementations of Serializable as `@internal` --- Config/AutowireServiceResource.php | 6 ++++++ Config/ContainerParametersResource.php | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Config/AutowireServiceResource.php b/Config/AutowireServiceResource.php index 6bb9bb0d1..0c3d8f575 100644 --- a/Config/AutowireServiceResource.php +++ b/Config/AutowireServiceResource.php @@ -58,11 +58,17 @@ public function __toString() return 'service.autowire.'.$this->class; } + /** + * @internal + */ public function serialize() { return serialize([$this->class, $this->filePath, $this->autowiringMetadata]); } + /** + * @internal + */ public function unserialize($serialized) { if (\PHP_VERSION_ID >= 70000) { diff --git a/Config/ContainerParametersResource.php b/Config/ContainerParametersResource.php index 072f0580a..7560c3356 100644 --- a/Config/ContainerParametersResource.php +++ b/Config/ContainerParametersResource.php @@ -39,7 +39,7 @@ public function __toString() } /** - * {@inheritdoc} + * @internal */ public function serialize() { @@ -47,7 +47,7 @@ public function serialize() } /** - * {@inheritdoc} + * @internal */ public function unserialize($serialized) { From c54847638c8c89376d70a7a5e4342d1d2cc9319e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 30 Jan 2019 18:15:16 +0100 Subject: [PATCH 20/72] [DI] Fix dumping Doctrine-like service graphs --- Compiler/InlineServiceDefinitionsPass.php | 4 ---- Dumper/PhpDumper.php | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Compiler/InlineServiceDefinitionsPass.php b/Compiler/InlineServiceDefinitionsPass.php index ee3d7e526..326ee1932 100644 --- a/Compiler/InlineServiceDefinitionsPass.php +++ b/Compiler/InlineServiceDefinitionsPass.php @@ -148,10 +148,6 @@ private function isInlineableDefinition($id, Definition $definition, ServiceRefe return false; } - if ($isReferencedByConstructor && $this->container->getDefinition($ids[0])->isLazy() && ($definition->getProperties() || $definition->getMethodCalls() || $definition->getConfigurator())) { - return false; - } - return $this->container->getDefinition($ids[0])->isShared(); } } diff --git a/Dumper/PhpDumper.php b/Dumper/PhpDumper.php index dc14f967f..0a1385ecc 100644 --- a/Dumper/PhpDumper.php +++ b/Dumper/PhpDumper.php @@ -661,6 +661,7 @@ private function addService($id, Definition $definition, &$file = null) $autowired = $definition->isAutowired() ? ' autowired' : ''; if ($definition->isLazy()) { + unset($this->circularReferences[$id]); $lazyInitialization = '$lazyLoad = true'; } else { $lazyInitialization = ''; From ca1653d4356720d5cb6b5d25a6aecb35ace76e1b Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Feb 2019 14:34:02 +0100 Subject: [PATCH 21/72] be keen to newcomers --- LazyProxy/Instantiator/RealServiceInstantiator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LazyProxy/Instantiator/RealServiceInstantiator.php b/LazyProxy/Instantiator/RealServiceInstantiator.php index 3b0b57ef0..532e76868 100644 --- a/LazyProxy/Instantiator/RealServiceInstantiator.php +++ b/LazyProxy/Instantiator/RealServiceInstantiator.php @@ -17,7 +17,7 @@ /** * {@inheritdoc} * - * Noop proxy instantiator - simply produces the real service instead of a proxy instance. + * Noop proxy instantiator - produces the real service instead of a proxy instance. * * @author Marco Pivetta */ From c3dd7b7ea8cd8ec12304a5e222d7dc01cac8fa11 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 23 Feb 2019 16:06:07 +0100 Subject: [PATCH 22/72] Apply php-cs-fixer rule for array_key_exists() --- ChildDefinition.php | 2 +- Compiler/AutowirePass.php | 2 +- Compiler/RegisterServiceSubscribersPass.php | 4 ++-- Compiler/ResolveBindingsPass.php | 4 ++-- Compiler/ResolveNamedArgumentsPass.php | 2 +- Container.php | 2 +- Definition.php | 4 ++-- Dumper/GraphvizDumper.php | 2 +- Extension/Extension.php | 2 +- Loader/XmlFileLoader.php | 2 +- Loader/YamlFileLoader.php | 12 ++++++------ ParameterBag/ParameterBag.php | 4 ++-- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ChildDefinition.php b/ChildDefinition.php index 85cc86038..29fbd48f2 100644 --- a/ChildDefinition.php +++ b/ChildDefinition.php @@ -71,7 +71,7 @@ public function setParent($parent) */ public function getArgument($index) { - if (array_key_exists('index_'.$index, $this->arguments)) { + if (\array_key_exists('index_'.$index, $this->arguments)) { return $this->arguments['index_'.$index]; } diff --git a/Compiler/AutowirePass.php b/Compiler/AutowirePass.php index b411b30f2..252b304f1 100644 --- a/Compiler/AutowirePass.php +++ b/Compiler/AutowirePass.php @@ -214,7 +214,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a } foreach ($parameters as $index => $parameter) { - if (array_key_exists($index, $arguments) && '' !== $arguments[$index]) { + if (\array_key_exists($index, $arguments) && '' !== $arguments[$index]) { continue; } diff --git a/Compiler/RegisterServiceSubscribersPass.php b/Compiler/RegisterServiceSubscribersPass.php index 8eac9f006..bf1387c04 100644 --- a/Compiler/RegisterServiceSubscribersPass.php +++ b/Compiler/RegisterServiceSubscribersPass.php @@ -43,10 +43,10 @@ protected function processValue($value, $isRoot = false) if ([] !== array_diff(array_keys($attributes), ['id', 'key'])) { throw new InvalidArgumentException(sprintf('The "container.service_subscriber" tag accepts only the "key" and "id" attributes, "%s" given for service "%s".', implode('", "', array_keys($attributes)), $this->currentId)); } - if (!array_key_exists('id', $attributes)) { + if (!\array_key_exists('id', $attributes)) { throw new InvalidArgumentException(sprintf('Missing "id" attribute on "container.service_subscriber" tag with key="%s" for service "%s".', $attributes['key'], $this->currentId)); } - if (!array_key_exists('key', $attributes)) { + if (!\array_key_exists('key', $attributes)) { $attributes['key'] = $attributes['id']; } if (isset($serviceMap[$attributes['key']])) { diff --git a/Compiler/ResolveBindingsPass.php b/Compiler/ResolveBindingsPass.php index 0fad285e5..20b262b6d 100644 --- a/Compiler/ResolveBindingsPass.php +++ b/Compiler/ResolveBindingsPass.php @@ -119,11 +119,11 @@ protected function processValue($value, $isRoot = false) } foreach ($reflectionMethod->getParameters() as $key => $parameter) { - if (array_key_exists($key, $arguments) && '' !== $arguments[$key]) { + if (\array_key_exists($key, $arguments) && '' !== $arguments[$key]) { continue; } - if (array_key_exists('$'.$parameter->name, $bindings)) { + if (\array_key_exists('$'.$parameter->name, $bindings)) { $arguments[$key] = $this->getBindingValue($bindings['$'.$parameter->name]); continue; diff --git a/Compiler/ResolveNamedArgumentsPass.php b/Compiler/ResolveNamedArgumentsPass.php index ee54288ec..0b7928011 100644 --- a/Compiler/ResolveNamedArgumentsPass.php +++ b/Compiler/ResolveNamedArgumentsPass.php @@ -71,7 +71,7 @@ protected function processValue($value, $isRoot = false) $typeFound = false; foreach ($parameters as $j => $p) { - if (!array_key_exists($j, $resolvedArguments) && ProxyHelper::getTypeHint($r, $p, true) === $key) { + if (!\array_key_exists($j, $resolvedArguments) && ProxyHelper::getTypeHint($r, $p, true) === $key) { $resolvedArguments[$j] = $argument; $typeFound = true; } diff --git a/Container.php b/Container.php index ea4a6d763..e82264343 100644 --- a/Container.php +++ b/Container.php @@ -466,7 +466,7 @@ protected function getEnv($name) if (isset($this->resolving[$envName = "env($name)"])) { throw new ParameterCircularReferenceException(array_keys($this->resolving)); } - if (isset($this->envCache[$name]) || array_key_exists($name, $this->envCache)) { + if (isset($this->envCache[$name]) || \array_key_exists($name, $this->envCache)) { return $this->envCache[$name]; } if (!$this->has($id = 'container.env_var_processors_locator')) { diff --git a/Definition.php b/Definition.php index 171bcaf46..ee5803471 100644 --- a/Definition.php +++ b/Definition.php @@ -263,7 +263,7 @@ public function replaceArgument($index, $argument) throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, \count($this->arguments) - 1)); } - if (!array_key_exists($index, $this->arguments)) { + if (!\array_key_exists($index, $this->arguments)) { throw new OutOfBoundsException(sprintf('The argument "%s" doesn\'t exist.', $index)); } @@ -308,7 +308,7 @@ public function getArguments() */ public function getArgument($index) { - if (!array_key_exists($index, $this->arguments)) { + if (!\array_key_exists($index, $this->arguments)) { throw new OutOfBoundsException(sprintf('The argument "%s" doesn\'t exist.', $index)); } diff --git a/Dumper/GraphvizDumper.php b/Dumper/GraphvizDumper.php index 3adcef79b..f06e6e80d 100644 --- a/Dumper/GraphvizDumper.php +++ b/Dumper/GraphvizDumper.php @@ -193,7 +193,7 @@ private function findNodes() } foreach ($container->getServiceIds() as $id) { - if (array_key_exists($id, $container->getAliases())) { + if (\array_key_exists($id, $container->getAliases())) { continue; } diff --git a/Extension/Extension.php b/Extension/Extension.php index 80a9419c5..a9389862c 100644 --- a/Extension/Extension.php +++ b/Extension/Extension.php @@ -115,7 +115,7 @@ final public function getProcessedConfigs() */ protected function isConfigEnabled(ContainerBuilder $container, array $config) { - if (!array_key_exists('enabled', $config)) { + if (!\array_key_exists('enabled', $config)) { throw new InvalidArgumentException("The config array has no 'enabled' key."); } diff --git a/Loader/XmlFileLoader.php b/Loader/XmlFileLoader.php index a02a6c8ea..fd2a20a87 100644 --- a/Loader/XmlFileLoader.php +++ b/Loader/XmlFileLoader.php @@ -333,7 +333,7 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults) continue; } - if (false !== strpos($name, '-') && false === strpos($name, '_') && !array_key_exists($normalizedName = str_replace('-', '_', $name), $parameters)) { + if (false !== strpos($name, '-') && false === strpos($name, '_') && !\array_key_exists($normalizedName = str_replace('-', '_', $name), $parameters)) { $parameters[$normalizedName] = XmlUtils::phpize($node->nodeValue); } // keep not normalized key diff --git a/Loader/YamlFileLoader.php b/Loader/YamlFileLoader.php index 5dc41e034..a3a799024 100644 --- a/Loader/YamlFileLoader.php +++ b/Loader/YamlFileLoader.php @@ -213,7 +213,7 @@ private function parseDefinitions(array $content, $file) throw new InvalidArgumentException(sprintf('The "services" key should contain an array in %s. Check your YAML syntax.', $file)); } - if (array_key_exists('_instanceof', $content['services'])) { + if (\array_key_exists('_instanceof', $content['services'])) { $instanceof = $content['services']['_instanceof']; unset($content['services']['_instanceof']); @@ -250,7 +250,7 @@ private function parseDefinitions(array $content, $file) */ private function parseDefaults(array &$content, $file) { - if (!array_key_exists('_defaults', $content['services'])) { + if (!\array_key_exists('_defaults', $content['services'])) { return []; } $defaults = $content['services']['_defaults']; @@ -361,7 +361,7 @@ private function parseDefinition($id, $service, $file, array $defaults) if (isset($service['alias'])) { $this->container->setAlias($id, $alias = new Alias($service['alias'])); - if (array_key_exists('public', $service)) { + if (\array_key_exists('public', $service)) { $alias->setPublic($service['public']); } elseif (isset($defaults['public'])) { $alias->setPublic($defaults['public']); @@ -438,7 +438,7 @@ private function parseDefinition($id, $service, $file, array $defaults) $definition->setAbstract($service['abstract']); } - if (array_key_exists('deprecated', $service)) { + if (\array_key_exists('deprecated', $service)) { $definition->setDeprecated(true, $service['deprecated']); } @@ -571,11 +571,11 @@ private function parseDefinition($id, $service, $file, array $defaults) } } - if (array_key_exists('namespace', $service) && !array_key_exists('resource', $service)) { + if (\array_key_exists('namespace', $service) && !\array_key_exists('resource', $service)) { throw new InvalidArgumentException(sprintf('A "resource" attribute must be set when the "namespace" attribute is set for service "%s" in %s. Check your YAML syntax.', $id, $file)); } - if (array_key_exists('resource', $service)) { + if (\array_key_exists('resource', $service)) { if (!\is_string($service['resource'])) { throw new InvalidArgumentException(sprintf('A "resource" attribute must be of type string for service "%s" in %s. Check your YAML syntax.', $id, $file)); } diff --git a/ParameterBag/ParameterBag.php b/ParameterBag/ParameterBag.php index 8a86f9417..c4e702181 100644 --- a/ParameterBag/ParameterBag.php +++ b/ParameterBag/ParameterBag.php @@ -70,7 +70,7 @@ public function get($name) { $name = $this->normalizeName($name); - if (!array_key_exists($name, $this->parameters)) { + if (!\array_key_exists($name, $this->parameters)) { if (!$name) { throw new ParameterNotFoundException($name); } @@ -121,7 +121,7 @@ public function set($name, $value) */ public function has($name) { - return array_key_exists($this->normalizeName($name), $this->parameters); + return \array_key_exists($this->normalizeName($name), $this->parameters); } /** From b63109c4a8b3cb137d1a48819d144b756d8b36f0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Mar 2019 10:53:10 +0100 Subject: [PATCH 23/72] moved XSD to HTTPS --- Dumper/XmlDumper.php | 2 +- Loader/XmlFileLoader.php | 3 ++- Tests/Dumper/XmlDumperTest.php | 8 ++++---- Tests/Fixtures/xml/class_from_id.xml | 2 +- Tests/Fixtures/xml/extension1/services.xml | 2 +- Tests/Fixtures/xml/extension2/services.xml | 2 +- Tests/Fixtures/xml/extensions/services2.xml | 2 +- Tests/Fixtures/xml/extensions/services3.xml | 2 +- Tests/Fixtures/xml/extensions/services5.xml | 2 +- Tests/Fixtures/xml/extensions/services6.xml | 2 +- Tests/Fixtures/xml/extensions/services7.xml | 2 +- Tests/Fixtures/xml/legacy_invalid_alias_definition.xml | 2 +- Tests/Fixtures/xml/namespaces.xml | 4 ++-- Tests/Fixtures/xml/nested_service_without_id.xml | 2 +- Tests/Fixtures/xml/services1.xml | 2 +- Tests/Fixtures/xml/services10.xml | 2 +- Tests/Fixtures/xml/services13.xml | 2 +- Tests/Fixtures/xml/services14.xml | 2 +- Tests/Fixtures/xml/services2.xml | 2 +- Tests/Fixtures/xml/services21.xml | 2 +- Tests/Fixtures/xml/services22.xml | 2 +- Tests/Fixtures/xml/services23.xml | 2 +- Tests/Fixtures/xml/services24.xml | 2 +- Tests/Fixtures/xml/services28.xml | 2 +- Tests/Fixtures/xml/services3.xml | 2 +- Tests/Fixtures/xml/services4.xml | 2 +- Tests/Fixtures/xml/services4_bad_import.xml | 2 +- Tests/Fixtures/xml/services5.xml | 2 +- Tests/Fixtures/xml/services6.xml | 2 +- Tests/Fixtures/xml/services7.xml | 2 +- Tests/Fixtures/xml/services8.xml | 2 +- Tests/Fixtures/xml/services9.xml | 2 +- Tests/Fixtures/xml/services_abstract.xml | 2 +- Tests/Fixtures/xml/services_autoconfigure.xml | 2 +- Tests/Fixtures/xml/services_autoconfigure_with_parent.xml | 2 +- Tests/Fixtures/xml/services_bindings.xml | 2 +- Tests/Fixtures/xml/services_defaults_with_parent.xml | 2 +- Tests/Fixtures/xml/services_deprecated.xml | 2 +- Tests/Fixtures/xml/services_dump_load.xml | 2 +- Tests/Fixtures/xml/services_inline_not_candidate.xml | 2 +- Tests/Fixtures/xml/services_instanceof.xml | 2 +- Tests/Fixtures/xml/services_instanceof_with_parent.xml | 2 +- Tests/Fixtures/xml/services_named_args.xml | 2 +- Tests/Fixtures/xml/services_prototype.xml | 2 +- Tests/Fixtures/xml/services_tsantos.xml | 2 +- Tests/Fixtures/xml/services_without_id.xml | 2 +- Tests/Fixtures/xml/tag_with_empty_name.xml | 2 +- Tests/Fixtures/xml/tag_without_name.xml | 2 +- Tests/Fixtures/xml/with_key_outside_collection.xml | 2 +- Tests/Fixtures/xml/xml_with_wrong_ext.php | 2 +- 50 files changed, 55 insertions(+), 54 deletions(-) diff --git a/Dumper/XmlDumper.php b/Dumper/XmlDumper.php index 36e3e121d..0fac16b14 100644 --- a/Dumper/XmlDumper.php +++ b/Dumper/XmlDumper.php @@ -47,7 +47,7 @@ public function dump(array $options = []) $container = $this->document->createElementNS('http://symfony.com/schema/dic/services', 'container'); $container->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); - $container->setAttribute('xsi:schemaLocation', 'http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd'); + $container->setAttribute('xsi:schemaLocation', 'http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd'); $this->addParameters($container); $this->addServices($container); diff --git a/Loader/XmlFileLoader.php b/Loader/XmlFileLoader.php index fd2a20a87..718592d8e 100644 --- a/Loader/XmlFileLoader.php +++ b/Loader/XmlFileLoader.php @@ -584,7 +584,8 @@ public function validateSchema(\DOMDocument $dom) } if (($extension = $this->container->getExtension($items[$i])) && false !== $extension->getXsdValidationBasePath()) { - $path = str_replace($extension->getNamespace(), str_replace('\\', '/', $extension->getXsdValidationBasePath()).'/', $items[$i + 1]); + $ns = $extension->getNamespace(); + $path = str_replace([$ns, str_replace('http://', 'https://', $ns)], str_replace('\\', '/', $extension->getXsdValidationBasePath()).'/', $items[$i + 1]); if (!is_file($path)) { throw new RuntimeException(sprintf('Extension "%s" references a non-existent XSD file "%s"', \get_class($extension), $path)); diff --git a/Tests/Dumper/XmlDumperTest.php b/Tests/Dumper/XmlDumperTest.php index ac274c6f2..e660c7e80 100644 --- a/Tests/Dumper/XmlDumperTest.php +++ b/Tests/Dumper/XmlDumperTest.php @@ -72,7 +72,7 @@ public function testDumpAnonymousServices() $container = include self::$fixturesPath.'/containers/container11.php'; $dumper = new XmlDumper($container); $this->assertEquals(' - + @@ -96,7 +96,7 @@ public function testDumpEntities() $container = include self::$fixturesPath.'/containers/container12.php'; $dumper = new XmlDumper($container); $this->assertEquals(" - + @@ -125,7 +125,7 @@ public function provideDecoratedServicesData() return [ [" - + @@ -135,7 +135,7 @@ public function provideDecoratedServicesData() ", include $fixturesPath.'/containers/container15.php'], [" - + diff --git a/Tests/Fixtures/xml/class_from_id.xml b/Tests/Fixtures/xml/class_from_id.xml index 45415cce4..5b7410090 100644 --- a/Tests/Fixtures/xml/class_from_id.xml +++ b/Tests/Fixtures/xml/class_from_id.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/extension1/services.xml b/Tests/Fixtures/xml/extension1/services.xml index 52df38d0c..1323dd5f2 100644 --- a/Tests/Fixtures/xml/extension1/services.xml +++ b/Tests/Fixtures/xml/extension1/services.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Tests/Fixtures/xml/extension2/services.xml b/Tests/Fixtures/xml/extension2/services.xml index 21a7ef58c..f9c01225d 100644 --- a/Tests/Fixtures/xml/extension2/services.xml +++ b/Tests/Fixtures/xml/extension2/services.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Tests/Fixtures/xml/extensions/services2.xml b/Tests/Fixtures/xml/extensions/services2.xml index 67d462be9..65c90696a 100644 --- a/Tests/Fixtures/xml/extensions/services2.xml +++ b/Tests/Fixtures/xml/extensions/services2.xml @@ -3,7 +3,7 @@ diff --git a/Tests/Fixtures/xml/extensions/services3.xml b/Tests/Fixtures/xml/extensions/services3.xml index c23f02a08..4c8184487 100644 --- a/Tests/Fixtures/xml/extensions/services3.xml +++ b/Tests/Fixtures/xml/extensions/services3.xml @@ -3,7 +3,7 @@ diff --git a/Tests/Fixtures/xml/extensions/services5.xml b/Tests/Fixtures/xml/extensions/services5.xml index 0eaaff2d2..c0343373a 100644 --- a/Tests/Fixtures/xml/extensions/services5.xml +++ b/Tests/Fixtures/xml/extensions/services5.xml @@ -3,7 +3,7 @@ diff --git a/Tests/Fixtures/xml/extensions/services6.xml b/Tests/Fixtures/xml/extensions/services6.xml index a9c01030d..da2b4bf2b 100644 --- a/Tests/Fixtures/xml/extensions/services6.xml +++ b/Tests/Fixtures/xml/extensions/services6.xml @@ -3,7 +3,7 @@ diff --git a/Tests/Fixtures/xml/extensions/services7.xml b/Tests/Fixtures/xml/extensions/services7.xml index e77780db6..fa5c364b3 100644 --- a/Tests/Fixtures/xml/extensions/services7.xml +++ b/Tests/Fixtures/xml/extensions/services7.xml @@ -3,7 +3,7 @@ diff --git a/Tests/Fixtures/xml/legacy_invalid_alias_definition.xml b/Tests/Fixtures/xml/legacy_invalid_alias_definition.xml index 52386e5bf..a5387b25a 100644 --- a/Tests/Fixtures/xml/legacy_invalid_alias_definition.xml +++ b/Tests/Fixtures/xml/legacy_invalid_alias_definition.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/namespaces.xml b/Tests/Fixtures/xml/namespaces.xml index 5a05cedd7..9dc27fadb 100644 --- a/Tests/Fixtures/xml/namespaces.xml +++ b/Tests/Fixtures/xml/namespaces.xml @@ -3,8 +3,8 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd + http://symfony.com/schema/dic/doctrine https://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd"> diff --git a/Tests/Fixtures/xml/nested_service_without_id.xml b/Tests/Fixtures/xml/nested_service_without_id.xml index f8eb00994..cfeed0ff5 100644 --- a/Tests/Fixtures/xml/nested_service_without_id.xml +++ b/Tests/Fixtures/xml/nested_service_without_id.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services1.xml b/Tests/Fixtures/xml/services1.xml index 6dc3ea661..7d8674a30 100644 --- a/Tests/Fixtures/xml/services1.xml +++ b/Tests/Fixtures/xml/services1.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services10.xml b/Tests/Fixtures/xml/services10.xml index a4da1bf74..921070e1b 100644 --- a/Tests/Fixtures/xml/services10.xml +++ b/Tests/Fixtures/xml/services10.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> true diff --git a/Tests/Fixtures/xml/services14.xml b/Tests/Fixtures/xml/services14.xml index 73446214e..639075f5d 100644 --- a/Tests/Fixtures/xml/services14.xml +++ b/Tests/Fixtures/xml/services14.xml @@ -1,7 +1,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> app diff --git a/Tests/Fixtures/xml/services2.xml b/Tests/Fixtures/xml/services2.xml index 0d2d66994..243a289f7 100644 --- a/Tests/Fixtures/xml/services2.xml +++ b/Tests/Fixtures/xml/services2.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> a string bar diff --git a/Tests/Fixtures/xml/services21.xml b/Tests/Fixtures/xml/services21.xml index 36fc8cfd8..20dd4cf47 100644 --- a/Tests/Fixtures/xml/services21.xml +++ b/Tests/Fixtures/xml/services21.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services22.xml b/Tests/Fixtures/xml/services22.xml index fa79d3894..6de7945be 100644 --- a/Tests/Fixtures/xml/services22.xml +++ b/Tests/Fixtures/xml/services22.xml @@ -1,5 +1,5 @@ - + Bar diff --git a/Tests/Fixtures/xml/services23.xml b/Tests/Fixtures/xml/services23.xml index 3f9e15fd4..eb56fd11d 100644 --- a/Tests/Fixtures/xml/services23.xml +++ b/Tests/Fixtures/xml/services23.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services24.xml b/Tests/Fixtures/xml/services24.xml index abf389bc8..23c91cdc2 100644 --- a/Tests/Fixtures/xml/services24.xml +++ b/Tests/Fixtures/xml/services24.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services28.xml b/Tests/Fixtures/xml/services28.xml index 0076cc31e..6b53c0989 100644 --- a/Tests/Fixtures/xml/services28.xml +++ b/Tests/Fixtures/xml/services28.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services3.xml b/Tests/Fixtures/xml/services3.xml index 87bf183db..5f0afeb49 100644 --- a/Tests/Fixtures/xml/services3.xml +++ b/Tests/Fixtures/xml/services3.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> foo diff --git a/Tests/Fixtures/xml/services4.xml b/Tests/Fixtures/xml/services4.xml index 47ec04e68..399da8159 100644 --- a/Tests/Fixtures/xml/services4.xml +++ b/Tests/Fixtures/xml/services4.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Tests/Fixtures/xml/services4_bad_import.xml b/Tests/Fixtures/xml/services4_bad_import.xml index 0b7f10a30..b30178f9e 100644 --- a/Tests/Fixtures/xml/services4_bad_import.xml +++ b/Tests/Fixtures/xml/services4_bad_import.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Tests/Fixtures/xml/services5.xml b/Tests/Fixtures/xml/services5.xml index 721f02828..6c6a14245 100644 --- a/Tests/Fixtures/xml/services5.xml +++ b/Tests/Fixtures/xml/services5.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Tests/Fixtures/xml/services6.xml b/Tests/Fixtures/xml/services6.xml index c85b7a7c0..84eb57bbe 100644 --- a/Tests/Fixtures/xml/services6.xml +++ b/Tests/Fixtures/xml/services6.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Tests/Fixtures/xml/services7.xml b/Tests/Fixtures/xml/services7.xml index 824d8b5d7..5b322105b 100644 --- a/Tests/Fixtures/xml/services7.xml +++ b/Tests/Fixtures/xml/services7.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Tests/Fixtures/xml/services8.xml b/Tests/Fixtures/xml/services8.xml index bc1186bd9..d0f9015c5 100644 --- a/Tests/Fixtures/xml/services8.xml +++ b/Tests/Fixtures/xml/services8.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> %baz% bar diff --git a/Tests/Fixtures/xml/services9.xml b/Tests/Fixtures/xml/services9.xml index d12c00319..128c1bac2 100644 --- a/Tests/Fixtures/xml/services9.xml +++ b/Tests/Fixtures/xml/services9.xml @@ -1,5 +1,5 @@ - + BazClass Bar\FooClass diff --git a/Tests/Fixtures/xml/services_abstract.xml b/Tests/Fixtures/xml/services_abstract.xml index 22abf5468..47fd3a53b 100644 --- a/Tests/Fixtures/xml/services_abstract.xml +++ b/Tests/Fixtures/xml/services_abstract.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services_autoconfigure.xml b/Tests/Fixtures/xml/services_autoconfigure.xml index 5e855c097..91cfa5f4d 100644 --- a/Tests/Fixtures/xml/services_autoconfigure.xml +++ b/Tests/Fixtures/xml/services_autoconfigure.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services_autoconfigure_with_parent.xml b/Tests/Fixtures/xml/services_autoconfigure_with_parent.xml index 103045d38..97a8facf4 100644 --- a/Tests/Fixtures/xml/services_autoconfigure_with_parent.xml +++ b/Tests/Fixtures/xml/services_autoconfigure_with_parent.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services_bindings.xml b/Tests/Fixtures/xml/services_bindings.xml index 408bca5f7..0fb57daa5 100644 --- a/Tests/Fixtures/xml/services_bindings.xml +++ b/Tests/Fixtures/xml/services_bindings.xml @@ -1,5 +1,5 @@ - + null diff --git a/Tests/Fixtures/xml/services_defaults_with_parent.xml b/Tests/Fixtures/xml/services_defaults_with_parent.xml index 875ed6d51..bb1511898 100644 --- a/Tests/Fixtures/xml/services_defaults_with_parent.xml +++ b/Tests/Fixtures/xml/services_defaults_with_parent.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services_deprecated.xml b/Tests/Fixtures/xml/services_deprecated.xml index c19a47adf..ae3a0b089 100644 --- a/Tests/Fixtures/xml/services_deprecated.xml +++ b/Tests/Fixtures/xml/services_deprecated.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services_dump_load.xml b/Tests/Fixtures/xml/services_dump_load.xml index e70be185c..7a91166c1 100644 --- a/Tests/Fixtures/xml/services_dump_load.xml +++ b/Tests/Fixtures/xml/services_dump_load.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services_inline_not_candidate.xml b/Tests/Fixtures/xml/services_inline_not_candidate.xml index 725605853..e6857813c 100644 --- a/Tests/Fixtures/xml/services_inline_not_candidate.xml +++ b/Tests/Fixtures/xml/services_inline_not_candidate.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services_instanceof.xml b/Tests/Fixtures/xml/services_instanceof.xml index 839776a3f..097687e1a 100644 --- a/Tests/Fixtures/xml/services_instanceof.xml +++ b/Tests/Fixtures/xml/services_instanceof.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services_instanceof_with_parent.xml b/Tests/Fixtures/xml/services_instanceof_with_parent.xml index 67ce69172..c2fce5eb2 100644 --- a/Tests/Fixtures/xml/services_instanceof_with_parent.xml +++ b/Tests/Fixtures/xml/services_instanceof_with_parent.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services_named_args.xml b/Tests/Fixtures/xml/services_named_args.xml index 95dabde9c..68ade19dd 100644 --- a/Tests/Fixtures/xml/services_named_args.xml +++ b/Tests/Fixtures/xml/services_named_args.xml @@ -1,5 +1,5 @@ - + ABCD diff --git a/Tests/Fixtures/xml/services_prototype.xml b/Tests/Fixtures/xml/services_prototype.xml index 381f95dd0..9d1d622d4 100644 --- a/Tests/Fixtures/xml/services_prototype.xml +++ b/Tests/Fixtures/xml/services_prototype.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services_tsantos.xml b/Tests/Fixtures/xml/services_tsantos.xml index bb310b279..2a35f4686 100644 --- a/Tests/Fixtures/xml/services_tsantos.xml +++ b/Tests/Fixtures/xml/services_tsantos.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/services_without_id.xml b/Tests/Fixtures/xml/services_without_id.xml index bc0f719bd..fe65f08f4 100644 --- a/Tests/Fixtures/xml/services_without_id.xml +++ b/Tests/Fixtures/xml/services_without_id.xml @@ -1,5 +1,5 @@ - + diff --git a/Tests/Fixtures/xml/tag_with_empty_name.xml b/Tests/Fixtures/xml/tag_with_empty_name.xml index 164629246..08e3e78fa 100644 --- a/Tests/Fixtures/xml/tag_with_empty_name.xml +++ b/Tests/Fixtures/xml/tag_with_empty_name.xml @@ -1,7 +1,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Tests/Fixtures/xml/tag_without_name.xml b/Tests/Fixtures/xml/tag_without_name.xml index bc7373df7..1ff392903 100644 --- a/Tests/Fixtures/xml/tag_without_name.xml +++ b/Tests/Fixtures/xml/tag_without_name.xml @@ -1,7 +1,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Tests/Fixtures/xml/with_key_outside_collection.xml b/Tests/Fixtures/xml/with_key_outside_collection.xml index 5f3a28436..1f6d32079 100644 --- a/Tests/Fixtures/xml/with_key_outside_collection.xml +++ b/Tests/Fixtures/xml/with_key_outside_collection.xml @@ -1,5 +1,5 @@ - + foo diff --git a/Tests/Fixtures/xml/xml_with_wrong_ext.php b/Tests/Fixtures/xml/xml_with_wrong_ext.php index 91ff5d460..dcf167db8 100644 --- a/Tests/Fixtures/xml/xml_with_wrong_ext.php +++ b/Tests/Fixtures/xml/xml_with_wrong_ext.php @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> from xml From e3739040696f9acf24160957b43ef117989b1bb5 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 8 Mar 2019 19:10:13 +0100 Subject: [PATCH 24/72] update docblock to match the actual behavior --- Container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Container.php b/Container.php index e82264343..e385f0689 100644 --- a/Container.php +++ b/Container.php @@ -159,7 +159,7 @@ public function setParameter($name, $value) /** * Sets a service. * - * Setting a service to null resets the service: has() returns false and get() + * Setting a synthetic service to null resets it: has() returns false and get() * behaves in the same way as if the service was never created. * * @param string $id The service identifier From 85172cca352fe0790fa6f485ad194862a8ac57ee Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Mon, 25 Mar 2019 08:48:46 +0100 Subject: [PATCH 25/72] use behavior instead of behaviour --- Dumper/XmlDumper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dumper/XmlDumper.php b/Dumper/XmlDumper.php index 0fac16b14..67b6dbebb 100644 --- a/Dumper/XmlDumper.php +++ b/Dumper/XmlDumper.php @@ -290,12 +290,12 @@ private function convertParameters(array $parameters, $type, \DOMElement $parent } elseif ($value instanceof Reference) { $element->setAttribute('type', 'service'); $element->setAttribute('id', (string) $value); - $behaviour = $value->getInvalidBehavior(); - if (ContainerInterface::NULL_ON_INVALID_REFERENCE == $behaviour) { + $behavior = $value->getInvalidBehavior(); + if (ContainerInterface::NULL_ON_INVALID_REFERENCE == $behavior) { $element->setAttribute('on-invalid', 'null'); - } elseif (ContainerInterface::IGNORE_ON_INVALID_REFERENCE == $behaviour) { + } elseif (ContainerInterface::IGNORE_ON_INVALID_REFERENCE == $behavior) { $element->setAttribute('on-invalid', 'ignore'); - } elseif (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE == $behaviour) { + } elseif (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE == $behavior) { $element->setAttribute('on-invalid', 'ignore_uninitialized'); } } elseif ($value instanceof Definition) { From 5243aca39f406202f2393ccc5e13f0daa4a365d5 Mon Sep 17 00:00:00 2001 From: Amrouche Hamza Date: Sat, 6 Apr 2019 14:30:12 +0200 Subject: [PATCH 26/72] [WIP] [DependencyInjection] Fix a wrong error when using a factory and a call --- Compiler/AutowirePass.php | 10 ++++- Compiler/ResolveBindingsPass.php | 9 ++++- Tests/Compiler/AutowirePassTest.php | 13 +++++++ Tests/Compiler/ResolveBindingsPassTest.php | 44 ++++++++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) diff --git a/Compiler/AutowirePass.php b/Compiler/AutowirePass.php index 252b304f1..c8e7a0f57 100644 --- a/Compiler/AutowirePass.php +++ b/Compiler/AutowirePass.php @@ -181,7 +181,15 @@ private function autowireCalls(\ReflectionClass $reflectionClass, array $methodC if ($method instanceof \ReflectionFunctionAbstract) { $reflectionMethod = $method; } else { - $reflectionMethod = $this->getReflectionMethod(new Definition($reflectionClass->name), $method); + $definition = new Definition($reflectionClass->name); + try { + $reflectionMethod = $this->getReflectionMethod($definition, $method); + } catch (RuntimeException $e) { + if ($definition->getFactory()) { + continue; + } + throw $e; + } } $arguments = $this->autowireMethod($reflectionMethod, $arguments); diff --git a/Compiler/ResolveBindingsPass.php b/Compiler/ResolveBindingsPass.php index 20b262b6d..bb67eb167 100644 --- a/Compiler/ResolveBindingsPass.php +++ b/Compiler/ResolveBindingsPass.php @@ -115,7 +115,14 @@ protected function processValue($value, $isRoot = false) if ($method instanceof \ReflectionFunctionAbstract) { $reflectionMethod = $method; } else { - $reflectionMethod = $this->getReflectionMethod($value, $method); + try { + $reflectionMethod = $this->getReflectionMethod($value, $method); + } catch (RuntimeException $e) { + if ($value->getFactory()) { + continue; + } + throw $e; + } } foreach ($reflectionMethod->getParameters() as $key => $parameter) { diff --git a/Tests/Compiler/AutowirePassTest.php b/Tests/Compiler/AutowirePassTest.php index 6bd49fa5c..6235ed50b 100644 --- a/Tests/Compiler/AutowirePassTest.php +++ b/Tests/Compiler/AutowirePassTest.php @@ -23,6 +23,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic; use Symfony\Component\DependencyInjection\TypedReference; +use Symfony\Component\HttpKernel\HttpKernelInterface; require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php'; @@ -605,6 +606,18 @@ public function testSetterInjection() ); } + public function testWithNonExistingSetterAndAutowiring() + { + $container = new ContainerBuilder(); + + $definition = $container->register(HttpKernelInterface::class, HttpKernelInterface::class)->setAutowired(true); + $definition->addMethodCall('setLogger'); + $this->expectException(RuntimeException::class); + (new ResolveClassPass())->process($container); + (new AutowireRequiredMethodsPass())->process($container); + (new AutowirePass())->process($container); + } + public function testExplicitMethodInjection() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index 5118b416f..84b3d6c65 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -16,11 +16,14 @@ use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy; use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists; use Symfony\Component\DependencyInjection\TypedReference; +use Symfony\Component\HttpKernel\HttpKernelInterface; require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php'; @@ -111,4 +114,45 @@ public function testScalarSetter() $this->assertEquals([['setDefaultLocale', ['fr']]], $definition->getMethodCalls()); } + + public function testWithNonExistingSetterAndBinding() + { + $container = new ContainerBuilder(); + + $bindings = [ + '$c' => (new Definition('logger'))->setFactory('logger'), + ]; + + $definition = $container->register(HttpKernelInterface::class, HttpKernelInterface::class); + $definition->addMethodCall('setLogger'); + $definition->setBindings($bindings); + $this->expectException(RuntimeException::class); + + $pass = new ResolveBindingsPass(); + $pass->process($container); + } + + public function testTupleBinding() + { + $container = new ContainerBuilder(); + + $bindings = [ + '$c' => new BoundArgument(new Reference('bar')), + CaseSensitiveClass::class.'$c' => new BoundArgument(new Reference('foo')), + ]; + + $definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class); + $definition->addMethodCall('setSensitiveClass'); + $definition->addMethodCall('setAnotherC'); + $definition->setBindings($bindings); + + $pass = new ResolveBindingsPass(); + $pass->process($container); + + $expected = [ + ['setSensitiveClass', [new Reference('foo')]], + ['setAnotherC', [new Reference('bar')]], + ]; + $this->assertEquals($expected, $definition->getMethodCalls()); + } } From 2f2ebf4c22907574db764ea872700647f54bd1c3 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 6 Apr 2019 20:39:34 +0200 Subject: [PATCH 27/72] fix tests --- Tests/Compiler/AutowirePassTest.php | 10 +++++-- Tests/Compiler/ResolveBindingsPassTest.php | 33 ++++------------------ 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/Tests/Compiler/AutowirePassTest.php b/Tests/Compiler/AutowirePassTest.php index 6235ed50b..31fa665ae 100644 --- a/Tests/Compiler/AutowirePassTest.php +++ b/Tests/Compiler/AutowirePassTest.php @@ -21,9 +21,9 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic; use Symfony\Component\DependencyInjection\TypedReference; -use Symfony\Component\HttpKernel\HttpKernelInterface; require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php'; @@ -606,13 +606,17 @@ public function testSetterInjection() ); } + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @exceptedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "setLogger()" does not exist. + */ public function testWithNonExistingSetterAndAutowiring() { $container = new ContainerBuilder(); - $definition = $container->register(HttpKernelInterface::class, HttpKernelInterface::class)->setAutowired(true); + $definition = $container->register(CaseSensitiveClass::class, CaseSensitiveClass::class)->setAutowired(true); $definition->addMethodCall('setLogger'); - $this->expectException(RuntimeException::class); + (new ResolveClassPass())->process($container); (new AutowireRequiredMethodsPass())->process($container); (new AutowirePass())->process($container); diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index 84b3d6c65..7bbecf620 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -17,13 +17,11 @@ use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy; use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists; use Symfony\Component\DependencyInjection\TypedReference; -use Symfony\Component\HttpKernel\HttpKernelInterface; require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php'; @@ -115,6 +113,10 @@ public function testScalarSetter() $this->assertEquals([['setDefaultLocale', ['fr']]], $definition->getMethodCalls()); } + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @exceptedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "setLogger()" does not exist. + */ public function testWithNonExistingSetterAndBinding() { $container = new ContainerBuilder(); @@ -123,36 +125,11 @@ public function testWithNonExistingSetterAndBinding() '$c' => (new Definition('logger'))->setFactory('logger'), ]; - $definition = $container->register(HttpKernelInterface::class, HttpKernelInterface::class); - $definition->addMethodCall('setLogger'); - $definition->setBindings($bindings); - $this->expectException(RuntimeException::class); - - $pass = new ResolveBindingsPass(); - $pass->process($container); - } - - public function testTupleBinding() - { - $container = new ContainerBuilder(); - - $bindings = [ - '$c' => new BoundArgument(new Reference('bar')), - CaseSensitiveClass::class.'$c' => new BoundArgument(new Reference('foo')), - ]; - $definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class); - $definition->addMethodCall('setSensitiveClass'); - $definition->addMethodCall('setAnotherC'); + $definition->addMethodCall('setLogger'); $definition->setBindings($bindings); $pass = new ResolveBindingsPass(); $pass->process($container); - - $expected = [ - ['setSensitiveClass', [new Reference('foo')]], - ['setAnotherC', [new Reference('bar')]], - ]; - $this->assertEquals($expected, $definition->getMethodCalls()); } } From da09ff8100a135ff78acba3da71ea9f70be11337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Bogusz?= Date: Mon, 21 Jan 2019 01:28:28 +0100 Subject: [PATCH 28/72] [DI] Fixes: #28326 - Overriding services autowired by name under _defaults bind not working --- Compiler/ResolveBindingsPass.php | 2 ++ ContainerBuilder.php | 31 +++++++++++++++++++++ Loader/Configurator/ServiceConfigurator.php | 2 ++ Loader/FileLoader.php | 2 ++ Tests/Fixtures/yaml/defaults_bindings.yml | 11 ++++++++ Tests/Fixtures/yaml/defaults_bindings2.yml | 7 +++++ Tests/Loader/YamlFileLoaderTest.php | 17 +++++++++++ 7 files changed, 72 insertions(+) create mode 100644 Tests/Fixtures/yaml/defaults_bindings.yml create mode 100644 Tests/Fixtures/yaml/defaults_bindings2.yml diff --git a/Compiler/ResolveBindingsPass.php b/Compiler/ResolveBindingsPass.php index 0fad285e5..a82d4163c 100644 --- a/Compiler/ResolveBindingsPass.php +++ b/Compiler/ResolveBindingsPass.php @@ -34,6 +34,8 @@ class ResolveBindingsPass extends AbstractRecursivePass */ public function process(ContainerBuilder $container) { + $this->usedBindings = $container->getRemovedBindingIds(); + try { parent::process($container); diff --git a/ContainerBuilder.php b/ContainerBuilder.php index 0c1966a42..72307464a 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -123,6 +123,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface private $removedIds = []; + private $removedBindingIds = []; + private static $internalTypes = [ 'int' => true, 'float' => true, @@ -1504,6 +1506,35 @@ public function normalizeId($id) return isset($this->definitions[$id]) || isset($this->aliasDefinitions[$id]) || isset($this->removedIds[$id]) ? $id : parent::normalizeId($id); } + /** + * Gets removed binding ids. + * + * @return array + * + * @internal + */ + public function getRemovedBindingIds() + { + return $this->removedBindingIds; + } + + /** + * Adds a removed binding id. + * + * @param int $id + * + * @internal + */ + public function addRemovedBindingIds($id) + { + if ($this->hasDefinition($id)) { + foreach ($this->getDefinition($id)->getBindings() as $key => $binding) { + list(, $bindingId) = $binding->getValues(); + $this->removedBindingIds[(int) $bindingId] = true; + } + } + } + /** * Returns the Service Conditionals. * diff --git a/Loader/Configurator/ServiceConfigurator.php b/Loader/Configurator/ServiceConfigurator.php index 12054cad0..21b1669d0 100644 --- a/Loader/Configurator/ServiceConfigurator.php +++ b/Loader/Configurator/ServiceConfigurator.php @@ -59,6 +59,8 @@ public function __destruct() { parent::__destruct(); + $this->container->addRemovedBindingIds($this->id); + if (!$this->definition instanceof ChildDefinition) { $this->container->setDefinition($this->id, $this->definition->setInstanceofConditionals($this->instanceof)); } else { diff --git a/Loader/FileLoader.php b/Loader/FileLoader.php index a428c6e35..0dd1a3d8b 100644 --- a/Loader/FileLoader.php +++ b/Loader/FileLoader.php @@ -91,6 +91,8 @@ public function registerClasses(Definition $prototype, $namespace, $resource, $e */ protected function setDefinition($id, Definition $definition) { + $this->container->addRemovedBindingIds($id); + if ($this->isLoadingInstanceof) { if (!$definition instanceof ChildDefinition) { throw new InvalidArgumentException(sprintf('Invalid type definition "%s": ChildDefinition expected, "%s" given.', $id, \get_class($definition))); diff --git a/Tests/Fixtures/yaml/defaults_bindings.yml b/Tests/Fixtures/yaml/defaults_bindings.yml new file mode 100644 index 000000000..2e054f563 --- /dev/null +++ b/Tests/Fixtures/yaml/defaults_bindings.yml @@ -0,0 +1,11 @@ +services: + _defaults: + bind: + $quz: value + $foo: [value] + + bar: + class: Symfony\Component\DependencyInjection\Tests\Fixtures\Bar + + foo: + class: Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy diff --git a/Tests/Fixtures/yaml/defaults_bindings2.yml b/Tests/Fixtures/yaml/defaults_bindings2.yml new file mode 100644 index 000000000..75e983452 --- /dev/null +++ b/Tests/Fixtures/yaml/defaults_bindings2.yml @@ -0,0 +1,7 @@ +services: + _defaults: + bind: + $quz: ~ + + bar: + class: Symfony\Component\DependencyInjection\Tests\Fixtures\Bar diff --git a/Tests/Loader/YamlFileLoaderTest.php b/Tests/Loader/YamlFileLoaderTest.php index 7bcf0ec05..001fa33e5 100644 --- a/Tests/Loader/YamlFileLoaderTest.php +++ b/Tests/Loader/YamlFileLoaderTest.php @@ -17,6 +17,7 @@ use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Config\Resource\GlobResource; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; +use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; @@ -732,4 +733,20 @@ public function testBindings() '$factory' => 'factory', ], array_map(function ($v) { return $v->getValues()[0]; }, $definition->getBindings())); } + + /** + * The pass may throw an exception, which will cause the test to fail. + */ + public function testOverriddenDefaultsBindings() + { + $container = new ContainerBuilder(); + + $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); + $loader->load('defaults_bindings.yml'); + $loader->load('defaults_bindings2.yml'); + + (new ResolveBindingsPass())->process($container); + + $this->assertTrue(true); + } } From cc9ffe65b9e6895064506810bc7b61b9aa1b4548 Mon Sep 17 00:00:00 2001 From: renanbr Date: Fri, 12 Apr 2019 14:54:30 +0200 Subject: [PATCH 29/72] more tests --- Tests/Fixtures/Bar.php | 3 +++ Tests/Fixtures/xml/defaults_bindings.xml | 15 +++++++++++++++ Tests/Fixtures/xml/defaults_bindings2.xml | 10 ++++++++++ Tests/Fixtures/yaml/defaults_bindings.yml | 2 +- Tests/Fixtures/yaml/defaults_bindings2.yml | 2 +- Tests/Loader/XmlFileLoaderTest.php | 17 +++++++++++++++++ Tests/Loader/YamlFileLoaderTest.php | 2 +- 7 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 Tests/Fixtures/xml/defaults_bindings.xml create mode 100644 Tests/Fixtures/xml/defaults_bindings2.xml diff --git a/Tests/Fixtures/Bar.php b/Tests/Fixtures/Bar.php index 83f2da12a..1aaca2f15 100644 --- a/Tests/Fixtures/Bar.php +++ b/Tests/Fixtures/Bar.php @@ -13,8 +13,11 @@ class Bar implements BarInterface { + public $quz; + public function __construct($quz = null, \NonExistent $nonExistent = null, BarInterface $decorated = null, array $foo = []) { + $this->quz = $quz; } public static function create(\NonExistent $nonExistent = null, $factory = null) diff --git a/Tests/Fixtures/xml/defaults_bindings.xml b/Tests/Fixtures/xml/defaults_bindings.xml new file mode 100644 index 000000000..d943dfad2 --- /dev/null +++ b/Tests/Fixtures/xml/defaults_bindings.xml @@ -0,0 +1,15 @@ + + + + + value + + value + + + + + + + + diff --git a/Tests/Fixtures/xml/defaults_bindings2.xml b/Tests/Fixtures/xml/defaults_bindings2.xml new file mode 100644 index 000000000..db41330f8 --- /dev/null +++ b/Tests/Fixtures/xml/defaults_bindings2.xml @@ -0,0 +1,10 @@ + + + + + overridden + + + + + diff --git a/Tests/Fixtures/yaml/defaults_bindings.yml b/Tests/Fixtures/yaml/defaults_bindings.yml index 2e054f563..ca5e5048d 100644 --- a/Tests/Fixtures/yaml/defaults_bindings.yml +++ b/Tests/Fixtures/yaml/defaults_bindings.yml @@ -8,4 +8,4 @@ services: class: Symfony\Component\DependencyInjection\Tests\Fixtures\Bar foo: - class: Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy + class: stdClass diff --git a/Tests/Fixtures/yaml/defaults_bindings2.yml b/Tests/Fixtures/yaml/defaults_bindings2.yml index 75e983452..01fc5af62 100644 --- a/Tests/Fixtures/yaml/defaults_bindings2.yml +++ b/Tests/Fixtures/yaml/defaults_bindings2.yml @@ -1,7 +1,7 @@ services: _defaults: bind: - $quz: ~ + $quz: overridden bar: class: Symfony\Component\DependencyInjection\Tests\Fixtures\Bar diff --git a/Tests/Loader/XmlFileLoaderTest.php b/Tests/Loader/XmlFileLoaderTest.php index d89887acc..03376a641 100644 --- a/Tests/Loader/XmlFileLoaderTest.php +++ b/Tests/Loader/XmlFileLoaderTest.php @@ -17,6 +17,7 @@ use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Config\Resource\GlobResource; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; +use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; @@ -820,4 +821,20 @@ public function testTsantosContainer() $dump = $dumper->dump(); $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_tsantos.php', $dumper->dump()); } + + /** + * The pass may throw an exception, which will cause the test to fail. + */ + public function testOverriddenDefaultsBindings() + { + $container = new ContainerBuilder(); + + $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); + $loader->load('defaults_bindings.xml'); + $loader->load('defaults_bindings2.xml'); + + (new ResolveBindingsPass())->process($container); + + $this->assertSame('overridden', $container->get('bar')->quz); + } } diff --git a/Tests/Loader/YamlFileLoaderTest.php b/Tests/Loader/YamlFileLoaderTest.php index 001fa33e5..05521bf78 100644 --- a/Tests/Loader/YamlFileLoaderTest.php +++ b/Tests/Loader/YamlFileLoaderTest.php @@ -747,6 +747,6 @@ public function testOverriddenDefaultsBindings() (new ResolveBindingsPass())->process($container); - $this->assertTrue(true); + $this->assertSame('overridden', $container->get('bar')->quz); } } From dee85a9148399cdb2731603802842bcfd8afe5ab Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 2 Apr 2019 19:55:56 +0200 Subject: [PATCH 30/72] [DI] Check service IDs are valid --- ContainerBuilder.php | 8 + Dumper/PhpDumper.php | 33 ++-- Tests/ContainerBuilderTest.php | 32 ++++ Tests/Dumper/PhpDumperTest.php | 8 +- Tests/Fixtures/php/services33.php | 4 +- Tests/Fixtures/php/services_adawson.php | 46 ++--- .../Fixtures/php/services_inline_requires.php | 8 +- .../Fixtures/php/services_inline_self_ref.php | 2 +- Tests/Fixtures/php/services_rot13_env.php | 4 +- Tests/Fixtures/php/services_subscriber.php | 12 +- .../php/services_unsupported_characters.php | 178 ++++++++++++++++++ 11 files changed, 282 insertions(+), 53 deletions(-) create mode 100644 Tests/Fixtures/php/services_unsupported_characters.php diff --git a/ContainerBuilder.php b/ContainerBuilder.php index 72307464a..e6a2aa053 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -868,6 +868,10 @@ public function setAlias($alias, $id) { $alias = $this->normalizeId($alias); + if ('' === $alias || '\\' === substr($alias, -1) || \strlen($alias) !== strcspn($alias, "\0\r\n'")) { + throw new InvalidArgumentException(sprintf('Invalid alias id: "%s"', $alias)); + } + if (\is_string($id)) { $id = new Alias($this->normalizeId($id)); } elseif (!$id instanceof Alias) { @@ -1021,6 +1025,10 @@ public function setDefinition($id, Definition $definition) $id = $this->normalizeId($id); + if ('' === $id || '\\' === substr($id, -1) || \strlen($id) !== strcspn($id, "\0\r\n'")) { + throw new InvalidArgumentException(sprintf('Invalid service id: "%s"', $id)); + } + unset($this->aliasDefinitions[$id], $this->removedIds[$id]); return $this->definitions[$id] = $definition; diff --git a/Dumper/PhpDumper.php b/Dumper/PhpDumper.php index 0a1385ecc..73c868f1e 100644 --- a/Dumper/PhpDumper.php +++ b/Dumper/PhpDumper.php @@ -483,7 +483,7 @@ private function addServiceInstance($id, Definition $definition, $isSimpleInstan $instantiation = ''; if (!$isProxyCandidate && $definition->isShared()) { - $instantiation = "\$this->services['$id'] = ".($isSimpleInstance ? '' : '$instance'); + $instantiation = sprintf('$this->services[%s] = %s', $this->doExport($id), $isSimpleInstance ? '' : '$instance'); } elseif (!$isSimpleInstance) { $instantiation = '$instance'; } @@ -679,6 +679,9 @@ private function addService($id, Definition $definition, &$file = null) * Gets the $public '$id'$shared$autowired service. * * $return +EOF; + $code = str_replace('*/', ' ', $code).<<getProxyDumper()->isProxyCandidate($definition)) { $factoryCode = $asFile ? "\$this->load('%s.php', false)" : '$this->%s(false)'; - $code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName)); + $code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName, $this->doExport($id))); } if ($definition->isDeprecated()) { @@ -767,14 +770,14 @@ private function addInlineReference($id, Definition $definition, $targetId, $for $code .= sprintf(<<<'EOTXT' - if (isset($this->%s['%s'])) { - return $this->%1$s['%2$s']; + if (isset($this->%s[%s])) { + return $this->%1$s[%2$s]; } EOTXT , 'services', - $id + $this->doExport($id) ); return $code; @@ -1530,14 +1533,14 @@ private function getServiceConditionals($value) if (!$this->container->hasDefinition($service)) { return 'false'; } - $conditions[] = sprintf("isset(\$this->services['%s'])", $service); + $conditions[] = sprintf('isset($this->services[%s])', $this->doExport($service)); } foreach (ContainerBuilder::getServiceConditionals($value) as $service) { if ($this->container->hasDefinition($service) && !$this->container->getDefinition($service)->isPublic()) { continue; } - $conditions[] = sprintf("\$this->has('%s')", $service); + $conditions[] = sprintf('$this->has(%s)', $this->doExport($service)); } if (!$conditions) { @@ -1776,6 +1779,8 @@ private function dumpLiteralClass($class) */ private function dumpParameter($name) { + $name = (string) $name; + if ($this->container->isCompiled() && $this->container->hasParameter($name)) { $value = $this->container->getParameter($name); $dumpedValue = $this->dumpValue($value, false); @@ -1785,11 +1790,11 @@ private function dumpParameter($name) } if (!preg_match("/\\\$this->(?:getEnv\('(?:\w++:)*+\w++'\)|targetDirs\[\d++\])/", $dumpedValue)) { - return sprintf("\$this->parameters['%s']", $name); + return sprintf('$this->parameters[%s]', $this->doExport($name)); } } - return sprintf("\$this->getParameter('%s')", $name); + return sprintf('$this->getParameter(%s)', $this->doExport($name)); } /** @@ -1813,7 +1818,7 @@ private function getServiceCall($id, Reference $reference = null) if ($this->container->hasDefinition($id) && $definition = $this->container->getDefinition($id)) { if ($definition->isSynthetic()) { - $code = sprintf('$this->get(\'%s\'%s)', $id, null !== $reference ? ', '.$reference->getInvalidBehavior() : ''); + $code = sprintf('$this->get(%s%s)', $this->doExport($id), null !== $reference ? ', '.$reference->getInvalidBehavior() : ''); } elseif (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) { $code = 'null'; if (!$definition->isShared()) { @@ -1822,7 +1827,7 @@ private function getServiceCall($id, Reference $reference = null) } elseif ($this->isTrivialInstance($definition)) { $code = substr($this->addNewInstance($definition, '', '', $id), 8, -2); if ($definition->isShared()) { - $code = sprintf('$this->services[\'%s\'] = %s', $id, $code); + $code = sprintf('$this->services[%s] = %s', $this->doExport($id), $code); } $code = "($code)"; } elseif ($this->asFiles && $definition->isShared() && !$this->isHotPath($definition)) { @@ -1833,14 +1838,14 @@ private function getServiceCall($id, Reference $reference = null) } elseif (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) { return 'null'; } elseif (null !== $reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) { - $code = sprintf('$this->get(\'%s\', /* ContainerInterface::NULL_ON_INVALID_REFERENCE */ %d)', $id, ContainerInterface::NULL_ON_INVALID_REFERENCE); + $code = sprintf('$this->get(%s, /* ContainerInterface::NULL_ON_INVALID_REFERENCE */ %d)', $this->doExport($id), ContainerInterface::NULL_ON_INVALID_REFERENCE); } else { - $code = sprintf('$this->get(\'%s\')', $id); + $code = sprintf('$this->get(%s)', $this->doExport($id)); } // The following is PHP 5.5 syntax for what could be written as "(\$this->services['$id'] ?? $code)" on PHP>=7.0 - return "\${(\$_ = isset(\$this->services['$id']) ? \$this->services['$id'] : $code) && false ?: '_'}"; + return sprintf("\${(\$_ = isset(\$this->services[%s]) ? \$this->services[%1\$s] : %s) && false ?: '_'}", $this->doExport($id), $code); } /** diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index 40afaa169..73cb670cd 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -195,6 +195,38 @@ public function testNonSharedServicesReturnsDifferentInstances() $this->assertNotSame($builder->get('bar'), $builder->get('bar')); } + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @dataProvider provideBadId + */ + public function testBadAliasId($id) + { + $builder = new ContainerBuilder(); + $builder->setAlias($id, 'foo'); + } + + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @dataProvider provideBadId + */ + public function testBadDefinitionId($id) + { + $builder = new ContainerBuilder(); + $builder->setDefinition($id, new Definition('Foo')); + } + + public function provideBadId() + { + return [ + [''], + ["\0"], + ["\r"], + ["\n"], + ["'"], + ['ab\\'], + ]; + } + /** * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException * @expectedExceptionMessage You have requested a synthetic service ("foo"). The DIC does not know how to construct this service. diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index 6d985eaca..761f7ef4d 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -234,12 +234,18 @@ public function testAddServiceIdWithUnsupportedCharacters() { $class = 'Symfony_DI_PhpDumper_Test_Unsupported_Characters'; $container = new ContainerBuilder(); + $container->setParameter("'", 'oh-no'); + $container->register("foo*/oh-no", 'FooClass')->setPublic(true); $container->register('bar$', 'FooClass')->setPublic(true); $container->register('bar$!', 'FooClass')->setPublic(true); $container->compile(); $dumper = new PhpDumper($container); - eval('?>'.$dumper->dump(['class' => $class])); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_unsupported_characters.php', $dumper->dump(['class' => $class])); + + require_once self::$fixturesPath.'/php/services_unsupported_characters.php'; + + $this->assertTrue(method_exists($class, 'getFooOhNoService')); $this->assertTrue(method_exists($class, 'getBarService')); $this->assertTrue(method_exists($class, 'getBar2Service')); } diff --git a/Tests/Fixtures/php/services33.php b/Tests/Fixtures/php/services33.php index 98e34bc9b..d4019a50a 100644 --- a/Tests/Fixtures/php/services33.php +++ b/Tests/Fixtures/php/services33.php @@ -66,7 +66,7 @@ public function isFrozen() */ protected function getFooService() { - return $this->services['Bar\Foo'] = new \Bar\Foo(); + return $this->services['Bar\\Foo'] = new \Bar\Foo(); } /** @@ -76,6 +76,6 @@ protected function getFooService() */ protected function getFoo2Service() { - return $this->services['Foo\Foo'] = new \Foo\Foo(); + return $this->services['Foo\\Foo'] = new \Foo\Foo(); } } diff --git a/Tests/Fixtures/php/services_adawson.php b/Tests/Fixtures/php/services_adawson.php index f222fc6e6..7986897d3 100644 --- a/Tests/Fixtures/php/services_adawson.php +++ b/Tests/Fixtures/php/services_adawson.php @@ -88,10 +88,10 @@ public function isFrozen() */ protected function getBusService() { - $this->services['App\Bus'] = $instance = new \App\Bus(${($_ = isset($this->services['App\Db']) ? $this->services['App\Db'] : $this->getDbService()) && false ?: '_'}); + $this->services['App\\Bus'] = $instance = new \App\Bus(${($_ = isset($this->services['App\\Db']) ? $this->services['App\\Db'] : $this->getDbService()) && false ?: '_'}); - $instance->handler1 = ${($_ = isset($this->services['App\Handler1']) ? $this->services['App\Handler1'] : $this->getHandler1Service()) && false ?: '_'}; - $instance->handler2 = ${($_ = isset($this->services['App\Handler2']) ? $this->services['App\Handler2'] : $this->getHandler2Service()) && false ?: '_'}; + $instance->handler1 = ${($_ = isset($this->services['App\\Handler1']) ? $this->services['App\\Handler1'] : $this->getHandler1Service()) && false ?: '_'}; + $instance->handler2 = ${($_ = isset($this->services['App\\Handler2']) ? $this->services['App\\Handler2'] : $this->getHandler2Service()) && false ?: '_'}; return $instance; } @@ -103,9 +103,9 @@ protected function getBusService() */ protected function getDbService() { - $this->services['App\Db'] = $instance = new \App\Db(); + $this->services['App\\Db'] = $instance = new \App\Db(); - $instance->schema = ${($_ = isset($this->services['App\Schema']) ? $this->services['App\Schema'] : $this->getSchemaService()) && false ?: '_'}; + $instance->schema = ${($_ = isset($this->services['App\\Schema']) ? $this->services['App\\Schema'] : $this->getSchemaService()) && false ?: '_'}; return $instance; } @@ -117,13 +117,13 @@ protected function getDbService() */ protected function getHandler1Service() { - $a = ${($_ = isset($this->services['App\Processor']) ? $this->services['App\Processor'] : $this->getProcessorService()) && false ?: '_'}; + $a = ${($_ = isset($this->services['App\\Processor']) ? $this->services['App\\Processor'] : $this->getProcessorService()) && false ?: '_'}; - if (isset($this->services['App\Handler1'])) { - return $this->services['App\Handler1']; + if (isset($this->services['App\\Handler1'])) { + return $this->services['App\\Handler1']; } - return $this->services['App\Handler1'] = new \App\Handler1(${($_ = isset($this->services['App\Db']) ? $this->services['App\Db'] : $this->getDbService()) && false ?: '_'}, ${($_ = isset($this->services['App\Schema']) ? $this->services['App\Schema'] : $this->getSchemaService()) && false ?: '_'}, $a); + return $this->services['App\\Handler1'] = new \App\Handler1(${($_ = isset($this->services['App\\Db']) ? $this->services['App\\Db'] : $this->getDbService()) && false ?: '_'}, ${($_ = isset($this->services['App\\Schema']) ? $this->services['App\\Schema'] : $this->getSchemaService()) && false ?: '_'}, $a); } /** @@ -133,13 +133,13 @@ protected function getHandler1Service() */ protected function getHandler2Service() { - $a = ${($_ = isset($this->services['App\Processor']) ? $this->services['App\Processor'] : $this->getProcessorService()) && false ?: '_'}; + $a = ${($_ = isset($this->services['App\\Processor']) ? $this->services['App\\Processor'] : $this->getProcessorService()) && false ?: '_'}; - if (isset($this->services['App\Handler2'])) { - return $this->services['App\Handler2']; + if (isset($this->services['App\\Handler2'])) { + return $this->services['App\\Handler2']; } - return $this->services['App\Handler2'] = new \App\Handler2(${($_ = isset($this->services['App\Db']) ? $this->services['App\Db'] : $this->getDbService()) && false ?: '_'}, ${($_ = isset($this->services['App\Schema']) ? $this->services['App\Schema'] : $this->getSchemaService()) && false ?: '_'}, $a); + return $this->services['App\\Handler2'] = new \App\Handler2(${($_ = isset($this->services['App\\Db']) ? $this->services['App\\Db'] : $this->getDbService()) && false ?: '_'}, ${($_ = isset($this->services['App\\Schema']) ? $this->services['App\\Schema'] : $this->getSchemaService()) && false ?: '_'}, $a); } /** @@ -149,13 +149,13 @@ protected function getHandler2Service() */ protected function getProcessorService() { - $a = ${($_ = isset($this->services['App\Registry']) ? $this->services['App\Registry'] : $this->getRegistryService()) && false ?: '_'}; + $a = ${($_ = isset($this->services['App\\Registry']) ? $this->services['App\\Registry'] : $this->getRegistryService()) && false ?: '_'}; - if (isset($this->services['App\Processor'])) { - return $this->services['App\Processor']; + if (isset($this->services['App\\Processor'])) { + return $this->services['App\\Processor']; } - return $this->services['App\Processor'] = new \App\Processor($a, ${($_ = isset($this->services['App\Db']) ? $this->services['App\Db'] : $this->getDbService()) && false ?: '_'}); + return $this->services['App\\Processor'] = new \App\Processor($a, ${($_ = isset($this->services['App\\Db']) ? $this->services['App\\Db'] : $this->getDbService()) && false ?: '_'}); } /** @@ -165,9 +165,9 @@ protected function getProcessorService() */ protected function getRegistryService() { - $this->services['App\Registry'] = $instance = new \App\Registry(); + $this->services['App\\Registry'] = $instance = new \App\Registry(); - $instance->processor = [0 => ${($_ = isset($this->services['App\Db']) ? $this->services['App\Db'] : $this->getDbService()) && false ?: '_'}, 1 => ${($_ = isset($this->services['App\Bus']) ? $this->services['App\Bus'] : $this->getBusService()) && false ?: '_'}]; + $instance->processor = [0 => ${($_ = isset($this->services['App\\Db']) ? $this->services['App\\Db'] : $this->getDbService()) && false ?: '_'}, 1 => ${($_ = isset($this->services['App\\Bus']) ? $this->services['App\\Bus'] : $this->getBusService()) && false ?: '_'}]; return $instance; } @@ -179,12 +179,12 @@ protected function getRegistryService() */ protected function getSchemaService() { - $a = ${($_ = isset($this->services['App\Db']) ? $this->services['App\Db'] : $this->getDbService()) && false ?: '_'}; + $a = ${($_ = isset($this->services['App\\Db']) ? $this->services['App\\Db'] : $this->getDbService()) && false ?: '_'}; - if (isset($this->services['App\Schema'])) { - return $this->services['App\Schema']; + if (isset($this->services['App\\Schema'])) { + return $this->services['App\\Schema']; } - return $this->services['App\Schema'] = new \App\Schema($a); + return $this->services['App\\Schema'] = new \App\Schema($a); } } diff --git a/Tests/Fixtures/php/services_inline_requires.php b/Tests/Fixtures/php/services_inline_requires.php index a23a69367..59582d9eb 100644 --- a/Tests/Fixtures/php/services_inline_requires.php +++ b/Tests/Fixtures/php/services_inline_requires.php @@ -87,7 +87,7 @@ public function isFrozen() */ protected function getParentNotExistsService() { - return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists(); + return $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\ParentNotExists'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists(); } /** @@ -97,7 +97,7 @@ protected function getParentNotExistsService() */ protected function getC1Service() { - return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C1'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C1(); + return $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C1'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C1(); } /** @@ -110,7 +110,7 @@ protected function getC2Service() include_once $this->targetDirs[1].'/includes/HotPath/C2.php'; include_once $this->targetDirs[1].'/includes/HotPath/C3.php'; - return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3())) && false ?: '_'}); + return $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C2'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2(${($_ = isset($this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C3']) ? $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C3'] : ($this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C3'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3())) && false ?: '_'}); } /** @@ -122,7 +122,7 @@ protected function getC3Service() { include_once $this->targetDirs[1].'/includes/HotPath/C3.php'; - return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3(); + return $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C3'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3(); } public function getParameter($name) diff --git a/Tests/Fixtures/php/services_inline_self_ref.php b/Tests/Fixtures/php/services_inline_self_ref.php index a2573eae6..271aeb668 100644 --- a/Tests/Fixtures/php/services_inline_self_ref.php +++ b/Tests/Fixtures/php/services_inline_self_ref.php @@ -69,7 +69,7 @@ protected function getFooService() $b = new \App\Baz($a); $b->bar = $a; - $this->services['App\Foo'] = $instance = new \App\Foo($b); + $this->services['App\\Foo'] = $instance = new \App\Foo($b); $a->foo = $instance; diff --git a/Tests/Fixtures/php/services_rot13_env.php b/Tests/Fixtures/php/services_rot13_env.php index 7c903b11d..8d1465c44 100644 --- a/Tests/Fixtures/php/services_rot13_env.php +++ b/Tests/Fixtures/php/services_rot13_env.php @@ -67,7 +67,7 @@ public function isFrozen() */ protected function getRot13EnvVarProcessorService() { - return $this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor(); + return $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Dumper\\Rot13EnvVarProcessor'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor(); } /** @@ -78,7 +78,7 @@ protected function getRot13EnvVarProcessorService() protected function getContainer_EnvVarProcessorsLocatorService() { return $this->services['container.env_var_processors_locator'] = new \Symfony\Component\DependencyInjection\ServiceLocator(['rot13' => function () { - return ${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor())) && false ?: '_'}; + return ${($_ = isset($this->services['Symfony\\Component\\DependencyInjection\\Tests\\Dumper\\Rot13EnvVarProcessor']) ? $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Dumper\\Rot13EnvVarProcessor'] : ($this->services['Symfony\\Component\\DependencyInjection\\Tests\\Dumper\\Rot13EnvVarProcessor'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor())) && false ?: '_'}; }]); } diff --git a/Tests/Fixtures/php/services_subscriber.php b/Tests/Fixtures/php/services_subscriber.php index 9424a7611..dbb51eab3 100644 --- a/Tests/Fixtures/php/services_subscriber.php +++ b/Tests/Fixtures/php/services_subscriber.php @@ -73,7 +73,7 @@ public function isFrozen() */ protected function getTestServiceSubscriberService() { - return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber(); + return $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber(); } /** @@ -84,13 +84,13 @@ protected function getTestServiceSubscriberService() protected function getFooServiceService() { return $this->services['foo_service'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber((new \Symfony\Component\DependencyInjection\ServiceLocator(['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => function () { - $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v = null) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition())) && false ?: '_'}); + $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v = null) { return $v; }; return $f(${($_ = isset($this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition']) ? $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition'] : ($this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition())) && false ?: '_'}); }, 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => function () { - $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber $v) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber())) && false ?: '_'}); + $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber $v) { return $v; }; return $f(${($_ = isset($this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber']) ? $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber'] : ($this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber())) && false ?: '_'}); }, 'bar' => function () { - $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber())) && false ?: '_'}); + $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v) { return $v; }; return $f(${($_ = isset($this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber']) ? $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber'] : ($this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber())) && false ?: '_'}); }, 'baz' => function () { - $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v = null) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] : ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition())) && false ?: '_'}); + $f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v = null) { return $v; }; return $f(${($_ = isset($this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition']) ? $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition'] : ($this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition())) && false ?: '_'}); }]))->withContext('foo_service', $this)); } @@ -101,6 +101,6 @@ protected function getFooServiceService() */ protected function getCustomDefinitionService() { - return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition(); + return $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition(); } } diff --git a/Tests/Fixtures/php/services_unsupported_characters.php b/Tests/Fixtures/php/services_unsupported_characters.php new file mode 100644 index 000000000..a4c841cab --- /dev/null +++ b/Tests/Fixtures/php/services_unsupported_characters.php @@ -0,0 +1,178 @@ +parameters = $this->getDefaultParameters(); + + $this->services = []; + $this->methodMap = [ + 'bar$' => 'getBarService', + 'bar$!' => 'getBar2Service', + 'foo*/oh-no' => 'getFooohnoService', + ]; + + $this->aliases = []; + } + + public function getRemovedIds() + { + return [ + 'Psr\\Container\\ContainerInterface' => true, + 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, + ]; + } + + public function compile() + { + throw new LogicException('You cannot compile a dumped container that was already compiled.'); + } + + public function isCompiled() + { + return true; + } + + public function isFrozen() + { + @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); + + return true; + } + + /** + * Gets the public 'bar$' shared service. + * + * @return \FooClass + */ + protected function getBarService() + { + return $this->services['bar$'] = new \FooClass(); + } + + /** + * Gets the public 'bar$!' shared service. + * + * @return \FooClass + */ + protected function getBar2Service() + { + return $this->services['bar$!'] = new \FooClass(); + } + + /** + * Gets the public 'foo oh-no' shared service. + * + * @return \FooClass + */ + protected function getFooohnoService() + { + return $this->services['foo*/oh-no'] = new \FooClass(); + } + + public function getParameter($name) + { + $name = (string) $name; + if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) { + $name = $this->normalizeParameterName($name); + + if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) { + throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name)); + } + } + if (isset($this->loadedDynamicParameters[$name])) { + return $this->loadedDynamicParameters[$name] ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); + } + + return $this->parameters[$name]; + } + + public function hasParameter($name) + { + $name = (string) $name; + $name = $this->normalizeParameterName($name); + + return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters); + } + + public function setParameter($name, $value) + { + throw new LogicException('Impossible to call set() on a frozen ParameterBag.'); + } + + public function getParameterBag() + { + if (null === $this->parameterBag) { + $parameters = $this->parameters; + foreach ($this->loadedDynamicParameters as $name => $loaded) { + $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); + } + $this->parameterBag = new FrozenParameterBag($parameters); + } + + return $this->parameterBag; + } + + private $loadedDynamicParameters = []; + private $dynamicParameters = []; + + /** + * Computes a dynamic parameter. + * + * @param string $name The name of the dynamic parameter to load + * + * @return mixed The value of the dynamic parameter + * + * @throws InvalidArgumentException When the dynamic parameter does not exist + */ + private function getDynamicParameter($name) + { + throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name)); + } + + private $normalizedParameterNames = []; + + private function normalizeParameterName($name) + { + if (isset($this->normalizedParameterNames[$normalizedName = strtolower($name)]) || isset($this->parameters[$normalizedName]) || array_key_exists($normalizedName, $this->parameters)) { + $normalizedName = isset($this->normalizedParameterNames[$normalizedName]) ? $this->normalizedParameterNames[$normalizedName] : $normalizedName; + if ((string) $name !== $normalizedName) { + @trigger_error(sprintf('Parameter names will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since Symfony 3.4.', $name, $normalizedName), E_USER_DEPRECATED); + } + } else { + $normalizedName = $this->normalizedParameterNames[$normalizedName] = (string) $name; + } + + return $normalizedName; + } + + /** + * Gets the default parameters. + * + * @return array An array of the default parameters + */ + protected function getDefaultParameters() + { + return [ + '\'' => 'oh-no', + ]; + } +} From be0feb3fa202aedfd8d1956f2dafd563fb13acbf Mon Sep 17 00:00:00 2001 From: Teoh Han Hui Date: Thu, 18 Apr 2019 20:04:31 +0200 Subject: [PATCH 31/72] Fix name and phpdoc of ContainerBuilder::removeBindings --- ContainerBuilder.php | 6 +++--- Loader/Configurator/ServiceConfigurator.php | 2 +- Loader/FileLoader.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ContainerBuilder.php b/ContainerBuilder.php index e6a2aa053..c322b4357 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -1527,13 +1527,13 @@ public function getRemovedBindingIds() } /** - * Adds a removed binding id. + * Removes bindings for a service. * - * @param int $id + * @param string $id The service identifier * * @internal */ - public function addRemovedBindingIds($id) + public function removeBindings($id) { if ($this->hasDefinition($id)) { foreach ($this->getDefinition($id)->getBindings() as $key => $binding) { diff --git a/Loader/Configurator/ServiceConfigurator.php b/Loader/Configurator/ServiceConfigurator.php index 21b1669d0..897dedaac 100644 --- a/Loader/Configurator/ServiceConfigurator.php +++ b/Loader/Configurator/ServiceConfigurator.php @@ -59,7 +59,7 @@ public function __destruct() { parent::__destruct(); - $this->container->addRemovedBindingIds($this->id); + $this->container->removeBindings($this->id); if (!$this->definition instanceof ChildDefinition) { $this->container->setDefinition($this->id, $this->definition->setInstanceofConditionals($this->instanceof)); diff --git a/Loader/FileLoader.php b/Loader/FileLoader.php index 0dd1a3d8b..f0d920189 100644 --- a/Loader/FileLoader.php +++ b/Loader/FileLoader.php @@ -91,7 +91,7 @@ public function registerClasses(Definition $prototype, $namespace, $resource, $e */ protected function setDefinition($id, Definition $definition) { - $this->container->addRemovedBindingIds($id); + $this->container->removeBindings($id); if ($this->isLoadingInstanceof) { if (!$definition instanceof ChildDefinition) { From e106c744ec12855dbdef55ce8c44328803dd7cb2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 7 May 2019 12:18:14 +0200 Subject: [PATCH 32/72] fixed CS --- Tests/Dumper/PhpDumperTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index 761f7ef4d..a1ccb52b6 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -235,7 +235,7 @@ public function testAddServiceIdWithUnsupportedCharacters() $class = 'Symfony_DI_PhpDumper_Test_Unsupported_Characters'; $container = new ContainerBuilder(); $container->setParameter("'", 'oh-no'); - $container->register("foo*/oh-no", 'FooClass')->setPublic(true); + $container->register('foo*/oh-no', 'FooClass')->setPublic(true); $container->register('bar$', 'FooClass')->setPublic(true); $container->register('bar$!', 'FooClass')->setPublic(true); $container->compile(); From 8f2a0452f086a66f6d6cf53a432867b575887768 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 19 May 2019 07:50:55 -0300 Subject: [PATCH 33/72] [DI] fix using bindings with locators of service subscribers --- Compiler/ServiceLocatorTagPass.php | 12 +- Tests/Compiler/ServiceLocatorTagPassTest.php | 147 +++++++++++++++++++ Tests/Fixtures/TestDefinition2.php | 9 ++ 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 Tests/Compiler/ServiceLocatorTagPassTest.php create mode 100644 Tests/Fixtures/TestDefinition2.php diff --git a/Compiler/ServiceLocatorTagPass.php b/Compiler/ServiceLocatorTagPass.php index 93e489c8f..51de4d7ac 100644 --- a/Compiler/ServiceLocatorTagPass.php +++ b/Compiler/ServiceLocatorTagPass.php @@ -48,6 +48,12 @@ protected function processValue($value, $isRoot = false) if (!$v instanceof Reference) { throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set, "%s" found for key "%s".', $this->currentId, \is_object($v) ? \get_class($v) : \gettype($v), $k)); } + + if (\is_int($k)) { + unset($arguments[0][$k]); + + $k = (string) $v; + } $arguments[0][$k] = new ServiceClosureArgument($v); } ksort($arguments[0]); @@ -91,7 +97,11 @@ public static function register(ContainerBuilder $container, array $refMap, $cal ->setPublic(false) ->addTag('container.service_locator'); - if (!$container->has($id = 'service_locator.'.ContainerBuilder::hash($locator))) { + if (null !== $callerId && $container->hasDefinition($callerId)) { + $locator->setBindings($container->getDefinition($callerId)->getBindings()); + } + + if (!$container->hasDefinition($id = 'service_locator.'.ContainerBuilder::hash($locator))) { $container->setDefinition($id, $locator); } diff --git a/Tests/Compiler/ServiceLocatorTagPassTest.php b/Tests/Compiler/ServiceLocatorTagPassTest.php new file mode 100644 index 000000000..27ee7db53 --- /dev/null +++ b/Tests/Compiler/ServiceLocatorTagPassTest.php @@ -0,0 +1,147 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Tests\Compiler; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\Argument\BoundArgument; +use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\ServiceLocator; +use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition; +use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1; +use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition2; + +require_once __DIR__.'/../Fixtures/includes/classes.php'; + +class ServiceLocatorTagPassTest extends TestCase +{ + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessage Invalid definition for service "foo": an array of references is expected as first argument when the "container.service_locator" tag is set. + */ + public function testNoServices() + { + $container = new ContainerBuilder(); + + $container->register('foo', ServiceLocator::class) + ->addTag('container.service_locator') + ; + + (new ServiceLocatorTagPass())->process($container); + } + + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessage Invalid definition for service "foo": an array of references is expected as first argument when the "container.service_locator" tag is set, "string" found for key "0". + */ + public function testInvalidServices() + { + $container = new ContainerBuilder(); + + $container->register('foo', ServiceLocator::class) + ->setArguments([[ + 'dummy', + ]]) + ->addTag('container.service_locator') + ; + + (new ServiceLocatorTagPass())->process($container); + } + + public function testProcessValue() + { + $container = new ContainerBuilder(); + + $container->register('bar', CustomDefinition::class); + $container->register('baz', CustomDefinition::class); + + $container->register('foo', ServiceLocator::class) + ->setArguments([[ + new Reference('bar'), + new Reference('baz'), + 'some.service' => new Reference('bar'), + ]]) + ->addTag('container.service_locator') + ; + + (new ServiceLocatorTagPass())->process($container); + + /** @var ServiceLocator $locator */ + $locator = $container->get('foo'); + + $this->assertSame(CustomDefinition::class, \get_class($locator('bar'))); + $this->assertSame(CustomDefinition::class, \get_class($locator('baz'))); + $this->assertSame(CustomDefinition::class, \get_class($locator('some.service'))); + } + + public function testServiceWithKeyOverwritesPreviousInheritedKey() + { + $container = new ContainerBuilder(); + + $container->register('bar', TestDefinition1::class); + $container->register('baz', TestDefinition2::class); + + $container->register('foo', ServiceLocator::class) + ->setArguments([[ + new Reference('bar'), + 'bar' => new Reference('baz'), + ]]) + ->addTag('container.service_locator') + ; + + (new ServiceLocatorTagPass())->process($container); + + /** @var ServiceLocator $locator */ + $locator = $container->get('foo'); + + $this->assertSame(TestDefinition2::class, \get_class($locator('bar'))); + } + + public function testInheritedKeyOverwritesPreviousServiceWithKey() + { + $container = new ContainerBuilder(); + + $container->register('bar', TestDefinition1::class); + $container->register('baz', TestDefinition2::class); + + $container->register('foo', ServiceLocator::class) + ->setArguments([[ + 'bar' => new Reference('baz'), + new Reference('bar'), + ]]) + ->addTag('container.service_locator') + ; + + (new ServiceLocatorTagPass())->process($container); + + /** @var ServiceLocator $locator */ + $locator = $container->get('foo'); + + $this->assertSame(TestDefinition1::class, \get_class($locator('bar'))); + } + + public function testBindingsAreCopied() + { + $container = new ContainerBuilder(); + + $container->register('foo') + ->setBindings(['foo' => 'foo']); + + $locator = ServiceLocatorTagPass::register($container, ['foo' => new Reference('foo')], 'foo'); + $locator = $container->getDefinition($locator); + $locator = $container->getDefinition($locator->getFactory()[0]); + + $this->assertSame(['foo'], array_keys($locator->getBindings())); + $this->assertInstanceOf(BoundArgument::class, $locator->getBindings()['foo']); + } +} diff --git a/Tests/Fixtures/TestDefinition2.php b/Tests/Fixtures/TestDefinition2.php new file mode 100644 index 000000000..2ec8f9cf8 --- /dev/null +++ b/Tests/Fixtures/TestDefinition2.php @@ -0,0 +1,9 @@ + Date: Thu, 30 May 2019 16:56:20 +0200 Subject: [PATCH 34/72] Use willReturn() instead of will(returnValue()). --- Tests/Compiler/AutowireExceptionPassTest.php | 20 +++++++++---------- .../MergeExtensionConfigurationPassTest.php | 12 +++++------ ...ContainerParametersResourceCheckerTest.php | 4 ++-- Tests/ContainerBuilderTest.php | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Tests/Compiler/AutowireExceptionPassTest.php b/Tests/Compiler/AutowireExceptionPassTest.php index 5bcb12342..c5ba149ae 100644 --- a/Tests/Compiler/AutowireExceptionPassTest.php +++ b/Tests/Compiler/AutowireExceptionPassTest.php @@ -31,13 +31,13 @@ public function testThrowsException() $autowireException = new AutowiringFailedException('foo_service_id', 'An autowiring exception message'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') - ->will($this->returnValue([$autowireException])); + ->willReturn([$autowireException]); $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') - ->will($this->returnValue([])); + ->willReturn([]); $container = new ContainerBuilder(); $container->register('foo_service_id'); @@ -60,18 +60,18 @@ public function testThrowExceptionIfServiceInlined() $autowireException = new AutowiringFailedException('a_service', 'An autowiring exception message'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') - ->will($this->returnValue([$autowireException])); + ->willReturn([$autowireException]); $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') - ->will($this->returnValue([ + ->willReturn([ // a_service inlined into b_service 'a_service' => ['b_service'], // b_service inlined into c_service 'b_service' => ['c_service'], - ])); + ]); $container = new ContainerBuilder(); // ONLY register c_service in the final container @@ -95,18 +95,18 @@ public function testDoNotThrowExceptionIfServiceInlinedButRemoved() $autowireException = new AutowiringFailedException('a_service', 'An autowiring exception message'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') - ->will($this->returnValue([$autowireException])); + ->willReturn([$autowireException]); $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') - ->will($this->returnValue([ + ->willReturn([ // a_service inlined into b_service 'a_service' => ['b_service'], // b_service inlined into c_service 'b_service' => ['c_service'], - ])); + ]); // do NOT register c_service in the container $container = new ContainerBuilder(); @@ -126,13 +126,13 @@ public function testNoExceptionIfServiceRemoved() $autowireException = new AutowiringFailedException('non_existent_service'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') - ->will($this->returnValue([$autowireException])); + ->willReturn([$autowireException]); $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') - ->will($this->returnValue([])); + ->willReturn([]); $container = new ContainerBuilder(); diff --git a/Tests/Compiler/MergeExtensionConfigurationPassTest.php b/Tests/Compiler/MergeExtensionConfigurationPassTest.php index 667ae3886..1bef795f2 100644 --- a/Tests/Compiler/MergeExtensionConfigurationPassTest.php +++ b/Tests/Compiler/MergeExtensionConfigurationPassTest.php @@ -30,18 +30,18 @@ public function testExpressionLanguageProviderForwarding() $extension = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface')->getMock(); $extension->expects($this->any()) ->method('getXsdValidationBasePath') - ->will($this->returnValue(false)); + ->willReturn(false); $extension->expects($this->any()) ->method('getNamespace') - ->will($this->returnValue('http://example.org/schema/dic/foo')); + ->willReturn('http://example.org/schema/dic/foo'); $extension->expects($this->any()) ->method('getAlias') - ->will($this->returnValue('foo')); + ->willReturn('foo'); $extension->expects($this->once()) ->method('load') - ->will($this->returnCallback(function (array $config, ContainerBuilder $container) use (&$tmpProviders) { + ->willReturnCallback(function (array $config, ContainerBuilder $container) use (&$tmpProviders) { $tmpProviders = $container->getExpressionLanguageProviders(); - })); + }); $provider = $this->getMockBuilder('Symfony\\Component\\ExpressionLanguage\\ExpressionFunctionProviderInterface')->getMock(); $container = new ContainerBuilder(new ParameterBag()); @@ -76,7 +76,7 @@ public function testExtensionConfigurationIsTrackedByDefault() $extension = $this->getMockBuilder(FooExtension::class)->setMethods(['getConfiguration'])->getMock(); $extension->expects($this->exactly(2)) ->method('getConfiguration') - ->will($this->returnValue(new FooConfiguration())); + ->willReturn(new FooConfiguration()); $container = new ContainerBuilder(new ParameterBag()); $container->registerExtension($extension); diff --git a/Tests/Config/ContainerParametersResourceCheckerTest.php b/Tests/Config/ContainerParametersResourceCheckerTest.php index fc2d85ecf..eb5fc5a99 100644 --- a/Tests/Config/ContainerParametersResourceCheckerTest.php +++ b/Tests/Config/ContainerParametersResourceCheckerTest.php @@ -67,10 +67,10 @@ public function isFreshProvider() [$this->equalTo('locales')], [$this->equalTo('default_locale')] ) - ->will($this->returnValueMap([ + ->willReturnMap([ ['locales', ['fr', 'en']], ['default_locale', 'fr'], - ])) + ]) ; }, true]; } diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index 73cb670cd..b3bea30b7 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -1059,7 +1059,7 @@ public function testExtension() public function testRegisteredButNotLoadedExtension() { $extension = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface')->getMock(); - $extension->expects($this->once())->method('getAlias')->will($this->returnValue('project')); + $extension->expects($this->once())->method('getAlias')->willReturn('project'); $extension->expects($this->never())->method('load'); $container = new ContainerBuilder(); @@ -1071,7 +1071,7 @@ public function testRegisteredButNotLoadedExtension() public function testRegisteredAndLoadedExtension() { $extension = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface')->getMock(); - $extension->expects($this->exactly(2))->method('getAlias')->will($this->returnValue('project')); + $extension->expects($this->exactly(2))->method('getAlias')->willReturn('project'); $extension->expects($this->once())->method('load')->with([['foo' => 'bar']]); $container = new ContainerBuilder(); From e90753502e9f6465cbfd4f6d94e513e5cc7f4392 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 29 Jun 2019 18:43:59 +0200 Subject: [PATCH 35/72] Annotated correct return type for getInEdges()/getOutEdges(). --- Compiler/ServiceReferenceGraphNode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Compiler/ServiceReferenceGraphNode.php b/Compiler/ServiceReferenceGraphNode.php index 6abd6c86a..50140b5ff 100644 --- a/Compiler/ServiceReferenceGraphNode.php +++ b/Compiler/ServiceReferenceGraphNode.php @@ -81,7 +81,7 @@ public function getId() /** * Returns the in edges. * - * @return array The in ServiceReferenceGraphEdge array + * @return ServiceReferenceGraphEdge[] */ public function getInEdges() { @@ -91,7 +91,7 @@ public function getInEdges() /** * Returns the out edges. * - * @return array The out ServiceReferenceGraphEdge array + * @return ServiceReferenceGraphEdge[] */ public function getOutEdges() { From 65bc9f1020f7effcb803758dca284d0d3bf18de0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 4 Jul 2019 11:24:58 +0200 Subject: [PATCH 36/72] [DI] fix processing of regular parameter bags by MergeExtensionConfigurationPass --- Compiler/MergeExtensionConfigurationPass.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Compiler/MergeExtensionConfigurationPass.php b/Compiler/MergeExtensionConfigurationPass.php index 63f8013c3..caa1fd225 100644 --- a/Compiler/MergeExtensionConfigurationPass.php +++ b/Compiler/MergeExtensionConfigurationPass.php @@ -186,6 +186,10 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs $bag = $this->getParameterBag(); $value = $bag->resolveValue($value); + if (!$bag instanceof EnvPlaceholderParameterBag) { + return parent::resolveEnvPlaceholders($value, $format, $usedEnvs); + } + foreach ($bag->getEnvPlaceholders() as $env => $placeholders) { if (false === strpos($env, ':')) { continue; From 24e97a8f52f5c1ffe13f790ed2c34719672609e9 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 8 Jul 2019 15:34:24 +0200 Subject: [PATCH 37/72] Added tests to cover the possibility of having scalars as services. --- Tests/ContainerBuilderTest.php | 15 +++++++++++++++ Tests/ContainerTest.php | 10 ++++++++++ Tests/Dumper/PhpDumperTest.php | 20 ++++++++++++++++++++ Tests/Fixtures/ScalarFactory.php | 14 ++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 Tests/Fixtures/ScalarFactory.php diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index b3bea30b7..46074a67a 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -38,6 +38,7 @@ use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition; +use Symfony\Component\DependencyInjection\Tests\Fixtures\ScalarFactory; use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy; use Symfony\Component\DependencyInjection\TypedReference; use Symfony\Component\ExpressionLanguage\Expression; @@ -1532,6 +1533,20 @@ public function testDecoratedSelfReferenceInvolvingPrivateServices() $this->assertSame(['service_container'], array_keys($container->getDefinitions())); } + + public function testScalarService() + { + $c = new ContainerBuilder(); + $c->register('foo', 'string') + ->setPublic(true) + ->setFactory([ScalarFactory::class, 'getSomeValue']) + ; + + $c->compile(); + + $this->assertTrue($c->has('foo')); + $this->assertSame('some value', $c->get('foo')); + } } class FooClass diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index d2616a34b..5dbec886e 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -386,6 +386,16 @@ public function testLegacyHas() $this->assertTrue($sc->has('foo\\baz'), '->has() returns true if a get*Method() is defined'); } + public function testScalarService() + { + $c = new Container(); + + $c->set('foo', 'some value'); + + $this->assertTrue($c->has('foo')); + $this->assertSame('some value', $c->get('foo')); + } + public function testInitialized() { $sc = new ProjectServiceContainer(); diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index a1ccb52b6..926933bb0 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -30,6 +30,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition; +use Symfony\Component\DependencyInjection\Tests\Fixtures\ScalarFactory; use Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator; use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber; use Symfony\Component\DependencyInjection\TypedReference; @@ -1115,6 +1116,25 @@ public function testReferenceWithLowerCaseId() $this->assertEquals((object) ['foo' => (object) []], $container->get('Bar')); } + + public function testScalarService() + { + $container = new ContainerBuilder(); + $container->register('foo', 'string') + ->setPublic(true) + ->setFactory([ScalarFactory::class, 'getSomeValue']) + ; + + $container->compile(); + + $dumper = new PhpDumper($container); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Scalar_Service'])); + + $container = new \Symfony_DI_PhpDumper_Test_Scalar_Service(); + + $this->assertTrue($container->has('foo')); + $this->assertSame('some value', $container->get('foo')); + } } class Rot13EnvVarProcessor implements EnvVarProcessorInterface diff --git a/Tests/Fixtures/ScalarFactory.php b/Tests/Fixtures/ScalarFactory.php new file mode 100644 index 000000000..15646a8d0 --- /dev/null +++ b/Tests/Fixtures/ScalarFactory.php @@ -0,0 +1,14 @@ + Date: Tue, 16 Jul 2019 16:45:57 +0200 Subject: [PATCH 38/72] Container*::getServiceIds() should return an array of string see #32549 --- Container.php | 4 ++-- ContainerBuilder.php | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Container.php b/Container.php index e385f0689..f2215acf1 100644 --- a/Container.php +++ b/Container.php @@ -386,7 +386,7 @@ public function reset() /** * Gets all service ids. * - * @return array An array of all defined service ids + * @return string[] An array of all defined service ids */ public function getServiceIds() { @@ -405,7 +405,7 @@ public function getServiceIds() } $ids[] = 'service_container'; - return array_unique(array_merge($ids, array_keys($this->methodMap), array_keys($this->fileMap), array_keys($this->services))); + return array_map('strval', array_unique(array_merge($ids, array_keys($this->methodMap), array_keys($this->fileMap), array_keys($this->services)))); } /** diff --git a/ContainerBuilder.php b/ContainerBuilder.php index c322b4357..73145fd8d 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -815,13 +815,11 @@ public function compile(/*$resolveEnvPlaceholders = false*/) } /** - * Gets all service ids. - * - * @return array An array of all defined service ids + * {@inheritdoc} */ public function getServiceIds() { - return array_unique(array_merge(array_keys($this->getDefinitions()), array_keys($this->aliasDefinitions), parent::getServiceIds())); + return array_map('strval', array_unique(array_merge(array_keys($this->getDefinitions()), array_keys($this->aliasDefinitions), parent::getServiceIds()))); } /** From ade939fe83d5ec5fcaa98628dc42d83232c8eb41 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Fri, 19 Jul 2019 13:42:31 +0200 Subject: [PATCH 39/72] Remove dead tests fixtures --- .../OtherDir/Component1/Dir3/Service3.php | 8 -------- Tests/Fixtures/Prototype/Sub/NoLoadAbstractBar.php | 7 ------- .../Fixtures/Prototype/Sub/NoLoadBarInterface.php | 7 ------- Tests/Fixtures/Prototype/Sub/NoLoadBarTrait.php | 7 ------- Tests/Fixtures/includes/autowiring_classes.php | 14 -------------- 5 files changed, 43 deletions(-) delete mode 100644 Tests/Fixtures/Prototype/OtherDir/Component1/Dir3/Service3.php delete mode 100644 Tests/Fixtures/Prototype/Sub/NoLoadAbstractBar.php delete mode 100644 Tests/Fixtures/Prototype/Sub/NoLoadBarInterface.php delete mode 100644 Tests/Fixtures/Prototype/Sub/NoLoadBarTrait.php diff --git a/Tests/Fixtures/Prototype/OtherDir/Component1/Dir3/Service3.php b/Tests/Fixtures/Prototype/OtherDir/Component1/Dir3/Service3.php deleted file mode 100644 index ee6498c9d..000000000 --- a/Tests/Fixtures/Prototype/OtherDir/Component1/Dir3/Service3.php +++ /dev/null @@ -1,8 +0,0 @@ - Date: Mon, 24 Jun 2019 12:50:01 -0400 Subject: [PATCH 40/72] Failing test case for complex near-circular situation + lazy --- Tests/ContainerBuilderTest.php | 7 ++ Tests/Dumper/PhpDumperTest.php | 7 ++ .../containers/container_almost_circular.php | 30 ++++++- .../php/services_almost_circular_private.php | 64 ++++++++++++++ .../php/services_almost_circular_public.php | 86 +++++++++++++++++++ 5 files changed, 193 insertions(+), 1 deletion(-) diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index 46074a67a..ec1636091 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -1423,6 +1423,13 @@ public function testAlmostCircular($visibility) $this->assertEquals((object) ['bar6' => (object) []], $foo6); $this->assertInstanceOf(\stdClass::class, $container->get('root')); + + $manager3 = $container->get('manager3'); + $listener3 = $container->get('listener3'); + $this->assertSame($manager3, $listener3->manager, 'Both should identically be the manager3 service'); + + $listener4 = $container->get('listener4'); + $this->assertInstanceOf('stdClass', $listener4); } public function provideAlmostCircular() diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index 926933bb0..0fca22cb6 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -842,6 +842,13 @@ public function testAlmostCircular($visibility) $this->assertEquals((object) ['bar6' => (object) []], $foo6); $this->assertInstanceOf(\stdClass::class, $container->get('root')); + + $manager3 = $container->get('manager3'); + $listener3 = $container->get('listener3'); + $this->assertSame($manager3, $listener3->manager); + + $listener4 = $container->get('listener4'); + $this->assertInstanceOf('stdClass', $listener4); } public function provideAlmostCircular() diff --git a/Tests/Fixtures/containers/container_almost_circular.php b/Tests/Fixtures/containers/container_almost_circular.php index df136cfa5..a1f885399 100644 --- a/Tests/Fixtures/containers/container_almost_circular.php +++ b/Tests/Fixtures/containers/container_almost_circular.php @@ -2,7 +2,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Dumper\PhpDumper; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\FooForCircularWithAddCalls; @@ -102,6 +101,35 @@ $container->register('subscriber2', 'stdClass')->setPublic(false) ->addArgument(new Reference('manager2')); +// doctrine-like event system with listener + +$container->register('manager3', 'stdClass') + ->setLazy(true) + ->setPublic(true) + ->addArgument(new Reference('connection3')); + +$container->register('connection3', 'stdClass') + ->setPublic($public) + ->setProperty('listener', [new Reference('listener3')]); + +$container->register('listener3', 'stdClass') + ->setPublic(true) + ->setProperty('manager', new Reference('manager3')); + +// doctrine-like event system with small differences + +$container->register('manager4', 'stdClass') + ->setLazy(true) + ->addArgument(new Reference('connection4')); + +$container->register('connection4', 'stdClass') + ->setPublic($public) + ->setProperty('listener', [new Reference('listener4')]); + +$container->register('listener4', 'stdClass') + ->setPublic(true) + ->addArgument(new Reference('manager4')); + // private service involved in a loop $container->register('foo6', 'stdClass') diff --git a/Tests/Fixtures/php/services_almost_circular_private.php b/Tests/Fixtures/php/services_almost_circular_private.php index 5345aa3b3..55ddf616c 100644 --- a/Tests/Fixtures/php/services_almost_circular_private.php +++ b/Tests/Fixtures/php/services_almost_circular_private.php @@ -39,9 +39,13 @@ public function __construct() 'level4' => 'getLevel4Service', 'level5' => 'getLevel5Service', 'level6' => 'getLevel6Service', + 'listener3' => 'getListener3Service', + 'listener4' => 'getListener4Service', 'logger' => 'getLoggerService', 'manager' => 'getManagerService', 'manager2' => 'getManager2Service', + 'manager3' => 'getManager3Service', + 'manager4' => 'getManager4Service', 'multiuse1' => 'getMultiuse1Service', 'root' => 'getRootService', 'subscriber' => 'getSubscriberService', @@ -53,6 +57,7 @@ public function __construct() 'level4' => true, 'level5' => true, 'level6' => true, + 'manager4' => true, 'multiuse1' => true, ]; @@ -69,6 +74,8 @@ public function getRemovedIds() 'bar6' => true, 'config' => true, 'config2' => true, + 'connection3' => true, + 'connection4' => true, 'dispatcher' => true, 'dispatcher2' => true, 'foo4' => true, @@ -81,6 +88,7 @@ public function getRemovedIds() 'level5' => true, 'level6' => true, 'logger2' => true, + 'manager4' => true, 'multiuse1' => true, 'subscriber2' => true, ]; @@ -272,6 +280,36 @@ protected function getFoobar4Service() return $instance; } + /** + * Gets the public 'listener3' shared service. + * + * @return \stdClass + */ + protected function getListener3Service() + { + $this->services['listener3'] = $instance = new \stdClass(); + + $instance->manager = ${($_ = isset($this->services['manager3']) ? $this->services['manager3'] : $this->getManager3Service()) && false ?: '_'}; + + return $instance; + } + + /** + * Gets the public 'listener4' shared service. + * + * @return \stdClass + */ + protected function getListener4Service() + { + $a = ${($_ = isset($this->services['manager4']) ? $this->services['manager4'] : $this->getManager4Service()) && false ?: '_'}; + + if (isset($this->services['listener4'])) { + return $this->services['listener4']; + } + + return $this->services['listener4'] = new \stdClass($a); + } + /** * Gets the public 'logger' shared service. * @@ -324,6 +362,19 @@ protected function getManager2Service() return $this->services['manager2'] = new \stdClass($a); } + /** + * Gets the public 'manager3' shared service. + * + * @return \stdClass + */ + protected function getManager3Service($lazyLoad = true) + { + $a = new \stdClass(); + $a->listener = [0 => ${($_ = isset($this->services['listener3']) ? $this->services['listener3'] : $this->getListener3Service()) && false ?: '_'}]; + + return $this->services['manager3'] = new \stdClass($a); + } + /** * Gets the public 'root' shared service. * @@ -430,6 +481,19 @@ protected function getLevel6Service() return $instance; } + /** + * Gets the private 'manager4' shared service. + * + * @return \stdClass + */ + protected function getManager4Service($lazyLoad = true) + { + $a = new \stdClass(); + $a->listener = [0 => ${($_ = isset($this->services['listener4']) ? $this->services['listener4'] : $this->getListener4Service()) && false ?: '_'}]; + + return $this->services['manager4'] = new \stdClass($a); + } + /** * Gets the private 'multiuse1' shared service. * diff --git a/Tests/Fixtures/php/services_almost_circular_public.php b/Tests/Fixtures/php/services_almost_circular_public.php index b569b335f..09ca4591b 100644 --- a/Tests/Fixtures/php/services_almost_circular_public.php +++ b/Tests/Fixtures/php/services_almost_circular_public.php @@ -30,6 +30,8 @@ public function __construct() 'baz6' => 'getBaz6Service', 'connection' => 'getConnectionService', 'connection2' => 'getConnection2Service', + 'connection3' => 'getConnection3Service', + 'connection4' => 'getConnection4Service', 'dispatcher' => 'getDispatcherService', 'dispatcher2' => 'getDispatcher2Service', 'foo' => 'getFooService', @@ -46,9 +48,13 @@ public function __construct() 'level4' => 'getLevel4Service', 'level5' => 'getLevel5Service', 'level6' => 'getLevel6Service', + 'listener3' => 'getListener3Service', + 'listener4' => 'getListener4Service', 'logger' => 'getLoggerService', 'manager' => 'getManagerService', 'manager2' => 'getManager2Service', + 'manager3' => 'getManager3Service', + 'manager4' => 'getManager4Service', 'multiuse1' => 'getMultiuse1Service', 'root' => 'getRootService', 'subscriber' => 'getSubscriberService', @@ -60,6 +66,7 @@ public function __construct() 'level4' => true, 'level5' => true, 'level6' => true, + 'manager4' => true, 'multiuse1' => true, ]; @@ -81,6 +88,7 @@ public function getRemovedIds() 'level5' => true, 'level6' => true, 'logger2' => true, + 'manager4' => true, 'multiuse1' => true, 'subscriber2' => true, ]; @@ -212,6 +220,34 @@ protected function getConnection2Service() return $instance; } + /** + * Gets the public 'connection3' shared service. + * + * @return \stdClass + */ + protected function getConnection3Service() + { + $this->services['connection3'] = $instance = new \stdClass(); + + $instance->listener = [0 => ${($_ = isset($this->services['listener3']) ? $this->services['listener3'] : $this->getListener3Service()) && false ?: '_'}]; + + return $instance; + } + + /** + * Gets the public 'connection4' shared service. + * + * @return \stdClass + */ + protected function getConnection4Service() + { + $this->services['connection4'] = $instance = new \stdClass(); + + $instance->listener = [0 => ${($_ = isset($this->services['listener4']) ? $this->services['listener4'] : $this->getListener4Service()) && false ?: '_'}]; + + return $instance; + } + /** * Gets the public 'dispatcher' shared service. * @@ -372,6 +408,36 @@ protected function getFoobar4Service() return $instance; } + /** + * Gets the public 'listener3' shared service. + * + * @return \stdClass + */ + protected function getListener3Service() + { + $this->services['listener3'] = $instance = new \stdClass(); + + $instance->manager = ${($_ = isset($this->services['manager3']) ? $this->services['manager3'] : $this->getManager3Service()) && false ?: '_'}; + + return $instance; + } + + /** + * Gets the public 'listener4' shared service. + * + * @return \stdClass + */ + protected function getListener4Service() + { + $a = ${($_ = isset($this->services['manager4']) ? $this->services['manager4'] : $this->getManager4Service()) && false ?: '_'}; + + if (isset($this->services['listener4'])) { + return $this->services['listener4']; + } + + return $this->services['listener4'] = new \stdClass($a); + } + /** * Gets the public 'logger' shared service. * @@ -424,6 +490,16 @@ protected function getManager2Service() return $this->services['manager2'] = new \stdClass($a); } + /** + * Gets the public 'manager3' shared service. + * + * @return \stdClass + */ + protected function getManager3Service($lazyLoad = true) + { + return $this->services['manager3'] = new \stdClass(${($_ = isset($this->services['connection3']) ? $this->services['connection3'] : $this->getConnection3Service()) && false ?: '_'}); + } + /** * Gets the public 'root' shared service. * @@ -530,6 +606,16 @@ protected function getLevel6Service() return $instance; } + /** + * Gets the private 'manager4' shared service. + * + * @return \stdClass + */ + protected function getManager4Service($lazyLoad = true) + { + return $this->services['manager4'] = new \stdClass(${($_ = isset($this->services['connection4']) ? $this->services['connection4'] : $this->getConnection4Service()) && false ?: '_'}); + } + /** * Gets the private 'multiuse1' shared service. * From 0c8d5cabe0d20df9e8b1daef9fa253aa99151841 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 6 Feb 2019 19:04:48 +0100 Subject: [PATCH 41/72] [DI] Fix dumping Doctrine-like service graphs (bis) --- Compiler/AnalyzeServiceReferencesPass.php | 2 +- Dumper/PhpDumper.php | 112 +++++++++++------- .../php/services_almost_circular_private.php | 16 ++- .../php/services_almost_circular_public.php | 16 ++- 4 files changed, 98 insertions(+), 48 deletions(-) diff --git a/Compiler/AnalyzeServiceReferencesPass.php b/Compiler/AnalyzeServiceReferencesPass.php index fc4047f90..8070920ff 100644 --- a/Compiler/AnalyzeServiceReferencesPass.php +++ b/Compiler/AnalyzeServiceReferencesPass.php @@ -122,7 +122,7 @@ protected function processValue($value, $isRoot = false) $this->lazy = false; $byConstructor = $this->byConstructor; - $this->byConstructor = true; + $this->byConstructor = $isRoot || $byConstructor; $this->processValue($value->getFactory()); $this->processValue($value->getArguments()); $this->byConstructor = $byConstructor; diff --git a/Dumper/PhpDumper.php b/Dumper/PhpDumper.php index 73c868f1e..a18d1665c 100644 --- a/Dumper/PhpDumper.php +++ b/Dumper/PhpDumper.php @@ -302,10 +302,10 @@ private function getProxyDumper() return $this->proxyDumper; } - private function analyzeCircularReferences($sourceId, array $edges, &$checkedNodes, &$currentPath = []) + private function analyzeCircularReferences($sourceId, array $edges, &$checkedNodes, &$currentPath = [], $byConstructor = true) { $checkedNodes[$sourceId] = true; - $currentPath[$sourceId] = $sourceId; + $currentPath[$sourceId] = $byConstructor; foreach ($edges as $edge) { $node = $edge->getDestNode(); @@ -314,44 +314,52 @@ private function analyzeCircularReferences($sourceId, array $edges, &$checkedNod if (!$node->getValue() instanceof Definition || $sourceId === $id || $edge->isLazy() || $edge->isWeak()) { // no-op } elseif (isset($currentPath[$id])) { - $currentId = $id; - foreach (array_reverse($currentPath) as $parentId) { - $this->circularReferences[$parentId][$currentId] = $currentId; - if ($parentId === $id) { - break; - } - $currentId = $parentId; - } + $this->addCircularReferences($id, $currentPath, $edge->isReferencedByConstructor()); } elseif (!isset($checkedNodes[$id])) { - $this->analyzeCircularReferences($id, $node->getOutEdges(), $checkedNodes, $currentPath); + $this->analyzeCircularReferences($id, $node->getOutEdges(), $checkedNodes, $currentPath, $edge->isReferencedByConstructor()); } elseif (isset($this->circularReferences[$id])) { - $this->connectCircularReferences($id, $currentPath); + $this->connectCircularReferences($id, $currentPath, $edge->isReferencedByConstructor()); } } unset($currentPath[$sourceId]); } - private function connectCircularReferences($sourceId, &$currentPath, &$subPath = []) + private function connectCircularReferences($sourceId, &$currentPath, $byConstructor, &$subPath = []) { - $subPath[$sourceId] = $sourceId; - $currentPath[$sourceId] = $sourceId; + $currentPath[$sourceId] = $subPath[$sourceId] = $byConstructor; - foreach ($this->circularReferences[$sourceId] as $id) { + foreach ($this->circularReferences[$sourceId] as $id => $byConstructor) { if (isset($currentPath[$id])) { - $currentId = $id; - foreach (array_reverse($currentPath) as $parentId) { - $this->circularReferences[$parentId][$currentId] = $currentId; - if ($parentId === $id) { - break; - } - $currentId = $parentId; - } + $this->addCircularReferences($id, $currentPath, $byConstructor); } elseif (!isset($subPath[$id]) && isset($this->circularReferences[$id])) { - $this->connectCircularReferences($id, $currentPath, $subPath); + $this->connectCircularReferences($id, $currentPath, $byConstructor, $subPath); } } - unset($currentPath[$sourceId]); - unset($subPath[$sourceId]); + unset($currentPath[$sourceId], $subPath[$sourceId]); + } + + private function addCircularReferences($id, $currentPath, $byConstructor) + { + $currentPath[$id] = $byConstructor; + $circularRefs = []; + + foreach (array_reverse($currentPath) as $parentId => $v) { + $byConstructor = $byConstructor && $v; + $circularRefs[] = $parentId; + + if ($parentId === $id) { + break; + } + } + + $currentId = $id; + foreach ($circularRefs as $parentId) { + if (empty($this->circularReferences[$parentId][$currentId])) { + $this->circularReferences[$parentId][$currentId] = $byConstructor; + } + + $currentId = $parentId; + } } private function collectLineage($class, array &$lineage) @@ -661,7 +669,6 @@ private function addService($id, Definition $definition, &$file = null) $autowired = $definition->isAutowired() ? ' autowired' : ''; if ($definition->isLazy()) { - unset($this->circularReferences[$id]); $lazyInitialization = '$lazyLoad = true'; } else { $lazyInitialization = ''; @@ -736,12 +743,12 @@ private function addInlineVariables($id, Definition $definition, array $argument private function addInlineReference($id, Definition $definition, $targetId, $forConstructor) { - list($callCount, $behavior) = $this->serviceCalls[$targetId]; - while ($this->container->hasAlias($targetId)) { $targetId = (string) $this->container->getAlias($targetId); } + list($callCount, $behavior) = $this->serviceCalls[$targetId]; + if ($id === $targetId) { return $this->addInlineService($id, $definition, $definition); } @@ -750,9 +757,13 @@ private function addInlineReference($id, Definition $definition, $targetId, $for return ''; } - $hasSelfRef = isset($this->circularReferences[$id][$targetId]); - $forConstructor = $forConstructor && !isset($this->definitionVariables[$definition]); - $code = $hasSelfRef && !$forConstructor ? $this->addInlineService($id, $definition, $definition) : ''; + $hasSelfRef = isset($this->circularReferences[$id][$targetId]) && !isset($this->definitionVariables[$definition]); + + if ($hasSelfRef && !$forConstructor && !$forConstructor = !$this->circularReferences[$id][$targetId]) { + $code = $this->addInlineService($id, $definition, $definition); + } else { + $code = ''; + } if (isset($this->referenceVariables[$targetId]) || (2 > $callCount && (!$hasSelfRef || !$forConstructor))) { return $code; @@ -785,15 +796,23 @@ private function addInlineReference($id, Definition $definition, $targetId, $for private function addInlineService($id, Definition $definition, Definition $inlineDef = null, $forConstructor = true) { - $isSimpleInstance = $isRootInstance = null === $inlineDef; + $code = ''; + + if ($isSimpleInstance = $isRootInstance = null === $inlineDef) { + foreach ($this->serviceCalls as $targetId => list($callCount, $behavior, $byConstructor)) { + if ($byConstructor && isset($this->circularReferences[$id][$targetId]) && !$this->circularReferences[$id][$targetId]) { + $code .= $this->addInlineReference($id, $definition, $targetId, $forConstructor); + } + } + } if (isset($this->definitionVariables[$inlineDef = $inlineDef ?: $definition])) { - return ''; + return $code; } $arguments = [$inlineDef->getArguments(), $inlineDef->getFactory()]; - $code = $this->addInlineVariables($id, $definition, $arguments, $forConstructor); + $code .= $this->addInlineVariables($id, $definition, $arguments, $forConstructor); if ($arguments = array_filter([$inlineDef->getProperties(), $inlineDef->getMethodCalls(), $inlineDef->getConfigurator()])) { $isSimpleInstance = false; @@ -1550,7 +1569,7 @@ private function getServiceConditionals($value) return implode(' && ', $conditions); } - private function getDefinitionsFromArguments(array $arguments, \SplObjectStorage $definitions = null, array &$calls = []) + private function getDefinitionsFromArguments(array $arguments, \SplObjectStorage $definitions = null, array &$calls = [], $byConstructor = null) { if (null === $definitions) { $definitions = new \SplObjectStorage(); @@ -1558,12 +1577,16 @@ private function getDefinitionsFromArguments(array $arguments, \SplObjectStorage foreach ($arguments as $argument) { if (\is_array($argument)) { - $this->getDefinitionsFromArguments($argument, $definitions, $calls); + $this->getDefinitionsFromArguments($argument, $definitions, $calls, $byConstructor); } elseif ($argument instanceof Reference) { $id = $this->container->normalizeId($argument); + while ($this->container->hasAlias($id)) { + $id = (string) $this->container->getAlias($id); + } + if (!isset($calls[$id])) { - $calls[$id] = [0, $argument->getInvalidBehavior()]; + $calls[$id] = [0, $argument->getInvalidBehavior(), $byConstructor]; } else { $calls[$id][1] = min($calls[$id][1], $argument->getInvalidBehavior()); } @@ -1575,8 +1598,10 @@ private function getDefinitionsFromArguments(array $arguments, \SplObjectStorage $definitions[$argument] = 1 + $definitions[$argument]; } else { $definitions[$argument] = 1; - $arguments = [$argument->getArguments(), $argument->getFactory(), $argument->getProperties(), $argument->getMethodCalls(), $argument->getConfigurator()]; - $this->getDefinitionsFromArguments($arguments, $definitions, $calls); + $arguments = [$argument->getArguments(), $argument->getFactory()]; + $this->getDefinitionsFromArguments($arguments, $definitions, $calls, null === $byConstructor || $byConstructor); + $arguments = [$argument->getProperties(), $argument->getMethodCalls(), $argument->getConfigurator()]; + $this->getDefinitionsFromArguments($arguments, $definitions, $calls, null !== $byConstructor && $byConstructor); } } @@ -1717,6 +1742,11 @@ private function dumpValue($value, $interpolate = true) return '$'.$value; } elseif ($value instanceof Reference) { $id = $this->container->normalizeId($value); + + while ($this->container->hasAlias($id)) { + $id = (string) $this->container->getAlias($id); + } + if (null !== $this->referenceVariables && isset($this->referenceVariables[$id])) { return $this->dumpValue($this->referenceVariables[$id], $interpolate); } diff --git a/Tests/Fixtures/php/services_almost_circular_private.php b/Tests/Fixtures/php/services_almost_circular_private.php index 55ddf616c..5f9bf8cee 100644 --- a/Tests/Fixtures/php/services_almost_circular_private.php +++ b/Tests/Fixtures/php/services_almost_circular_private.php @@ -369,10 +369,15 @@ protected function getManager2Service() */ protected function getManager3Service($lazyLoad = true) { - $a = new \stdClass(); - $a->listener = [0 => ${($_ = isset($this->services['listener3']) ? $this->services['listener3'] : $this->getListener3Service()) && false ?: '_'}]; + $a = ${($_ = isset($this->services['listener3']) ? $this->services['listener3'] : $this->getListener3Service()) && false ?: '_'}; + + if (isset($this->services['manager3'])) { + return $this->services['manager3']; + } + $b = new \stdClass(); + $b->listener = [0 => $a]; - return $this->services['manager3'] = new \stdClass($a); + return $this->services['manager3'] = new \stdClass($b); } /** @@ -489,9 +494,12 @@ protected function getLevel6Service() protected function getManager4Service($lazyLoad = true) { $a = new \stdClass(); + + $this->services['manager4'] = $instance = new \stdClass($a); + $a->listener = [0 => ${($_ = isset($this->services['listener4']) ? $this->services['listener4'] : $this->getListener4Service()) && false ?: '_'}]; - return $this->services['manager4'] = new \stdClass($a); + return $instance; } /** diff --git a/Tests/Fixtures/php/services_almost_circular_public.php b/Tests/Fixtures/php/services_almost_circular_public.php index 09ca4591b..f41f831b3 100644 --- a/Tests/Fixtures/php/services_almost_circular_public.php +++ b/Tests/Fixtures/php/services_almost_circular_public.php @@ -497,7 +497,13 @@ protected function getManager2Service() */ protected function getManager3Service($lazyLoad = true) { - return $this->services['manager3'] = new \stdClass(${($_ = isset($this->services['connection3']) ? $this->services['connection3'] : $this->getConnection3Service()) && false ?: '_'}); + $a = ${($_ = isset($this->services['connection3']) ? $this->services['connection3'] : $this->getConnection3Service()) && false ?: '_'}; + + if (isset($this->services['manager3'])) { + return $this->services['manager3']; + } + + return $this->services['manager3'] = new \stdClass($a); } /** @@ -613,7 +619,13 @@ protected function getLevel6Service() */ protected function getManager4Service($lazyLoad = true) { - return $this->services['manager4'] = new \stdClass(${($_ = isset($this->services['connection4']) ? $this->services['connection4'] : $this->getConnection4Service()) && false ?: '_'}); + $a = ${($_ = isset($this->services['connection4']) ? $this->services['connection4'] : $this->getConnection4Service()) && false ?: '_'}; + + if (isset($this->services['manager4'])) { + return $this->services['manager4']; + } + + return $this->services['manager4'] = new \stdClass($a); } /** From d42da5755a47db59b6e4c0c3773f40921b9bb5b6 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 31 Jul 2019 21:19:25 +0200 Subject: [PATCH 42/72] Make tests support phpunit 8 --- Tests/Compiler/ExtensionCompilerPassTest.php | 5 ++++- Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php | 5 ++++- Tests/Config/AutowireServiceResourceTest.php | 7 +++++-- Tests/Config/ContainerParametersResourceCheckerTest.php | 5 ++++- Tests/Config/ContainerParametersResourceTest.php | 5 ++++- Tests/CrossCheckTest.php | 5 ++++- Tests/Dumper/GraphvizDumperTest.php | 5 ++++- Tests/Dumper/PhpDumperTest.php | 5 ++++- Tests/Dumper/XmlDumperTest.php | 5 ++++- Tests/Dumper/YamlDumperTest.php | 5 ++++- Tests/Loader/DirectoryLoaderTest.php | 7 +++++-- Tests/Loader/FileLoaderTest.php | 5 ++++- Tests/Loader/IniFileLoaderTest.php | 5 ++++- Tests/Loader/LoaderResolverTest.php | 5 ++++- Tests/Loader/XmlFileLoaderTest.php | 5 ++++- Tests/Loader/YamlFileLoaderTest.php | 5 ++++- 16 files changed, 66 insertions(+), 18 deletions(-) diff --git a/Tests/Compiler/ExtensionCompilerPassTest.php b/Tests/Compiler/ExtensionCompilerPassTest.php index 810fbe48a..5b1862d97 100644 --- a/Tests/Compiler/ExtensionCompilerPassTest.php +++ b/Tests/Compiler/ExtensionCompilerPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\ExtensionCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -22,10 +23,12 @@ */ class ExtensionCompilerPassTest extends TestCase { + use ForwardCompatTestTrait; + private $container; private $pass; - protected function setUp() + private function doSetUp() { $this->container = new ContainerBuilder(); $this->pass = new ExtensionCompilerPass(); diff --git a/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php b/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php index 5aa647175..3e946932f 100644 --- a/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php +++ b/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php @@ -12,16 +12,19 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass; use Symfony\Component\DependencyInjection\ContainerBuilder; class ResolveParameterPlaceHoldersPassTest extends TestCase { + use ForwardCompatTestTrait; + private $compilerPass; private $container; private $fooDefinition; - protected function setUp() + private function doSetUp() { $this->compilerPass = new ResolveParameterPlaceHoldersPass(); $this->container = $this->createContainerBuilder(); diff --git a/Tests/Config/AutowireServiceResourceTest.php b/Tests/Config/AutowireServiceResourceTest.php index 153e0807e..03ed02035 100644 --- a/Tests/Config/AutowireServiceResourceTest.php +++ b/Tests/Config/AutowireServiceResourceTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Config; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\AutowirePass; use Symfony\Component\DependencyInjection\Config\AutowireServiceResource; @@ -20,6 +21,8 @@ */ class AutowireServiceResourceTest extends TestCase { + use ForwardCompatTestTrait; + /** * @var AutowireServiceResource */ @@ -28,7 +31,7 @@ class AutowireServiceResourceTest extends TestCase private $class; private $time; - protected function setUp() + private function doSetUp() { $this->file = realpath(sys_get_temp_dir()).'/tmp.php'; $this->time = time(); @@ -101,7 +104,7 @@ public function testNotFreshIfClassNotFound() $this->assertFalse($resource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the class no longer exists'); } - protected function tearDown() + private function doTearDown() { if (!file_exists($this->file)) { return; diff --git a/Tests/Config/ContainerParametersResourceCheckerTest.php b/Tests/Config/ContainerParametersResourceCheckerTest.php index eb5fc5a99..4b089936e 100644 --- a/Tests/Config/ContainerParametersResourceCheckerTest.php +++ b/Tests/Config/ContainerParametersResourceCheckerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Config; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\ResourceCheckerInterface; use Symfony\Component\DependencyInjection\Config\ContainerParametersResource; use Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker; @@ -19,6 +20,8 @@ class ContainerParametersResourceCheckerTest extends TestCase { + use ForwardCompatTestTrait; + /** @var ContainerParametersResource */ private $resource; @@ -28,7 +31,7 @@ class ContainerParametersResourceCheckerTest extends TestCase /** @var ContainerInterface */ private $container; - protected function setUp() + private function doSetUp() { $this->resource = new ContainerParametersResource(['locales' => ['fr', 'en'], 'default_locale' => 'fr']); $this->container = $this->getMockBuilder(ContainerInterface::class)->getMock(); diff --git a/Tests/Config/ContainerParametersResourceTest.php b/Tests/Config/ContainerParametersResourceTest.php index e177ac16b..392c84871 100644 --- a/Tests/Config/ContainerParametersResourceTest.php +++ b/Tests/Config/ContainerParametersResourceTest.php @@ -12,14 +12,17 @@ namespace Symfony\Component\DependencyInjection\Tests\Config; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Config\ContainerParametersResource; class ContainerParametersResourceTest extends TestCase { + use ForwardCompatTestTrait; + /** @var ContainerParametersResource */ private $resource; - protected function setUp() + private function doSetUp() { $this->resource = new ContainerParametersResource(['locales' => ['fr', 'en'], 'default_locale' => 'fr']); } diff --git a/Tests/CrossCheckTest.php b/Tests/CrossCheckTest.php index fe132af48..6afc5d9ae 100644 --- a/Tests/CrossCheckTest.php +++ b/Tests/CrossCheckTest.php @@ -12,14 +12,17 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; class CrossCheckTest extends TestCase { + use ForwardCompatTestTrait; + protected static $fixturesPath; - public static function setUpBeforeClass() + private static function doSetUpBeforeClass() { self::$fixturesPath = __DIR__.'/Fixtures/'; diff --git a/Tests/Dumper/GraphvizDumperTest.php b/Tests/Dumper/GraphvizDumperTest.php index ea11c7c53..23f1cb8bb 100644 --- a/Tests/Dumper/GraphvizDumperTest.php +++ b/Tests/Dumper/GraphvizDumperTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Dumper; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Dumper\GraphvizDumper; @@ -19,9 +20,11 @@ class GraphvizDumperTest extends TestCase { + use ForwardCompatTestTrait; + protected static $fixturesPath; - public static function setUpBeforeClass() + private static function doSetUpBeforeClass() { self::$fixturesPath = __DIR__.'/../Fixtures/'; } diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index 0fca22cb6..b4e361077 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; @@ -41,9 +42,11 @@ class PhpDumperTest extends TestCase { + use ForwardCompatTestTrait; + protected static $fixturesPath; - public static function setUpBeforeClass() + private static function doSetUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); } diff --git a/Tests/Dumper/XmlDumperTest.php b/Tests/Dumper/XmlDumperTest.php index e660c7e80..f9c545f01 100644 --- a/Tests/Dumper/XmlDumperTest.php +++ b/Tests/Dumper/XmlDumperTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Dumper; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -21,9 +22,11 @@ class XmlDumperTest extends TestCase { + use ForwardCompatTestTrait; + protected static $fixturesPath; - public static function setUpBeforeClass() + private static function doSetUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); } diff --git a/Tests/Dumper/YamlDumperTest.php b/Tests/Dumper/YamlDumperTest.php index 49ee8e6f3..e94dcfb19 100644 --- a/Tests/Dumper/YamlDumperTest.php +++ b/Tests/Dumper/YamlDumperTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Dumper; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -24,9 +25,11 @@ class YamlDumperTest extends TestCase { + use ForwardCompatTestTrait; + protected static $fixturesPath; - public static function setUpBeforeClass() + private static function doSetUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); } diff --git a/Tests/Loader/DirectoryLoaderTest.php b/Tests/Loader/DirectoryLoaderTest.php index c7c303b68..8de0b7d0d 100644 --- a/Tests/Loader/DirectoryLoaderTest.php +++ b/Tests/Loader/DirectoryLoaderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -22,17 +23,19 @@ class DirectoryLoaderTest extends TestCase { + use ForwardCompatTestTrait; + private static $fixturesPath; private $container; private $loader; - public static function setUpBeforeClass() + private static function doSetUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); } - protected function setUp() + private function doSetUp() { $locator = new FileLocator(self::$fixturesPath); $this->container = new ContainerBuilder(); diff --git a/Tests/Loader/FileLoaderTest.php b/Tests/Loader/FileLoaderTest.php index 065acdf1b..ee102c75b 100644 --- a/Tests/Loader/FileLoaderTest.php +++ b/Tests/Loader/FileLoaderTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface as PsrContainerInterface; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -35,9 +36,11 @@ class FileLoaderTest extends TestCase { + use ForwardCompatTestTrait; + protected static $fixturesPath; - public static function setUpBeforeClass() + private static function doSetUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../'); } diff --git a/Tests/Loader/IniFileLoaderTest.php b/Tests/Loader/IniFileLoaderTest.php index 1d7d3a93e..87a436c4b 100644 --- a/Tests/Loader/IniFileLoaderTest.php +++ b/Tests/Loader/IniFileLoaderTest.php @@ -12,16 +12,19 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; class IniFileLoaderTest extends TestCase { + use ForwardCompatTestTrait; + protected $container; protected $loader; - protected function setUp() + private function doSetUp() { $this->container = new ContainerBuilder(); $this->loader = new IniFileLoader($this->container, new FileLocator(realpath(__DIR__.'/../Fixtures/').'/ini')); diff --git a/Tests/Loader/LoaderResolverTest.php b/Tests/Loader/LoaderResolverTest.php index 9167e18ce..3200e3448 100644 --- a/Tests/Loader/LoaderResolverTest.php +++ b/Tests/Loader/LoaderResolverTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -23,12 +24,14 @@ class LoaderResolverTest extends TestCase { + use ForwardCompatTestTrait; + private static $fixturesPath; /** @var LoaderResolver */ private $resolver; - protected function setUp() + private function doSetUp() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); diff --git a/Tests/Loader/XmlFileLoaderTest.php b/Tests/Loader/XmlFileLoaderTest.php index 03376a641..cafe419c6 100644 --- a/Tests/Loader/XmlFileLoaderTest.php +++ b/Tests/Loader/XmlFileLoaderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Config\Resource\FileResource; @@ -33,9 +34,11 @@ class XmlFileLoaderTest extends TestCase { + use ForwardCompatTestTrait; + protected static $fixturesPath; - public static function setUpBeforeClass() + private static function doSetUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); require_once self::$fixturesPath.'/includes/foo.php'; diff --git a/Tests/Loader/YamlFileLoaderTest.php b/Tests/Loader/YamlFileLoaderTest.php index 05521bf78..45d9ff10d 100644 --- a/Tests/Loader/YamlFileLoaderTest.php +++ b/Tests/Loader/YamlFileLoaderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Config\Resource\FileResource; @@ -33,9 +34,11 @@ class YamlFileLoaderTest extends TestCase { + use ForwardCompatTestTrait; + protected static $fixturesPath; - public static function setUpBeforeClass() + private static function doSetUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); require_once self::$fixturesPath.'/includes/foo.php'; From 87e0accc9a2f538c0637b55917be09ec72c5747a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 1 Aug 2019 09:31:22 +0200 Subject: [PATCH 43/72] Fix assertInternalType deprecation in phpunit 9 --- Tests/ContainerBuilderTest.php | 7 +++++-- Tests/Loader/YamlFileLoaderTest.php | 2 +- Tests/ParameterBag/EnvPlaceholderParameterBagTest.php | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index ec1636091..de0bede4c 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -16,6 +16,7 @@ use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface as PsrContainerInterface; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\Resource\ComposerResource; use Symfony\Component\Config\Resource\DirectoryResource; use Symfony\Component\Config\Resource\FileResource; @@ -45,6 +46,8 @@ class ContainerBuilderTest extends TestCase { + use ForwardCompatTestTrait; + public function testDefaultRegisteredDefinitions() { $builder = new ContainerBuilder(); @@ -168,7 +171,7 @@ public function testGetCreatesServiceBasedOnDefinition() $builder = new ContainerBuilder(); $builder->register('foo', 'stdClass'); - $this->assertInternalType('object', $builder->get('foo'), '->get() returns the service definition associated with the id'); + $this->assertIsObject($builder->get('foo'), '->get() returns the service definition associated with the id'); } public function testGetReturnsRegisteredService() @@ -662,7 +665,7 @@ public function testResolveEnvValuesWithArray() $container->resolveEnvPlaceholders('%dummy%', true); $container->resolveEnvPlaceholders('%dummy2%', true); - $this->assertInternalType('array', $container->resolveEnvPlaceholders('%dummy2%', true)); + $this->assertIsArray($container->resolveEnvPlaceholders('%dummy2%', true)); foreach ($dummyArray as $key => $value) { $this->assertArrayHasKey($key, $container->resolveEnvPlaceholders('%dummy2%', true)); diff --git a/Tests/Loader/YamlFileLoaderTest.php b/Tests/Loader/YamlFileLoaderTest.php index 45d9ff10d..d4d14a2cb 100644 --- a/Tests/Loader/YamlFileLoaderTest.php +++ b/Tests/Loader/YamlFileLoaderTest.php @@ -599,7 +599,7 @@ public function testAnonymousServices() // Anonymous service in a callable $factory = $definition->getFactory(); - $this->assertInternalType('array', $factory); + $this->assertIsArray($factory); $this->assertInstanceOf(Reference::class, $factory[0]); $this->assertTrue($container->has((string) $factory[0])); $this->assertRegExp('/^\d+_Quz~[._A-Za-z0-9]{7}$/', (string) $factory[0]); diff --git a/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php b/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php index e7c88d2bb..bd0613e5c 100644 --- a/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php +++ b/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php @@ -12,10 +12,13 @@ namespace Symfony\Component\DependencyInjection\Tests\ParameterBag; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; class EnvPlaceholderParameterBagTest extends TestCase { + use ForwardCompatTestTrait; + /** * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ @@ -42,7 +45,7 @@ public function testMergeWillNotDuplicateIdenticalParameters() $placeholder = array_values($placeholderForVariable)[0]; $this->assertCount(1, $placeholderForVariable); - $this->assertInternalType('string', $placeholder); + $this->assertIsString($placeholder); $this->assertContains($envVariableName, $placeholder); } @@ -65,7 +68,7 @@ public function testMergeWhereFirstBagIsEmptyWillWork() $placeholder = array_values($placeholderForVariable)[0]; $this->assertCount(1, $placeholderForVariable); - $this->assertInternalType('string', $placeholder); + $this->assertIsString($placeholder); $this->assertContains($envVariableName, $placeholder); } From b3c614b4e99a3680c6238332171a3a79f33101ef Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Aug 2019 14:16:51 +0200 Subject: [PATCH 44/72] Skip tests that fatal-error on PHP 7.4 because of missing parent classes --- Tests/Compiler/AutowirePassTest.php | 13 +++++++++++++ Tests/Compiler/ResolveBindingsPassTest.php | 5 +++++ Tests/Dumper/PhpDumperTest.php | 5 +++++ Tests/Loader/FileLoaderTest.php | 13 +++++++++++++ 4 files changed, 36 insertions(+) diff --git a/Tests/Compiler/AutowirePassTest.php b/Tests/Compiler/AutowirePassTest.php index 31fa665ae..85979f367 100644 --- a/Tests/Compiler/AutowirePassTest.php +++ b/Tests/Compiler/AutowirePassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Warning; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Compiler\AutowirePass; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; @@ -395,6 +396,10 @@ public function testClassNotFoundThrowsException() */ public function testParentClassNotFoundThrowsException() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); $aDefinition = $container->register('a', __NAMESPACE__.'\BadParentTypeHintedArgument'); @@ -707,6 +712,10 @@ public function getCreateResourceTests() public function testIgnoreServiceWithClassNotExisting() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); $container->register('class_not_exist', __NAMESPACE__.'\OptionalServiceClass'); @@ -917,6 +926,10 @@ public function testExceptionWhenAliasExists() */ public function testExceptionWhenAliasDoesNotExist() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); // multiple I instances... but no IInterface alias diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index 7bbecf620..303e3abd4 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Warning; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass; @@ -69,6 +70,10 @@ public function testUnusedBinding() */ public function testMissingParent() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); $definition = $container->register(ParentNotExists::class, ParentNotExists::class); diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index b4e361077..6a5cff108 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Dumper; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Warning; use Psr\Container\ContainerInterface; use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; @@ -906,6 +907,10 @@ public function testInlineSelfRef() public function testHotPathOptimizations() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = include self::$fixturesPath.'/containers/container_inline_requires.php'; $container->setParameter('inline_requires', true); $container->compile(); diff --git a/Tests/Loader/FileLoaderTest.php b/Tests/Loader/FileLoaderTest.php index ee102c75b..8493642b4 100644 --- a/Tests/Loader/FileLoaderTest.php +++ b/Tests/Loader/FileLoaderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Warning; use Psr\Container\ContainerInterface as PsrContainerInterface; use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; @@ -112,6 +113,10 @@ public function testRegisterClasses() public function testRegisterClassesWithExclude() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); $container->setParameter('other_dir', 'OtherDir'); $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures')); @@ -141,6 +146,10 @@ public function testRegisterClassesWithExclude() public function testNestedRegisterClasses() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures')); @@ -169,6 +178,10 @@ public function testNestedRegisterClasses() public function testMissingParentClass() { + if (\PHP_VERSION_ID >= 70400) { + throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); + } + $container = new ContainerBuilder(); $container->setParameter('bad_classes_dir', 'BadClasses'); $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures')); From 17eea3cc44e8b747e454e7fced7674ce04c41505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 1 Aug 2019 16:27:42 +0200 Subject: [PATCH 45/72] Replace calls to setExpectedException by Pollyfill --- Tests/Compiler/AutowirePassTest.php | 11 +++++------ Tests/ContainerBuilderTest.php | 2 +- Tests/DefinitionTest.php | 11 +++++------ Tests/Dumper/PhpDumperTest.php | 8 ++------ Tests/ParameterBag/ParameterBagTest.php | 11 +++++------ 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/Tests/Compiler/AutowirePassTest.php b/Tests/Compiler/AutowirePassTest.php index 85979f367..ce834f5c4 100644 --- a/Tests/Compiler/AutowirePassTest.php +++ b/Tests/Compiler/AutowirePassTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Warning; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Compiler\AutowirePass; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; @@ -33,6 +34,8 @@ */ class AutowirePassTest extends TestCase { + use ForwardCompatTestTrait; + public function testProcess() { $container = new ContainerBuilder(); @@ -841,12 +844,8 @@ public function testNotWireableCalls($method, $expectedMsg) $foo->addMethodCall($method, []); } - if (method_exists($this, 'expectException')) { - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage($expectedMsg); - } else { - $this->setExpectedException(RuntimeException::class, $expectedMsg); - } + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage($expectedMsg); (new ResolveClassPass())->process($container); (new AutowireRequiredMethodsPass())->process($container); diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index de0bede4c..a811ac8c3 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -1056,7 +1056,7 @@ public function testExtension() $container->registerExtension($extension = new \ProjectExtension()); $this->assertSame($container->getExtension('project'), $extension, '->registerExtension() registers an extension'); - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('LogicException'); + $this->expectException('LogicException'); $container->getExtension('no_registered'); } diff --git a/Tests/DefinitionTest.php b/Tests/DefinitionTest.php index 3581fe855..d1f13dc7b 100644 --- a/Tests/DefinitionTest.php +++ b/Tests/DefinitionTest.php @@ -12,10 +12,13 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Definition; class DefinitionTest extends TestCase { + use ForwardCompatTestTrait; + public function testConstructor() { $def = new Definition('stdClass'); @@ -69,12 +72,8 @@ public function testSetGetDecoratedService() $def = new Definition('stdClass'); - if (method_exists($this, 'expectException')) { - $this->expectException('InvalidArgumentException'); - $this->expectExceptionMessage('The decorated service inner name for "foo" must be different than the service name itself.'); - } else { - $this->setExpectedException('InvalidArgumentException', 'The decorated service inner name for "foo" must be different than the service name itself.'); - } + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('The decorated service inner name for "foo" must be different than the service name itself.'); $def->setDecoratedService('foo', 'foo'); } diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index 6a5cff108..4140894fc 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -550,12 +550,8 @@ public function testCircularReferenceAllowanceForLazyServices() $dumper = new PhpDumper($container); $message = 'Circular reference detected for service "foo", path: "foo -> bar -> foo". Try running "composer require symfony/proxy-manager-bridge".'; - if (method_exists($this, 'expectException')) { - $this->expectException(ServiceCircularReferenceException::class); - $this->expectExceptionMessage($message); - } else { - $this->setExpectedException(ServiceCircularReferenceException::class, $message); - } + $this->expectException(ServiceCircularReferenceException::class); + $this->expectExceptionMessage($message); $dumper->dump(); } diff --git a/Tests/ParameterBag/ParameterBagTest.php b/Tests/ParameterBag/ParameterBagTest.php index e67e393df..31a1957c1 100644 --- a/Tests/ParameterBag/ParameterBagTest.php +++ b/Tests/ParameterBag/ParameterBagTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\ParameterBag; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException; use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; @@ -19,6 +20,8 @@ class ParameterBagTest extends TestCase { + use ForwardCompatTestTrait; + public function testConstructor() { $bag = new ParameterBag($parameters = [ @@ -78,12 +81,8 @@ public function testGetThrowParameterNotFoundException($parameterKey, $exception 'fiz' => ['bar' => ['boo' => 12]], ]); - if (method_exists($this, 'expectException')) { - $this->expectException(ParameterNotFoundException::class); - $this->expectExceptionMessage($exceptionMessage); - } else { - $this->setExpectedException(ParameterNotFoundException::class, $exceptionMessage); - } + $this->expectException(ParameterNotFoundException::class); + $this->expectExceptionMessage($exceptionMessage); $bag->get($parameterKey); } From 8dd0d5596cefd0c57104f896216ea61ad38030f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Fri, 2 Aug 2019 00:48:42 +0200 Subject: [PATCH 46/72] Fix deprecated phpunit annotation --- Tests/ChildDefinitionTest.php | 19 ++-- Tests/Compiler/AutoAliasServicePassTest.php | 11 +- Tests/Compiler/AutowirePassTest.php | 76 +++++-------- .../CheckArgumentsValidityPassTest.php | 5 +- .../CheckCircularReferencesPassTest.php | 27 ++--- .../CheckDefinitionValidityPassTest.php | 23 ++-- ...tionOnInvalidReferenceBehaviorPassTest.php | 11 +- .../CheckReferenceValidityPassTest.php | 7 +- .../DefinitionErrorExceptionPassTest.php | 9 +- .../InlineServiceDefinitionsPassTest.php | 9 +- .../MergeExtensionConfigurationPassTest.php | 9 +- .../RegisterEnvVarProcessorsPassTest.php | 9 +- .../RegisterServiceSubscribersPassTest.php | 21 ++-- ...ReplaceAliasByActualDefinitionPassTest.php | 7 +- Tests/Compiler/ResolveBindingsPassTest.php | 17 ++- .../ResolveChildDefinitionsPassTest.php | 9 +- Tests/Compiler/ResolveClassPassTest.php | 9 +- .../Compiler/ResolveFactoryClassPassTest.php | 9 +- .../ResolveInstanceofConditionalsPassTest.php | 21 ++-- .../ResolveNamedArgumentsPassTest.php | 27 ++--- .../ResolveReferencesToAliasesPassTest.php | 7 +- Tests/Compiler/ServiceLocatorTagPassTest.php | 15 ++- Tests/ContainerBuilderTest.php | 102 ++++++------------ Tests/ContainerTest.php | 21 ++-- Tests/DefinitionDecoratorTest.php | 11 +- Tests/DefinitionTest.php | 24 ++--- Tests/Dumper/PhpDumperTest.php | 18 ++-- Tests/EnvVarProcessorTest.php | 31 +++--- Tests/Extension/ExtensionTest.php | 9 +- Tests/Loader/DirectoryLoaderTest.php | 6 +- Tests/Loader/FileLoaderTest.php | 6 +- Tests/Loader/IniFileLoaderTest.php | 18 ++-- Tests/Loader/PhpFileLoaderTest.php | 15 ++- Tests/Loader/XmlFileLoaderTest.php | 28 ++--- Tests/Loader/YamlFileLoaderTest.php | 94 ++++++---------- .../EnvPlaceholderParameterBagTest.php | 16 +-- Tests/ParameterBag/FrozenParameterBagTest.php | 19 ++-- Tests/ServiceLocatorTest.php | 33 +++--- 38 files changed, 318 insertions(+), 490 deletions(-) diff --git a/Tests/ChildDefinitionTest.php b/Tests/ChildDefinitionTest.php index cbae0eaaa..483bed80f 100644 --- a/Tests/ChildDefinitionTest.php +++ b/Tests/ChildDefinitionTest.php @@ -12,11 +12,14 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\DefinitionDecorator; class ChildDefinitionTest extends TestCase { + use ForwardCompatTestTrait; + public function testConstructor() { $def = new ChildDefinition('foo'); @@ -90,11 +93,9 @@ public function testSetArgument() $this->assertSame(['index_0' => 'foo'], $def->getArguments()); } - /** - * @expectedException \InvalidArgumentException - */ public function testReplaceArgumentShouldRequireIntegerIndex() { + $this->expectException('InvalidArgumentException'); $def = new ChildDefinition('foo'); $def->replaceArgument('0', 'foo'); @@ -119,11 +120,9 @@ public function testReplaceArgument() $this->assertSame([0 => 'foo', 1 => 'bar', 'index_1' => 'baz', '$bar' => 'val'], $def->getArguments()); } - /** - * @expectedException \OutOfBoundsException - */ public function testGetArgumentShouldCheckBounds() { + $this->expectException('OutOfBoundsException'); $def = new ChildDefinition('foo'); $def->setArguments([0 => 'foo']); @@ -137,20 +136,16 @@ public function testDefinitionDecoratorAliasExistsForBackwardsCompatibility() $this->assertInstanceOf(ChildDefinition::class, new DefinitionDecorator('foo')); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\BadMethodCallException - */ public function testCannotCallSetAutoconfigured() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\BadMethodCallException'); $def = new ChildDefinition('foo'); $def->setAutoconfigured(true); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\BadMethodCallException - */ public function testCannotCallSetInstanceofConditionals() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\BadMethodCallException'); $def = new ChildDefinition('foo'); $def->setInstanceofConditionals(['Foo' => new ChildDefinition('')]); } diff --git a/Tests/Compiler/AutoAliasServicePassTest.php b/Tests/Compiler/AutoAliasServicePassTest.php index d029636a7..159342f6f 100644 --- a/Tests/Compiler/AutoAliasServicePassTest.php +++ b/Tests/Compiler/AutoAliasServicePassTest.php @@ -12,16 +12,17 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\AutoAliasServicePass; use Symfony\Component\DependencyInjection\ContainerBuilder; class AutoAliasServicePassTest extends TestCase { - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException - */ + use ForwardCompatTestTrait; + public function testProcessWithMissingParameter() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException'); $container = new ContainerBuilder(); $container->register('example') @@ -31,11 +32,9 @@ public function testProcessWithMissingParameter() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - */ public function testProcessWithMissingFormat() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $container = new ContainerBuilder(); $container->register('example') diff --git a/Tests/Compiler/AutowirePassTest.php b/Tests/Compiler/AutowirePassTest.php index ce834f5c4..2cd26a950 100644 --- a/Tests/Compiler/AutowirePassTest.php +++ b/Tests/Compiler/AutowirePassTest.php @@ -186,12 +186,10 @@ public function testExceptionsAreStored() $this->assertCount(1, $pass->getAutowiringExceptions()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessage Invalid service "private_service": constructor of class "Symfony\Component\DependencyInjection\Tests\Compiler\PrivateConstructor" must be public. - */ public function testPrivateConstructorThrowsAutowireException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); + $this->expectExceptionMessage('Invalid service "private_service": constructor of class "Symfony\Component\DependencyInjection\Tests\Compiler\PrivateConstructor" must be public.'); $container = new ContainerBuilder(); $container->autowire('private_service', __NAMESPACE__.'\PrivateConstructor'); @@ -200,12 +198,10 @@ public function testPrivateConstructorThrowsAutowireException() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessage Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2", "c3". - */ public function testTypeCollision() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); + $this->expectExceptionMessage('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2", "c3".'); $container = new ContainerBuilder(); $container->register('c1', __NAMESPACE__.'\CollisionA'); @@ -218,12 +214,10 @@ public function testTypeCollision() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessage Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgument::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2". - */ public function testTypeNotGuessable() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); + $this->expectExceptionMessage('Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgument::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2".'); $container = new ContainerBuilder(); $container->register('a1', __NAMESPACE__.'\Foo'); @@ -235,12 +229,10 @@ public function testTypeNotGuessable() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessage Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgumentForSubclass::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2". - */ public function testTypeNotGuessableWithSubclass() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); + $this->expectExceptionMessage('Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgumentForSubclass::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2".'); $container = new ContainerBuilder(); $container->register('a1', __NAMESPACE__.'\B'); @@ -252,12 +244,10 @@ public function testTypeNotGuessableWithSubclass() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessage Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. - */ public function testTypeNotGuessableNoServicesFound() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); + $this->expectExceptionMessage('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists.'); $container = new ContainerBuilder(); $aDefinition = $container->register('a', __NAMESPACE__.'\CannotBeAutowired'); @@ -376,12 +366,10 @@ public function testDontTriggerAutowiring() $this->assertCount(0, $container->getDefinition('bar')->getArguments()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found. - */ public function testClassNotFoundThrowsException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); + $this->expectExceptionMessage('Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.'); $container = new ContainerBuilder(); $aDefinition = $container->register('a', __NAMESPACE__.'\BadTypeHintedArgument'); @@ -393,12 +381,10 @@ public function testClassNotFoundThrowsException() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class is missing a parent class (Class Symfony\Bug\NotExistClass not found). - */ public function testParentClassNotFoundThrowsException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); + $this->expectExceptionMessage('Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class is missing a parent class (Class Symfony\Bug\NotExistClass not found).'); if (\PHP_VERSION_ID >= 70400) { throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); } @@ -463,12 +449,10 @@ public function testSomeSpecificArgumentsAreSet() ); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessage Cannot autowire service "arg_no_type_hint": argument "$bar" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" is type-hinted "array", you should configure its value explicitly. - */ public function testScalarArgsCannotBeAutowired() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); + $this->expectExceptionMessage('Cannot autowire service "arg_no_type_hint": argument "$bar" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" is type-hinted "array", you should configure its value explicitly.'); $container = new ContainerBuilder(); $container->register(A::class); @@ -481,12 +465,10 @@ public function testScalarArgsCannotBeAutowired() (new AutowirePass())->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessage Cannot autowire service "arg_no_type_hint": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" has no type-hint, you should configure its value explicitly. - */ public function testNoTypeArgsCannotBeAutowired() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); + $this->expectExceptionMessage('Cannot autowire service "arg_no_type_hint": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" has no type-hint, you should configure its value explicitly.'); $container = new ContainerBuilder(); $container->register(A::class); @@ -615,11 +597,11 @@ public function testSetterInjection() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException * @exceptedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "setLogger()" does not exist. */ public function testWithNonExistingSetterAndAutowiring() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $container = new ContainerBuilder(); $definition = $container->register(CaseSensitiveClass::class, CaseSensitiveClass::class)->setAutowired(true); @@ -756,12 +738,10 @@ public function testSetterInjectionCollisionThrowsException() $this->assertSame('Cannot autowire service "setter_injection_collision": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\SetterInjectionCollision::setMultipleInstancesForOneArg()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2".', $e->getMessage()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessage Cannot autowire service "my_service": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\K::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" but no such service exists. Did you create a class that implements this interface? - */ public function testInterfaceWithNoImplementationSuggestToWriteOne() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); + $this->expectExceptionMessage('Cannot autowire service "my_service": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\K::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" but no such service exists. Did you create a class that implements this interface?'); $container = new ContainerBuilder(); $aDefinition = $container->register('my_service', K::class); @@ -827,10 +807,10 @@ public function testWithFactory() /** * @dataProvider provideNotWireableCalls - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException */ public function testNotWireableCalls($method, $expectedMsg) { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); $container = new ContainerBuilder(); $foo = $container->register('foo', NotWireable::class)->setAutowired(true) @@ -899,12 +879,10 @@ public function testTypedReferenceDeprecationNotice() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessage Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead. - */ public function testExceptionWhenAliasExists() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); + $this->expectExceptionMessage('Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.'); $container = new ContainerBuilder(); // multiple I services... but there *is* IInterface available @@ -919,12 +897,10 @@ public function testExceptionWhenAliasExists() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessage Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. You should maybe alias this class to one of these existing services: "i", "i2". - */ public function testExceptionWhenAliasDoesNotExist() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); + $this->expectExceptionMessage('Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. You should maybe alias this class to one of these existing services: "i", "i2".'); if (\PHP_VERSION_ID >= 70400) { throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); } diff --git a/Tests/Compiler/CheckArgumentsValidityPassTest.php b/Tests/Compiler/CheckArgumentsValidityPassTest.php index c1e47b308..a1a700337 100644 --- a/Tests/Compiler/CheckArgumentsValidityPassTest.php +++ b/Tests/Compiler/CheckArgumentsValidityPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\CheckArgumentsValidityPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -20,6 +21,8 @@ */ class CheckArgumentsValidityPassTest extends TestCase { + use ForwardCompatTestTrait; + public function testProcess() { $container = new ContainerBuilder(); @@ -41,11 +44,11 @@ public function testProcess() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException * @dataProvider definitionProvider */ public function testException(array $arguments, array $methodCalls) { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $container = new ContainerBuilder(); $definition = $container->register('foo'); $definition->setArguments($arguments); diff --git a/Tests/Compiler/CheckCircularReferencesPassTest.php b/Tests/Compiler/CheckCircularReferencesPassTest.php index 8423c5616..86adf3d42 100644 --- a/Tests/Compiler/CheckCircularReferencesPassTest.php +++ b/Tests/Compiler/CheckCircularReferencesPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass; use Symfony\Component\DependencyInjection\Compiler\CheckCircularReferencesPass; @@ -21,11 +22,11 @@ class CheckCircularReferencesPassTest extends TestCase { - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - */ + use ForwardCompatTestTrait; + public function testProcess() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); $container = new ContainerBuilder(); $container->register('a')->addArgument(new Reference('b')); $container->register('b')->addArgument(new Reference('a')); @@ -33,11 +34,9 @@ public function testProcess() $this->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - */ public function testProcessWithAliases() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); $container = new ContainerBuilder(); $container->register('a')->addArgument(new Reference('b')); $container->setAlias('b', 'c'); @@ -46,11 +45,9 @@ public function testProcessWithAliases() $this->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - */ public function testProcessWithFactory() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); $container = new ContainerBuilder(); $container @@ -64,11 +61,9 @@ public function testProcessWithFactory() $this->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - */ public function testProcessDetectsIndirectCircularReference() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); $container = new ContainerBuilder(); $container->register('a')->addArgument(new Reference('b')); $container->register('b')->addArgument(new Reference('c')); @@ -77,11 +72,9 @@ public function testProcessDetectsIndirectCircularReference() $this->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - */ public function testProcessDetectsIndirectCircularReferenceWithFactory() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); $container = new ContainerBuilder(); $container->register('a')->addArgument(new Reference('b')); @@ -95,11 +88,9 @@ public function testProcessDetectsIndirectCircularReferenceWithFactory() $this->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - */ public function testDeepCircularReference() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); $container = new ContainerBuilder(); $container->register('a')->addArgument(new Reference('b')); $container->register('b')->addArgument(new Reference('c')); diff --git a/Tests/Compiler/CheckDefinitionValidityPassTest.php b/Tests/Compiler/CheckDefinitionValidityPassTest.php index e1dd60b66..26bb1851d 100644 --- a/Tests/Compiler/CheckDefinitionValidityPassTest.php +++ b/Tests/Compiler/CheckDefinitionValidityPassTest.php @@ -12,27 +12,26 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass; use Symfony\Component\DependencyInjection\ContainerBuilder; class CheckDefinitionValidityPassTest extends TestCase { - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - */ + use ForwardCompatTestTrait; + public function testProcessDetectsSyntheticNonPublicDefinitions() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $container = new ContainerBuilder(); $container->register('a')->setSynthetic(true)->setPublic(false); $this->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - */ public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $container = new ContainerBuilder(); $container->register('a')->setSynthetic(false)->setAbstract(false); @@ -65,22 +64,18 @@ public function testValidTags() $this->addToAssertionCount(1); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - */ public function testInvalidTags() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $container = new ContainerBuilder(); $container->register('a', 'class')->addTag('foo', ['bar' => ['baz' => 'baz']]); $this->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException - */ public function testDynamicPublicServiceName() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\EnvParameterException'); $container = new ContainerBuilder(); $env = $container->getParameterBag()->get('env(BAR)'); $container->register("foo.$env", 'class')->setPublic(true); @@ -88,11 +83,9 @@ public function testDynamicPublicServiceName() $this->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException - */ public function testDynamicPublicAliasName() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\EnvParameterException'); $container = new ContainerBuilder(); $env = $container->getParameterBag()->get('env(BAR)'); $container->setAlias("foo.$env", 'class')->setPublic(true); diff --git a/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php b/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php index 38717eaf1..faecec987 100644 --- a/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php +++ b/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -20,6 +21,8 @@ class CheckExceptionOnInvalidReferenceBehaviorPassTest extends TestCase { + use ForwardCompatTestTrait; + public function testProcess() { $container = new ContainerBuilder(); @@ -35,11 +38,9 @@ public function testProcess() $this->addToAssertionCount(1); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException - */ public function testProcessThrowsExceptionOnInvalidReference() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException'); $container = new ContainerBuilder(); $container @@ -50,11 +51,9 @@ public function testProcessThrowsExceptionOnInvalidReference() $this->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException - */ public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinition() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException'); $container = new ContainerBuilder(); $def = new Definition(); diff --git a/Tests/Compiler/CheckReferenceValidityPassTest.php b/Tests/Compiler/CheckReferenceValidityPassTest.php index 22b6fd154..6ac8630b2 100644 --- a/Tests/Compiler/CheckReferenceValidityPassTest.php +++ b/Tests/Compiler/CheckReferenceValidityPassTest.php @@ -12,17 +12,18 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\CheckReferenceValidityPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; class CheckReferenceValidityPassTest extends TestCase { - /** - * @expectedException \RuntimeException - */ + use ForwardCompatTestTrait; + public function testProcessDetectsReferenceToAbstractDefinition() { + $this->expectException('RuntimeException'); $container = new ContainerBuilder(); $container->register('a')->setAbstract(true); diff --git a/Tests/Compiler/DefinitionErrorExceptionPassTest.php b/Tests/Compiler/DefinitionErrorExceptionPassTest.php index ce6f0496e..528e883dc 100644 --- a/Tests/Compiler/DefinitionErrorExceptionPassTest.php +++ b/Tests/Compiler/DefinitionErrorExceptionPassTest.php @@ -12,18 +12,19 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; class DefinitionErrorExceptionPassTest extends TestCase { - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage Things went wrong! - */ + use ForwardCompatTestTrait; + public function testThrowsException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('Things went wrong!'); $container = new ContainerBuilder(); $def = new Definition(); $def->addError('Things went wrong!'); diff --git a/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/Tests/Compiler/InlineServiceDefinitionsPassTest.php index 6e5c80a7d..b0aa67cf9 100644 --- a/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass; @@ -23,6 +24,8 @@ class InlineServiceDefinitionsPassTest extends TestCase { + use ForwardCompatTestTrait; + public function testProcess() { $container = new ContainerBuilder(); @@ -111,12 +114,10 @@ public function testProcessDoesNotInlineMixedServicesLoop() $this->assertEquals(new Reference('bar'), $container->getDefinition('foo')->getArgument(0)); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - * @expectedExceptionMessage Circular reference detected for service "bar", path: "bar -> foo -> bar". - */ public function testProcessThrowsOnNonSharedLoops() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); + $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> foo -> bar".'); $container = new ContainerBuilder(); $container ->register('foo') diff --git a/Tests/Compiler/MergeExtensionConfigurationPassTest.php b/Tests/Compiler/MergeExtensionConfigurationPassTest.php index 1bef795f2..b4119253d 100644 --- a/Tests/Compiler/MergeExtensionConfigurationPassTest.php +++ b/Tests/Compiler/MergeExtensionConfigurationPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Resource\FileResource; @@ -23,6 +24,8 @@ class MergeExtensionConfigurationPassTest extends TestCase { + use ForwardCompatTestTrait; + public function testExpressionLanguageProviderForwarding() { $tmpProviders = []; @@ -102,12 +105,10 @@ public function testOverriddenEnvsAreMerged() $this->assertSame(['BAZ' => 1, 'FOO' => 0], $container->getEnvCounters()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage Using a cast in "env(int:FOO)" is incompatible with resolution at compile time in "Symfony\Component\DependencyInjection\Tests\Compiler\BarExtension". The logic in the extension should be moved to a compiler pass, or an env parameter with no cast should be used instead. - */ public function testProcessedEnvsAreIncompatibleWithResolve() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('Using a cast in "env(int:FOO)" is incompatible with resolution at compile time in "Symfony\Component\DependencyInjection\Tests\Compiler\BarExtension". The logic in the extension should be moved to a compiler pass, or an env parameter with no cast should be used instead.'); $container = new ContainerBuilder(); $container->registerExtension(new BarExtension()); $container->prependExtensionConfig('bar', []); diff --git a/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php b/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php index 3d3fdf769..df72aa113 100644 --- a/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php +++ b/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php @@ -12,12 +12,15 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\RegisterEnvVarProcessorsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\EnvVarProcessorInterface; class RegisterEnvVarProcessorsPassTest extends TestCase { + use ForwardCompatTestTrait; + public function testSimpleProcessor() { $container = new ContainerBuilder(); @@ -53,12 +56,10 @@ public function testNoProcessor() $this->assertFalse($container->has('container.env_var_processors_locator')); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid type "foo" returned by "Symfony\Component\DependencyInjection\Tests\Compiler\BadProcessor::getProvidedTypes()", expected one of "array", "bool", "float", "int", "string". - */ public function testBadProcessor() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Invalid type "foo" returned by "Symfony\Component\DependencyInjection\Tests\Compiler\BadProcessor::getProvidedTypes()", expected one of "array", "bool", "float", "int", "string".'); $container = new ContainerBuilder(); $container->register('foo', BadProcessor::class)->addTag('container.env_var_processor'); diff --git a/Tests/Compiler/RegisterServiceSubscribersPassTest.php b/Tests/Compiler/RegisterServiceSubscribersPassTest.php index 0356c9713..1dfcfad71 100644 --- a/Tests/Compiler/RegisterServiceSubscribersPassTest.php +++ b/Tests/Compiler/RegisterServiceSubscribersPassTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface as PsrContainerInterface; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\Compiler\RegisterServiceSubscribersPass; use Symfony\Component\DependencyInjection\Compiler\ResolveServiceSubscribersPass; @@ -28,12 +29,12 @@ class RegisterServiceSubscribersPassTest extends TestCase { - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Service "foo" must implement interface "Symfony\Component\DependencyInjection\ServiceSubscriberInterface". - */ + use ForwardCompatTestTrait; + public function testInvalidClass() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Service "foo" must implement interface "Symfony\Component\DependencyInjection\ServiceSubscriberInterface".'); $container = new ContainerBuilder(); $container->register('foo', CustomDefinition::class) @@ -44,12 +45,10 @@ public function testInvalidClass() (new ResolveServiceSubscribersPass())->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage The "container.service_subscriber" tag accepts only the "key" and "id" attributes, "bar" given for service "foo". - */ public function testInvalidAttributes() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('The "container.service_subscriber" tag accepts only the "key" and "id" attributes, "bar" given for service "foo".'); $container = new ContainerBuilder(); $container->register('foo', TestServiceSubscriber::class) @@ -118,12 +117,10 @@ public function testWithAttributes() $this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0)); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Service key "test" does not exist in the map returned by "Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber::getSubscribedServices()" for service "foo_service". - */ public function testExtraServiceSubscriber() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Service key "test" does not exist in the map returned by "Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber::getSubscribedServices()" for service "foo_service".'); $container = new ContainerBuilder(); $container->register('foo_service', TestServiceSubscriber::class) ->setAutowired(true) diff --git a/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php b/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php index f9c755c35..a924d2629 100644 --- a/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php +++ b/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitionPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -21,6 +22,8 @@ class ReplaceAliasByActualDefinitionPassTest extends TestCase { + use ForwardCompatTestTrait; + public function testProcess() { $container = new ContainerBuilder(); @@ -53,11 +56,9 @@ public function testProcess() $this->assertSame('b_alias', (string) $resolvedFactory[0]); } - /** - * @expectedException \InvalidArgumentException - */ public function testProcessWithInvalidAlias() { + $this->expectException('InvalidArgumentException'); $container = new ContainerBuilder(); $container->setAlias('a_alias', 'a'); $this->process($container); diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index 303e3abd4..e17db3921 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Warning; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass; @@ -28,6 +29,8 @@ class ResolveBindingsPassTest extends TestCase { + use ForwardCompatTestTrait; + public function testProcess() { $container = new ContainerBuilder(); @@ -49,12 +52,10 @@ public function testProcess() $this->assertEquals([['setSensitiveClass', [new Reference('foo')]]], $definition->getMethodCalls()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Unused binding "$quz" in service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy". - */ public function testUnusedBinding() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Unused binding "$quz" in service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy".'); $container = new ContainerBuilder(); $definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class); @@ -64,12 +65,10 @@ public function testUnusedBinding() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageRegexp Unused binding "$quz" in service [\s\S]+ Invalid service ".*\\ParentNotExists": class NotExists not found\. - */ public function testMissingParent() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('Unused binding "$quz" in service [\s\S]+ Invalid service ".*\\ParentNotExists": class NotExists not found\.'); if (\PHP_VERSION_ID >= 70400) { throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); } @@ -119,11 +118,11 @@ public function testScalarSetter() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException * @exceptedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "setLogger()" does not exist. */ public function testWithNonExistingSetterAndBinding() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $container = new ContainerBuilder(); $bindings = [ diff --git a/Tests/Compiler/ResolveChildDefinitionsPassTest.php b/Tests/Compiler/ResolveChildDefinitionsPassTest.php index 4eca8f707..1cb1139c7 100644 --- a/Tests/Compiler/ResolveChildDefinitionsPassTest.php +++ b/Tests/Compiler/ResolveChildDefinitionsPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass; @@ -19,6 +20,8 @@ class ResolveChildDefinitionsPassTest extends TestCase { + use ForwardCompatTestTrait; + public function testProcess() { $container = new ContainerBuilder(); @@ -432,12 +435,10 @@ protected function process(ContainerBuilder $container) $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - * @expectedExceptionMessageRegExp /^Circular reference detected for service "c", path: "c -> b -> a -> c"./ - */ public function testProcessDetectsChildDefinitionIndirectCircularReference() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); + $this->expectExceptionMessageRegExp('/^Circular reference detected for service "c", path: "c -> b -> a -> c"./'); $container = new ContainerBuilder(); $container->register('a'); diff --git a/Tests/Compiler/ResolveClassPassTest.php b/Tests/Compiler/ResolveClassPassTest.php index 48df3843d..e791ceae0 100644 --- a/Tests/Compiler/ResolveClassPassTest.php +++ b/Tests/Compiler/ResolveClassPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -19,6 +20,8 @@ class ResolveClassPassTest extends TestCase { + use ForwardCompatTestTrait; + /** * @dataProvider provideValidClassId */ @@ -82,12 +85,10 @@ public function testClassFoundChildDefinition() $this->assertSame(self::class, $child->getClass()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Service definition "App\Foo\Child" has a parent but no class, and its name looks like a FQCN. Either the class is missing or you want to inherit it from the parent service. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class. - */ public function testAmbiguousChildDefinition() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Service definition "App\Foo\Child" has a parent but no class, and its name looks like a FQCN. Either the class is missing or you want to inherit it from the parent service. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class.'); $container = new ContainerBuilder(); $parent = $container->register('App\Foo', null); $child = $container->setDefinition('App\Foo\Child', new ChildDefinition('App\Foo')); diff --git a/Tests/Compiler/ResolveFactoryClassPassTest.php b/Tests/Compiler/ResolveFactoryClassPassTest.php index 3438fad06..8511172fb 100644 --- a/Tests/Compiler/ResolveFactoryClassPassTest.php +++ b/Tests/Compiler/ResolveFactoryClassPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\ResolveFactoryClassPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -19,6 +20,8 @@ class ResolveFactoryClassPassTest extends TestCase { + use ForwardCompatTestTrait; + public function testProcess() { $container = new ContainerBuilder(); @@ -71,12 +74,10 @@ public function testIgnoresFulfilledFactories($factory) $this->assertSame($factory, $container->getDefinition('factory')->getFactory()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage The "factory" service is defined to be created by a factory, but is missing the factory class. Did you forget to define the factory or service class? - */ public function testNotAnyClassThrowsException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('The "factory" service is defined to be created by a factory, but is missing the factory class. Did you forget to define the factory or service class?'); $container = new ContainerBuilder(); $factory = $container->register('factory'); diff --git a/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php b/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php index 26560b4ca..c01968332 100644 --- a/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php +++ b/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; @@ -20,6 +21,8 @@ class ResolveInstanceofConditionalsPassTest extends TestCase { + use ForwardCompatTestTrait; + public function testProcess() { $container = new ContainerBuilder(); @@ -172,12 +175,10 @@ public function testProcessDoesNotUseAutoconfiguredInstanceofIfNotEnabled() $this->assertFalse($def->isAutowired()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage "App\FakeInterface" is set as an "instanceof" conditional, but it does not exist. - */ public function testBadInterfaceThrowsException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('"App\FakeInterface" is set as an "instanceof" conditional, but it does not exist.'); $container = new ContainerBuilder(); $def = $container->register('normal_service', self::class); $def->setInstanceofConditionals([ @@ -200,12 +201,10 @@ public function testBadInterfaceForAutomaticInstanceofIsOk() $this->assertTrue($container->hasDefinition('normal_service')); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Autoconfigured instanceof for type "PHPUnit\Framework\TestCase" defines method calls but these are not supported and should be removed. - */ public function testProcessThrowsExceptionForAutoconfiguredCalls() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Autoconfigured instanceof for type "PHPUnit\Framework\TestCase" defines method calls but these are not supported and should be removed.'); $container = new ContainerBuilder(); $container->registerForAutoconfiguration(parent::class) ->addMethodCall('setFoo'); @@ -213,12 +212,10 @@ public function testProcessThrowsExceptionForAutoconfiguredCalls() (new ResolveInstanceofConditionalsPass())->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Autoconfigured instanceof for type "PHPUnit\Framework\TestCase" defines arguments but these are not supported and should be removed. - */ public function testProcessThrowsExceptionForArguments() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Autoconfigured instanceof for type "PHPUnit\Framework\TestCase" defines arguments but these are not supported and should be removed.'); $container = new ContainerBuilder(); $container->registerForAutoconfiguration(parent::class) ->addArgument('bar'); diff --git a/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/Tests/Compiler/ResolveNamedArgumentsPassTest.php index e25d96f53..55fa2ab06 100644 --- a/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\ResolveNamedArgumentsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -26,6 +27,8 @@ */ class ResolveNamedArgumentsPassTest extends TestCase { + use ForwardCompatTestTrait; + public function testProcess() { $container = new ContainerBuilder(); @@ -60,11 +63,9 @@ public function testWithFactory() $this->assertSame([0 => '123'], $definition->getArguments()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - */ public function testClassNull() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $container = new ContainerBuilder(); $definition = $container->register(NamedArgumentsDummy::class); @@ -74,11 +75,9 @@ public function testClassNull() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - */ public function testClassNotExist() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $container = new ContainerBuilder(); $definition = $container->register(NotExist::class, NotExist::class); @@ -88,11 +87,9 @@ public function testClassNotExist() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - */ public function testClassNoConstructor() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $container = new ContainerBuilder(); $definition = $container->register(NoConstructor::class, NoConstructor::class); @@ -102,12 +99,10 @@ public function testClassNoConstructor() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "__construct()" has no argument named "$notFound". Check your service definition. - */ public function testArgumentNotFound() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "__construct()" has no argument named "$notFound". Check your service definition.'); $container = new ContainerBuilder(); $definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class); @@ -117,12 +112,10 @@ public function testArgumentNotFound() $pass->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummyWithoutReturnTypes::createTestDefinition1()" has no argument named "$notFound". Check your service definition. - */ public function testCorrectMethodReportedInException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummyWithoutReturnTypes::createTestDefinition1()" has no argument named "$notFound". Check your service definition.'); $container = new ContainerBuilder(); $container->register(FactoryDummyWithoutReturnTypes::class, FactoryDummyWithoutReturnTypes::class); diff --git a/Tests/Compiler/ResolveReferencesToAliasesPassTest.php b/Tests/Compiler/ResolveReferencesToAliasesPassTest.php index 55b47057b..6c320ae82 100644 --- a/Tests/Compiler/ResolveReferencesToAliasesPassTest.php +++ b/Tests/Compiler/ResolveReferencesToAliasesPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -20,6 +21,8 @@ class ResolveReferencesToAliasesPassTest extends TestCase { + use ForwardCompatTestTrait; + public function testProcess() { $container = new ContainerBuilder(); @@ -51,11 +54,9 @@ public function testProcessRecursively() $this->assertEquals('foo', (string) $arguments[0]); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - */ public function testAliasCircularReference() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); $container = new ContainerBuilder(); $container->setAlias('bar', 'foo'); $container->setAlias('foo', 'bar'); diff --git a/Tests/Compiler/ServiceLocatorTagPassTest.php b/Tests/Compiler/ServiceLocatorTagPassTest.php index 27ee7db53..f30c96357 100644 --- a/Tests/Compiler/ServiceLocatorTagPassTest.php +++ b/Tests/Compiler/ServiceLocatorTagPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -25,12 +26,12 @@ class ServiceLocatorTagPassTest extends TestCase { - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid definition for service "foo": an array of references is expected as first argument when the "container.service_locator" tag is set. - */ + use ForwardCompatTestTrait; + public function testNoServices() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Invalid definition for service "foo": an array of references is expected as first argument when the "container.service_locator" tag is set.'); $container = new ContainerBuilder(); $container->register('foo', ServiceLocator::class) @@ -40,12 +41,10 @@ public function testNoServices() (new ServiceLocatorTagPass())->process($container); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid definition for service "foo": an array of references is expected as first argument when the "container.service_locator" tag is set, "string" found for key "0". - */ public function testInvalidServices() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Invalid definition for service "foo": an array of references is expected as first argument when the "container.service_locator" tag is set, "string" found for key "0".'); $container = new ContainerBuilder(); $container->register('foo', ServiceLocator::class) diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index a811ac8c3..b42d60001 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -131,12 +131,10 @@ public function testHas() $this->assertTrue($builder->has('bar'), '->has() returns true if a service exists'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException - * @expectedExceptionMessage You have requested a non-existent service "foo". - */ public function testGetThrowsExceptionIfServiceDoesNotExist() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException'); + $this->expectExceptionMessage('You have requested a non-existent service "foo".'); $builder = new ContainerBuilder(); $builder->get('foo'); } @@ -148,11 +146,9 @@ public function testGetReturnsNullIfServiceDoesNotExistAndInvalidReferenceIsUsed $this->assertNull($builder->get('foo', ContainerInterface::NULL_ON_INVALID_REFERENCE), '->get() returns null if the service does not exist and NULL_ON_INVALID_REFERENCE is passed as a second argument'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - */ public function testGetThrowsCircularReferenceExceptionIfServiceHasReferenceToItself() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); $builder = new ContainerBuilder(); $builder->register('baz', 'stdClass')->setArguments([new Reference('baz')]); $builder->get('baz'); @@ -200,21 +196,21 @@ public function testNonSharedServicesReturnsDifferentInstances() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException * @dataProvider provideBadId */ public function testBadAliasId($id) { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $builder = new ContainerBuilder(); $builder->setAlias($id, 'foo'); } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException * @dataProvider provideBadId */ public function testBadDefinitionId($id) { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $builder = new ContainerBuilder(); $builder->setDefinition($id, new Definition('Foo')); } @@ -231,12 +227,10 @@ public function provideBadId() ]; } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage You have requested a synthetic service ("foo"). The DIC does not know how to construct this service. - */ public function testGetUnsetLoadingServiceWhenCreateServiceThrowsAnException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('You have requested a synthetic service ("foo"). The DIC does not know how to construct this service.'); $builder = new ContainerBuilder(); $builder->register('foo', 'stdClass')->setSynthetic(true); @@ -515,11 +509,9 @@ public function testCreateServiceWithIteratorArgument() $this->assertEquals(0, $i); } - /** - * @expectedException \RuntimeException - */ public function testCreateSyntheticService() { + $this->expectException('RuntimeException'); $builder = new ContainerBuilder(); $builder->register('foo', 'Bar\FooClass')->setSynthetic(true); $builder->get('foo'); @@ -543,12 +535,10 @@ public function testResolveServices() $this->assertEquals($builder->get('foo'), $builder->resolveServices(new Expression('service("foo")')), '->resolveServices() resolves expressions'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage Constructing service "foo" from a parent definition is not supported at build time. - */ public function testResolveServicesWithDecoratedDefinition() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('Constructing service "foo" from a parent definition is not supported at build time.'); $builder = new ContainerBuilder(); $builder->setDefinition('grandpa', new Definition('stdClass')); $builder->setDefinition('parent', new ChildDefinition('grandpa')); @@ -624,12 +614,10 @@ public function testMerge() $this->assertSame(['AInterface' => $childDefA, 'BInterface' => $childDefB], $container->getAutoconfiguredInstanceof()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage "AInterface" has already been autoconfigured and merge() does not support merging autoconfiguration for the same class/interface. - */ public function testMergeThrowsExceptionForDuplicateAutomaticInstanceofDefinitions() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('"AInterface" has already been autoconfigured and merge() does not support merging autoconfiguration for the same class/interface.'); $container = new ContainerBuilder(); $config = new ContainerBuilder(); $container->registerForAutoconfiguration('AInterface'); @@ -731,12 +719,10 @@ public function testCompileWithArrayAndAnotherResolveEnv() putenv('ARRAY'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage A string value must be composed of strings and/or numbers, but found parameter "env(json:ARRAY)" of type array inside string value "ABC %env(json:ARRAY)%". - */ public function testCompileWithArrayInStringResolveEnv() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('A string value must be composed of strings and/or numbers, but found parameter "env(json:ARRAY)" of type array inside string value "ABC %env(json:ARRAY)%".'); putenv('ARRAY={"foo":"bar"}'); $container = new ContainerBuilder(); @@ -746,12 +732,10 @@ public function testCompileWithArrayInStringResolveEnv() putenv('ARRAY'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\EnvNotFoundException - * @expectedExceptionMessage Environment variable not found: "FOO". - */ public function testCompileWithResolveMissingEnv() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\EnvNotFoundException'); + $this->expectExceptionMessage('Environment variable not found: "FOO".'); $container = new ContainerBuilder(); $container->setParameter('foo', '%env(FOO)%'); $container->compile(true); @@ -830,12 +814,10 @@ public function testEnvInId() $this->assertSame(['baz_bar'], array_keys($container->getDefinition('foo')->getArgument(1))); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException - * @expectedExceptionMessage Circular reference detected for parameter "env(resolve:DUMMY_ENV_VAR)" ("env(resolve:DUMMY_ENV_VAR)" > "env(resolve:DUMMY_ENV_VAR)"). - */ public function testCircularDynamicEnv() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException'); + $this->expectExceptionMessage('Circular reference detected for parameter "env(resolve:DUMMY_ENV_VAR)" ("env(resolve:DUMMY_ENV_VAR)" > "env(resolve:DUMMY_ENV_VAR)").'); putenv('DUMMY_ENV_VAR=some%foo%'); $container = new ContainerBuilder(); @@ -849,11 +831,9 @@ public function testCircularDynamicEnv() } } - /** - * @expectedException \LogicException - */ public function testMergeLogicException() { + $this->expectException('LogicException'); $container = new ContainerBuilder(); $container->setResourceTracking(false); $container->compile(); @@ -1103,11 +1083,9 @@ public function testPrivateServiceUser() $this->assertInstanceOf('BarClass', $container->get('bar_user')->bar); } - /** - * @expectedException \BadMethodCallException - */ public function testThrowsExceptionWhenSetServiceOnACompiledContainer() { + $this->expectException('BadMethodCallException'); $container = new ContainerBuilder(); $container->setResourceTracking(false); $container->register('a', 'stdClass')->setPublic(true); @@ -1134,11 +1112,9 @@ public function testNoExceptionWhenSetSyntheticServiceOnACompiledContainer() $this->assertEquals($a, $container->get('a')); } - /** - * @expectedException \BadMethodCallException - */ public function testThrowsExceptionWhenSetDefinitionOnACompiledContainer() { + $this->expectException('BadMethodCallException'); $container = new ContainerBuilder(); $container->setResourceTracking(false); $container->compile(); @@ -1230,12 +1206,10 @@ public function testInlinedDefinitions() $this->assertNotSame($bar->foo, $barUser->foo); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - * @expectedExceptionMessage Circular reference detected for service "app.test_class", path: "app.test_class -> App\TestClass -> app.test_class". - */ public function testThrowsCircularExceptionForCircularAliases() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); + $this->expectExceptionMessage('Circular reference detected for service "app.test_class", path: "app.test_class -> App\TestClass -> app.test_class".'); $builder = new ContainerBuilder(); $builder->setAliases([ @@ -1288,60 +1262,50 @@ public function testClassFromId() $this->assertEquals(CaseSensitiveClass::class, $autoloadClass->getClass()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage The definition for "DateTime" has no class attribute, and appears to reference a class or interface in the global namespace. - */ public function testNoClassFromGlobalNamespaceClassId() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('The definition for "DateTime" has no class attribute, and appears to reference a class or interface in the global namespace.'); $container = new ContainerBuilder(); $definition = $container->register(\DateTime::class); $container->compile(); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage The definition for "\DateTime" has no class attribute, and appears to reference a class or interface in the global namespace. - */ public function testNoClassFromGlobalNamespaceClassIdWithLeadingSlash() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('The definition for "\DateTime" has no class attribute, and appears to reference a class or interface in the global namespace.'); $container = new ContainerBuilder(); $container->register('\\'.\DateTime::class); $container->compile(); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage The definition for "\Symfony\Component\DependencyInjection\Tests\FooClass" has no class attribute, and appears to reference a class or interface. Please specify the class attribute explicitly or remove the leading backslash by renaming the service to "Symfony\Component\DependencyInjection\Tests\FooClass" to get rid of this error. - */ public function testNoClassFromNamespaceClassIdWithLeadingSlash() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('The definition for "\Symfony\Component\DependencyInjection\Tests\FooClass" has no class attribute, and appears to reference a class or interface. Please specify the class attribute explicitly or remove the leading backslash by renaming the service to "Symfony\Component\DependencyInjection\Tests\FooClass" to get rid of this error.'); $container = new ContainerBuilder(); $container->register('\\'.FooClass::class); $container->compile(); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage The definition for "123_abc" has no class. - */ public function testNoClassFromNonClassId() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('The definition for "123_abc" has no class.'); $container = new ContainerBuilder(); $definition = $container->register('123_abc'); $container->compile(); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage The definition for "\foo" has no class. - */ public function testNoClassFromNsSeparatorId() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('The definition for "\foo" has no class.'); $container = new ContainerBuilder(); $definition = $container->register('\\foo'); diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index 5dbec886e..57e3e382f 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -20,6 +21,8 @@ class ContainerTest extends TestCase { + use ForwardCompatTestTrait; + public function testConstructor() { $sc = new Container(); @@ -331,24 +334,20 @@ public function testGetCircularReference() } } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException - * @expectedExceptionMessage The "request" service is synthetic, it needs to be set at boot time before it can be used. - */ public function testGetSyntheticServiceThrows() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException'); + $this->expectExceptionMessage('The "request" service is synthetic, it needs to be set at boot time before it can be used.'); require_once __DIR__.'/Fixtures/php/services9_compiled.php'; $container = new \ProjectServiceContainer(); $container->get('request'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException - * @expectedExceptionMessage The "inlined" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead. - */ public function testGetRemovedServiceThrows() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException'); + $this->expectExceptionMessage('The "inlined" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.'); require_once __DIR__.'/Fixtures/php/services9_compiled.php'; $container = new \ProjectServiceContainer(); @@ -430,12 +429,10 @@ public function testReset() $this->assertNull($c->get('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Something went terribly wrong! - */ public function testGetThrowsException() { + $this->expectException('Exception'); + $this->expectExceptionMessage('Something went terribly wrong!'); $c = new ProjectServiceContainer(); try { diff --git a/Tests/DefinitionDecoratorTest.php b/Tests/DefinitionDecoratorTest.php index ac58d3455..093c5d060 100644 --- a/Tests/DefinitionDecoratorTest.php +++ b/Tests/DefinitionDecoratorTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\DefinitionDecorator; /** @@ -19,6 +20,8 @@ */ class DefinitionDecoratorTest extends TestCase { + use ForwardCompatTestTrait; + public function testConstructor() { $def = new DefinitionDecorator('foo'); @@ -92,11 +95,9 @@ public function testSetArgument() $this->assertEquals(['index_0' => 'foo'], $def->getArguments()); } - /** - * @expectedException \InvalidArgumentException - */ public function testReplaceArgumentShouldRequireIntegerIndex() { + $this->expectException('InvalidArgumentException'); $def = new DefinitionDecorator('foo'); $def->replaceArgument('0', 'foo'); @@ -117,11 +118,9 @@ public function testReplaceArgument() $this->assertEquals([0 => 'foo', 1 => 'bar', 'index_1' => 'baz'], $def->getArguments()); } - /** - * @expectedException \OutOfBoundsException - */ public function testGetArgumentShouldCheckBounds() { + $this->expectException('OutOfBoundsException'); $def = new DefinitionDecorator('foo'); $def->setArguments([0 => 'foo']); diff --git a/Tests/DefinitionTest.php b/Tests/DefinitionTest.php index d1f13dc7b..6657761e0 100644 --- a/Tests/DefinitionTest.php +++ b/Tests/DefinitionTest.php @@ -100,12 +100,10 @@ public function testMethodCalls() $this->assertEquals([['foo', ['foo']]], $def->getMethodCalls(), '->removeMethodCall() removes a method to call'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Method name cannot be empty. - */ public function testExceptionOnEmptyMethodCall() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Method name cannot be empty.'); $def = new Definition('stdClass'); $def->addMethodCall(''); } @@ -168,10 +166,10 @@ public function testSetIsDeprecated() /** * @dataProvider invalidDeprecationMessageProvider - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testSetDeprecatedWithInvalidDeprecationTemplate($message) { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $def = new Definition('stdClass'); $def->setDeprecated(false, $message); } @@ -253,35 +251,29 @@ public function testSetArgument() $this->assertSame(['foo', 'bar'], $def->getArguments()); } - /** - * @expectedException \OutOfBoundsException - */ public function testGetArgumentShouldCheckBounds() { + $this->expectException('OutOfBoundsException'); $def = new Definition('stdClass'); $def->addArgument('foo'); $def->getArgument(1); } - /** - * @expectedException \OutOfBoundsException - * @expectedExceptionMessage The index "1" is not in the range [0, 0]. - */ public function testReplaceArgumentShouldCheckBounds() { + $this->expectException('OutOfBoundsException'); + $this->expectExceptionMessage('The index "1" is not in the range [0, 0].'); $def = new Definition('stdClass'); $def->addArgument('foo'); $def->replaceArgument(1, 'bar'); } - /** - * @expectedException \OutOfBoundsException - * @expectedExceptionMessage Cannot replace arguments if none have been configured yet. - */ public function testReplaceArgumentWithoutExistingArgumentsShouldCheckBounds() { + $this->expectException('OutOfBoundsException'); + $this->expectExceptionMessage('Cannot replace arguments if none have been configured yet.'); $def = new Definition('stdClass'); $def->replaceArgument(0, 'bar'); } diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index 4140894fc..118758ee0 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -154,10 +154,10 @@ public function testDumpCustomContainerClassWithMandatoryArgumentLessConstructor /** * @dataProvider provideInvalidParameters - * @expectedException \InvalidArgumentException */ public function testExportParameters($parameters) { + $this->expectException('InvalidArgumentException'); $container = new ContainerBuilder(new ParameterBag($parameters)); $container->compile(); $dumper = new PhpDumper($container); @@ -288,11 +288,11 @@ public function testConflictingMethodsWithParent() /** * @dataProvider provideInvalidFactories - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage Cannot dump definition */ public function testInvalidFactories($factory) { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('Cannot dump definition'); $container = new ContainerBuilder(); $def = new Definition('stdClass'); $def->setPublic(true); @@ -452,12 +452,10 @@ public function testFileEnvProcessor() $this->assertStringEqualsFile(__FILE__, $container->getParameter('random')); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException - * @expectedExceptionMessage Environment variables "FOO" are never used. Please, check your container's configuration. - */ public function testUnusedEnvParameter() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\EnvParameterException'); + $this->expectExceptionMessage('Environment variables "FOO" are never used. Please, check your container\'s configuration.'); $container = new ContainerBuilder(); $container->getParameter('env(FOO)'); $container->compile(); @@ -465,12 +463,10 @@ public function testUnusedEnvParameter() $dumper->dump(); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException - * @expectedExceptionMessage Circular reference detected for parameter "env(resolve:DUMMY_ENV_VAR)" ("env(resolve:DUMMY_ENV_VAR)" > "env(resolve:DUMMY_ENV_VAR)"). - */ public function testCircularDynamicEnv() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException'); + $this->expectExceptionMessage('Circular reference detected for parameter "env(resolve:DUMMY_ENV_VAR)" ("env(resolve:DUMMY_ENV_VAR)" > "env(resolve:DUMMY_ENV_VAR)").'); $container = new ContainerBuilder(); $container->setParameter('foo', '%bar%'); $container->setParameter('bar', '%env(resolve:DUMMY_ENV_VAR)%'); diff --git a/Tests/EnvVarProcessorTest.php b/Tests/EnvVarProcessorTest.php index 972350467..a0190af93 100644 --- a/Tests/EnvVarProcessorTest.php +++ b/Tests/EnvVarProcessorTest.php @@ -3,12 +3,15 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\EnvVarProcessor; class EnvVarProcessorTest extends TestCase { + use ForwardCompatTestTrait; + const TEST_CONST = 'test'; /** @@ -98,12 +101,12 @@ public function validInts() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage Non-numeric env var * @dataProvider invalidInts */ public function testGetEnvIntInvalid($value) { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('Non-numeric env var'); $processor = new EnvVarProcessor(new Container()); $processor->getEnv('int', 'foo', function ($name) use ($value) { @@ -148,12 +151,12 @@ public function validFloats() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage Non-numeric env var * @dataProvider invalidFloats */ public function testGetEnvFloatInvalid($value) { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('Non-numeric env var'); $processor = new EnvVarProcessor(new Container()); $processor->getEnv('float', 'foo', function ($name) use ($value) { @@ -197,12 +200,12 @@ public function validConsts() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage undefined constant * @dataProvider invalidConsts */ public function testGetEnvConstInvalid($value) { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('undefined constant'); $processor = new EnvVarProcessor(new Container()); $processor->getEnv('const', 'foo', function ($name) use ($value) { @@ -246,12 +249,10 @@ public function testGetEnvJson() $this->assertSame([1], $result); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage Syntax error - */ public function testGetEnvInvalidJson() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('Syntax error'); $processor = new EnvVarProcessor(new Container()); $processor->getEnv('json', 'foo', function ($name) { @@ -262,12 +263,12 @@ public function testGetEnvInvalidJson() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage Invalid JSON env var * @dataProvider otherJsonValues */ public function testGetEnvJsonOther($value) { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('Invalid JSON env var'); $processor = new EnvVarProcessor(new Container()); $processor->getEnv('json', 'foo', function ($name) use ($value) { @@ -287,12 +288,10 @@ public function otherJsonValues() ]; } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage Unsupported env var prefix - */ public function testGetEnvUnknown() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('Unsupported env var prefix'); $processor = new EnvVarProcessor(new Container()); $processor->getEnv('unknown', 'foo', function ($name) { diff --git a/Tests/Extension/ExtensionTest.php b/Tests/Extension/ExtensionTest.php index 3c912f2a1..cd01a897f 100644 --- a/Tests/Extension/ExtensionTest.php +++ b/Tests/Extension/ExtensionTest.php @@ -12,11 +12,14 @@ namespace Symfony\Component\DependencyInjection\Tests\Extension; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; class ExtensionTest extends TestCase { + use ForwardCompatTestTrait; + /** * @dataProvider getResolvedEnabledFixtures */ @@ -34,12 +37,10 @@ public function getResolvedEnabledFixtures() ]; } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage The config array has no 'enabled' key. - */ public function testIsConfigEnabledOnNonEnableableConfig() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('The config array has no \'enabled\' key.'); $extension = new EnableableExtension(); $extension->isConfigEnabled(new ContainerBuilder(), []); diff --git a/Tests/Loader/DirectoryLoaderTest.php b/Tests/Loader/DirectoryLoaderTest.php index 8de0b7d0d..59f7e9ad3 100644 --- a/Tests/Loader/DirectoryLoaderTest.php +++ b/Tests/Loader/DirectoryLoaderTest.php @@ -61,12 +61,10 @@ public function testImports() $this->assertEquals(['ini' => 'ini', 'yaml' => 'yaml'], $this->container->getParameterBag()->all(), '->load() takes a single file that imports a directory'); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The file "foo" does not exist (in: - */ public function testExceptionIsRaisedWhenDirectoryDoesNotExist() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('The file "foo" does not exist (in:'); $this->loader->load('foo/'); } diff --git a/Tests/Loader/FileLoaderTest.php b/Tests/Loader/FileLoaderTest.php index 8493642b4..426b720f3 100644 --- a/Tests/Loader/FileLoaderTest.php +++ b/Tests/Loader/FileLoaderTest.php @@ -200,12 +200,10 @@ public function testMissingParentClass() ); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageRegExp /Expected to find class "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\Prototype\\Bar" in file ".+" while importing services from resource "Prototype\/Sub\/\*", but it was not found\! Check the namespace prefix used with the resource/ - */ public function testRegisterClassesWithBadPrefix() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('/Expected to find class "Symfony\\\Component\\\DependencyInjection\\\Tests\\\Fixtures\\\Prototype\\\Bar" in file ".+" while importing services from resource "Prototype\/Sub\/\*", but it was not found\! Check the namespace prefix used with the resource/'); $container = new ContainerBuilder(); $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures')); diff --git a/Tests/Loader/IniFileLoaderTest.php b/Tests/Loader/IniFileLoaderTest.php index 87a436c4b..06cc8b2eb 100644 --- a/Tests/Loader/IniFileLoaderTest.php +++ b/Tests/Loader/IniFileLoaderTest.php @@ -98,30 +98,24 @@ public function getTypeConversions() ]; } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The file "foo.ini" does not exist (in: - */ public function testExceptionIsRaisedWhenIniFileDoesNotExist() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('The file "foo.ini" does not exist (in:'); $this->loader->load('foo.ini'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage The "nonvalid.ini" file is not valid. - */ public function testExceptionIsRaisedWhenIniFileCannotBeParsed() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('The "nonvalid.ini" file is not valid.'); @$this->loader->load('nonvalid.ini'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage The "almostvalid.ini" file is not valid. - */ public function testExceptionIsRaisedWhenIniFileIsAlmostValid() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('The "almostvalid.ini" file is not valid.'); @$this->loader->load('almostvalid.ini'); } diff --git a/Tests/Loader/PhpFileLoaderTest.php b/Tests/Loader/PhpFileLoaderTest.php index 4f7c16890..ab2fb11f6 100644 --- a/Tests/Loader/PhpFileLoaderTest.php +++ b/Tests/Loader/PhpFileLoaderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; @@ -20,6 +21,8 @@ class PhpFileLoaderTest extends TestCase { + use ForwardCompatTestTrait; + public function testSupports() { $loader = new PhpFileLoader(new ContainerBuilder(), new FileLocator()); @@ -77,12 +80,10 @@ public function provideConfig() } } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage The service "child_service" cannot have a "parent" and also have "autoconfigure". Try disabling autoconfiguration for the service. - */ public function testAutoConfigureAndChildDefinitionNotAllowed() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('The service "child_service" cannot have a "parent" and also have "autoconfigure". Try disabling autoconfiguration for the service.'); $fixtures = realpath(__DIR__.'/../Fixtures'); $container = new ContainerBuilder(); $loader = new PhpFileLoader($container, new FileLocator()); @@ -90,12 +91,10 @@ public function testAutoConfigureAndChildDefinitionNotAllowed() $container->compile(); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid factory "factory:method": the `service:method` notation is not available when using PHP-based DI configuration. Use "[ref('factory'), 'method']" instead. - */ public function testFactoryShortNotationNotAllowed() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Invalid factory "factory:method": the `service:method` notation is not available when using PHP-based DI configuration. Use "[ref(\'factory\'), \'method\']" instead.'); $fixtures = realpath(__DIR__.'/../Fixtures'); $container = new ContainerBuilder(); $loader = new PhpFileLoader($container, new FileLocator()); diff --git a/Tests/Loader/XmlFileLoaderTest.php b/Tests/Loader/XmlFileLoaderTest.php index cafe419c6..6c33dba13 100644 --- a/Tests/Loader/XmlFileLoaderTest.php +++ b/Tests/Loader/XmlFileLoaderTest.php @@ -328,22 +328,18 @@ public function testParsesTags() } } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - */ public function testParseTagsWithoutNameThrowsException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $container = new ContainerBuilder(); $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('tag_without_name.xml'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageRegExp /The tag name for service ".+" in .* must be a non-empty string/ - */ public function testParseTagWithEmptyNameThrowsException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('/The tag name for service ".+" in .* must be a non-empty string/'); $container = new ContainerBuilder(); $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('tag_with_empty_name.xml'); @@ -733,36 +729,30 @@ public function testInstanceof() $this->assertSame(['foo' => [[]], 'bar' => [[]]], $definition->getTags()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage The service "child_service" cannot use the "parent" option in the same file where "instanceof" configuration is defined as using both is not supported. Move your child definitions to a separate file. - */ public function testInstanceOfAndChildDefinitionNotAllowed() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('The service "child_service" cannot use the "parent" option in the same file where "instanceof" configuration is defined as using both is not supported. Move your child definitions to a separate file.'); $container = new ContainerBuilder(); $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('services_instanceof_with_parent.xml'); $container->compile(); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage The service "child_service" cannot have a "parent" and also have "autoconfigure". Try setting autoconfigure="false" for the service. - */ public function testAutoConfigureAndChildDefinitionNotAllowed() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('The service "child_service" cannot have a "parent" and also have "autoconfigure". Try setting autoconfigure="false" for the service.'); $container = new ContainerBuilder(); $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('services_autoconfigure_with_parent.xml'); $container->compile(); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Attribute "autowire" on service "child_service" cannot be inherited from "defaults" when a "parent" is set. Move your child definitions to a separate file or define this attribute explicitly. - */ public function testDefaultsAndChildDefinitionNotAllowed() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Attribute "autowire" on service "child_service" cannot be inherited from "defaults" when a "parent" is set. Move your child definitions to a separate file or define this attribute explicitly.'); $container = new ContainerBuilder(); $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('services_defaults_with_parent.xml'); diff --git a/Tests/Loader/YamlFileLoaderTest.php b/Tests/Loader/YamlFileLoaderTest.php index d4d14a2cb..94ec67256 100644 --- a/Tests/Loader/YamlFileLoaderTest.php +++ b/Tests/Loader/YamlFileLoaderTest.php @@ -45,12 +45,10 @@ private static function doSetUpBeforeClass() require_once self::$fixturesPath.'/includes/ProjectExtension.php'; } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageRegExp /The file ".+" does not exist./ - */ public function testLoadUnExistFile() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('/The file ".+" does not exist./'); $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/ini')); $r = new \ReflectionObject($loader); $m = $r->getMethod('loadFile'); @@ -59,12 +57,10 @@ public function testLoadUnExistFile() $m->invoke($loader, 'foo.yml'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageRegExp /The file ".+" does not contain valid YAML./ - */ public function testLoadInvalidYamlFile() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('/The file ".+" does not contain valid YAML./'); $path = self::$fixturesPath.'/ini'; $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator($path)); $r = new \ReflectionObject($loader); @@ -76,10 +72,10 @@ public function testLoadInvalidYamlFile() /** * @dataProvider provideInvalidFiles - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testLoadInvalidFile($file) { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); $loader->load($file.'.yml'); @@ -304,40 +300,32 @@ public function testLoadYamlOnlyWithKeys() $this->assertEquals(['manager' => [['alias' => 'user']]], $definition->getTags()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageRegExp /The tag name for service ".+" in .+ must be a non-empty string/ - */ public function testTagWithEmptyNameThrowsException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('/The tag name for service ".+" in .+ must be a non-empty string/'); $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('tag_name_empty_string.yml'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageREgExp /The tag name for service "\.+" must be a non-empty string/ - */ public function testTagWithNonStringNameThrowsException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('The tag name for service "\.+" must be a non-empty string'); $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('tag_name_no_string.yml'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - */ public function testTypesNotArray() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('bad_types1.yml'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - */ public function testTypeNotString() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('bad_types2.yml'); } @@ -433,12 +421,10 @@ public function testPrototypeWithNamespace() $this->assertFalse($container->getDefinition(Prototype\OtherDir\Component2\Dir2\Service5::class)->hasTag('foo')); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageRegExp /A "resource" attribute must be set when the "namespace" attribute is set for service ".+" in .+/ - */ public function testPrototypeWithNamespaceAndNoResource() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('/A "resource" attribute must be set when the "namespace" attribute is set for service ".+" in .+/'); $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('services_prototype_namespace_without_resource.yml'); @@ -509,58 +495,48 @@ public function testInstanceof() $this->assertSame(['foo' => [[]], 'bar' => [[]]], $definition->getTags()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage The service "child_service" cannot use the "parent" option in the same file where "_instanceof" configuration is defined as using both is not supported. Move your child definitions to a separate file. - */ public function testInstanceOfAndChildDefinitionNotAllowed() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('The service "child_service" cannot use the "parent" option in the same file where "_instanceof" configuration is defined as using both is not supported. Move your child definitions to a separate file.'); $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('services_instanceof_with_parent.yml'); $container->compile(); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage The service "child_service" cannot have a "parent" and also have "autoconfigure". Try setting "autoconfigure: false" for the service. - */ public function testAutoConfigureAndChildDefinitionNotAllowed() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('The service "child_service" cannot have a "parent" and also have "autoconfigure". Try setting "autoconfigure: false" for the service.'); $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('services_autoconfigure_with_parent.yml'); $container->compile(); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Attribute "autowire" on service "child_service" cannot be inherited from "_defaults" when a "parent" is set. Move your child definitions to a separate file or define this attribute explicitly. - */ public function testDefaultsAndChildDefinitionNotAllowed() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Attribute "autowire" on service "child_service" cannot be inherited from "_defaults" when a "parent" is set. Move your child definitions to a separate file or define this attribute explicitly.'); $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('services_defaults_with_parent.yml'); $container->compile(); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage The value of the "decorates" option for the "bar" service must be the id of the service without the "@" prefix (replace "@foo" with "foo"). - */ public function testDecoratedServicesWithWrongSyntaxThrowsException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('The value of the "decorates" option for the "bar" service must be the id of the service without the "@" prefix (replace "@foo" with "foo").'); $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('bad_decorates.yml'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageRegExp /Parameter "tags" must be an array for service "Foo\\Bar" in .+services31_invalid_tags\.yml\. Check your YAML syntax./ - */ public function testInvalidTagsWithDefaults() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('/Parameter "tags" must be an array for service "Foo\\\Bar" in .+services31_invalid_tags\.yml\. Check your YAML syntax./'); $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('services31_invalid_tags.yml'); } @@ -649,23 +625,19 @@ public function testAnonymousServicesInInstanceof() $this->assertFalse($container->has('Bar')); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageRegExp /Creating an alias using the tag "!service" is not allowed in ".+anonymous_services_alias\.yml"\./ - */ public function testAnonymousServicesWithAliases() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('/Creating an alias using the tag "!service" is not allowed in ".+anonymous_services_alias\.yml"\./'); $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('anonymous_services_alias.yml'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageRegExp /Using an anonymous service in a parameter is not allowed in ".+anonymous_services_in_parameters\.yml"\./ - */ public function testAnonymousServicesInParameters() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('/Using an anonymous service in a parameter is not allowed in ".+anonymous_services_in_parameters\.yml"\./'); $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('anonymous_services_in_parameters.yml'); @@ -681,23 +653,19 @@ public function testAutoConfigureInstanceof() $this->assertFalse($container->getDefinition('override_defaults_settings_to_false')->isAutoconfigured()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageRegExp /Service "_defaults" key must be an array, "NULL" given in ".+bad_empty_defaults\.yml"\./ - */ public function testEmptyDefaultsThrowsClearException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('/Service "_defaults" key must be an array, "NULL" given in ".+bad_empty_defaults\.yml"\./'); $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('bad_empty_defaults.yml'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessageRegExp /Service "_instanceof" key must be an array, "NULL" given in ".+bad_empty_instanceof\.yml"\./ - */ public function testEmptyInstanceofThrowsClearException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectExceptionMessageRegExp('/Service "_instanceof" key must be an array, "NULL" given in ".+bad_empty_instanceof\.yml"\./'); $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('bad_empty_instanceof.yml'); diff --git a/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php b/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php index bd0613e5c..e0a978580 100644 --- a/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php +++ b/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php @@ -19,11 +19,9 @@ class EnvPlaceholderParameterBagTest extends TestCase { use ForwardCompatTestTrait; - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - */ public function testGetThrowsInvalidArgumentExceptionIfEnvNameContainsNonWordCharacters() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $bag = new EnvPlaceholderParameterBag(); $bag->get('env(%foo%)'); } @@ -132,12 +130,10 @@ public function testResolveEnvAllowsNull() $this->assertNull($bag->all()['env(NULL_VAR)']); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage The default value of env parameter "ARRAY_VAR" must be scalar or null, array given. - */ public function testResolveThrowsOnBadDefaultValue() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('The default value of env parameter "ARRAY_VAR" must be scalar or null, array given.'); $bag = new EnvPlaceholderParameterBag(); $bag->get('env(ARRAY_VAR)'); $bag->set('env(ARRAY_VAR)', []); @@ -154,12 +150,10 @@ public function testGetEnvAllowsNull() $this->assertNull($bag->all()['env(NULL_VAR)']); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessage The default value of an env() parameter must be scalar or null, but "array" given to "env(ARRAY_VAR)". - */ public function testGetThrowsOnBadDefaultValue() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('The default value of an env() parameter must be scalar or null, but "array" given to "env(ARRAY_VAR)".'); $bag = new EnvPlaceholderParameterBag(); $bag->set('env(ARRAY_VAR)', []); $bag->get('env(ARRAY_VAR)'); diff --git a/Tests/ParameterBag/FrozenParameterBagTest.php b/Tests/ParameterBag/FrozenParameterBagTest.php index b168e0c20..532a5a014 100644 --- a/Tests/ParameterBag/FrozenParameterBagTest.php +++ b/Tests/ParameterBag/FrozenParameterBagTest.php @@ -12,10 +12,13 @@ namespace Symfony\Component\DependencyInjection\Tests\ParameterBag; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; class FrozenParameterBagTest extends TestCase { + use ForwardCompatTestTrait; + public function testConstructor() { $parameters = [ @@ -26,38 +29,30 @@ public function testConstructor() $this->assertEquals($parameters, $bag->all(), '__construct() takes an array of parameters as its first argument'); } - /** - * @expectedException \LogicException - */ public function testClear() { + $this->expectException('LogicException'); $bag = new FrozenParameterBag([]); $bag->clear(); } - /** - * @expectedException \LogicException - */ public function testSet() { + $this->expectException('LogicException'); $bag = new FrozenParameterBag([]); $bag->set('foo', 'bar'); } - /** - * @expectedException \LogicException - */ public function testAdd() { + $this->expectException('LogicException'); $bag = new FrozenParameterBag([]); $bag->add([]); } - /** - * @expectedException \LogicException - */ public function testRemove() { + $this->expectException('LogicException'); $bag = new FrozenParameterBag(['foo' => 'bar']); $bag->remove('foo'); } diff --git a/Tests/ServiceLocatorTest.php b/Tests/ServiceLocatorTest.php index aa9ebab68..a88a489bb 100644 --- a/Tests/ServiceLocatorTest.php +++ b/Tests/ServiceLocatorTest.php @@ -12,12 +12,15 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; class ServiceLocatorTest extends TestCase { + use ForwardCompatTestTrait; + public function testHas() { $locator = new ServiceLocator([ @@ -58,12 +61,10 @@ public function testGetDoesNotMemoize() $this->assertSame(2, $i); } - /** - * @expectedException \Psr\Container\NotFoundExceptionInterface - * @expectedExceptionMessage Service "dummy" not found: the container inside "Symfony\Component\DependencyInjection\Tests\ServiceLocatorTest" is a smaller service locator that only knows about the "foo" and "bar" services. - */ public function testGetThrowsOnUndefinedService() { + $this->expectException('Psr\Container\NotFoundExceptionInterface'); + $this->expectExceptionMessage('Service "dummy" not found: the container inside "Symfony\Component\DependencyInjection\Tests\ServiceLocatorTest" is a smaller service locator that only knows about the "foo" and "bar" services.'); $locator = new ServiceLocator([ 'foo' => function () { return 'bar'; }, 'bar' => function () { return 'baz'; }, @@ -72,12 +73,10 @@ public function testGetThrowsOnUndefinedService() $locator->get('dummy'); } - /** - * @expectedException \Psr\Container\NotFoundExceptionInterface - * @expectedExceptionMessage The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service. - */ public function testThrowsOnUndefinedInternalService() { + $this->expectException('Psr\Container\NotFoundExceptionInterface'); + $this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.'); $locator = new ServiceLocator([ 'foo' => function () use (&$locator) { return $locator->get('bar'); }, ]); @@ -85,12 +84,10 @@ public function testThrowsOnUndefinedInternalService() $locator->get('foo'); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException - * @expectedExceptionMessage Circular reference detected for service "bar", path: "bar -> baz -> bar". - */ public function testThrowsOnCircularReference() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); + $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".'); $locator = new ServiceLocator([ 'foo' => function () use (&$locator) { return $locator->get('bar'); }, 'bar' => function () use (&$locator) { return $locator->get('baz'); }, @@ -100,12 +97,10 @@ public function testThrowsOnCircularReference() $locator->get('foo'); } - /** - * @expectedException \Psr\Container\NotFoundExceptionInterface - * @expectedExceptionMessage Service "foo" not found: even though it exists in the app's container, the container inside "caller" is a smaller service locator that only knows about the "bar" service. Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "SomeServiceSubscriber::getSubscribedServices()". - */ public function testThrowsInServiceSubscriber() { + $this->expectException('Psr\Container\NotFoundExceptionInterface'); + $this->expectExceptionMessage('Service "foo" not found: even though it exists in the app\'s container, the container inside "caller" is a smaller service locator that only knows about the "bar" service. Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "SomeServiceSubscriber::getSubscribedServices()".'); $container = new Container(); $container->set('foo', new \stdClass()); $subscriber = new SomeServiceSubscriber(); @@ -115,12 +110,10 @@ public function testThrowsInServiceSubscriber() $subscriber->getFoo(); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException - * @expectedExceptionMessage Service "foo" not found: even though it exists in the app's container, the container inside "foo" is a smaller service locator that is empty... Try using dependency injection instead. - */ public function testGetThrowsServiceNotFoundException() { + $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException'); + $this->expectExceptionMessage('Service "foo" not found: even though it exists in the app\'s container, the container inside "foo" is a smaller service locator that is empty... Try using dependency injection instead.'); $container = new Container(); $container->set('foo', new \stdClass()); From 5cc779af4329d8239a0a9726d3ff20dabf788a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Fri, 2 Aug 2019 01:19:44 +0200 Subject: [PATCH 47/72] Fix tests --- Tests/Compiler/ResolveBindingsPassTest.php | 2 +- Tests/Loader/YamlFileLoaderTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index e17db3921..089f4a78e 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -68,7 +68,7 @@ public function testUnusedBinding() public function testMissingParent() { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); - $this->expectExceptionMessageRegExp('Unused binding "$quz" in service [\s\S]+ Invalid service ".*\\ParentNotExists": class NotExists not found\.'); + $this->expectExceptionMessageRegExp('/Unused binding "\$quz" in service [\s\S]+/'); if (\PHP_VERSION_ID >= 70400) { throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); } diff --git a/Tests/Loader/YamlFileLoaderTest.php b/Tests/Loader/YamlFileLoaderTest.php index 94ec67256..f149d7a55 100644 --- a/Tests/Loader/YamlFileLoaderTest.php +++ b/Tests/Loader/YamlFileLoaderTest.php @@ -311,7 +311,7 @@ public function testTagWithEmptyNameThrowsException() public function testTagWithNonStringNameThrowsException() { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); - $this->expectExceptionMessageRegExp('The tag name for service "\.+" must be a non-empty string'); + $this->expectExceptionMessageRegExp('/The tag name for service ".+" in .+ must be a non-empty string/'); $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('tag_name_no_string.yml'); } From 1019ffc93d090d0c3edb2cea41592aead7506aad Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 2 Aug 2019 15:23:07 +0200 Subject: [PATCH 48/72] Adopt `@PHPUnit55Migration:risky` rule of php-cs-fixer --- ContainerBuilder.php | 4 ++-- Tests/ContainerTest.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ContainerBuilder.php b/ContainerBuilder.php index 73145fd8d..6676c33ca 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -946,8 +946,8 @@ public function getAlias($id) * This methods allows for simple registration of service definition * with a fluid interface. * - * @param string $id The service identifier - * @param string $class|null The service class + * @param string $id The service identifier + * @param string|null $class The service class * * @return Definition A Definition instance */ diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index 57e3e382f..286a98b9d 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; -use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; From d6ffe8974ae0323af4802c9c701bb20ce99c1f7e Mon Sep 17 00:00:00 2001 From: ABGEO Date: Thu, 1 Aug 2019 19:16:41 +0400 Subject: [PATCH 49/72] #32853 Check if $this->parameters is array. --- Dumper/PhpDumper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dumper/PhpDumper.php b/Dumper/PhpDumper.php index a18d1665c..3e586ff71 100644 --- a/Dumper/PhpDumper.php +++ b/Dumper/PhpDumper.php @@ -969,7 +969,7 @@ private function startClass($class, $baseClass, $baseClassWithNamespace) */ class $class extends $baseClass { - private \$parameters; + private \$parameters = []; private \$targetDirs = []; public function __construct() From 442eb38b8685e442ae693f42f2021060af36337a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Fri, 2 Aug 2019 19:02:27 +0200 Subject: [PATCH 50/72] Remove use of ForwardCompatTrait --- Tests/ChildDefinitionTest.php | 3 --- Tests/Compiler/AutoAliasServicePassTest.php | 3 --- Tests/Compiler/AutowirePassTest.php | 3 --- Tests/Compiler/CheckArgumentsValidityPassTest.php | 3 --- Tests/Compiler/CheckCircularReferencesPassTest.php | 3 --- Tests/Compiler/CheckDefinitionValidityPassTest.php | 3 --- .../CheckExceptionOnInvalidReferenceBehaviorPassTest.php | 3 --- Tests/Compiler/CheckReferenceValidityPassTest.php | 3 --- Tests/Compiler/DefinitionErrorExceptionPassTest.php | 3 --- Tests/Compiler/ExtensionCompilerPassTest.php | 5 +---- Tests/Compiler/InlineServiceDefinitionsPassTest.php | 3 --- Tests/Compiler/MergeExtensionConfigurationPassTest.php | 3 --- Tests/Compiler/RegisterEnvVarProcessorsPassTest.php | 3 --- Tests/Compiler/RegisterServiceSubscribersPassTest.php | 3 --- Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php | 3 --- Tests/Compiler/ResolveBindingsPassTest.php | 3 --- Tests/Compiler/ResolveChildDefinitionsPassTest.php | 3 --- Tests/Compiler/ResolveClassPassTest.php | 3 --- Tests/Compiler/ResolveFactoryClassPassTest.php | 3 --- Tests/Compiler/ResolveInstanceofConditionalsPassTest.php | 3 --- Tests/Compiler/ResolveNamedArgumentsPassTest.php | 3 --- Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php | 5 +---- Tests/Compiler/ResolveReferencesToAliasesPassTest.php | 3 --- Tests/Compiler/ServiceLocatorTagPassTest.php | 3 --- Tests/Config/AutowireServiceResourceTest.php | 7 ++----- Tests/Config/ContainerParametersResourceCheckerTest.php | 5 +---- Tests/Config/ContainerParametersResourceTest.php | 5 +---- Tests/ContainerBuilderTest.php | 3 --- Tests/ContainerTest.php | 3 --- Tests/CrossCheckTest.php | 5 +---- Tests/DefinitionDecoratorTest.php | 3 --- Tests/DefinitionTest.php | 3 --- Tests/Dumper/GraphvizDumperTest.php | 5 +---- Tests/Dumper/PhpDumperTest.php | 5 +---- Tests/Dumper/XmlDumperTest.php | 5 +---- Tests/Dumper/YamlDumperTest.php | 5 +---- Tests/EnvVarProcessorTest.php | 3 --- Tests/Extension/ExtensionTest.php | 3 --- .../Prototype/OtherDir/Component1/Dir2/Service2.php | 1 - .../Prototype/OtherDir/Component2/Dir2/Service5.php | 1 - Tests/Fixtures/StubbedTranslator.php | 1 - Tests/Loader/DirectoryLoaderTest.php | 7 ++----- Tests/Loader/FileLoaderTest.php | 5 +---- Tests/Loader/IniFileLoaderTest.php | 5 +---- Tests/Loader/LoaderResolverTest.php | 5 +---- Tests/Loader/PhpFileLoaderTest.php | 3 --- Tests/Loader/XmlFileLoaderTest.php | 5 +---- Tests/Loader/YamlFileLoaderTest.php | 5 +---- Tests/ParameterBag/EnvPlaceholderParameterBagTest.php | 3 --- Tests/ParameterBag/FrozenParameterBagTest.php | 3 --- Tests/ParameterBag/ParameterBagTest.php | 3 --- Tests/ServiceLocatorTest.php | 3 --- 52 files changed, 18 insertions(+), 168 deletions(-) diff --git a/Tests/ChildDefinitionTest.php b/Tests/ChildDefinitionTest.php index 483bed80f..509174839 100644 --- a/Tests/ChildDefinitionTest.php +++ b/Tests/ChildDefinitionTest.php @@ -12,14 +12,11 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\DefinitionDecorator; class ChildDefinitionTest extends TestCase { - use ForwardCompatTestTrait; - public function testConstructor() { $def = new ChildDefinition('foo'); diff --git a/Tests/Compiler/AutoAliasServicePassTest.php b/Tests/Compiler/AutoAliasServicePassTest.php index 159342f6f..4e17778f8 100644 --- a/Tests/Compiler/AutoAliasServicePassTest.php +++ b/Tests/Compiler/AutoAliasServicePassTest.php @@ -12,14 +12,11 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\AutoAliasServicePass; use Symfony\Component\DependencyInjection\ContainerBuilder; class AutoAliasServicePassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcessWithMissingParameter() { $this->expectException('Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException'); diff --git a/Tests/Compiler/AutowirePassTest.php b/Tests/Compiler/AutowirePassTest.php index 2cd26a950..84d396beb 100644 --- a/Tests/Compiler/AutowirePassTest.php +++ b/Tests/Compiler/AutowirePassTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Warning; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Compiler\AutowirePass; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; @@ -34,8 +33,6 @@ */ class AutowirePassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcess() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/CheckArgumentsValidityPassTest.php b/Tests/Compiler/CheckArgumentsValidityPassTest.php index a1a700337..9554c23bb 100644 --- a/Tests/Compiler/CheckArgumentsValidityPassTest.php +++ b/Tests/Compiler/CheckArgumentsValidityPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\CheckArgumentsValidityPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -21,8 +20,6 @@ */ class CheckArgumentsValidityPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcess() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/CheckCircularReferencesPassTest.php b/Tests/Compiler/CheckCircularReferencesPassTest.php index 86adf3d42..8d501368e 100644 --- a/Tests/Compiler/CheckCircularReferencesPassTest.php +++ b/Tests/Compiler/CheckCircularReferencesPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass; use Symfony\Component\DependencyInjection\Compiler\CheckCircularReferencesPass; @@ -22,8 +21,6 @@ class CheckCircularReferencesPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcess() { $this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); diff --git a/Tests/Compiler/CheckDefinitionValidityPassTest.php b/Tests/Compiler/CheckDefinitionValidityPassTest.php index 26bb1851d..6caa38c7b 100644 --- a/Tests/Compiler/CheckDefinitionValidityPassTest.php +++ b/Tests/Compiler/CheckDefinitionValidityPassTest.php @@ -12,14 +12,11 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass; use Symfony\Component\DependencyInjection\ContainerBuilder; class CheckDefinitionValidityPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcessDetectsSyntheticNonPublicDefinitions() { $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); diff --git a/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php b/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php index faecec987..c4f331b18 100644 --- a/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php +++ b/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -21,8 +20,6 @@ class CheckExceptionOnInvalidReferenceBehaviorPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcess() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/CheckReferenceValidityPassTest.php b/Tests/Compiler/CheckReferenceValidityPassTest.php index 6ac8630b2..85a8a40f1 100644 --- a/Tests/Compiler/CheckReferenceValidityPassTest.php +++ b/Tests/Compiler/CheckReferenceValidityPassTest.php @@ -12,15 +12,12 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\CheckReferenceValidityPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; class CheckReferenceValidityPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcessDetectsReferenceToAbstractDefinition() { $this->expectException('RuntimeException'); diff --git a/Tests/Compiler/DefinitionErrorExceptionPassTest.php b/Tests/Compiler/DefinitionErrorExceptionPassTest.php index 528e883dc..273261976 100644 --- a/Tests/Compiler/DefinitionErrorExceptionPassTest.php +++ b/Tests/Compiler/DefinitionErrorExceptionPassTest.php @@ -12,15 +12,12 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; class DefinitionErrorExceptionPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testThrowsException() { $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); diff --git a/Tests/Compiler/ExtensionCompilerPassTest.php b/Tests/Compiler/ExtensionCompilerPassTest.php index 5b1862d97..810fbe48a 100644 --- a/Tests/Compiler/ExtensionCompilerPassTest.php +++ b/Tests/Compiler/ExtensionCompilerPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\ExtensionCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -23,12 +22,10 @@ */ class ExtensionCompilerPassTest extends TestCase { - use ForwardCompatTestTrait; - private $container; private $pass; - private function doSetUp() + protected function setUp() { $this->container = new ContainerBuilder(); $this->pass = new ExtensionCompilerPass(); diff --git a/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/Tests/Compiler/InlineServiceDefinitionsPassTest.php index b0aa67cf9..d98db6406 100644 --- a/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass; @@ -24,8 +23,6 @@ class InlineServiceDefinitionsPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcess() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/MergeExtensionConfigurationPassTest.php b/Tests/Compiler/MergeExtensionConfigurationPassTest.php index b4119253d..dc0a37d60 100644 --- a/Tests/Compiler/MergeExtensionConfigurationPassTest.php +++ b/Tests/Compiler/MergeExtensionConfigurationPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Resource\FileResource; @@ -24,8 +23,6 @@ class MergeExtensionConfigurationPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testExpressionLanguageProviderForwarding() { $tmpProviders = []; diff --git a/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php b/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php index df72aa113..2c42ba0ce 100644 --- a/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php +++ b/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php @@ -12,15 +12,12 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\RegisterEnvVarProcessorsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\EnvVarProcessorInterface; class RegisterEnvVarProcessorsPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testSimpleProcessor() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/RegisterServiceSubscribersPassTest.php b/Tests/Compiler/RegisterServiceSubscribersPassTest.php index 1dfcfad71..a16bfc169 100644 --- a/Tests/Compiler/RegisterServiceSubscribersPassTest.php +++ b/Tests/Compiler/RegisterServiceSubscribersPassTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface as PsrContainerInterface; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\Compiler\RegisterServiceSubscribersPass; use Symfony\Component\DependencyInjection\Compiler\ResolveServiceSubscribersPass; @@ -29,8 +28,6 @@ class RegisterServiceSubscribersPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testInvalidClass() { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); diff --git a/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php b/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php index a924d2629..2f0a413ca 100644 --- a/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php +++ b/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitionPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -22,8 +21,6 @@ class ReplaceAliasByActualDefinitionPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcess() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index 089f4a78e..85d6e0262 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Warning; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass; @@ -29,8 +28,6 @@ class ResolveBindingsPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcess() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/ResolveChildDefinitionsPassTest.php b/Tests/Compiler/ResolveChildDefinitionsPassTest.php index 1cb1139c7..27bb9157c 100644 --- a/Tests/Compiler/ResolveChildDefinitionsPassTest.php +++ b/Tests/Compiler/ResolveChildDefinitionsPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass; @@ -20,8 +19,6 @@ class ResolveChildDefinitionsPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcess() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/ResolveClassPassTest.php b/Tests/Compiler/ResolveClassPassTest.php index e791ceae0..0ab630316 100644 --- a/Tests/Compiler/ResolveClassPassTest.php +++ b/Tests/Compiler/ResolveClassPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -20,8 +19,6 @@ class ResolveClassPassTest extends TestCase { - use ForwardCompatTestTrait; - /** * @dataProvider provideValidClassId */ diff --git a/Tests/Compiler/ResolveFactoryClassPassTest.php b/Tests/Compiler/ResolveFactoryClassPassTest.php index 8511172fb..b87fb3db9 100644 --- a/Tests/Compiler/ResolveFactoryClassPassTest.php +++ b/Tests/Compiler/ResolveFactoryClassPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\ResolveFactoryClassPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -20,8 +19,6 @@ class ResolveFactoryClassPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcess() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php b/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php index c01968332..1996216aa 100644 --- a/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php +++ b/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; @@ -21,8 +20,6 @@ class ResolveInstanceofConditionalsPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcess() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/Tests/Compiler/ResolveNamedArgumentsPassTest.php index 55fa2ab06..a10d226f1 100644 --- a/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\ResolveNamedArgumentsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -27,8 +26,6 @@ */ class ResolveNamedArgumentsPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcess() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php b/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php index 3e946932f..5aa647175 100644 --- a/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php +++ b/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php @@ -12,19 +12,16 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass; use Symfony\Component\DependencyInjection\ContainerBuilder; class ResolveParameterPlaceHoldersPassTest extends TestCase { - use ForwardCompatTestTrait; - private $compilerPass; private $container; private $fooDefinition; - private function doSetUp() + protected function setUp() { $this->compilerPass = new ResolveParameterPlaceHoldersPass(); $this->container = $this->createContainerBuilder(); diff --git a/Tests/Compiler/ResolveReferencesToAliasesPassTest.php b/Tests/Compiler/ResolveReferencesToAliasesPassTest.php index 6c320ae82..2465bb7e3 100644 --- a/Tests/Compiler/ResolveReferencesToAliasesPassTest.php +++ b/Tests/Compiler/ResolveReferencesToAliasesPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -21,8 +20,6 @@ class ResolveReferencesToAliasesPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testProcess() { $container = new ContainerBuilder(); diff --git a/Tests/Compiler/ServiceLocatorTagPassTest.php b/Tests/Compiler/ServiceLocatorTagPassTest.php index f30c96357..1de02d257 100644 --- a/Tests/Compiler/ServiceLocatorTagPassTest.php +++ b/Tests/Compiler/ServiceLocatorTagPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -26,8 +25,6 @@ class ServiceLocatorTagPassTest extends TestCase { - use ForwardCompatTestTrait; - public function testNoServices() { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); diff --git a/Tests/Config/AutowireServiceResourceTest.php b/Tests/Config/AutowireServiceResourceTest.php index 03ed02035..153e0807e 100644 --- a/Tests/Config/AutowireServiceResourceTest.php +++ b/Tests/Config/AutowireServiceResourceTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Config; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Compiler\AutowirePass; use Symfony\Component\DependencyInjection\Config\AutowireServiceResource; @@ -21,8 +20,6 @@ */ class AutowireServiceResourceTest extends TestCase { - use ForwardCompatTestTrait; - /** * @var AutowireServiceResource */ @@ -31,7 +28,7 @@ class AutowireServiceResourceTest extends TestCase private $class; private $time; - private function doSetUp() + protected function setUp() { $this->file = realpath(sys_get_temp_dir()).'/tmp.php'; $this->time = time(); @@ -104,7 +101,7 @@ public function testNotFreshIfClassNotFound() $this->assertFalse($resource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the class no longer exists'); } - private function doTearDown() + protected function tearDown() { if (!file_exists($this->file)) { return; diff --git a/Tests/Config/ContainerParametersResourceCheckerTest.php b/Tests/Config/ContainerParametersResourceCheckerTest.php index 4b089936e..eb5fc5a99 100644 --- a/Tests/Config/ContainerParametersResourceCheckerTest.php +++ b/Tests/Config/ContainerParametersResourceCheckerTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Config; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\ResourceCheckerInterface; use Symfony\Component\DependencyInjection\Config\ContainerParametersResource; use Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker; @@ -20,8 +19,6 @@ class ContainerParametersResourceCheckerTest extends TestCase { - use ForwardCompatTestTrait; - /** @var ContainerParametersResource */ private $resource; @@ -31,7 +28,7 @@ class ContainerParametersResourceCheckerTest extends TestCase /** @var ContainerInterface */ private $container; - private function doSetUp() + protected function setUp() { $this->resource = new ContainerParametersResource(['locales' => ['fr', 'en'], 'default_locale' => 'fr']); $this->container = $this->getMockBuilder(ContainerInterface::class)->getMock(); diff --git a/Tests/Config/ContainerParametersResourceTest.php b/Tests/Config/ContainerParametersResourceTest.php index 392c84871..e177ac16b 100644 --- a/Tests/Config/ContainerParametersResourceTest.php +++ b/Tests/Config/ContainerParametersResourceTest.php @@ -12,17 +12,14 @@ namespace Symfony\Component\DependencyInjection\Tests\Config; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Config\ContainerParametersResource; class ContainerParametersResourceTest extends TestCase { - use ForwardCompatTestTrait; - /** @var ContainerParametersResource */ private $resource; - private function doSetUp() + protected function setUp() { $this->resource = new ContainerParametersResource(['locales' => ['fr', 'en'], 'default_locale' => 'fr']); } diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index b42d60001..199179c9b 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -16,7 +16,6 @@ use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface as PsrContainerInterface; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\Resource\ComposerResource; use Symfony\Component\Config\Resource\DirectoryResource; use Symfony\Component\Config\Resource\FileResource; @@ -46,8 +45,6 @@ class ContainerBuilderTest extends TestCase { - use ForwardCompatTestTrait; - public function testDefaultRegisteredDefinitions() { $builder = new ContainerBuilder(); diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index 286a98b9d..ebc422ca9 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; @@ -20,8 +19,6 @@ class ContainerTest extends TestCase { - use ForwardCompatTestTrait; - public function testConstructor() { $sc = new Container(); diff --git a/Tests/CrossCheckTest.php b/Tests/CrossCheckTest.php index 6afc5d9ae..fe132af48 100644 --- a/Tests/CrossCheckTest.php +++ b/Tests/CrossCheckTest.php @@ -12,17 +12,14 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; class CrossCheckTest extends TestCase { - use ForwardCompatTestTrait; - protected static $fixturesPath; - private static function doSetUpBeforeClass() + public static function setUpBeforeClass() { self::$fixturesPath = __DIR__.'/Fixtures/'; diff --git a/Tests/DefinitionDecoratorTest.php b/Tests/DefinitionDecoratorTest.php index 093c5d060..8d382f81f 100644 --- a/Tests/DefinitionDecoratorTest.php +++ b/Tests/DefinitionDecoratorTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\DefinitionDecorator; /** @@ -20,8 +19,6 @@ */ class DefinitionDecoratorTest extends TestCase { - use ForwardCompatTestTrait; - public function testConstructor() { $def = new DefinitionDecorator('foo'); diff --git a/Tests/DefinitionTest.php b/Tests/DefinitionTest.php index 6657761e0..1f1cd380f 100644 --- a/Tests/DefinitionTest.php +++ b/Tests/DefinitionTest.php @@ -12,13 +12,10 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Definition; class DefinitionTest extends TestCase { - use ForwardCompatTestTrait; - public function testConstructor() { $def = new Definition('stdClass'); diff --git a/Tests/Dumper/GraphvizDumperTest.php b/Tests/Dumper/GraphvizDumperTest.php index 23f1cb8bb..ea11c7c53 100644 --- a/Tests/Dumper/GraphvizDumperTest.php +++ b/Tests/Dumper/GraphvizDumperTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Dumper; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Dumper\GraphvizDumper; @@ -20,11 +19,9 @@ class GraphvizDumperTest extends TestCase { - use ForwardCompatTestTrait; - protected static $fixturesPath; - private static function doSetUpBeforeClass() + public static function setUpBeforeClass() { self::$fixturesPath = __DIR__.'/../Fixtures/'; } diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index 118758ee0..1d3aa3397 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -14,7 +14,6 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Warning; use Psr\Container\ContainerInterface; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; @@ -43,11 +42,9 @@ class PhpDumperTest extends TestCase { - use ForwardCompatTestTrait; - protected static $fixturesPath; - private static function doSetUpBeforeClass() + public static function setUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); } diff --git a/Tests/Dumper/XmlDumperTest.php b/Tests/Dumper/XmlDumperTest.php index f9c545f01..e660c7e80 100644 --- a/Tests/Dumper/XmlDumperTest.php +++ b/Tests/Dumper/XmlDumperTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Dumper; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -22,11 +21,9 @@ class XmlDumperTest extends TestCase { - use ForwardCompatTestTrait; - protected static $fixturesPath; - private static function doSetUpBeforeClass() + public static function setUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); } diff --git a/Tests/Dumper/YamlDumperTest.php b/Tests/Dumper/YamlDumperTest.php index e94dcfb19..49ee8e6f3 100644 --- a/Tests/Dumper/YamlDumperTest.php +++ b/Tests/Dumper/YamlDumperTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Dumper; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -25,11 +24,9 @@ class YamlDumperTest extends TestCase { - use ForwardCompatTestTrait; - protected static $fixturesPath; - private static function doSetUpBeforeClass() + public static function setUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); } diff --git a/Tests/EnvVarProcessorTest.php b/Tests/EnvVarProcessorTest.php index a0190af93..2830d46a7 100644 --- a/Tests/EnvVarProcessorTest.php +++ b/Tests/EnvVarProcessorTest.php @@ -3,15 +3,12 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\EnvVarProcessor; class EnvVarProcessorTest extends TestCase { - use ForwardCompatTestTrait; - const TEST_CONST = 'test'; /** diff --git a/Tests/Extension/ExtensionTest.php b/Tests/Extension/ExtensionTest.php index cd01a897f..9f35b4a41 100644 --- a/Tests/Extension/ExtensionTest.php +++ b/Tests/Extension/ExtensionTest.php @@ -12,14 +12,11 @@ namespace Symfony\Component\DependencyInjection\Tests\Extension; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; class ExtensionTest extends TestCase { - use ForwardCompatTestTrait; - /** * @dataProvider getResolvedEnabledFixtures */ diff --git a/Tests/Fixtures/Prototype/OtherDir/Component1/Dir2/Service2.php b/Tests/Fixtures/Prototype/OtherDir/Component1/Dir2/Service2.php index 44e7cacd2..ba103fce0 100644 --- a/Tests/Fixtures/Prototype/OtherDir/Component1/Dir2/Service2.php +++ b/Tests/Fixtures/Prototype/OtherDir/Component1/Dir2/Service2.php @@ -4,5 +4,4 @@ class Service2 { - } diff --git a/Tests/Fixtures/Prototype/OtherDir/Component2/Dir2/Service5.php b/Tests/Fixtures/Prototype/OtherDir/Component2/Dir2/Service5.php index 691b42771..d2cff5b95 100644 --- a/Tests/Fixtures/Prototype/OtherDir/Component2/Dir2/Service5.php +++ b/Tests/Fixtures/Prototype/OtherDir/Component2/Dir2/Service5.php @@ -4,5 +4,4 @@ class Service5 { - } diff --git a/Tests/Fixtures/StubbedTranslator.php b/Tests/Fixtures/StubbedTranslator.php index 8e1c2a6ce..eed18426a 100644 --- a/Tests/Fixtures/StubbedTranslator.php +++ b/Tests/Fixtures/StubbedTranslator.php @@ -20,7 +20,6 @@ class StubbedTranslator { public function __construct(ContainerInterface $container) { - } public function addResource($format, $resource, $locale, $domain = null) diff --git a/Tests/Loader/DirectoryLoaderTest.php b/Tests/Loader/DirectoryLoaderTest.php index 59f7e9ad3..b4f969a0e 100644 --- a/Tests/Loader/DirectoryLoaderTest.php +++ b/Tests/Loader/DirectoryLoaderTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -23,19 +22,17 @@ class DirectoryLoaderTest extends TestCase { - use ForwardCompatTestTrait; - private static $fixturesPath; private $container; private $loader; - private static function doSetUpBeforeClass() + public static function setUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); } - private function doSetUp() + protected function setUp() { $locator = new FileLocator(self::$fixturesPath); $this->container = new ContainerBuilder(); diff --git a/Tests/Loader/FileLoaderTest.php b/Tests/Loader/FileLoaderTest.php index 426b720f3..7d002ff03 100644 --- a/Tests/Loader/FileLoaderTest.php +++ b/Tests/Loader/FileLoaderTest.php @@ -14,7 +14,6 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Warning; use Psr\Container\ContainerInterface as PsrContainerInterface; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -37,11 +36,9 @@ class FileLoaderTest extends TestCase { - use ForwardCompatTestTrait; - protected static $fixturesPath; - private static function doSetUpBeforeClass() + public static function setUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../'); } diff --git a/Tests/Loader/IniFileLoaderTest.php b/Tests/Loader/IniFileLoaderTest.php index 06cc8b2eb..6f02b9ff6 100644 --- a/Tests/Loader/IniFileLoaderTest.php +++ b/Tests/Loader/IniFileLoaderTest.php @@ -12,19 +12,16 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; class IniFileLoaderTest extends TestCase { - use ForwardCompatTestTrait; - protected $container; protected $loader; - private function doSetUp() + protected function setUp() { $this->container = new ContainerBuilder(); $this->loader = new IniFileLoader($this->container, new FileLocator(realpath(__DIR__.'/../Fixtures/').'/ini')); diff --git a/Tests/Loader/LoaderResolverTest.php b/Tests/Loader/LoaderResolverTest.php index 3200e3448..9167e18ce 100644 --- a/Tests/Loader/LoaderResolverTest.php +++ b/Tests/Loader/LoaderResolverTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -24,14 +23,12 @@ class LoaderResolverTest extends TestCase { - use ForwardCompatTestTrait; - private static $fixturesPath; /** @var LoaderResolver */ private $resolver; - private function doSetUp() + protected function setUp() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); diff --git a/Tests/Loader/PhpFileLoaderTest.php b/Tests/Loader/PhpFileLoaderTest.php index ab2fb11f6..e1812305e 100644 --- a/Tests/Loader/PhpFileLoaderTest.php +++ b/Tests/Loader/PhpFileLoaderTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; @@ -21,8 +20,6 @@ class PhpFileLoaderTest extends TestCase { - use ForwardCompatTestTrait; - public function testSupports() { $loader = new PhpFileLoader(new ContainerBuilder(), new FileLocator()); diff --git a/Tests/Loader/XmlFileLoaderTest.php b/Tests/Loader/XmlFileLoaderTest.php index 6c33dba13..9fbeed91f 100644 --- a/Tests/Loader/XmlFileLoaderTest.php +++ b/Tests/Loader/XmlFileLoaderTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Config\Resource\FileResource; @@ -34,11 +33,9 @@ class XmlFileLoaderTest extends TestCase { - use ForwardCompatTestTrait; - protected static $fixturesPath; - private static function doSetUpBeforeClass() + public static function setUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); require_once self::$fixturesPath.'/includes/foo.php'; diff --git a/Tests/Loader/YamlFileLoaderTest.php b/Tests/Loader/YamlFileLoaderTest.php index f149d7a55..1d187848b 100644 --- a/Tests/Loader/YamlFileLoaderTest.php +++ b/Tests/Loader/YamlFileLoaderTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Config\Resource\FileResource; @@ -34,11 +33,9 @@ class YamlFileLoaderTest extends TestCase { - use ForwardCompatTestTrait; - protected static $fixturesPath; - private static function doSetUpBeforeClass() + public static function setUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); require_once self::$fixturesPath.'/includes/foo.php'; diff --git a/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php b/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php index e0a978580..8c4a99f7d 100644 --- a/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php +++ b/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php @@ -12,13 +12,10 @@ namespace Symfony\Component\DependencyInjection\Tests\ParameterBag; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; class EnvPlaceholderParameterBagTest extends TestCase { - use ForwardCompatTestTrait; - public function testGetThrowsInvalidArgumentExceptionIfEnvNameContainsNonWordCharacters() { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); diff --git a/Tests/ParameterBag/FrozenParameterBagTest.php b/Tests/ParameterBag/FrozenParameterBagTest.php index 532a5a014..ed89c8e4e 100644 --- a/Tests/ParameterBag/FrozenParameterBagTest.php +++ b/Tests/ParameterBag/FrozenParameterBagTest.php @@ -12,13 +12,10 @@ namespace Symfony\Component\DependencyInjection\Tests\ParameterBag; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; class FrozenParameterBagTest extends TestCase { - use ForwardCompatTestTrait; - public function testConstructor() { $parameters = [ diff --git a/Tests/ParameterBag/ParameterBagTest.php b/Tests/ParameterBag/ParameterBagTest.php index 31a1957c1..0a75b445b 100644 --- a/Tests/ParameterBag/ParameterBagTest.php +++ b/Tests/ParameterBag/ParameterBagTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\ParameterBag; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException; use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; @@ -20,8 +19,6 @@ class ParameterBagTest extends TestCase { - use ForwardCompatTestTrait; - public function testConstructor() { $bag = new ParameterBag($parameters = [ diff --git a/Tests/ServiceLocatorTest.php b/Tests/ServiceLocatorTest.php index a88a489bb..52466af94 100644 --- a/Tests/ServiceLocatorTest.php +++ b/Tests/ServiceLocatorTest.php @@ -12,15 +12,12 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; class ServiceLocatorTest extends TestCase { - use ForwardCompatTestTrait; - public function testHas() { $locator = new ServiceLocator([ From dddd42d9c6fec4eb83bb5048c8b238328c2177f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 5 Aug 2019 10:06:54 +0200 Subject: [PATCH 51/72] Use namespaced Phpunit classes --- Tests/Compiler/ResolveInstanceofConditionalsPassTest.php | 4 ++-- Tests/Config/ContainerParametersResourceCheckerTest.php | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php b/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php index 1996216aa..83be84bd0 100644 --- a/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php +++ b/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php @@ -201,7 +201,7 @@ public function testBadInterfaceForAutomaticInstanceofIsOk() public function testProcessThrowsExceptionForAutoconfiguredCalls() { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); - $this->expectExceptionMessage('Autoconfigured instanceof for type "PHPUnit\Framework\TestCase" defines method calls but these are not supported and should be removed.'); + $this->expectExceptionMessageRegExp('/Autoconfigured instanceof for type "PHPUnit[\\\\_]Framework[\\\\_]TestCase" defines method calls but these are not supported and should be removed\./'); $container = new ContainerBuilder(); $container->registerForAutoconfiguration(parent::class) ->addMethodCall('setFoo'); @@ -212,7 +212,7 @@ public function testProcessThrowsExceptionForAutoconfiguredCalls() public function testProcessThrowsExceptionForArguments() { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); - $this->expectExceptionMessage('Autoconfigured instanceof for type "PHPUnit\Framework\TestCase" defines arguments but these are not supported and should be removed.'); + $this->expectExceptionMessageRegExp('/Autoconfigured instanceof for type "PHPUnit[\\\\_]Framework[\\\\_]TestCase" defines arguments but these are not supported and should be removed\./'); $container = new ContainerBuilder(); $container->registerForAutoconfiguration(parent::class) ->addArgument('bar'); diff --git a/Tests/Config/ContainerParametersResourceCheckerTest.php b/Tests/Config/ContainerParametersResourceCheckerTest.php index eb5fc5a99..51af451c1 100644 --- a/Tests/Config/ContainerParametersResourceCheckerTest.php +++ b/Tests/Config/ContainerParametersResourceCheckerTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Config; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\ResourceCheckerInterface; use Symfony\Component\DependencyInjection\Config\ContainerParametersResource; @@ -52,15 +53,15 @@ public function testIsFresh(callable $mockContainer, $expected) public function isFreshProvider() { - yield 'not fresh on missing parameter' => [function (\PHPUnit_Framework_MockObject_MockObject $container) { + yield 'not fresh on missing parameter' => [function (MockObject $container) { $container->method('hasParameter')->with('locales')->willReturn(false); }, false]; - yield 'not fresh on different value' => [function (\PHPUnit_Framework_MockObject_MockObject $container) { + yield 'not fresh on different value' => [function (MockObject $container) { $container->method('getParameter')->with('locales')->willReturn(['nl', 'es']); }, false]; - yield 'fresh on every identical parameters' => [function (\PHPUnit_Framework_MockObject_MockObject $container) { + yield 'fresh on every identical parameters' => [function (MockObject $container) { $container->expects($this->exactly(2))->method('hasParameter')->willReturn(true); $container->expects($this->exactly(2))->method('getParameter') ->withConsecutive( From fb6abbc7239314e8adc459d1075eb47cb5bc1e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 5 Aug 2019 23:28:51 +0200 Subject: [PATCH 52/72] Use assert assertContainsEquals when needed --- Tests/Compiler/MergeExtensionConfigurationPassTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Compiler/MergeExtensionConfigurationPassTest.php b/Tests/Compiler/MergeExtensionConfigurationPassTest.php index dc0a37d60..13692657b 100644 --- a/Tests/Compiler/MergeExtensionConfigurationPassTest.php +++ b/Tests/Compiler/MergeExtensionConfigurationPassTest.php @@ -85,7 +85,7 @@ public function testExtensionConfigurationIsTrackedByDefault() $pass = new MergeExtensionConfigurationPass(); $pass->process($container); - $this->assertContains(new FileResource(__FILE__), $container->getResources(), '', false, false); + $this->assertContainsEquals(new FileResource(__FILE__), $container->getResources()); } public function testOverriddenEnvsAreMerged() From 8371dca04fc1511b11de0eab8e47bbc421ae6f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Tue, 6 Aug 2019 00:37:40 +0200 Subject: [PATCH 53/72] Use assertStringContainsString when needed --- Tests/Loader/XmlFileLoaderTest.php | 4 ++-- Tests/ParameterBag/EnvPlaceholderParameterBagTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Loader/XmlFileLoaderTest.php b/Tests/Loader/XmlFileLoaderTest.php index 9fbeed91f..1b6e51c56 100644 --- a/Tests/Loader/XmlFileLoaderTest.php +++ b/Tests/Loader/XmlFileLoaderTest.php @@ -438,7 +438,7 @@ public function testExtensions() $e = $e->getPrevious(); $this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); - $this->assertContains('The attribute \'bar\' is not allowed', $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); + $this->assertStringContainsString('The attribute \'bar\' is not allowed', $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); } // non-registered extension @@ -478,7 +478,7 @@ public function testExtensionInPhar() $e = $e->getPrevious(); $this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); - $this->assertContains('The attribute \'bar\' is not allowed', $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); + $this->assertStringContainsString('The attribute \'bar\' is not allowed', $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); } } diff --git a/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php b/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php index 8c4a99f7d..4fcb2c840 100644 --- a/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php +++ b/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php @@ -41,7 +41,7 @@ public function testMergeWillNotDuplicateIdenticalParameters() $this->assertCount(1, $placeholderForVariable); $this->assertIsString($placeholder); - $this->assertContains($envVariableName, $placeholder); + $this->assertStringContainsString($envVariableName, $placeholder); } public function testMergeWhereFirstBagIsEmptyWillWork() @@ -64,7 +64,7 @@ public function testMergeWhereFirstBagIsEmptyWillWork() $this->assertCount(1, $placeholderForVariable); $this->assertIsString($placeholder); - $this->assertContains($envVariableName, $placeholder); + $this->assertStringContainsString($envVariableName, $placeholder); } public function testMergeWherePlaceholderOnlyExistsInSecond() From 8cc59b40e8ad1bec76ae738ca94ab005ace96f02 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 7 Aug 2019 13:13:33 +0200 Subject: [PATCH 54/72] Fix inconsistent return points. --- Compiler/AutowirePass.php | 12 ++++++++---- Loader/XmlFileLoader.php | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Compiler/AutowirePass.php b/Compiler/AutowirePass.php index c8e7a0f57..f2a5b4699 100644 --- a/Compiler/AutowirePass.php +++ b/Compiler/AutowirePass.php @@ -318,7 +318,7 @@ private function getAutowiredReference(TypedReference $reference, $deprecationMe } if (!$reference->canBeAutoregistered() || isset($this->types[$type]) || isset($this->ambiguousServiceTypes[$type])) { - return; + return null; } if (isset($this->autowired[$type])) { @@ -328,6 +328,8 @@ private function getAutowiredReference(TypedReference $reference, $deprecationMe if (!$this->strictMode) { return $this->createAutowiredDefinition($type); } + + return null; } /** @@ -425,7 +427,7 @@ private function set($type, $id) private function createAutowiredDefinition($type) { if (!($typeHint = $this->container->getReflectionClass($type, false)) || !$typeHint->isInstantiable()) { - return; + return null; } $currentId = $this->currentId; @@ -445,7 +447,7 @@ private function createAutowiredDefinition($type) $this->lastFailure = $e->getMessage(); $this->container->log($this, $this->lastFailure); - return; + return null; } finally { $this->throwOnAutowiringException = $originalThrowSetting; $this->currentId = $currentId; @@ -518,7 +520,7 @@ private function createTypeAlternatives(TypedReference $reference) } elseif ($reference->getRequiringClass() && !$reference->canBeAutoregistered() && !$this->strictMode) { return ' It cannot be auto-registered because it is from a different root namespace.'; } else { - return; + return ''; } return sprintf(' You should maybe alias this %s to %s.', class_exists($type, false) ? 'class' : 'interface', $message); @@ -572,5 +574,7 @@ private function getAliasesSuggestionForType($type, $extraContext = null) if ($aliases) { return sprintf('Try changing the type-hint%s to "%s" instead.', $extraContext, $aliases[0]); } + + return null; } } diff --git a/Loader/XmlFileLoader.php b/Loader/XmlFileLoader.php index 718592d8e..60102eaa8 100644 --- a/Loader/XmlFileLoader.php +++ b/Loader/XmlFileLoader.php @@ -211,7 +211,7 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults) $alias->setPublic($defaults['public']); } - return; + return null; } if ($this->isLoadingInstanceof) { From 7f3d063e0d025e3cb819ed0dff80936d2304a37b Mon Sep 17 00:00:00 2001 From: Arman Hosseini <44655055+Arman-Hosseini@users.noreply.github.com> Date: Mon, 29 Jul 2019 21:55:29 +0430 Subject: [PATCH 55/72] Improve some URLs --- Compiler/PriorityTaggedServiceTrait.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Compiler/PriorityTaggedServiceTrait.php b/Compiler/PriorityTaggedServiceTrait.php index daff3495a..5b7475b39 100644 --- a/Compiler/PriorityTaggedServiceTrait.php +++ b/Compiler/PriorityTaggedServiceTrait.php @@ -28,8 +28,8 @@ trait PriorityTaggedServiceTrait * and knowing that the \SplPriorityQueue class does not respect the FIFO method, * we should not use that class. * - * @see https://bugs.php.net/bug.php?id=53710 - * @see https://bugs.php.net/bug.php?id=60926 + * @see https://bugs.php.net/53710 + * @see https://bugs.php.net/60926 * * @param string $tagName * @param ContainerBuilder $container From 9f0bd4200e44c56a24927b5a47b50c73ccab2135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 8 Aug 2019 21:45:19 +0200 Subject: [PATCH 56/72] Replace warning by isolated test --- Tests/Compiler/AutowirePassTest.php | 20 +++++++++----------- Tests/Compiler/ResolveBindingsPassTest.php | 7 +++---- Tests/Dumper/PhpDumperTest.php | 8 +++----- Tests/Loader/FileLoaderTest.php | 22 +++++++++------------- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/Tests/Compiler/AutowirePassTest.php b/Tests/Compiler/AutowirePassTest.php index 84d396beb..e84968100 100644 --- a/Tests/Compiler/AutowirePassTest.php +++ b/Tests/Compiler/AutowirePassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use PHPUnit\Framework\Warning; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Compiler\AutowirePass; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; @@ -378,13 +377,13 @@ public function testClassNotFoundThrowsException() $pass->process($container); } + /** + * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 + */ public function testParentClassNotFoundThrowsException() { $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); $this->expectExceptionMessage('Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class is missing a parent class (Class Symfony\Bug\NotExistClass not found).'); - if (\PHP_VERSION_ID >= 70400) { - throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); - } $container = new ContainerBuilder(); @@ -692,12 +691,11 @@ public function getCreateResourceTests() ]; } + /** + * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 + */ public function testIgnoreServiceWithClassNotExisting() { - if (\PHP_VERSION_ID >= 70400) { - throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); - } - $container = new ContainerBuilder(); $container->register('class_not_exist', __NAMESPACE__.'\OptionalServiceClass'); @@ -894,13 +892,13 @@ public function testExceptionWhenAliasExists() $pass->process($container); } + /** + * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 + */ public function testExceptionWhenAliasDoesNotExist() { $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); $this->expectExceptionMessage('Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. You should maybe alias this class to one of these existing services: "i", "i2".'); - if (\PHP_VERSION_ID >= 70400) { - throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); - } $container = new ContainerBuilder(); diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index 85d6e0262..c91eeadfd 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; -use PHPUnit\Framework\Warning; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass; @@ -62,13 +61,13 @@ public function testUnusedBinding() $pass->process($container); } + /** + * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 + */ public function testMissingParent() { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $this->expectExceptionMessageRegExp('/Unused binding "\$quz" in service [\s\S]+/'); - if (\PHP_VERSION_ID >= 70400) { - throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); - } $container = new ContainerBuilder(); diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index 1d3aa3397..20f9da9e1 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Dumper; use PHPUnit\Framework\TestCase; -use PHPUnit\Framework\Warning; use Psr\Container\ContainerInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; @@ -894,12 +893,11 @@ public function testInlineSelfRef() $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_inline_self_ref.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Inline_Self_Ref'])); } + /** + * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 + */ public function testHotPathOptimizations() { - if (\PHP_VERSION_ID >= 70400) { - throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); - } - $container = include self::$fixturesPath.'/containers/container_inline_requires.php'; $container->setParameter('inline_requires', true); $container->compile(); diff --git a/Tests/Loader/FileLoaderTest.php b/Tests/Loader/FileLoaderTest.php index 7d002ff03..3a2b59315 100644 --- a/Tests/Loader/FileLoaderTest.php +++ b/Tests/Loader/FileLoaderTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; -use PHPUnit\Framework\Warning; use Psr\Container\ContainerInterface as PsrContainerInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; @@ -108,12 +107,11 @@ public function testRegisterClasses() ); } + /** + * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 + */ public function testRegisterClassesWithExclude() { - if (\PHP_VERSION_ID >= 70400) { - throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); - } - $container = new ContainerBuilder(); $container->setParameter('other_dir', 'OtherDir'); $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures')); @@ -141,12 +139,11 @@ public function testRegisterClassesWithExclude() ); } + /** + * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 + */ public function testNestedRegisterClasses() { - if (\PHP_VERSION_ID >= 70400) { - throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); - } - $container = new ContainerBuilder(); $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures')); @@ -173,12 +170,11 @@ public function testNestedRegisterClasses() $this->assertFalse($alias->isPrivate()); } + /** + * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 + */ public function testMissingParentClass() { - if (\PHP_VERSION_ID >= 70400) { - throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.'); - } - $container = new ContainerBuilder(); $container->setParameter('bad_classes_dir', 'BadClasses'); $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures')); From 76a51651aba67b8b21d83ea3fe60df8b82fca98a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 12 Aug 2019 22:21:04 +0200 Subject: [PATCH 57/72] Fix return statements --- LazyProxy/ProxyHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LazyProxy/ProxyHelper.php b/LazyProxy/ProxyHelper.php index fb21ba2e4..33737082a 100644 --- a/LazyProxy/ProxyHelper.php +++ b/LazyProxy/ProxyHelper.php @@ -37,7 +37,7 @@ public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionPa $type = method_exists($r, 'getReturnType') ? $r->getReturnType() : null; } if (!$type) { - return; + return null; } if (!\is_string($type)) { $name = $type instanceof \ReflectionNamedType ? $type->getName() : $type->__toString(); @@ -53,7 +53,7 @@ public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionPa return $prefix.$name; } if (!$r instanceof \ReflectionMethod) { - return; + return null; } if ('self' === $lcName) { return $prefix.$r->getDeclaringClass()->name; From 7c980275be7c28b78219f169211021ced49466b1 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 13 Aug 2019 22:09:12 +0200 Subject: [PATCH 58/72] [DI] fix docblocks in Container* --- Container.php | 6 +++--- ContainerBuilder.php | 10 +++++----- ContainerInterface.php | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Container.php b/Container.php index f2215acf1..ab69579ad 100644 --- a/Container.php +++ b/Container.php @@ -162,8 +162,8 @@ public function setParameter($name, $value) * Setting a synthetic service to null resets it: has() returns false and get() * behaves in the same way as if the service was never created. * - * @param string $id The service identifier - * @param object $service The service instance + * @param string $id The service identifier + * @param object|null $service The service instance */ public function set($id, $service) { @@ -263,7 +263,7 @@ public function has($id) * @param string $id The service identifier * @param int $invalidBehavior The behavior when the service does not exist * - * @return object The associated service + * @return object|null The associated service * * @throws ServiceCircularReferenceException When a circular reference is detected * @throws ServiceNotFoundException When the service is not defined diff --git a/ContainerBuilder.php b/ContainerBuilder.php index 6676c33ca..a30d984e1 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -519,8 +519,8 @@ public function getCompiler() /** * Sets a service. * - * @param string $id The service identifier - * @param object $service The service instance + * @param string $id The service identifier + * @param object|null $service The service instance * * @throws BadMethodCallException When this ContainerBuilder is compiled */ @@ -571,7 +571,7 @@ public function has($id) * @param string $id The service identifier * @param int $invalidBehavior The behavior when the service does not exist * - * @return object The associated service + * @return object|null The associated service * * @throws InvalidArgumentException when no definitions are available * @throws ServiceCircularReferenceException When a circular reference is detected @@ -1104,7 +1104,7 @@ public function findDefinition($id) * @param string $id The service identifier * @param bool $tryProxy Whether to try proxying the service with a lazy proxy * - * @return object The service described by the service definition + * @return mixed The service described by the service definition * * @throws RuntimeException When the factory definition is incomplete * @throws RuntimeException When the service is a synthetic service @@ -1651,7 +1651,7 @@ private function callMethod($service, $call, array &$inlineServices) * Shares a given service in the container. * * @param Definition $definition - * @param object $service + * @param mixed $service * @param string|null $id */ private function shareService(Definition $definition, $service, $id, array &$inlineServices) diff --git a/ContainerInterface.php b/ContainerInterface.php index 2274ec7bb..c5ab4c2ed 100644 --- a/ContainerInterface.php +++ b/ContainerInterface.php @@ -32,8 +32,8 @@ interface ContainerInterface extends PsrContainerInterface /** * Sets a service. * - * @param string $id The service identifier - * @param object $service The service instance + * @param string $id The service identifier + * @param object|null $service The service instance */ public function set($id, $service); @@ -43,7 +43,7 @@ public function set($id, $service); * @param string $id The service identifier * @param int $invalidBehavior The behavior when the service does not exist * - * @return object The associated service + * @return object|null The associated service * * @throws ServiceCircularReferenceException When a circular reference is detected * @throws ServiceNotFoundException When the service is not defined From d25a40fe6332bee9d52c4a11561b17c3a863d23c Mon Sep 17 00:00:00 2001 From: Philippe Segatori Date: Tue, 13 Aug 2019 22:27:05 +0200 Subject: [PATCH 59/72] Remove superfluous phpdoc tags --- Argument/RewindableGenerator.php | 1 - Compiler/AbstractRecursivePass.php | 6 ++-- Compiler/AutowirePass.php | 11 +----- Compiler/Compiler.php | 5 ++- Compiler/PassConfig.php | 5 ++- Compiler/PriorityTaggedServiceTrait.php | 3 +- Compiler/ResolveReferencesToAliasesPass.php | 3 +- Compiler/ServiceLocatorTagPass.php | 5 ++- Compiler/ServiceReferenceGraph.php | 3 -- Compiler/ServiceReferenceGraphEdge.php | 10 +++--- ContainerBuilder.php | 1 - Definition.php | 2 -- Dumper/PhpDumper.php | 19 ++++------- Dumper/XmlDumper.php | 15 +++----- Dumper/YamlDumper.php | 7 ++-- LazyProxy/PhpDumper/DumperInterface.php | 4 +-- Loader/FileLoader.php | 3 +- Loader/XmlFileLoader.php | 38 +++++++-------------- Loader/YamlFileLoader.php | 6 ---- 19 files changed, 42 insertions(+), 105 deletions(-) diff --git a/Argument/RewindableGenerator.php b/Argument/RewindableGenerator.php index f8f771d62..b00a36c34 100644 --- a/Argument/RewindableGenerator.php +++ b/Argument/RewindableGenerator.php @@ -20,7 +20,6 @@ class RewindableGenerator implements \IteratorAggregate, \Countable private $count; /** - * @param callable $generator * @param int|callable $count */ public function __construct(callable $generator, $count) diff --git a/Compiler/AbstractRecursivePass.php b/Compiler/AbstractRecursivePass.php index cff09d57d..a89bf1647 100644 --- a/Compiler/AbstractRecursivePass.php +++ b/Compiler/AbstractRecursivePass.php @@ -81,8 +81,7 @@ protected function processValue($value, $isRoot = false) } /** - * @param Definition $definition - * @param bool $required + * @param bool $required * * @return \ReflectionFunctionAbstract|null * @@ -137,8 +136,7 @@ protected function getConstructor(Definition $definition, $required) } /** - * @param Definition $definition - * @param string $method + * @param string $method * * @throws RuntimeException * diff --git a/Compiler/AutowirePass.php b/Compiler/AutowirePass.php index f2a5b4699..91b279c77 100644 --- a/Compiler/AutowirePass.php +++ b/Compiler/AutowirePass.php @@ -79,8 +79,6 @@ public function process(ContainerBuilder $container) /** * Creates a resource to help know if this service has changed. * - * @param \ReflectionClass $reflectionClass - * * @return AutowireServiceResource * * @deprecated since version 3.3, to be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead. @@ -168,9 +166,6 @@ private function doProcessValue($value, $isRoot = false) } /** - * @param \ReflectionClass $reflectionClass - * @param array $methodCalls - * * @return array */ private function autowireCalls(\ReflectionClass $reflectionClass, array $methodCalls) @@ -205,9 +200,6 @@ private function autowireCalls(\ReflectionClass $reflectionClass, array $methodC /** * Autowires the constructor or a method. * - * @param \ReflectionFunctionAbstract $reflectionMethod - * @param array $arguments - * * @return array The autowired arguments * * @throws AutowiringFailedException @@ -350,8 +342,7 @@ private function populateAvailableTypes($onlyAutowiringTypes = false) /** * Populates the list of available types for a given definition. * - * @param string $id - * @param Definition $definition + * @param string $id */ private function populateAvailableType($id, Definition $definition, $onlyAutowiringTypes) { diff --git a/Compiler/Compiler.php b/Compiler/Compiler.php index a6ae94d8c..bf0d9c3ea 100644 --- a/Compiler/Compiler.php +++ b/Compiler/Compiler.php @@ -73,9 +73,8 @@ public function getLoggingFormatter() /** * Adds a pass to the PassConfig. * - * @param CompilerPassInterface $pass A compiler pass - * @param string $type The type of the pass - * @param int $priority Used to sort the passes + * @param CompilerPassInterface $pass A compiler pass + * @param string $type The type of the pass */ public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/*, int $priority = 0*/) { diff --git a/Compiler/PassConfig.php b/Compiler/PassConfig.php index 77f4e9531..323faad57 100644 --- a/Compiler/PassConfig.php +++ b/Compiler/PassConfig.php @@ -113,9 +113,8 @@ public function getPasses() /** * Adds a pass. * - * @param CompilerPassInterface $pass A Compiler pass - * @param string $type The pass type - * @param int $priority Used to sort the passes + * @param CompilerPassInterface $pass A Compiler pass + * @param string $type The pass type * * @throws InvalidArgumentException when a pass type doesn't exist */ diff --git a/Compiler/PriorityTaggedServiceTrait.php b/Compiler/PriorityTaggedServiceTrait.php index 5b7475b39..c7e12536e 100644 --- a/Compiler/PriorityTaggedServiceTrait.php +++ b/Compiler/PriorityTaggedServiceTrait.php @@ -31,8 +31,7 @@ trait PriorityTaggedServiceTrait * @see https://bugs.php.net/53710 * @see https://bugs.php.net/60926 * - * @param string $tagName - * @param ContainerBuilder $container + * @param string $tagName * * @return Reference[] */ diff --git a/Compiler/ResolveReferencesToAliasesPass.php b/Compiler/ResolveReferencesToAliasesPass.php index b80e45256..2559dcf10 100644 --- a/Compiler/ResolveReferencesToAliasesPass.php +++ b/Compiler/ResolveReferencesToAliasesPass.php @@ -56,8 +56,7 @@ protected function processValue($value, $isRoot = false) /** * Resolves an alias into a definition id. * - * @param string $id The definition or alias id to resolve - * @param ContainerBuilder $container + * @param string $id The definition or alias id to resolve * * @return string The definition id with aliases resolved */ diff --git a/Compiler/ServiceLocatorTagPass.php b/Compiler/ServiceLocatorTagPass.php index 51de4d7ac..0d77d7e48 100644 --- a/Compiler/ServiceLocatorTagPass.php +++ b/Compiler/ServiceLocatorTagPass.php @@ -76,9 +76,8 @@ protected function processValue($value, $isRoot = false) } /** - * @param ContainerBuilder $container - * @param Reference[] $refMap - * @param string|null $callerId + * @param Reference[] $refMap + * @param string|null $callerId * * @return Reference */ diff --git a/Compiler/ServiceReferenceGraph.php b/Compiler/ServiceReferenceGraph.php index 23d4745ed..e419e297e 100644 --- a/Compiler/ServiceReferenceGraph.php +++ b/Compiler/ServiceReferenceGraph.php @@ -89,9 +89,6 @@ public function clear() * @param string $destId * @param mixed $destValue * @param string $reference - * @param bool $lazy - * @param bool $weak - * @param bool $byConstructor */ public function connect($sourceId, $sourceValue, $destId, $destValue = null, $reference = null/*, bool $lazy = false, bool $weak = false, bool $byConstructor = false*/) { diff --git a/Compiler/ServiceReferenceGraphEdge.php b/Compiler/ServiceReferenceGraphEdge.php index 5b8c84b6d..911e7a5f5 100644 --- a/Compiler/ServiceReferenceGraphEdge.php +++ b/Compiler/ServiceReferenceGraphEdge.php @@ -28,12 +28,10 @@ class ServiceReferenceGraphEdge private $byConstructor; /** - * @param ServiceReferenceGraphNode $sourceNode - * @param ServiceReferenceGraphNode $destNode - * @param mixed $value - * @param bool $lazy - * @param bool $weak - * @param bool $byConstructor + * @param mixed $value + * @param bool $lazy + * @param bool $weak + * @param bool $byConstructor */ public function __construct(ServiceReferenceGraphNode $sourceNode, ServiceReferenceGraphNode $destNode, $value = null, $lazy = false, $weak = false, $byConstructor = false) { diff --git a/ContainerBuilder.php b/ContainerBuilder.php index a30d984e1..4797047bb 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -1650,7 +1650,6 @@ private function callMethod($service, $call, array &$inlineServices) /** * Shares a given service in the container. * - * @param Definition $definition * @param mixed $service * @param string|null $id */ diff --git a/Definition.php b/Definition.php index ee5803471..3f820c0c8 100644 --- a/Definition.php +++ b/Definition.php @@ -936,8 +936,6 @@ public function getBindings() * injected in the matching parameters (of the constructor, of methods * called and of controller actions). * - * @param array $bindings - * * @return $this */ public function setBindings(array $bindings) diff --git a/Dumper/PhpDumper.php b/Dumper/PhpDumper.php index 3e586ff71..b6d0b03b2 100644 --- a/Dumper/PhpDumper.php +++ b/Dumper/PhpDumper.php @@ -470,9 +470,8 @@ private function addServiceInclude($cId, Definition $definition) /** * Generates the service instance. * - * @param string $id - * @param Definition $definition - * @param bool $isSimpleInstance + * @param string $id + * @param bool $isSimpleInstance * * @return string * @@ -509,8 +508,6 @@ private function addServiceInstance($id, Definition $definition, $isSimpleInstan /** * Checks if the definition is a trivial instance. * - * @param Definition $definition - * * @return bool */ private function isTrivialInstance(Definition $definition) @@ -554,8 +551,7 @@ private function isTrivialInstance(Definition $definition) /** * Adds method calls to a service definition. * - * @param Definition $definition - * @param string $variableName + * @param string $variableName * * @return string */ @@ -587,8 +583,7 @@ private function addServiceProperties(Definition $definition, $variableName = 'i /** * Adds configurator definition. * - * @param Definition $definition - * @param string $variableName + * @param string $variableName * * @return string */ @@ -624,9 +619,8 @@ private function addServiceConfigurator(Definition $definition, $variableName = /** * Adds a service. * - * @param string $id - * @param Definition $definition - * @param string &$file + * @param string $id + * @param string &$file * * @return string */ @@ -1471,7 +1465,6 @@ protected function getDefaultParameters() /** * Exports parameters. * - * @param array $parameters * @param string $path * @param int $indent * diff --git a/Dumper/XmlDumper.php b/Dumper/XmlDumper.php index 67b6dbebb..cfc932843 100644 --- a/Dumper/XmlDumper.php +++ b/Dumper/XmlDumper.php @@ -90,9 +90,8 @@ private function addMethodCalls(array $methodcalls, \DOMElement $parent) /** * Adds a service. * - * @param Definition $definition - * @param string $id - * @param \DOMElement $parent + * @param Definition $definition + * @param string $id */ private function addService($definition, $id, \DOMElement $parent) { @@ -221,9 +220,7 @@ private function addService($definition, $id, \DOMElement $parent) /** * Adds a service alias. * - * @param string $alias - * @param Alias $id - * @param \DOMElement $parent + * @param string $alias */ private function addServiceAlias($alias, Alias $id, \DOMElement $parent) { @@ -261,10 +258,8 @@ private function addServices(\DOMElement $parent) /** * Converts parameters. * - * @param array $parameters - * @param string $type - * @param \DOMElement $parent - * @param string $keyAttribute + * @param string $type + * @param string $keyAttribute */ private function convertParameters(array $parameters, $type, \DOMElement $parent, $keyAttribute = 'key') { diff --git a/Dumper/YamlDumper.php b/Dumper/YamlDumper.php index 8f3fcddf3..be6bf5a72 100644 --- a/Dumper/YamlDumper.php +++ b/Dumper/YamlDumper.php @@ -57,8 +57,7 @@ public function dump(array $options = []) /** * Adds a service. * - * @param string $id - * @param Definition $definition + * @param string $id * * @return string */ @@ -171,7 +170,6 @@ private function addService($id, Definition $definition) * Adds a service alias. * * @param string $alias - * @param Alias $id * * @return string */ @@ -337,8 +335,7 @@ private function getExpressionCall($expression) /** * Prepares parameters. * - * @param array $parameters - * @param bool $escape + * @param bool $escape * * @return array */ diff --git a/LazyProxy/PhpDumper/DumperInterface.php b/LazyProxy/PhpDumper/DumperInterface.php index f2d0476f6..3946eafaf 100644 --- a/LazyProxy/PhpDumper/DumperInterface.php +++ b/LazyProxy/PhpDumper/DumperInterface.php @@ -30,9 +30,7 @@ public function isProxyCandidate(Definition $definition); /** * Generates the code to be used to instantiate a proxy in the dumped factory code. * - * @param Definition $definition - * @param string $id Service identifier - * @param string $factoryCode The code to execute to create the service, will be added to the interface in 4.0 + * @param string $id Service identifier * * @return string */ diff --git a/Loader/FileLoader.php b/Loader/FileLoader.php index f0d920189..186c9c4ce 100644 --- a/Loader/FileLoader.php +++ b/Loader/FileLoader.php @@ -86,8 +86,7 @@ public function registerClasses(Definition $prototype, $namespace, $resource, $e /** * Registers a definition in the container with its instanceof-conditionals. * - * @param string $id - * @param Definition $definition + * @param string $id */ protected function setDefinition($id, Definition $definition) { diff --git a/Loader/XmlFileLoader.php b/Loader/XmlFileLoader.php index 60102eaa8..799b60d98 100644 --- a/Loader/XmlFileLoader.php +++ b/Loader/XmlFileLoader.php @@ -86,8 +86,7 @@ public function supports($resource, $type = null) /** * Parses parameters. * - * @param \DOMDocument $xml - * @param string $file + * @param string $file */ private function parseParameters(\DOMDocument $xml, $file) { @@ -99,8 +98,7 @@ private function parseParameters(\DOMDocument $xml, $file) /** * Parses imports. * - * @param \DOMDocument $xml - * @param string $file + * @param string $file */ private function parseImports(\DOMDocument $xml, $file) { @@ -121,8 +119,7 @@ private function parseImports(\DOMDocument $xml, $file) /** * Parses multiple definitions. * - * @param \DOMDocument $xml - * @param string $file + * @param string $file */ private function parseDefinitions(\DOMDocument $xml, $file, $defaults) { @@ -193,9 +190,7 @@ private function getServiceDefaults(\DOMDocument $xml, $file) /** * Parses an individual Definition. * - * @param \DOMElement $service - * @param string $file - * @param array $defaults + * @param string $file * * @return Definition|null */ @@ -394,9 +389,8 @@ private function parseFileToDOM($file) /** * Processes anonymous services. * - * @param \DOMDocument $xml - * @param string $file - * @param array $defaults + * @param string $file + * @param array $defaults */ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults) { @@ -456,10 +450,9 @@ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults) /** * Returns arguments as valid php types. * - * @param \DOMElement $node - * @param string $name - * @param string $file - * @param bool $lowercase + * @param string $name + * @param string $file + * @param bool $lowercase * * @return mixed */ @@ -546,8 +539,7 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase = /** * Get child elements by name. * - * @param \DOMNode $node - * @param mixed $name + * @param mixed $name * * @return \DOMElement[] */ @@ -566,8 +558,6 @@ private function getChildren(\DOMNode $node, $name) /** * Validates a documents XML schema. * - * @param \DOMDocument $dom - * * @return bool * * @throws RuntimeException When extension references a non-existent XSD file @@ -645,8 +635,7 @@ public function validateSchema(\DOMDocument $dom) /** * Validates an alias. * - * @param \DOMElement $alias - * @param string $file + * @param string $file */ private function validateAlias(\DOMElement $alias, $file) { @@ -666,8 +655,7 @@ private function validateAlias(\DOMElement $alias, $file) /** * Validates an extension. * - * @param \DOMDocument $dom - * @param string $file + * @param string $file * * @throws InvalidArgumentException When no extension is found corresponding to a tag */ @@ -688,8 +676,6 @@ private function validateExtensions(\DOMDocument $dom, $file) /** * Loads from an extension. - * - * @param \DOMDocument $xml */ private function loadFromExtensions(\DOMDocument $xml) { diff --git a/Loader/YamlFileLoader.php b/Loader/YamlFileLoader.php index a3a799024..891689bc1 100644 --- a/Loader/YamlFileLoader.php +++ b/Loader/YamlFileLoader.php @@ -170,7 +170,6 @@ public function supports($resource, $type = null) /** * Parses all imports. * - * @param array $content * @param string $file */ private function parseImports(array $content, $file) @@ -200,7 +199,6 @@ private function parseImports(array $content, $file) /** * Parses definitions. * - * @param array $content * @param string $file */ private function parseDefinitions(array $content, $file) @@ -241,7 +239,6 @@ private function parseDefinitions(array $content, $file) } /** - * @param array $content * @param string $file * * @return array @@ -306,8 +303,6 @@ private function parseDefaults(array &$content, $file) } /** - * @param array $service - * * @return bool */ private function isUsingShortSyntax(array $service) @@ -327,7 +322,6 @@ private function isUsingShortSyntax(array $service) * @param string $id * @param array|string $service * @param string $file - * @param array $defaults * * @throws InvalidArgumentException When tags are invalid */ From 07e9a7ebb9e0436d254e9b6d8eacd60b73fb0a5f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 18 Aug 2019 22:04:16 +0200 Subject: [PATCH 60/72] [DI] fix docblock --- ChildDefinition.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChildDefinition.php b/ChildDefinition.php index 29fbd48f2..123b38747 100644 --- a/ChildDefinition.php +++ b/ChildDefinition.php @@ -89,7 +89,7 @@ public function getArgument($index) * @param int|string $index * @param mixed $value * - * @return self the current instance + * @return $this * * @throws InvalidArgumentException when $index isn't an integer */ From c91a1337b75167e99732922545a2d65477e48cdc Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 20 Aug 2019 13:58:36 +0200 Subject: [PATCH 61/72] cs fix --- Dumper/YamlDumper.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dumper/YamlDumper.php b/Dumper/YamlDumper.php index be6bf5a72..1e795c7da 100644 --- a/Dumper/YamlDumper.php +++ b/Dumper/YamlDumper.php @@ -228,9 +228,7 @@ private function addParameters() /** * Dumps callable to YAML format. * - * @param callable $callable - * - * @return callable + * @param mixed $callable */ private function dumpCallable($callable) { From 7868846b9d62888c9f6bb7eb13376701a84af48d Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 19 Aug 2019 23:30:37 +0200 Subject: [PATCH 62/72] Fix inconsistent return points. --- Compiler/AnalyzeServiceReferencesPass.php | 2 +- Compiler/CheckArgumentsValidityPass.php | 2 ++ ContainerBuilder.php | 4 ++-- EnvVarProcessor.php | 4 ++-- Extension/Extension.php | 7 ++++--- LazyProxy/ProxyHelper.php | 5 ++--- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Compiler/AnalyzeServiceReferencesPass.php b/Compiler/AnalyzeServiceReferencesPass.php index 8070920ff..bff9d4207 100644 --- a/Compiler/AnalyzeServiceReferencesPass.php +++ b/Compiler/AnalyzeServiceReferencesPass.php @@ -156,7 +156,7 @@ private function getDefinitionId($id) } if (!$this->container->hasDefinition($id)) { - return; + return null; } return $this->container->normalizeId($id); diff --git a/Compiler/CheckArgumentsValidityPass.php b/Compiler/CheckArgumentsValidityPass.php index feb05c049..30a6f524a 100644 --- a/Compiler/CheckArgumentsValidityPass.php +++ b/Compiler/CheckArgumentsValidityPass.php @@ -81,5 +81,7 @@ protected function processValue($value, $isRoot = false) } } } + + return null; } } diff --git a/ContainerBuilder.php b/ContainerBuilder.php index 4797047bb..53873c15e 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -354,7 +354,7 @@ public function addClassResource(\ReflectionClass $class) public function getReflectionClass($class, $throw = true) { if (!$class = $this->getParameterBag()->resolveValue($class)) { - return; + return null; } if (isset(self::$internalTypes[$class])) { @@ -621,7 +621,7 @@ private function doGet($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_ $definition = $this->getDefinition($id); } catch (ServiceNotFoundException $e) { if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) { - return; + return null; } throw $e; diff --git a/EnvVarProcessor.php b/EnvVarProcessor.php index a23b83436..885408093 100644 --- a/EnvVarProcessor.php +++ b/EnvVarProcessor.php @@ -65,7 +65,7 @@ public function getEnv($prefix, $name, \Closure $getEnv) if (false !== $i || 'string' !== $prefix) { if (null === $env = $getEnv($name)) { - return; + return null; } } elseif (isset($_ENV[$name])) { $env = $_ENV[$name]; @@ -77,7 +77,7 @@ public function getEnv($prefix, $name, \Closure $getEnv) } if (null === $env = $this->container->getParameter("env($name)")) { - return; + return null; } } diff --git a/Extension/Extension.php b/Extension/Extension.php index a9389862c..7df483064 100644 --- a/Extension/Extension.php +++ b/Extension/Extension.php @@ -84,11 +84,12 @@ public function getConfiguration(array $config, ContainerBuilder $container) $class = $container->getReflectionClass($class); $constructor = $class ? $class->getConstructor() : null; - if ($class && (!$constructor || !$constructor->getNumberOfRequiredParameters())) { - return $class->newInstance(); - } + return $class && (!$constructor || !$constructor->getNumberOfRequiredParameters()) ? $class->newInstance() : null; } + /** + * @return array + */ final protected function processConfiguration(ConfigurationInterface $configuration, array $configs) { $processor = new Processor(); diff --git a/LazyProxy/ProxyHelper.php b/LazyProxy/ProxyHelper.php index 33737082a..cb19c729c 100644 --- a/LazyProxy/ProxyHelper.php +++ b/LazyProxy/ProxyHelper.php @@ -58,8 +58,7 @@ public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionPa if ('self' === $lcName) { return $prefix.$r->getDeclaringClass()->name; } - if ($parent = $r->getDeclaringClass()->getParentClass()) { - return $prefix.$parent->name; - } + + return ($parent = $r->getDeclaringClass()->getParentClass()) ? $prefix.$parent->name : null; } } From 2e2ab9f5e920d2f0de518d4572dc3d625f154bf0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 21 Aug 2019 20:56:01 +0200 Subject: [PATCH 63/72] Use PHP 7.4 on deps=low --- Tests/Compiler/AutowirePassTest.php | 6 ++++++ Tests/Compiler/ResolveBindingsPassTest.php | 2 ++ Tests/Dumper/PhpDumperTest.php | 2 ++ Tests/Loader/FileLoaderTest.php | 6 ++++++ 4 files changed, 16 insertions(+) diff --git a/Tests/Compiler/AutowirePassTest.php b/Tests/Compiler/AutowirePassTest.php index e84968100..b2a08c4d6 100644 --- a/Tests/Compiler/AutowirePassTest.php +++ b/Tests/Compiler/AutowirePassTest.php @@ -378,6 +378,8 @@ public function testClassNotFoundThrowsException() } /** + * @group issue-32995 + * * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 */ public function testParentClassNotFoundThrowsException() @@ -692,6 +694,8 @@ public function getCreateResourceTests() } /** + * @group issue-32995 + * * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 */ public function testIgnoreServiceWithClassNotExisting() @@ -893,6 +897,8 @@ public function testExceptionWhenAliasExists() } /** + * @group issue-32995 + * * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 */ public function testExceptionWhenAliasDoesNotExist() diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index c91eeadfd..9a6404b5c 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -62,6 +62,8 @@ public function testUnusedBinding() } /** + * @group issue-32995 + * * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 */ public function testMissingParent() diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index 20f9da9e1..c19f71753 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -894,6 +894,8 @@ public function testInlineSelfRef() } /** + * @group issue-32995 + * * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 */ public function testHotPathOptimizations() diff --git a/Tests/Loader/FileLoaderTest.php b/Tests/Loader/FileLoaderTest.php index 3a2b59315..c5f1725fb 100644 --- a/Tests/Loader/FileLoaderTest.php +++ b/Tests/Loader/FileLoaderTest.php @@ -108,6 +108,8 @@ public function testRegisterClasses() } /** + * @group issue-32995 + * * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 */ public function testRegisterClassesWithExclude() @@ -140,6 +142,8 @@ public function testRegisterClassesWithExclude() } /** + * @group issue-32995 + * * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 */ public function testNestedRegisterClasses() @@ -171,6 +175,8 @@ public function testNestedRegisterClasses() } /** + * @group issue-32995 + * * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 */ public function testMissingParentClass() From 32f2bf537b7a471136e4828391f611cf5b48fd23 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 23 Aug 2019 13:30:52 +0200 Subject: [PATCH 64/72] [HttpKernel] Fix return type declarations --- Container.php | 2 -- Dumper/DumperInterface.php | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Container.php b/Container.php index ab69579ad..ad06c7e24 100644 --- a/Container.php +++ b/Container.php @@ -444,8 +444,6 @@ public static function underscore($id) /** * Creates a service by requiring its factory file. - * - * @return object The service created by the file */ protected function load($file) { diff --git a/Dumper/DumperInterface.php b/Dumper/DumperInterface.php index 1ea775ddf..8abc19250 100644 --- a/Dumper/DumperInterface.php +++ b/Dumper/DumperInterface.php @@ -21,9 +21,7 @@ interface DumperInterface /** * Dumps the service container. * - * @param array $options An array of options - * - * @return string The representation of the service container + * @return string|array The representation of the service container */ public function dump(array $options = []); } From bec0a6f4d9f91430b81b09dae0e0482d48b65a50 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 23 Aug 2019 22:10:22 +0200 Subject: [PATCH 65/72] [DI] fix return type declarations --- Definition.php | 2 +- Extension/ExtensionInterface.php | 2 +- Loader/XmlFileLoader.php | 2 +- ParameterBag/ParameterBag.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Definition.php b/Definition.php index 3f820c0c8..c7d204948 100644 --- a/Definition.php +++ b/Definition.php @@ -796,7 +796,7 @@ public function setConfigurator($configurator) /** * Gets the configurator to call after the service is fully initialized. * - * @return callable|null The PHP callable to call + * @return callable|array|null */ public function getConfigurator() { diff --git a/Extension/ExtensionInterface.php b/Extension/ExtensionInterface.php index 18de31272..6a7a2cf02 100644 --- a/Extension/ExtensionInterface.php +++ b/Extension/ExtensionInterface.php @@ -37,7 +37,7 @@ public function getNamespace(); /** * Returns the base path for the XSD files. * - * @return string The XSD base path + * @return string|false */ public function getXsdValidationBasePath(); diff --git a/Loader/XmlFileLoader.php b/Loader/XmlFileLoader.php index 799b60d98..c4b9b69a0 100644 --- a/Loader/XmlFileLoader.php +++ b/Loader/XmlFileLoader.php @@ -710,7 +710,7 @@ private function loadFromExtensions(\DOMDocument $xml) * * @param \DOMElement $element A \DOMElement instance * - * @return array A PHP array + * @return mixed */ public static function convertDomElementToArray(\DOMElement $element) { diff --git a/ParameterBag/ParameterBag.php b/ParameterBag/ParameterBag.php index c4e702181..e13d2824f 100644 --- a/ParameterBag/ParameterBag.php +++ b/ParameterBag/ParameterBag.php @@ -195,7 +195,7 @@ public function resolveValue($value, array $resolving = []) * @param string $value The string to resolve * @param array $resolving An array of keys that are being resolved (used internally to detect circular references) * - * @return string The resolved string + * @return mixed The resolved string * * @throws ParameterNotFoundException if a placeholder references a parameter that does not exist * @throws ParameterCircularReferenceException if a circular reference if detected From 255ef9fe5f00352a1a598359dbf7ee30106d7088 Mon Sep 17 00:00:00 2001 From: pdommelen Date: Mon, 26 Aug 2019 09:37:14 +0200 Subject: [PATCH 66/72] [DependencyInjection] Fixed the `getServiceIds` implementation to always return aliases --- Container.php | 2 +- Tests/ContainerTest.php | 4 ++-- Tests/Dumper/PhpDumperTest.php | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Container.php b/Container.php index ab69579ad..28b54da0e 100644 --- a/Container.php +++ b/Container.php @@ -405,7 +405,7 @@ public function getServiceIds() } $ids[] = 'service_container'; - return array_map('strval', array_unique(array_merge($ids, array_keys($this->methodMap), array_keys($this->fileMap), array_keys($this->services)))); + return array_map('strval', array_unique(array_merge($ids, array_keys($this->methodMap), array_keys($this->fileMap), array_keys($this->aliases), array_keys($this->services)))); } /** diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index ebc422ca9..46527e09d 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -156,7 +156,7 @@ public function testGetServiceIds() $sc = new ProjectServiceContainer(); $sc->set('foo', $obj = new \stdClass()); - $this->assertEquals(['service_container', 'internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'internal_dependency', 'foo'], $sc->getServiceIds(), '->getServiceIds() returns defined service ids by factory methods in the method map, followed by service ids defined by set()'); + $this->assertEquals(['service_container', 'internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'internal_dependency', 'alias', 'foo'], $sc->getServiceIds(), '->getServiceIds() returns defined service ids by factory methods in the method map, followed by service ids defined by set()'); } /** @@ -168,7 +168,7 @@ public function testGetLegacyServiceIds() $sc = new LegacyProjectServiceContainer(); $sc->set('foo', $obj = new \stdClass()); - $this->assertEquals(['internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'foo'], $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()'); + $this->assertEquals(['internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'alias', 'foo'], $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()'); } public function testSet() diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index c19f71753..c63380d3d 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -1139,6 +1139,30 @@ public function testScalarService() $this->assertTrue($container->has('foo')); $this->assertSame('some value', $container->get('foo')); } + + public function testAliasCanBeFoundInTheDumpedContainerWhenBothTheAliasAndTheServiceArePublic() + { + $container = new ContainerBuilder(); + + $container->register('foo', 'stdClass')->setPublic(true); + $container->setAlias('bar', 'foo')->setPublic(true); + + $container->compile(); + + // Bar is found in the compiled container + $service_ids = $container->getServiceIds(); + $this->assertContains('bar', $service_ids); + + $dumper = new PhpDumper($container); + $dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_AliasesCanBeFoundInTheDumpedContainer']); + eval('?>'.$dump); + + $container = new \Symfony_DI_PhpDumper_AliasesCanBeFoundInTheDumpedContainer(); + + // Bar should still be found in the compiled container + $service_ids = $container->getServiceIds(); + $this->assertContains('bar', $service_ids); + } } class Rot13EnvVarProcessor implements EnvVarProcessorInterface From c52e96a9baecb494b5ed2106b18b4c3a28fb0343 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 13 Sep 2019 11:27:15 +0200 Subject: [PATCH 67/72] Re-enable previously failing PHP 7.4 test cases --- Tests/Compiler/AutowirePassTest.php | 15 --------------- Tests/Compiler/ResolveBindingsPassTest.php | 5 ----- Tests/Dumper/PhpDumperTest.php | 5 ----- Tests/Loader/FileLoaderTest.php | 15 --------------- 4 files changed, 40 deletions(-) diff --git a/Tests/Compiler/AutowirePassTest.php b/Tests/Compiler/AutowirePassTest.php index b2a08c4d6..f729f72ba 100644 --- a/Tests/Compiler/AutowirePassTest.php +++ b/Tests/Compiler/AutowirePassTest.php @@ -377,11 +377,6 @@ public function testClassNotFoundThrowsException() $pass->process($container); } - /** - * @group issue-32995 - * - * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 - */ public function testParentClassNotFoundThrowsException() { $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); @@ -693,11 +688,6 @@ public function getCreateResourceTests() ]; } - /** - * @group issue-32995 - * - * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 - */ public function testIgnoreServiceWithClassNotExisting() { $container = new ContainerBuilder(); @@ -896,11 +886,6 @@ public function testExceptionWhenAliasExists() $pass->process($container); } - /** - * @group issue-32995 - * - * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 - */ public function testExceptionWhenAliasDoesNotExist() { $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index 9a6404b5c..a44fea4d6 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -61,11 +61,6 @@ public function testUnusedBinding() $pass->process($container); } - /** - * @group issue-32995 - * - * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 - */ public function testMissingParent() { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index c63380d3d..4e6083d99 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -893,11 +893,6 @@ public function testInlineSelfRef() $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_inline_self_ref.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Inline_Self_Ref'])); } - /** - * @group issue-32995 - * - * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 - */ public function testHotPathOptimizations() { $container = include self::$fixturesPath.'/containers/container_inline_requires.php'; diff --git a/Tests/Loader/FileLoaderTest.php b/Tests/Loader/FileLoaderTest.php index c5f1725fb..b6a816e40 100644 --- a/Tests/Loader/FileLoaderTest.php +++ b/Tests/Loader/FileLoaderTest.php @@ -107,11 +107,6 @@ public function testRegisterClasses() ); } - /** - * @group issue-32995 - * - * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 - */ public function testRegisterClassesWithExclude() { $container = new ContainerBuilder(); @@ -141,11 +136,6 @@ public function testRegisterClassesWithExclude() ); } - /** - * @group issue-32995 - * - * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 - */ public function testNestedRegisterClasses() { $container = new ContainerBuilder(); @@ -174,11 +164,6 @@ public function testNestedRegisterClasses() $this->assertFalse($alias->isPrivate()); } - /** - * @group issue-32995 - * - * @runInSeparateProcess https://github.com/symfony/symfony/issues/32995 - */ public function testMissingParentClass() { $container = new ContainerBuilder(); From 9cf81798f857205c5bbb4c8c7895f838d40b0c4b Mon Sep 17 00:00:00 2001 From: k0d3r1s Date: Wed, 18 Sep 2019 16:21:11 +0300 Subject: [PATCH 68/72] [DependencyInjection] Fix wrong exception when service is synthetic --- Compiler/AbstractRecursivePass.php | 4 ++++ Tests/Compiler/AutowirePassTest.php | 4 +--- Tests/Compiler/ResolveBindingsPassTest.php | 27 +++++++++++++++++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Compiler/AbstractRecursivePass.php b/Compiler/AbstractRecursivePass.php index a89bf1647..5ca2b2246 100644 --- a/Compiler/AbstractRecursivePass.php +++ b/Compiler/AbstractRecursivePass.php @@ -89,6 +89,10 @@ protected function processValue($value, $isRoot = false) */ protected function getConstructor(Definition $definition, $required) { + if ($definition->isSynthetic()) { + return null; + } + if (\is_string($factory = $definition->getFactory())) { if (!\function_exists($factory)) { throw new RuntimeException(sprintf('Invalid service "%s": function "%s" does not exist.', $this->currentId, $factory)); diff --git a/Tests/Compiler/AutowirePassTest.php b/Tests/Compiler/AutowirePassTest.php index f729f72ba..7eb7f6024 100644 --- a/Tests/Compiler/AutowirePassTest.php +++ b/Tests/Compiler/AutowirePassTest.php @@ -589,12 +589,10 @@ public function testSetterInjection() ); } - /** - * @exceptedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "setLogger()" does not exist. - */ public function testWithNonExistingSetterAndAutowiring() { $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass": method "setLogger()" does not exist.'); $container = new ContainerBuilder(); $definition = $container->register(CaseSensitiveClass::class, CaseSensitiveClass::class)->setAutowired(true); diff --git a/Tests/Compiler/ResolveBindingsPassTest.php b/Tests/Compiler/ResolveBindingsPassTest.php index a44fea4d6..fd526caa9 100644 --- a/Tests/Compiler/ResolveBindingsPassTest.php +++ b/Tests/Compiler/ResolveBindingsPassTest.php @@ -14,9 +14,11 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; +use Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass; use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy; @@ -110,12 +112,10 @@ public function testScalarSetter() $this->assertEquals([['setDefaultLocale', ['fr']]], $definition->getMethodCalls()); } - /** - * @exceptedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "setLogger()" does not exist. - */ public function testWithNonExistingSetterAndBinding() { $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "setLogger()" does not exist.'); $container = new ContainerBuilder(); $bindings = [ @@ -129,4 +129,25 @@ public function testWithNonExistingSetterAndBinding() $pass = new ResolveBindingsPass(); $pass->process($container); } + + public function testSyntheticServiceWithBind() + { + $container = new ContainerBuilder(); + $argument = new BoundArgument('bar'); + + $container->register('foo', 'stdClass') + ->addArgument(new Reference('synthetic.service')); + + $container->register('synthetic.service') + ->setSynthetic(true) + ->setBindings(['$apiKey' => $argument]); + + $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class) + ->setBindings(['$apiKey' => $argument]); + + (new ResolveBindingsPass())->process($container); + (new DefinitionErrorExceptionPass())->process($container); + + $this->assertSame([1 => 'bar'], $container->getDefinition(NamedArgumentsDummy::class)->getArguments()); + } } From 413a2c0cae6a1a5d8720bdfeebc0dbbfac24155d Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Thu, 24 Oct 2019 14:44:17 +0200 Subject: [PATCH 69/72] Remove unused local variables in tests --- Dumper/PhpDumper.php | 2 +- Tests/Compiler/AnalyzeServiceReferencesPassTest.php | 10 +++++----- Tests/Compiler/IntegrationTest.php | 2 +- Tests/Compiler/ResolveChildDefinitionsPassTest.php | 2 +- Tests/Compiler/ResolveClassPassTest.php | 4 ++-- Tests/ContainerBuilderTest.php | 6 +++--- Tests/Dumper/PhpDumperTest.php | 3 +-- Tests/Loader/XmlFileLoaderTest.php | 1 - 8 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Dumper/PhpDumper.php b/Dumper/PhpDumper.php index b6d0b03b2..7596b9953 100644 --- a/Dumper/PhpDumper.php +++ b/Dumper/PhpDumper.php @@ -219,7 +219,7 @@ public function dump(array $options = []) foreach ($ids as $id) { $c .= ' '.$this->doExport($id)." => true,\n"; } - $files['removed-ids.php'] = $c .= "];\n"; + $files['removed-ids.php'] = $c."];\n"; } foreach ($this->generateServiceFiles() as $file => $c) { diff --git a/Tests/Compiler/AnalyzeServiceReferencesPassTest.php b/Tests/Compiler/AnalyzeServiceReferencesPassTest.php index 0bd94a3e6..66b6e19cc 100644 --- a/Tests/Compiler/AnalyzeServiceReferencesPassTest.php +++ b/Tests/Compiler/AnalyzeServiceReferencesPassTest.php @@ -25,28 +25,28 @@ public function testProcess() { $container = new ContainerBuilder(); - $a = $container + $container ->register('a') ->addArgument($ref1 = new Reference('b')) ; - $b = $container + $container ->register('b') ->addMethodCall('setA', [$ref2 = new Reference('a')]) ; - $c = $container + $container ->register('c') ->addArgument($ref3 = new Reference('a')) ->addArgument($ref4 = new Reference('b')) ; - $d = $container + $container ->register('d') ->setProperty('foo', $ref5 = new Reference('b')) ; - $e = $container + $container ->register('e') ->setConfigurator([$ref6 = new Reference('b'), 'methodName']) ; diff --git a/Tests/Compiler/IntegrationTest.php b/Tests/Compiler/IntegrationTest.php index 10c34aa48..348d1d7f5 100644 --- a/Tests/Compiler/IntegrationTest.php +++ b/Tests/Compiler/IntegrationTest.php @@ -43,7 +43,7 @@ public function testProcessRemovesAndInlinesRecursively() ->addArgument(new Reference('c')) ; - $b = $container + $container ->register('b', '\stdClass') ->addArgument(new Reference('c')) ->setPublic(false) diff --git a/Tests/Compiler/ResolveChildDefinitionsPassTest.php b/Tests/Compiler/ResolveChildDefinitionsPassTest.php index 27bb9157c..eee4cf730 100644 --- a/Tests/Compiler/ResolveChildDefinitionsPassTest.php +++ b/Tests/Compiler/ResolveChildDefinitionsPassTest.php @@ -390,7 +390,7 @@ public function testBindings() ->setBindings(['a' => '1', 'b' => '2']) ; - $child = $container->setDefinition('child', new ChildDefinition('parent')) + $container->setDefinition('child', new ChildDefinition('parent')) ->setBindings(['b' => 'B', 'c' => 'C']) ; diff --git a/Tests/Compiler/ResolveClassPassTest.php b/Tests/Compiler/ResolveClassPassTest.php index 0ab630316..81e05fb28 100644 --- a/Tests/Compiler/ResolveClassPassTest.php +++ b/Tests/Compiler/ResolveClassPassTest.php @@ -87,8 +87,8 @@ public function testAmbiguousChildDefinition() $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $this->expectExceptionMessage('Service definition "App\Foo\Child" has a parent but no class, and its name looks like a FQCN. Either the class is missing or you want to inherit it from the parent service. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class.'); $container = new ContainerBuilder(); - $parent = $container->register('App\Foo', null); - $child = $container->setDefinition('App\Foo\Child', new ChildDefinition('App\Foo')); + $container->register('App\Foo', null); + $container->setDefinition('App\Foo\Child', new ChildDefinition('App\Foo')); (new ResolveClassPass())->process($container); } diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index 199179c9b..f2666ef96 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -1265,7 +1265,7 @@ public function testNoClassFromGlobalNamespaceClassId() $this->expectExceptionMessage('The definition for "DateTime" has no class attribute, and appears to reference a class or interface in the global namespace.'); $container = new ContainerBuilder(); - $definition = $container->register(\DateTime::class); + $container->register(\DateTime::class); $container->compile(); } @@ -1295,7 +1295,7 @@ public function testNoClassFromNonClassId() $this->expectExceptionMessage('The definition for "123_abc" has no class.'); $container = new ContainerBuilder(); - $definition = $container->register('123_abc'); + $container->register('123_abc'); $container->compile(); } @@ -1305,7 +1305,7 @@ public function testNoClassFromNsSeparatorId() $this->expectExceptionMessage('The definition for "\foo" has no class.'); $container = new ContainerBuilder(); - $definition = $container->register('\\foo'); + $container->register('\\foo'); $container->compile(); } diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index 4e6083d99..b2cbb3caf 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -886,7 +886,7 @@ public function testInlineSelfRef() ->setPublic(true) ->addArgument($baz); - $passConfig = $container->getCompiler()->getPassConfig(); + $container->getCompiler()->getPassConfig(); $container->compile(); $dumper = new PhpDumper($container); @@ -978,7 +978,6 @@ public function testAdawsonContainer() $container->compile(); $dumper = new PhpDumper($container); - $dump = $dumper->dump(); $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_adawson.php', $dumper->dump()); } diff --git a/Tests/Loader/XmlFileLoaderTest.php b/Tests/Loader/XmlFileLoaderTest.php index 1b6e51c56..2b963968d 100644 --- a/Tests/Loader/XmlFileLoaderTest.php +++ b/Tests/Loader/XmlFileLoaderTest.php @@ -808,7 +808,6 @@ public function testTsantosContainer() $container->compile(); $dumper = new PhpDumper($container); - $dump = $dumper->dump(); $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_tsantos.php', $dumper->dump()); } From 4e9104631c0b3ca29356f73c51f4db41f0b8af7c Mon Sep 17 00:00:00 2001 From: Chi-teck Date: Mon, 4 Nov 2019 12:40:30 +0500 Subject: [PATCH 70/72] [DependencyInjection] Fix broken references in tests --- Tests/LazyProxy/Instantiator/RealServiceInstantiatorTest.php | 2 +- Tests/LazyProxy/PhpDumper/NullDumperTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/LazyProxy/Instantiator/RealServiceInstantiatorTest.php b/Tests/LazyProxy/Instantiator/RealServiceInstantiatorTest.php index f93965f46..7f757297b 100644 --- a/Tests/LazyProxy/Instantiator/RealServiceInstantiatorTest.php +++ b/Tests/LazyProxy/Instantiator/RealServiceInstantiatorTest.php @@ -16,7 +16,7 @@ use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator; /** - * Tests for {@see \Symfony\Component\DependencyInjection\Instantiator\RealServiceInstantiator}. + * Tests for {@see \Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator}. * * @author Marco Pivetta */ diff --git a/Tests/LazyProxy/PhpDumper/NullDumperTest.php b/Tests/LazyProxy/PhpDumper/NullDumperTest.php index b1b9b399c..5ae149324 100644 --- a/Tests/LazyProxy/PhpDumper/NullDumperTest.php +++ b/Tests/LazyProxy/PhpDumper/NullDumperTest.php @@ -16,7 +16,7 @@ use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\NullDumper; /** - * Tests for {@see \Symfony\Component\DependencyInjection\PhpDumper\NullDumper}. + * Tests for {@see \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\NullDumper}. * * @author Marco Pivetta */ From e32d6bd3fdd2b1acc228814c4a6328f2305c3bee Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 7 Nov 2019 14:06:15 +0100 Subject: [PATCH 71/72] [DI] Dont cache classes with missing parents --- ContainerBuilder.php | 3 +-- Loader/FileLoader.php | 7 +------ Tests/Compiler/AutowirePassTest.php | 2 +- Tests/Loader/FileLoaderTest.php | 6 +++--- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/ContainerBuilder.php b/ContainerBuilder.php index 53873c15e..f9bfcb521 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -361,7 +361,7 @@ public function getReflectionClass($class, $throw = true) return null; } - $resource = null; + $resource = $classReflector = null; try { if (isset($this->classReflectors[$class])) { @@ -376,7 +376,6 @@ public function getReflectionClass($class, $throw = true) if ($throw) { throw $e; } - $classReflector = false; } if ($this->trackResources) { diff --git a/Loader/FileLoader.php b/Loader/FileLoader.php index 186c9c4ce..77cad3c04 100644 --- a/Loader/FileLoader.php +++ b/Loader/FileLoader.php @@ -149,12 +149,7 @@ private function findClasses($namespace, $pattern, $excludePattern) try { $r = $this->container->getReflectionClass($class); } catch (\ReflectionException $e) { - $classes[$class] = sprintf( - 'While discovering services from namespace "%s", an error was thrown when processing the class "%s": "%s".', - $namespace, - $class, - $e->getMessage() - ); + $classes[$class] = $e->getMessage(); continue; } // check to make sure the expected class exists diff --git a/Tests/Compiler/AutowirePassTest.php b/Tests/Compiler/AutowirePassTest.php index 7eb7f6024..c5bcc660a 100644 --- a/Tests/Compiler/AutowirePassTest.php +++ b/Tests/Compiler/AutowirePassTest.php @@ -380,7 +380,7 @@ public function testClassNotFoundThrowsException() public function testParentClassNotFoundThrowsException() { $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class is missing a parent class (Class Symfony\Bug\NotExistClass not found).'); + $this->expectExceptionMessageRegExp('{^Cannot autowire service "a": argument "\$r" of method "(Symfony\\\\Component\\\\DependencyInjection\\\\Tests\\\\Compiler\\\\)BadParentTypeHintedArgument::__construct\(\)" has type "\1OptionalServiceClass" but this class is missing a parent class \(Class "?Symfony\\\\Bug\\\\NotExistClass"? not found}'); $container = new ContainerBuilder(); diff --git a/Tests/Loader/FileLoaderTest.php b/Tests/Loader/FileLoaderTest.php index b6a816e40..ffe58a67e 100644 --- a/Tests/Loader/FileLoaderTest.php +++ b/Tests/Loader/FileLoaderTest.php @@ -178,9 +178,9 @@ public function testMissingParentClass() $this->assertTrue($container->has(MissingParent::class)); - $this->assertSame( - ['While discovering services from namespace "Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\", an error was thrown when processing the class "Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\MissingParent": "Class Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\MissingClass not found".'], - $container->getDefinition(MissingParent::class)->getErrors() + $this->assertRegExp( + '{Class "?Symfony\\\\Component\\\\DependencyInjection\\\\Tests\\\\Fixtures\\\\Prototype\\\\BadClasses\\\\MissingClass"? not found}', + $container->getDefinition(MissingParent::class)->getErrors()[0] ); } From 0ea4d39ca82409a25a43b61ce828048a90000920 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 8 Nov 2019 17:10:53 +0100 Subject: [PATCH 72/72] [DI] fix locators with numeric keys --- Compiler/ServiceLocatorTagPass.php | 7 ++++++- Tests/Compiler/ServiceLocatorTagPassTest.php | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Compiler/ServiceLocatorTagPass.php b/Compiler/ServiceLocatorTagPass.php index 0d77d7e48..a7427c5a5 100644 --- a/Compiler/ServiceLocatorTagPass.php +++ b/Compiler/ServiceLocatorTagPass.php @@ -41,6 +41,8 @@ protected function processValue($value, $isRoot = false) throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set.', $this->currentId)); } + $i = 0; + foreach ($arguments[0] as $k => $v) { if ($v instanceof ServiceClosureArgument) { continue; @@ -49,10 +51,13 @@ protected function processValue($value, $isRoot = false) throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set, "%s" found for key "%s".', $this->currentId, \is_object($v) ? \get_class($v) : \gettype($v), $k)); } - if (\is_int($k)) { + if ($i === $k) { unset($arguments[0][$k]); $k = (string) $v; + ++$i; + } elseif (\is_int($k)) { + $i = null; } $arguments[0][$k] = new ServiceClosureArgument($v); } diff --git a/Tests/Compiler/ServiceLocatorTagPassTest.php b/Tests/Compiler/ServiceLocatorTagPassTest.php index 1de02d257..66af69b54 100644 --- a/Tests/Compiler/ServiceLocatorTagPassTest.php +++ b/Tests/Compiler/ServiceLocatorTagPassTest.php @@ -114,6 +114,7 @@ public function testInheritedKeyOverwritesPreviousServiceWithKey() ->setArguments([[ 'bar' => new Reference('baz'), new Reference('bar'), + 16 => new Reference('baz'), ]]) ->addTag('container.service_locator') ; @@ -124,6 +125,7 @@ public function testInheritedKeyOverwritesPreviousServiceWithKey() $locator = $container->get('foo'); $this->assertSame(TestDefinition1::class, \get_class($locator('bar'))); + $this->assertSame(TestDefinition2::class, \get_class($locator(16))); } public function testBindingsAreCopied()