Skip to content

Commit 6a7a175

Browse files
committed
definitions are valid objects
1 parent d443981 commit 6a7a175

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Compiler/CheckTypeDeclarationsPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
152152
return;
153153
}
154154

155+
if ('object' === $type) {
156+
return;
157+
}
158+
155159
if (is_a($class, $type, true)) {
156160
return;
157161
}

Tests/Compiler/CheckTypeDeclarationsPassTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1616
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\DependencyInjection\Definition;
1819
use Symfony\Component\DependencyInjection\Reference;
1920
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Bar;
2021
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall;
2122
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgument;
2223
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgumentNotNull;
2324
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo;
25+
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\FooObject;
2426

2527
/**
2628
* @author Nicolas Grekas <[email protected]>
@@ -390,6 +392,18 @@ public function testProcessSuccessWhenPassingAnIteratorArgumentToIterable()
390392
$this->addToAssertionCount(1);
391393
}
392394

395+
public function testProcessSuccessWhenPassingDefintionForObjectType()
396+
{
397+
$container = new ContainerBuilder();
398+
399+
$container->register('foo_object', FooObject::class)
400+
->addArgument(new Definition(Foo::class));
401+
402+
(new CheckTypeDeclarationsPass(true))->process($container);
403+
404+
$this->addToAssertionCount(1);
405+
}
406+
393407
public function testProcessFactory()
394408
{
395409
$container = new ContainerBuilder();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass;
4+
5+
class FooObject
6+
{
7+
public function __construct(object $foo)
8+
{
9+
}
10+
}

0 commit comments

Comments
 (0)