* * 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\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; class ResolveClassPassTest extends TestCase { /** * @dataProvider provideValidClassId */ public function testResolveClassFromId($serviceId) { $container = new ContainerBuilder(); $def = $container->register($serviceId); (new ResolveClassPass())->process($container); $this->assertSame($serviceId, $def->getClass()); } public function provideValidClassId() { yield array('Acme\UnknownClass'); yield array(CaseSensitiveClass::class); } /** * @dataProvider provideInvalidClassId */ public function testWontResolveClassFromId($serviceId) { $container = new ContainerBuilder(); $def = $container->register($serviceId); (new ResolveClassPass())->process($container); $this->assertNull($def->getClass()); } public function provideInvalidClassId() { yield array(\stdClass::class); yield array('bar'); yield array('\DateTime'); } public function testNonFqcnChildDefinition() { $container = new ContainerBuilder(); $parent = $container->register('App\Foo', null); $child = $container->setDefinition('App\Foo.child', new ChildDefinition('App\Foo')); (new ResolveClassPass())->process($container); $this->assertSame('App\Foo', $parent->getClass()); $this->assertNull($child->getClass()); } public function testClassFoundChildDefinition() { $container = new ContainerBuilder(); $parent = $container->register('App\Foo', null); $child = $container->setDefinition(self::class, new ChildDefinition('App\Foo')); (new ResolveClassPass())->process($container); $this->assertSame('App\Foo', $parent->getClass()); $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() { $container = new ContainerBuilder(); $parent = $container->register('App\Foo', null); $child = $container->setDefinition('App\Foo\Child', new ChildDefinition('App\Foo')); (new ResolveClassPass())->process($container); } } __halt_compiler();----SIGNATURE:----wZcll1b0/ixTSDlTFbJek4lx99hja0whY90abUtiB3TRKCBoiymfQJjMCMTADyQMtgAk2xhSJAsreLVon6O6t1nVtLWiRLrrosFVBqprg1KnUSbMnNhkTFlDdd7MJYtiS8GQ5FkMMY9XKbMKVVWaXvWuEr/3WLbGeyRfyZYMFC1oevdtuHS6m0mydmwZ8bBuiSDxEcRQXLh7T7AeL6JwW/+21ZAnHQ5QkFXaPOpokeKljgA/fGGQmqQ+77hS+O+PMHWEmYqjbxeo+h5qAqF2ZuWZYSu91/9eIlFxK78mIPimInyjVQHpLm4BxJohlwNHY/2Xyg0Ub3UHJqG0p1Ff03zk/a/vOyA85FUHjRX7hdDOvKwiepiNkGRkKd6Y6h9/4e3lO1XSAkCq1/285vVBK4B6h89odCidyOfw9RhnVIGqSHZarZldqTICLCa6uX5yBfTaShb/uEKumgN0xy1hUsTB7NoghnVslbgcJZ8K3RQxP+bH0AtiwzY7GEIzwoypX6MP5/yBY2a4nbyvB5z9M/2DdmShqMIHHwXvcUHPJT+mlrgIlfCwXfPV131Vy1zKf8a25VyH3HpZMtjKLOTPgj0SIksJraZ/YJLchdtDd70SrQ+VlEDFcJ9rrs+qRmADiH9Y4fh66j5v97NtyobmKbX45FhzD11/U1TLa9hxuSk=----ATTACHMENT:----NDAzNjMyNTA4ODYyNjg2IDQ4Nzg5Njc3MjgyMTE5MzAgMzM1NTIxMDEwNjI0NTI0OA==