* * 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\Compiler\FactoryReturnTypePass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\factoryFunction; use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy; use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryParent; /** * @author Guilhem N. * * @group legacy */ class FactoryReturnTypePassTest extends TestCase { public function testProcess() { $container = new ContainerBuilder(); $factory = $container->register('factory'); $factory->setFactory(array(FactoryDummy::class, 'createFactory')); $container->setAlias('alias_factory', 'factory'); $foo = $container->register('foo'); $foo->setFactory(array(new Reference('alias_factory'), 'create')); $bar = $container->register('bar', __CLASS__); $bar->setFactory(array(new Reference('factory'), 'create')); $pass = new FactoryReturnTypePass(); $pass->process($container); if (method_exists(\ReflectionMethod::class, 'getReturnType')) { $this->assertEquals(FactoryDummy::class, $factory->getClass()); $this->assertEquals(\stdClass::class, $foo->getClass()); } else { $this->assertNull($factory->getClass()); $this->assertNull($foo->getClass()); } $this->assertEquals(__CLASS__, $bar->getClass()); } /** * @dataProvider returnTypesProvider */ public function testReturnTypes($factory, $returnType, $hhvmSupport = true) { if (!$hhvmSupport && defined('HHVM_VERSION')) { $this->markTestSkipped('Scalar typehints not supported by hhvm.'); } $container = new ContainerBuilder(); $service = $container->register('service'); $service->setFactory($factory); $pass = new FactoryReturnTypePass(); $pass->process($container); if (method_exists(\ReflectionMethod::class, 'getReturnType')) { $this->assertEquals($returnType, $service->getClass()); } else { $this->assertNull($service->getClass()); } } public function returnTypesProvider() { return array( // must be loaded before the function as they are in the same file array(array(FactoryDummy::class, 'createBuiltin'), null, false), array(array(FactoryDummy::class, 'createParent'), FactoryParent::class), array(array(FactoryDummy::class, 'createSelf'), FactoryDummy::class), array(factoryFunction::class, FactoryDummy::class), ); } public function testCircularReference() { $container = new ContainerBuilder(); $factory = $container->register('factory'); $factory->setFactory(array(new Reference('factory2'), 'createSelf')); $factory2 = $container->register('factory2'); $factory2->setFactory(array(new Reference('factory'), 'create')); $pass = new FactoryReturnTypePass(); $pass->process($container); $this->assertNull($factory->getClass()); $this->assertNull($factory2->getClass()); } /** * @requires function ReflectionMethod::getReturnType * @expectedDeprecation Relying on its factory's return-type to define the class of service "factory" is deprecated since Symfony 3.3 and won't work in 4.0. Set the "class" attribute to "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy" on the service definition instead. */ public function testCompile() { $container = new ContainerBuilder(); $factory = $container->register('factory'); $factory->setFactory(array(FactoryDummy::class, 'createFactory')); $container->compile(); $this->assertEquals(FactoryDummy::class, $container->getDefinition('factory')->getClass()); } } __halt_compiler();----SIGNATURE:----m/MD0xsyWna6IKMzSxYJRIRMT+gAM8Xm4Rrh4KYP4YGPwZFB/uhoc6+0+YuyyOGd8EIj7zP2dEg/RxOIhbBbIjSRTlNk9XWGWDV33qWUd0BoE40tyRQIkozAP3eimgj8fIEc1oWF2eIwvuPo9KE2kZBYWmxVgRyP8+rL4iSc76LP2jQA00xLBE6Z7+hLMUrTrKgGHpNUbquep2A0BTicwuBcM5i6d585ULF0lsGh6dfldKMZ4Aq9YlDiyrTNhuPmBdA7gPz8l2984TIHrVCbhL9ldIIN0r9mmEoMDcFw+NMVsbttPSWsGV5zz179ktQbzd4H3wSrV4DubXtsiBI9R5sK2ACk3nyS78QihpluKxWxcDCewfT2YAoCSt8NM6Vd/Uj7wqh5i7u1naNPqpJDMTwF52ZcP51m/2HWCRqH9oqBQqvQdbLmPR3IwU4tKaXXrPcSGdiTFTVImhDRHu6TrY/wF6TnmHc4b6OdXuQXa6Sw2zKnBXYaZyJU9cV6S+k8ZLWtXafd6S+Wb8sVPOXO4vk4rAG0OZqyO5y7msq97VWWjiHNqGiWB9Ej+11uRk/pdx/mdoUODEcEbyzd6AOydcOso5TuXr/3zrnHTdcdLBVW+jLMQPDaQhB4CW7iRp9auFo2w9dgHFz39Kegc3mJFY/kdcisW/wCX4HfOJ/iaYI=----ATTACHMENT:----MTAwMzQxMDcxNTk0NDU3NSA0Mzc4NTI1OTczMzgwODg1IDQ4ODA0NzUwNzI3OTQ1NzI=