|
55 | 55 | use Symfony\Component\DependencyInjection\Tests\Compiler\Wither;
|
56 | 56 | use Symfony\Component\DependencyInjection\Tests\Compiler\WitherAnnotation;
|
57 | 57 | use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
|
| 58 | +use Symfony\Component\DependencyInjection\Tests\Fixtures\DependencyContainer; |
| 59 | +use Symfony\Component\DependencyInjection\Tests\Fixtures\DependencyContainerInterface; |
58 | 60 | use Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithEnumAttribute;
|
59 | 61 | use Symfony\Component\DependencyInjection\Tests\Fixtures\FooUnitEnum;
|
60 | 62 | use Symfony\Component\DependencyInjection\Tests\Fixtures\FooWithAbstractArgument;
|
@@ -1677,6 +1679,59 @@ public function testWitherWithStaticReturnType()
|
1677 | 1679 | $this->assertInstanceOf(Foo::class, $wither->foo);
|
1678 | 1680 | }
|
1679 | 1681 |
|
| 1682 | + public function testCloningLazyGhostWithDependency() |
| 1683 | + { |
| 1684 | + $container = new ContainerBuilder(); |
| 1685 | + $container->register('dependency', \stdClass::class); |
| 1686 | + $container->register(DependencyContainer::class) |
| 1687 | + ->addArgument(new Reference('dependency')) |
| 1688 | + ->setLazy(true) |
| 1689 | + ->setPublic(true); |
| 1690 | + |
| 1691 | + $container->compile(); |
| 1692 | + $dumper = new PhpDumper($container); |
| 1693 | + $dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Service_CloningLazyGhostWithDependency']); |
| 1694 | + eval('?>'.$dump); |
| 1695 | + |
| 1696 | + $container = new \Symfony_DI_PhpDumper_Service_CloningLazyGhostWithDependency(); |
| 1697 | + |
| 1698 | + $bar = $container->get(DependencyContainer::class); |
| 1699 | + $this->assertInstanceOf(DependencyContainer::class, $bar); |
| 1700 | + |
| 1701 | + $first_clone = clone $bar; |
| 1702 | + $second_clone = clone $bar; |
| 1703 | + |
| 1704 | + $this->assertSame($first_clone->dependency, $second_clone->dependency); |
| 1705 | + } |
| 1706 | + |
| 1707 | + public function testCloningProxyWithDependency() |
| 1708 | + { |
| 1709 | + $container = new ContainerBuilder(); |
| 1710 | + $container->register('dependency', \stdClass::class); |
| 1711 | + $container->register(DependencyContainer::class) |
| 1712 | + ->addArgument(new Reference('dependency')) |
| 1713 | + ->setLazy(true) |
| 1714 | + ->addTag('proxy', [ |
| 1715 | + 'interface' => DependencyContainerInterface::class, |
| 1716 | + ]) |
| 1717 | + ->setPublic(true); |
| 1718 | + |
| 1719 | + $container->compile(); |
| 1720 | + $dumper = new PhpDumper($container); |
| 1721 | + $dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Service_CloningProxyWithDependency']); |
| 1722 | + eval('?>'.$dump); |
| 1723 | + |
| 1724 | + $container = new \Symfony_DI_PhpDumper_Service_CloningProxyWithDependency(); |
| 1725 | + |
| 1726 | + $bar = $container->get(DependencyContainer::class); |
| 1727 | + $this->assertInstanceOf(DependencyContainerInterface::class, $bar); |
| 1728 | + |
| 1729 | + $first_clone = clone $bar; |
| 1730 | + $second_clone = clone $bar; |
| 1731 | + |
| 1732 | + $this->assertSame($first_clone->getDependency(), $second_clone->getDependency()); |
| 1733 | + } |
| 1734 | + |
1680 | 1735 | public function testCurrentFactoryInlining()
|
1681 | 1736 | {
|
1682 | 1737 | $container = new ContainerBuilder();
|
|
0 commit comments