* * 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\AutowireExceptionPass; use Symfony\Component\DependencyInjection\Compiler\AutowirePass; use Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException; /** * @group legacy */ class AutowireExceptionPassTest extends TestCase { public function testThrowsException() { $autowirePass = $this->getMockBuilder(AutowirePass::class) ->getMock(); $autowireException = new AutowiringFailedException('foo_service_id', 'An autowiring exception message'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') ->will($this->returnValue(array($autowireException))); $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') ->will($this->returnValue(array())); $container = new ContainerBuilder(); $container->register('foo_service_id'); $pass = new AutowireExceptionPass($autowirePass, $inlinePass); try { $pass->process($container); $this->fail('->process() should throw the exception if the service id exists'); } catch (\Exception $e) { $this->assertSame($autowireException, $e); } } public function testThrowExceptionIfServiceInlined() { $autowirePass = $this->getMockBuilder(AutowirePass::class) ->getMock(); $autowireException = new AutowiringFailedException('a_service', 'An autowiring exception message'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') ->will($this->returnValue(array($autowireException))); $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') ->will($this->returnValue(array( // a_service inlined into b_service 'a_service' => array('b_service'), // b_service inlined into c_service 'b_service' => array('c_service'), ))); $container = new ContainerBuilder(); // ONLY register c_service in the final container $container->register('c_service', 'stdClass'); $pass = new AutowireExceptionPass($autowirePass, $inlinePass); try { $pass->process($container); $this->fail('->process() should throw the exception if the service id exists'); } catch (\Exception $e) { $this->assertSame($autowireException, $e); } } public function testDoNotThrowExceptionIfServiceInlinedButRemoved() { $autowirePass = $this->getMockBuilder(AutowirePass::class) ->getMock(); $autowireException = new AutowiringFailedException('a_service', 'An autowiring exception message'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') ->will($this->returnValue(array($autowireException))); $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') ->will($this->returnValue(array( // a_service inlined into b_service 'a_service' => array('b_service'), // b_service inlined into c_service 'b_service' => array('c_service'), ))); // do NOT register c_service in the container $container = new ContainerBuilder(); $pass = new AutowireExceptionPass($autowirePass, $inlinePass); $pass->process($container); // mark the test as passed $this->assertTrue(true); } public function testNoExceptionIfServiceRemoved() { $autowirePass = $this->getMockBuilder(AutowirePass::class) ->getMock(); $autowireException = new AutowiringFailedException('non_existent_service'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') ->will($this->returnValue(array($autowireException))); $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') ->will($this->returnValue(array())); $container = new ContainerBuilder(); $pass = new AutowireExceptionPass($autowirePass, $inlinePass); $pass->process($container); // mark the test as passed $this->assertTrue(true); } } __halt_compiler();----SIGNATURE:----hjnIaguhNPoay+6emTm6DuNkrIrDDRfFlX3CaD+QB6Hdy6Zfrde/5KrBesaYrldiq5fBhXSwtTdGDhqpyxU6tNlLNfCSbBvoGM65qib5P5kBDznkoxDqPP5a36GmDDY/PeafVFywYCRsKeB9byiEjkHKORKBcSIxpQMOrYVH5UjFgxIrzt3MFyMZPIkygaP5sqx8AQxD0wTC+mO5gM7TLfF9qmuqDnHG3qiPFytSu+JUvNOx8XgWKPZ5HAsPL7pvR+vPUyi49gIMTeIITca3Acazt4a30v2DwcXOblo+kBT9UthuP3wi+X2c6hEpbeg3NTDYlwZqDJK1YpH98MWfaI/Ly8i7UHUifANMFBkgek5/6U65i67D58k/8M6cpaMIvsLL7GfmcDvxr61f2E+ZlWbLuKdX6RAPTXqxSkYibHqtwplMSiXTydxjlw5cn42+gjGGw76y3gkcxMlSMYFiogFr3dvqMzFKgw5zw73Ak9WKDeUQtkPKv0oeM4r7vtq9cbY9VDieVpX3mOw6SAutJzFcjpLKNCjd3LD6mC5XAH8ZYHIU8rN41lFRMZ2Ni+IYwCuyJX/RhwlhR8s51FBgEcn3eEENpEA14CFU7MZBLV0aYZRV3dDLjy3yboLqHBmG//1Wuans7uMKS7mgKbFCHv87IoR4o9kZCRmxqSsNA6A=----ATTACHMENT:----NzYxMjA4MzYwMjc4MjE2NiA4OTgzNzkzODA1NjM4MzkgNDUzNjM0MTU0ODQ5MjMxMw==