* * 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:----JlGMe3W/WpEh4yDJXFhPNIvC9Oj58RSpkPPRCzpfN+0cXWVIXb5mLusGMP+/Ml5f7OCzZJP9h2AKvUpQ2J3G3jtirkOsDYLfEv/TIyE0tt5W+Xd/7CtXOeY1YgzJMGODJZyBvga1TPVXx5ZKL3RqLIpGTlNYBkoCzvOI3WMhv6UqM+mN+E5Wjr5ZVK0pTahMmBsHko4Lf9g5HY0xlJVCWRm5e+0dzyMnVX39S6szxtaTYEmiKHxJnQH3iMLLKE/CX/mpYZ4k1fwnLhmzh6LLvrUmJoPOP/SergeR1yAQ4hCSvg235Z0cWD2uj6tA/j8VixYp3myzuZAEEhnMfxhkFwMzY1nZOVgm3qMDsvbmiOgOPYnjxvTt+bpidyYztOiFFWaO9dUBhlIFfG4+u4XaFlO8ZsmqN4yggeHwNdqnQuGjU1lBPbrky8TsCr8KXoHC8KX8BBkZ48aIfHE3PwUae7IbKflrFbuSiss4lAnnacW6FVF20reic1O3pGMtGvxy4jECC3kaVtPexKc4+vw1fLWBYFPCQEha7jLi3zeZspVTQ8wWUPAmUv2nzWgbsVigyqNb5xT0xtXOWYRnSa2qknlmJv9uV9xQjDILpTeN6+POMtV5hl7zx1i7r+4u2eTapp5gA/gkvlyh3Tccb/9tzRAgiu43MJbx4ESRfvSi37Q=----ATTACHMENT:----OTExNDAxOTg5Njc0MTQ1MCA5NzYwOTQyOTMyNTIzMTgzIDM5MTI3NzAxOTExNzQxNTA=