bug #34515 [DependencyInjection] definitions are valid objects (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[DependencyInjection] definitions are valid objects

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34480
| License       | MIT
| Doc PR        |

Commits
-------

0acaa5cfb3 definitions are valid objects
This commit is contained in:
Fabien Potencier 2019-11-25 08:06:53 +01:00
commit f6c4b67fe3
3 changed files with 28 additions and 0 deletions

View File

@ -152,6 +152,10 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
return;
}
if ('object' === $type) {
return;
}
if (is_a($class, $type, true)) {
return;
}

View File

@ -15,12 +15,14 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Bar;
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\Foo;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\FooObject;
/**
* @author Nicolas Grekas <p@tchwork.com>
@ -390,6 +392,18 @@ class CheckTypeDeclarationsPassTest extends TestCase
$this->addToAssertionCount(1);
}
public function testProcessSuccessWhenPassingDefintionForObjectType()
{
$container = new ContainerBuilder();
$container->register('foo_object', FooObject::class)
->addArgument(new Definition(Foo::class));
(new CheckTypeDeclarationsPass(true))->process($container);
$this->addToAssertionCount(1);
}
public function testProcessFactory()
{
$container = new ContainerBuilder();

View File

@ -0,0 +1,10 @@
<?php
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass;
class FooObject
{
public function __construct(object $foo)
{
}
}