From 4bd7b921f4047fa32478459a9b50e63001372aee Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 12 Jul 2017 12:01:37 +0200 Subject: [PATCH] [DI] Remove remaining deprecated features --- .../Bundle/FrameworkBundle/CHANGELOG.md | 1 + .../FrameworkExtension.php | 11 +- .../DependencyInjection/CHANGELOG.md | 8 ++ .../DependencyInjection/ChildDefinition.php | 2 - .../Compiler/AutowirePass.php | 68 +-------- .../DependencyInjection/Compiler/Compiler.php | 32 ----- .../Compiler/FactoryReturnTypePass.php | 108 -------------- .../Compiler/LoggingFormatter.php | 54 ------- .../Compiler/PassConfig.php | 3 +- .../Compiler/ResolveClassPass.php | 16 --- .../Config/AutowireServiceResource.php | 78 ----------- .../DependencyInjection/ContainerBuilder.php | 16 --- .../DefinitionDecorator.php | 29 ---- .../Loader/XmlFileLoader.php | 26 +--- .../schema/dic/services/services-1.0.xsd | 2 - .../Tests/ChildDefinitionTest.php | 6 - .../Tests/Compiler/AutowirePassTest.php | 97 ++----------- .../Compiler/FactoryReturnTypePassTest.php | 109 --------------- .../Config/AutowireServiceResourceTest.php | 124 ---------------- .../Tests/ContainerBuilderTest.php | 26 ---- .../Tests/DefinitionDecoratorTest.php | 132 ------------------ ...ition.xml => invalid_alias_definition.xml} | 7 +- .../Tests/Fixtures/xml/services5.xml | 3 - .../Tests/Loader/XmlFileLoaderTest.php | 24 +--- .../Component/HttpFoundation/Request.php | 2 +- 25 files changed, 40 insertions(+), 944 deletions(-) delete mode 100644 src/Symfony/Component/DependencyInjection/Compiler/FactoryReturnTypePass.php delete mode 100644 src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php delete mode 100644 src/Symfony/Component/DependencyInjection/Config/AutowireServiceResource.php delete mode 100644 src/Symfony/Component/DependencyInjection/DefinitionDecorator.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Config/AutowireServiceResourceTest.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php rename src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/{legacy_invalid_alias_definition.xml => invalid_alias_definition.xml} (62%) diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index cd4312f923e8a..9a765a4d96fcb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -19,6 +19,7 @@ CHANGELOG * Removed absolute template paths support in the template name parser * Removed support of the `KERNEL_DIR` environment variable with `KernelTestCase::getKernelClass()`. * Removed the `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()` methods. + * Removed the "framework.validation.cache" configuration option. Configure the "cache.validator" service under "framework.cache.pools" instead. 3.4.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index cafb0f6d24181..e97f8242932c1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1050,16 +1050,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder } } - if (isset($config['cache']) && $config['cache']) { - @trigger_error('The "framework.validation.cache" option is deprecated since Symfony 3.2 and will be removed in 4.0. Configure the "cache.validator" service under "framework.cache.pools" instead.', E_USER_DEPRECATED); - - $container->setParameter( - 'validator.mapping.cache.prefix', - 'validator_'.$this->getKernelRootHash($container) - ); - - $validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache']))); - } elseif (!$container->getParameter('kernel.debug')) { + if (!$container->getParameter('kernel.debug')) { $validatorBuilder->addMethodCall('setMetadataCache', array(new Reference('validator.mapping.cache.symfony'))); } } diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 7c01c34021d7e..2f31f9a29cefb 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 4.0.0 ----- + * removed autowiring services based on the types they implement * added a third `$methodName` argument to the `getProxyFactoryCode()` method of the `DumperInterface` * removed support for autowiring types @@ -11,6 +12,13 @@ CHANGELOG * removed support for dumping an ucompiled container in `PhpDumper` * removed support for generating a dumped `Container` without populating the method map * removed support for case insensitive service identifiers + * removed the `DefinitionDecorator` class, replaced by `ChildDefinition` + * removed the `AutowireServiceResource` class and related `AutowirePass::createResourceForClass()` method + * removed `LoggingFormatter`, `Compiler::getLoggingFormatter()` and `addLogMessage()` class and methods, use the `ContainerBuilder::log()` method instead + * removed `FactoryReturnTypePass` + * removed `ContainerBuilder::addClassResource()`, use the `addObjectResource()` or the `getReflectionClass()` method instead. + * removed support for top-level anonymous services + * removed silent behavior for unused attributes and elements 3.4.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/ChildDefinition.php b/src/Symfony/Component/DependencyInjection/ChildDefinition.php index 5701caa474e57..644a05a3e01ed 100644 --- a/src/Symfony/Component/DependencyInjection/ChildDefinition.php +++ b/src/Symfony/Component/DependencyInjection/ChildDefinition.php @@ -121,5 +121,3 @@ public function setInstanceofConditionals(array $instanceof) throw new BadMethodCallException('A ChildDefinition cannot have instanceof conditionals set on it.'); } } - -class_alias(ChildDefinition::class, DefinitionDecorator::class); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index 40e55d33663ae..48c7c8124870a 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -11,7 +11,6 @@ namespace Symfony\Component\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\Config\AutowireServiceResource; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException; @@ -67,30 +66,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. - */ - public static function createResourceForClass(\ReflectionClass $reflectionClass) - { - @trigger_error('The '.__METHOD__.'() method is deprecated since version 3.3 and will be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead.', E_USER_DEPRECATED); - - $metadata = array(); - - foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) { - if (!$reflectionMethod->isStatic()) { - $metadata[$reflectionMethod->name] = self::getResourceMetadataForMethod($reflectionMethod); - } - } - - return new AutowireServiceResource($reflectionClass->name, $reflectionClass->getFileName(), $metadata); - } - /** * {@inheritdoc} */ @@ -323,24 +298,15 @@ private function getAutowiredReference(TypedReference $reference, $deprecationMe return $reference; } - if (null === $this->types) { - $this->populateAvailableTypes(); + if (!$reference->canBeAutoregistered()) { + return; } - if (isset($this->types[$type])) { - $message = 'Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won\'t be supported in version 4.0.'; - if ($aliasSuggestion = $this->getAliasesSuggestionForType($type = $reference->getType(), $deprecationMessage)) { - $message .= ' '.$aliasSuggestion; - } else { - $message .= sprintf(' You should %s the "%s" service to "%s" instead.', isset($this->types[$this->types[$type]]) ? 'alias' : 'rename (or alias)', $this->types[$type], $type); - } - - @trigger_error($message, E_USER_DEPRECATED); - - return new TypedReference($this->types[$type], $type); + if (null === $this->types) { + $this->populateAvailableTypes(); } - if (!$reference->canBeAutoregistered() || isset($this->types[$type]) || isset($this->ambiguousServiceTypes[$type])) { + if (isset($this->types[$type]) || isset($this->ambiguousServiceTypes[$type])) { return; } @@ -499,30 +465,6 @@ private function createTypeAlternatives(TypedReference $reference) return sprintf(' You should maybe alias this %s to %s.', class_exists($type, false) ? 'class' : 'interface', $message); } - /** - * @deprecated since version 3.3, to be removed in 4.0. - */ - private static function getResourceMetadataForMethod(\ReflectionMethod $method) - { - $methodArgumentsMetadata = array(); - foreach ($method->getParameters() as $parameter) { - try { - $class = $parameter->getClass(); - } catch (\ReflectionException $e) { - // type-hint is against a non-existent class - $class = false; - } - - $methodArgumentsMetadata[] = array( - 'class' => $class, - 'isOptional' => $parameter->isOptional(), - 'defaultValue' => ($parameter->isOptional() && !$parameter->isVariadic()) ? $parameter->getDefaultValue() : null, - ); - } - - return $methodArgumentsMetadata; - } - private function getAliasesSuggestionForType($type, $extraContext = null) { $aliases = array(); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php b/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php index 8f7fc32b0b1b6..5919c1db85e26 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php @@ -52,24 +52,6 @@ public function getServiceReferenceGraph() return $this->serviceReferenceGraph; } - /** - * Returns the logging formatter which can be used by compilation passes. - * - * @return LoggingFormatter - * - * @deprecated since version 3.3, to be removed in 4.0. Use the ContainerBuilder::log() method instead. - */ - public function getLoggingFormatter() - { - if (null === $this->loggingFormatter) { - @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.', __METHOD__), E_USER_DEPRECATED); - - $this->loggingFormatter = new LoggingFormatter(); - } - - return $this->loggingFormatter; - } - /** * Adds a pass to the PassConfig. * @@ -82,20 +64,6 @@ public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BE $this->passConfig->addPass($pass, $type, $priority); } - /** - * Adds a log message. - * - * @param string $string The log message - * - * @deprecated since version 3.3, to be removed in 4.0. Use the ContainerBuilder::log() method instead. - */ - public function addLogMessage($string) - { - @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.', __METHOD__), E_USER_DEPRECATED); - - $this->log[] = $string; - } - /** * @final */ diff --git a/src/Symfony/Component/DependencyInjection/Compiler/FactoryReturnTypePass.php b/src/Symfony/Component/DependencyInjection/Compiler/FactoryReturnTypePass.php deleted file mode 100644 index 8834ff7e4f2b7..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Compiler/FactoryReturnTypePass.php +++ /dev/null @@ -1,108 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Compiler; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Reference; - -/** - * @author Guilhem N. - * - * @deprecated since version 3.3, to be removed in 4.0. - */ -class FactoryReturnTypePass implements CompilerPassInterface -{ - private $resolveClassPass; - - public function __construct(ResolveClassPass $resolveClassPass = null) - { - if (null === $resolveClassPass) { - @trigger_error('The '.__CLASS__.' class is deprecated since version 3.3 and will be removed in 4.0.', E_USER_DEPRECATED); - } - $this->resolveClassPass = $resolveClassPass; - } - - /** - * {@inheritdoc} - */ - public function process(ContainerBuilder $container) - { - $resolveClassPassChanges = null !== $this->resolveClassPass ? $this->resolveClassPass->getChanges() : array(); - - 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()) - { - // circular reference - $lcId = strtolower($id); - if (isset($previous[$lcId])) { - return; - } - - $factory = $definition->getFactory(); - if (null === $factory || (!isset($resolveClassPassChanges[$lcId]) && null !== $definition->getClass())) { - return; - } - - $class = null; - if (is_string($factory)) { - try { - $m = new \ReflectionFunction($factory); - if (false !== $m->getFileName() && file_exists($m->getFileName())) { - $container->fileExists($m->getFileName()); - } - } catch (\ReflectionException $e) { - return; - } - } else { - if ($factory[0] instanceof Reference) { - $previous[$lcId] = true; - $factoryDefinition = $container->findDefinition((string) $factory[0]); - $this->updateDefinition($container, $factory[0], $factoryDefinition, $resolveClassPassChanges, $previous); - $class = $factoryDefinition->getClass(); - } else { - $class = $factory[0]; - } - - if (!$m = $container->getReflectionClass($class)) { - return; - } - try { - $m = $m->getMethod($factory[1]); - } catch (\ReflectionException $e) { - return; - } - } - - $returnType = $m->getReturnType(); - if (null !== $returnType && !$returnType->isBuiltin()) { - $returnType = $returnType->getName(); - if (null !== $class) { - $declaringClass = $m->getDeclaringClass()->getName(); - if ('self' === strtolower($returnType)) { - $returnType = $declaringClass; - } elseif ('parent' === strtolower($returnType)) { - $returnType = get_parent_class($declaringClass) ?: null; - } - } - - if (null !== $returnType && (!isset($resolveClassPassChanges[$lcId]) || $returnType !== $resolveClassPassChanges[$lcId])) { - @trigger_error(sprintf('Relying on its factory\'s return-type to define the class of service "%s" is deprecated since Symfony 3.3 and won\'t work in 4.0. Set the "class" attribute to "%s" on the service definition instead.', $id, $returnType), E_USER_DEPRECATED); - } - $definition->setClass($returnType); - } - } -} diff --git a/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php b/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php deleted file mode 100644 index 0e126efaa5797..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php +++ /dev/null @@ -1,54 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Compiler; - -@trigger_error('The '.__NAMESPACE__.'\LoggingFormatter class is deprecated since version 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.', E_USER_DEPRECATED); - -/** - * Used to format logging messages during the compilation. - * - * @author Johannes M. Schmitt - * - * @deprecated since version 3.3, to be removed in 4.0. Use the ContainerBuilder::log() method instead. - */ -class LoggingFormatter -{ - public function formatRemoveService(CompilerPassInterface $pass, $id, $reason) - { - return $this->format($pass, sprintf('Removed service "%s"; reason: %s.', $id, $reason)); - } - - public function formatInlineService(CompilerPassInterface $pass, $id, $target) - { - return $this->format($pass, sprintf('Inlined service "%s" to "%s".', $id, $target)); - } - - public function formatUpdateReference(CompilerPassInterface $pass, $serviceId, $oldDestId, $newDestId) - { - return $this->format($pass, sprintf('Changed reference of service "%s" previously pointing to "%s" to "%s".', $serviceId, $oldDestId, $newDestId)); - } - - public function formatResolveInheritance(CompilerPassInterface $pass, $childId, $parentId) - { - return $this->format($pass, sprintf('Resolving inheritance for "%s" (parent: %s).', $childId, $parentId)); - } - - public function formatUnusedAutowiringPatterns(CompilerPassInterface $pass, $id, array $patterns) - { - return $this->format($pass, sprintf('Autowiring\'s patterns "%s" for service "%s" don\'t match any method.', implode('", "', $patterns), $id)); - } - - public function format(CompilerPassInterface $pass, $message) - { - return sprintf('%s: %s', get_class($pass), $message); - } -} diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index fa6d2c72fd535..97665c1f6e828 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -41,7 +41,7 @@ public function __construct() $this->beforeOptimizationPasses = array( 100 => array( - $resolveClassPass = new ResolveClassPass(), + new ResolveClassPass(), new ResolveInstanceofConditionalsPass(), ), ); @@ -53,7 +53,6 @@ public function __construct() new DecoratorServicePass(), new ResolveParameterPlaceHoldersPass(false), new ResolveFactoryClassPass(), - new FactoryReturnTypePass($resolveClassPass), new CheckDefinitionValidityPass(), new RegisterServiceSubscribersPass(), new ResolveNamedArgumentsPass(), diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveClassPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveClassPass.php index c40d6f5d3d0f1..0235e5abb8e3b 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveClassPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveClassPass.php @@ -20,8 +20,6 @@ */ class ResolveClassPass implements CompilerPassInterface { - private $changes = array(); - /** * {@inheritdoc} */ @@ -35,22 +33,8 @@ public function process(ContainerBuilder $container) if ($definition instanceof ChildDefinition && !class_exists($id)) { throw new InvalidArgumentException(sprintf('Service definition "%s" 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.', $id)); } - $this->changes[strtolower($id)] = $id; $definition->setClass($id); } } } - - /** - * @internal - * - * @deprecated since 3.3, to be removed in 4.0. - */ - public function getChanges() - { - $changes = $this->changes; - $this->changes = array(); - - return $changes; - } } diff --git a/src/Symfony/Component/DependencyInjection/Config/AutowireServiceResource.php b/src/Symfony/Component/DependencyInjection/Config/AutowireServiceResource.php deleted file mode 100644 index 8b507efe82eec..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Config/AutowireServiceResource.php +++ /dev/null @@ -1,78 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Config; - -@trigger_error('The '.__NAMESPACE__.'\AutowireServiceResource class is deprecated since version 3.3 and will be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead.', E_USER_DEPRECATED); - -use Symfony\Component\Config\Resource\SelfCheckingResourceInterface; -use Symfony\Component\DependencyInjection\Compiler\AutowirePass; - -/** - * @deprecated since version 3.3, to be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead. - */ -class AutowireServiceResource implements SelfCheckingResourceInterface, \Serializable -{ - private $class; - private $filePath; - private $autowiringMetadata = array(); - - public function __construct($class, $path, array $autowiringMetadata) - { - $this->class = $class; - $this->filePath = $path; - $this->autowiringMetadata = $autowiringMetadata; - } - - public function isFresh($timestamp) - { - if (!file_exists($this->filePath)) { - return false; - } - - // has the file *not* been modified? Definitely fresh - if (@filemtime($this->filePath) <= $timestamp) { - return true; - } - - try { - $reflectionClass = new \ReflectionClass($this->class); - } catch (\ReflectionException $e) { - // the class does not exist anymore! - return false; - } - - return (array) $this === (array) AutowirePass::createResourceForClass($reflectionClass); - } - - public function __toString() - { - return 'service.autowire.'.$this->class; - } - - public function serialize() - { - return serialize(array($this->class, $this->filePath, $this->autowiringMetadata)); - } - - public function unserialize($serialized) - { - list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized, array('allowed_classes' => false)); - } - - /** - * @deprecated Implemented for compatibility with Symfony 2.8 - */ - public function getResource() - { - return $this->filePath; - } -} diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index a14c29d55d206..3423ad515cc23 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -316,22 +316,6 @@ public function addObjectResource($object) return $this; } - /** - * Adds the given class hierarchy as resources. - * - * @param \ReflectionClass $class - * - * @return $this - * - * @deprecated since version 3.3, to be removed in 4.0. Use addObjectResource() or getReflectionClass() instead. - */ - public function addClassResource(\ReflectionClass $class) - { - @trigger_error('The '.__METHOD__.'() method is deprecated since version 3.3 and will be removed in 4.0. Use the addObjectResource() or the getReflectionClass() method instead.', E_USER_DEPRECATED); - - return $this->addObjectResource($class->name); - } - /** * Retrieves the requested reflection class and registers it for resource tracking. * diff --git a/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php b/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php deleted file mode 100644 index 25109d16b5e80..0000000000000 --- a/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection; - -@trigger_error('The '.__NAMESPACE__.'\DefinitionDecorator class is deprecated since version 3.3 and will be removed in 4.0. Use the Symfony\Component\DependencyInjection\ChildDefinition class instead.', E_USER_DEPRECATED); - -class_exists(ChildDefinition::class); - -if (false) { - /** - * This definition decorates another definition. - * - * @author Johannes M. Schmitt - * - * @deprecated The DefinitionDecorator class is deprecated since version 3.3 and will be removed in 4.0. Use the Symfony\Component\DependencyInjection\ChildDefinition class instead. - */ - class DefinitionDecorator extends Definition - { - } -} diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 692bb3e5d85de..4bec02a8871c5 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -395,7 +395,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] = array($services[0], $file); $services[0]->setAttribute('id', $id); // anonymous services are always private @@ -408,27 +408,16 @@ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults) // anonymous services "in the wild" if (false !== $nodes = $xpath->query('//container:services/container:service[not(@id)]')) { foreach ($nodes as $node) { - @trigger_error(sprintf('Top-level anonymous services are deprecated since Symfony 3.4, the "id" attribute will be required in version 4.0 in %s at line %d.', $file, $node->getLineNo()), E_USER_DEPRECATED); - - // give it a unique name - $id = sprintf('%d_%s', ++$count, hash('sha256', $file)); - $node->setAttribute('id', $id); - $definitions[$id] = array($node, $file, true); + throw new InvalidArgumentException(sprintf('Top-level services must have "id" attribute, none found in %s at line %d.', $file, $node->getLineNo())); } } // 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())) { + foreach (array_reverse($definitions) as $id => list($domElement, $file)) { + if (null !== $definition = $this->parseDefinition($domElement, $file, array())) { $this->setDefinition($id, $definition); } - - if (true === $wild) { - $tmpDomElement = new \DOMElement('_services', null, self::NS); - $domElement->parentNode->replaceChild($tmpDomElement, $domElement); - $tmpDomElement->setAttribute('id', $id); - } } } @@ -481,9 +470,6 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase = 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')) { - @trigger_error(sprintf('The "strict" attribute used when referencing the "%s" service is deprecated since version 3.3 and will be removed in 4.0.', $arg->getAttribute('id')), E_USER_DEPRECATED); - } $arguments[$key] = new Reference($arg->getAttribute('id'), $invalidBehavior); break; @@ -619,13 +605,13 @@ private function validateAlias(\DOMElement $alias, $file) { foreach ($alias->attributes as $name => $node) { if (!in_array($name, array('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); + throw new InvalidArgumentException(sprintf('Invalid attribute "%s" defined for alias "%s" in "%s".', $name, $alias->getAttribute('id'), $file)); } } foreach ($alias->childNodes as $child) { if ($child instanceof \DOMElement && $child->namespaceURI === self::NS) { - @trigger_error(sprintf('Using the element "%s" is deprecated for the service "%s" which is defined as an alias in "%s". The XmlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported elements.', $child->localName, $alias->getAttribute('id'), $file), E_USER_DEPRECATED); + throw new InvalidArgumentException(sprintf('Invalid child element "%s" defined for alias "%s" in "%s".', $child->localName, $alias->getAttribute('id'), $file)); } } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd b/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd index 967d080611c43..d644997e7d1a0 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd +++ b/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd @@ -203,7 +203,6 @@ - @@ -216,7 +215,6 @@ - diff --git a/src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php index a941b960746be..7f359b94f5311 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ChildDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; class ChildDefinitionTest extends TestCase { @@ -132,11 +131,6 @@ public function testGetArgumentShouldCheckBounds() $def->getArgument(1); } - public function testDefinitionDecoratorAliasExistsForBackwardsCompatibility() - { - $this->assertInstanceOf(ChildDefinition::class, new DefinitionDecorator('foo')); - } - /** * @expectedException \Symfony\Component\DependencyInjection\Exception\BadMethodCallException */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index d5b00fecc5af3..b94b189125d02 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -55,10 +55,8 @@ public function testProcessVariadic() } /** - * @group legacy - * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should alias the "Symfony\Component\DependencyInjection\Tests\Compiler\B" service to "Symfony\Component\DependencyInjection\Tests\Compiler\A" instead. - * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessageInSymfony4 Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service. + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionMessage Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service. */ public function testProcessAutowireParent() { @@ -76,32 +74,8 @@ public function testProcessAutowireParent() } /** - * @group legacy - * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" to "Symfony\Component\DependencyInjection\Tests\Compiler\AInterface" instead. - * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessageInSymfony4 Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service. - */ - public function testProcessLegacyAutowireWithAvailableInterface() - { - $container = new ContainerBuilder(); - - $container->setAlias(AInterface::class, B::class); - $container->register(B::class); - $cDefinition = $container->register('c', __NAMESPACE__.'\C'); - $cDefinition->setAutowired(true); - - (new ResolveClassPass())->process($container); - (new AutowirePass())->process($container); - - $this->assertCount(1, $container->getDefinition('c')->getArguments()); - $this->assertEquals(B::class, (string) $container->getDefinition('c')->getArgument(0)); - } - - /** - * @group legacy - * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should alias the "Symfony\Component\DependencyInjection\Tests\Compiler\F" service to "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" instead. - * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMessageInSymfony4 Cannot autowire service "g": argument "$d" of method "Symfony\Component\DependencyInjection\Tests\Compiler\G::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" but no such service exists. You should maybe alias this interface to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\F" service. + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionMessage Cannot autowire service "g": argument "$d" of method "Symfony\Component\DependencyInjection\Tests\Compiler\G::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" but no such service exists. You should maybe alias this interface to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\F" service. */ public function testProcessAutowireInterface() { @@ -385,10 +359,8 @@ public function testParentClassNotFoundThrowsException() } /** - * @group legacy - * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "foo" service to "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" instead. - * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessageInSymfony4 Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but this service is abstract. You should maybe alias this class to the existing "foo" service. + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException + * @expectedExceptionMessage Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but this service is abstract. You should maybe alias this class to the existing "foo" service. */ public function testDontUseAbstractServices() { @@ -590,32 +562,6 @@ public function testTypedReference() $this->assertSame(A::class, $container->getDefinition('autowired.'.A::class)->getClass()); } - /** - * @dataProvider getCreateResourceTests - * @group legacy - */ - public function testCreateResourceForClass($className, $isEqual) - { - $startingResource = AutowirePass::createResourceForClass( - new \ReflectionClass(__NAMESPACE__.'\ClassForResource') - ); - $newResource = AutowirePass::createResourceForClass( - new \ReflectionClass(__NAMESPACE__.'\\'.$className) - ); - - // hack so the objects don't differ by the class name - $startingReflObject = new \ReflectionObject($startingResource); - $reflProp = $startingReflObject->getProperty('class'); - $reflProp->setAccessible(true); - $reflProp->setValue($startingResource, __NAMESPACE__.'\\'.$className); - - if ($isEqual) { - $this->assertEquals($startingResource, $newResource); - } else { - $this->assertNotEquals($startingResource, $newResource); - } - } - public function getCreateResourceTests() { return array( @@ -657,10 +603,8 @@ public function testSetterInjectionCollisionThrowsException() } /** - * @group legacy - * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "foo" service to "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" instead. - * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessageInSymfony4 Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to the existing "foo" service. + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException + * @expectedExceptionMessage Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to the existing "foo" service. */ public function testProcessDoesNotTriggerDeprecations() { @@ -748,10 +692,8 @@ public function provideNotWireableCalls() } /** - * @group legacy - * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead. - * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException - * @expectedExceptionMessageInSymfony4 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. + * @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 testByIdAlternative() { @@ -766,25 +708,6 @@ public function testByIdAlternative() $pass->process($container); } - /** - * @group legacy - * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for "Symfony\Component\DependencyInjection\Tests\Compiler\A" in "Symfony\Component\DependencyInjection\Tests\Compiler\Bar" to "Symfony\Component\DependencyInjection\Tests\Compiler\AInterface" instead. - */ - public function testTypedReferenceDeprecationNotice() - { - $container = new ContainerBuilder(); - - $container->register('aClass', A::class); - $container->setAlias(AInterface::class, 'aClass'); - $container - ->register('bar', Bar::class) - ->setProperty('a', array(new TypedReference(A::class, A::class, Bar::class))) - ; - - $pass = new AutowirePass(); - $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. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php deleted file mode 100644 index e4d16a1f60c5b..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php +++ /dev/null @@ -1,109 +0,0 @@ - - * - * 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\Compiler\FactoryReturnTypePass; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\DependencyInjection\Tests\Fixtures\factoryFunction; -use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy; -use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryParent; - -/** - * @author Guilhem N. - * - * @group legacy - */ -class FactoryReturnTypePassTest extends TestCase -{ - public function testProcess() - { - $container = new ContainerBuilder(); - - $factory = $container->register('factory'); - $factory->setFactory(array(FactoryDummy::class, 'createFactory')); - - $container->setAlias('alias_factory', 'factory'); - - $foo = $container->register('foo'); - $foo->setFactory(array(new Reference('alias_factory'), 'create')); - - $bar = $container->register('bar', __CLASS__); - $bar->setFactory(array(new Reference('factory'), 'create')); - - $pass = new FactoryReturnTypePass(); - $pass->process($container); - - $this->assertEquals(FactoryDummy::class, $factory->getClass()); - $this->assertEquals(\stdClass::class, $foo->getClass()); - $this->assertEquals(__CLASS__, $bar->getClass()); - } - - /** - * @dataProvider returnTypesProvider - */ - public function testReturnTypes($factory, $returnType) - { - $container = new ContainerBuilder(); - - $service = $container->register('service'); - $service->setFactory($factory); - - $pass = new FactoryReturnTypePass(); - $pass->process($container); - - $this->assertEquals($returnType, $service->getClass()); - } - - public function returnTypesProvider() - { - return array( - // must be loaded before the function as they are in the same file - array(array(FactoryDummy::class, 'createBuiltin'), null), - array(array(FactoryDummy::class, 'createParent'), FactoryParent::class), - array(array(FactoryDummy::class, 'createSelf'), FactoryDummy::class), - array(factoryFunction::class, FactoryDummy::class), - ); - } - - public function testCircularReference() - { - $container = new ContainerBuilder(); - - $factory = $container->register('factory'); - $factory->setFactory(array(new Reference('factory2'), 'createSelf')); - - $factory2 = $container->register('factory2'); - $factory2->setFactory(array(new Reference('factory'), 'create')); - - $pass = new FactoryReturnTypePass(); - $pass->process($container); - - $this->assertNull($factory->getClass()); - $this->assertNull($factory2->getClass()); - } - - /** - * @expectedDeprecation Relying on its factory's return-type to define the class of service "factory" is deprecated since Symfony 3.3 and won't work in 4.0. Set the "class" attribute to "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy" on the service definition instead. - */ - public function testCompile() - { - $container = new ContainerBuilder(); - - $factory = $container->register('factory'); - $factory->setFactory(array(FactoryDummy::class, 'createFactory')); - $container->compile(); - - $this->assertEquals(FactoryDummy::class, $container->getDefinition('factory')->getClass()); - } -} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Config/AutowireServiceResourceTest.php b/src/Symfony/Component/DependencyInjection/Tests/Config/AutowireServiceResourceTest.php deleted file mode 100644 index 64d99e6375b8f..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Config/AutowireServiceResourceTest.php +++ /dev/null @@ -1,124 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Tests\Config; - -use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\Compiler\AutowirePass; -use Symfony\Component\DependencyInjection\Config\AutowireServiceResource; - -/** - * @group legacy - */ -class AutowireServiceResourceTest extends TestCase -{ - /** - * @var AutowireServiceResource - */ - private $resource; - private $file; - private $class; - private $time; - - protected function setUp() - { - $this->file = realpath(sys_get_temp_dir()).'/tmp.php'; - $this->time = time(); - touch($this->file, $this->time); - - $this->class = __NAMESPACE__.'\Foo'; - $this->resource = new AutowireServiceResource( - $this->class, - $this->file, - array() - ); - } - - public function testToString() - { - $this->assertSame('service.autowire.'.$this->class, (string) $this->resource); - } - - public function testSerializeUnserialize() - { - $unserialized = unserialize(serialize($this->resource)); - - $this->assertEquals($this->resource, $unserialized); - } - - public function testIsFresh() - { - $this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second'); - $this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed'); - $this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated'); - } - - public function testIsFreshForDeletedResources() - { - unlink($this->file); - - $this->assertFalse($this->resource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the resource does not exist'); - } - - public function testIsNotFreshChangedResource() - { - $oldResource = new AutowireServiceResource( - $this->class, - $this->file, - array('will_be_different') - ); - - // test with a stale file *and* a resource that *will* be different than the actual - $this->assertFalse($oldResource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the constructor arguments have changed'); - } - - public function testIsFreshSameConstructorArgs() - { - $oldResource = AutowirePass::createResourceForClass( - new \ReflectionClass(__NAMESPACE__.'\Foo') - ); - - // test with a stale file *but* the resource will not be changed - $this->assertTrue($oldResource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the constructor arguments have changed'); - } - - 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'); - } - - protected function tearDown() - { - if (!file_exists($this->file)) { - return; - } - - unlink($this->file); - } - - private function getStaleFileTime() - { - return $this->time - 10; - } -} - -class Foo -{ - public function __construct($foo) - { - } -} diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index a8b7f88313a6e..31c17c6fc2f0e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -712,32 +712,6 @@ public function testAddObjectResource() $this->assertSame(realpath(__DIR__.'/Fixtures/includes/classes.php'), realpath($resource->getResource())); } - /** - * @group legacy - */ - public function testAddClassResource() - { - $container = new ContainerBuilder(); - - $container->setResourceTracking(false); - $container->addClassResource(new \ReflectionClass('BarClass')); - - $this->assertEmpty($container->getResources(), 'No resources get registered without resource tracking'); - - $container->setResourceTracking(true); - $container->addClassResource(new \ReflectionClass('BarClass')); - - $resources = $container->getResources(); - - $this->assertCount(2, $resources, '2 resources were registered'); - - /* @var $resource \Symfony\Component\Config\Resource\FileResource */ - $resource = end($resources); - - $this->assertInstanceOf('Symfony\Component\Config\Resource\FileResource', $resource); - $this->assertSame(realpath(__DIR__.'/Fixtures/includes/classes.php'), realpath($resource->getResource())); - } - public function testGetReflectionClass() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php b/src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php deleted file mode 100644 index 92a212ec416a6..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php +++ /dev/null @@ -1,132 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Tests; - -use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\DefinitionDecorator; - -/** - * @group legacy - */ -class DefinitionDecoratorTest extends TestCase -{ - public function testConstructor() - { - $def = new DefinitionDecorator('foo'); - - $this->assertEquals('foo', $def->getParent()); - $this->assertEquals(array(), $def->getChanges()); - } - - /** - * @dataProvider getPropertyTests - */ - public function testSetProperty($property, $changeKey) - { - $def = new DefinitionDecorator('foo'); - - $getter = 'get'.ucfirst($property); - $setter = 'set'.ucfirst($property); - - $this->assertNull($def->$getter()); - $this->assertSame($def, $def->$setter('foo')); - $this->assertEquals('foo', $def->$getter()); - $this->assertEquals(array($changeKey => true), $def->getChanges()); - } - - public function getPropertyTests() - { - return array( - array('class', 'class'), - array('factory', 'factory'), - array('configurator', 'configurator'), - array('file', 'file'), - ); - } - - public function testSetPublic() - { - $def = new DefinitionDecorator('foo'); - - $this->assertTrue($def->isPublic()); - $this->assertSame($def, $def->setPublic(false)); - $this->assertFalse($def->isPublic()); - $this->assertEquals(array('public' => true), $def->getChanges()); - } - - public function testSetLazy() - { - $def = new DefinitionDecorator('foo'); - - $this->assertFalse($def->isLazy()); - $this->assertSame($def, $def->setLazy(false)); - $this->assertFalse($def->isLazy()); - $this->assertEquals(array('lazy' => true), $def->getChanges()); - } - - public function testSetAutowired() - { - $def = new DefinitionDecorator('foo'); - - $this->assertFalse($def->isAutowired()); - $this->assertSame($def, $def->setAutowired(true)); - $this->assertTrue($def->isAutowired()); - $this->assertSame(array('autowired' => true), $def->getChanges()); - } - - public function testSetArgument() - { - $def = new DefinitionDecorator('foo'); - - $this->assertEquals(array(), $def->getArguments()); - $this->assertSame($def, $def->replaceArgument(0, 'foo')); - $this->assertEquals(array('index_0' => 'foo'), $def->getArguments()); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testReplaceArgumentShouldRequireIntegerIndex() - { - $def = new DefinitionDecorator('foo'); - - $def->replaceArgument('0', 'foo'); - } - - public function testReplaceArgument() - { - $def = new DefinitionDecorator('foo'); - - $def->setArguments(array(0 => 'foo', 1 => 'bar')); - $this->assertEquals('foo', $def->getArgument(0)); - $this->assertEquals('bar', $def->getArgument(1)); - - $this->assertSame($def, $def->replaceArgument(1, 'baz')); - $this->assertEquals('foo', $def->getArgument(0)); - $this->assertEquals('baz', $def->getArgument(1)); - - $this->assertEquals(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments()); - } - - /** - * @expectedException \OutOfBoundsException - */ - public function testGetArgumentShouldCheckBounds() - { - $def = new DefinitionDecorator('foo'); - - $def->setArguments(array(0 => 'foo')); - $def->replaceArgument(0, 'foo'); - - $def->getArgument(1); - } -} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy_invalid_alias_definition.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/invalid_alias_definition.xml similarity index 62% rename from src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy_invalid_alias_definition.xml rename to src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/invalid_alias_definition.xml index 52386e5bf52df..8e99561dca608 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy_invalid_alias_definition.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/invalid_alias_definition.xml @@ -1,11 +1,6 @@ - - - - - - + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services5.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services5.xml index 721f028287750..1b72e778c3835 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services5.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services5.xml @@ -18,8 +18,5 @@ - - - diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php index e2ebd090ebefe..9a0376b6270f4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php @@ -183,7 +183,7 @@ public function testLoadAnonymousServices() $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('services5.xml'); $services = $container->getDefinitions(); - $this->assertCount(7, $services, '->load() attributes unique ids to anonymous services'); + $this->assertCount(6, $services, '->load() attributes unique ids to anonymous services'); // anonymous service as an argument $args = $services['foo']->getArguments(); @@ -212,16 +212,6 @@ public function testLoadAnonymousServices() $this->assertEquals('BuzClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones'); $this->assertFalse($inner->isPublic()); - // "wild" service - $service = $container->findTaggedServiceIds('biz_tag'); - $this->assertCount(1, $service); - - foreach ($service as $id => $tag) { - $service = $container->getDefinition($id); - } - $this->assertEquals('BizClass', $service->getClass(), '->load() uses the same configuration as for the anonymous ones'); - $this->assertTrue($service->isPublic()); - // anonymous services are shared when using decoration definitions $container->compile(); $services = $container->getDefinitions(); @@ -231,8 +221,8 @@ public function testLoadAnonymousServices() } /** - * @group legacy - * @expectedDeprecation Top-level anonymous services are deprecated since Symfony 3.4, the "id" attribute will be required in version 4.0 in %sservices_without_id.xml at line 4. + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessage Top-level services must have "id" attribute, none found in */ public function testLoadAnonymousServicesWithoutId() { @@ -625,17 +615,15 @@ public function testPrototype() } /** - * @group legacy - * @expectedDeprecation Using the attribute "class" is deprecated for the service "bar" which is defined as an alias %s. - * @expectedDeprecation Using the element "tag" is deprecated for the service "bar" which is defined as an alias %s. - * @expectedDeprecation Using the element "factory" is deprecated for the service "bar" which is defined as an alias %s. + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessage Invalid attribute "class" defined for alias "bar" in */ public function testAliasDefinitionContainsUnsupportedElements() { $container = new ContainerBuilder(); $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); - $loader->load('legacy_invalid_alias_definition.xml'); + $loader->load('invalid_alias_definition.xml'); $this->assertTrue($container->has('bar')); } diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index e38eb7b7822f8..ed60a1606c3bb 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1418,7 +1418,7 @@ public function isMethodSafe(/* $andCacheable = true */) { if (!func_num_args() || func_get_arg(0)) { // setting $andCacheable to false should be deprecated in 4.1 - throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.', E_USER_DEPRECATED); + throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.'); } return in_array($this->getMethod(), array('GET', 'HEAD', 'OPTIONS', 'TRACE'));