[DI] Skip deprecated definitions in CheckTypeDeclarationsPass

This commit is contained in:
Robin Chalas 2021-01-15 18:01:26 +01:00
parent 8076c2f8ba
commit 531c81a06e
3 changed files with 24 additions and 1 deletions

View File

@ -84,7 +84,7 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
return $value;
}
if (!$value instanceof Definition || $value->hasErrors()) {
if (!$value instanceof Definition || $value->hasErrors() || $value->isDeprecated()) {
return parent::processValue($value, $isRoot);
}

View File

@ -24,6 +24,7 @@ use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPa
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgument;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgumentNotNull;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Deprecated;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\FooObject;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructor;
@ -723,6 +724,19 @@ class CheckTypeDeclarationsPassTest extends TestCase
$this->addToAssertionCount(1);
}
public function testProcessSkipsDeprecatedDefinitions()
{
$container = new ContainerBuilder();
$container
->register('foobar', Deprecated::class)
->setDeprecated(true)
;
(new CheckTypeDeclarationsPass(true))->process($container);
$this->addToAssertionCount(1);
}
public function testProcessHandleClosureForCallable()
{
$closureDefinition = new Definition(\Closure::class);

View File

@ -0,0 +1,9 @@
<?php
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass;
trigger_deprecation('foo/bar', '1.2.3', 'Deprecated class.');
class Deprecated
{
}