48
48
use Symfony \Component \DependencyInjection \Tests \Compiler \AInterface ;
49
49
use Symfony \Component \DependencyInjection \Tests \Compiler \Foo ;
50
50
use Symfony \Component \DependencyInjection \Tests \Compiler \FooAnnotation ;
51
+ use Symfony \Component \DependencyInjection \Tests \Compiler \FooVoid ;
51
52
use Symfony \Component \DependencyInjection \Tests \Compiler \IInterface ;
52
53
use Symfony \Component \DependencyInjection \Tests \Compiler \MyCallable ;
53
54
use Symfony \Component \DependencyInjection \Tests \Compiler \SingleMethodInterface ;
@@ -1874,12 +1875,18 @@ public function testAutowireClosure()
1874
1875
public function testLazyClosure ()
1875
1876
{
1876
1877
$ container = new ContainerBuilder ();
1877
- $ container ->register ('closure ' , 'Closure ' )
1878
+ $ container ->register ('closure1 ' , 'Closure ' )
1878
1879
->setPublic ('true ' )
1879
1880
->setFactory (['Closure ' , 'fromCallable ' ])
1880
1881
->setLazy (true )
1881
1882
->setArguments ([[new Reference ('foo ' ), 'cloneFoo ' ]]);
1883
+ $ container ->register ('closure2 ' , 'Closure ' )
1884
+ ->setPublic ('true ' )
1885
+ ->setFactory (['Closure ' , 'fromCallable ' ])
1886
+ ->setLazy (true )
1887
+ ->setArguments ([[new Reference ('foo_void ' ), '__invoke ' ]]);
1882
1888
$ container ->register ('foo ' , Foo::class);
1889
+ $ container ->register ('foo_void ' , FooVoid::class);
1883
1890
$ container ->compile ();
1884
1891
$ dumper = new PhpDumper ($ container );
1885
1892
@@ -1890,11 +1897,18 @@ public function testLazyClosure()
1890
1897
$ container = new \Symfony_DI_PhpDumper_Test_Lazy_Closure ();
1891
1898
1892
1899
$ cloned = Foo::$ counter ;
1893
- $ this ->assertInstanceOf (\Closure::class, $ container ->get ('closure ' ));
1900
+ $ this ->assertInstanceOf (\Closure::class, $ container ->get ('closure1 ' ));
1894
1901
$ this ->assertSame ($ cloned , Foo::$ counter );
1895
- $ this ->assertInstanceOf (Foo::class, $ container ->get ('closure ' )());
1902
+ $ this ->assertInstanceOf (Foo::class, $ container ->get ('closure1 ' )());
1896
1903
$ this ->assertSame (1 + $ cloned , Foo::$ counter );
1897
- $ this ->assertSame (1 , (new \ReflectionFunction ($ container ->get ('closure ' )))->getNumberOfParameters ());
1904
+ $ this ->assertSame (1 , (new \ReflectionFunction ($ container ->get ('closure1 ' )))->getNumberOfParameters ());
1905
+
1906
+ $ counter = FooVoid::$ counter ;
1907
+ $ this ->assertInstanceOf (\Closure::class, $ container ->get ('closure2 ' ));
1908
+ $ this ->assertSame ($ counter , FooVoid::$ counter );
1909
+ $ container ->get ('closure2 ' )('Hello ' );
1910
+ $ this ->assertSame (1 + $ counter , FooVoid::$ counter );
1911
+ $ this ->assertSame (1 , (new \ReflectionFunction ($ container ->get ('closure2 ' )))->getNumberOfParameters ());
1898
1912
}
1899
1913
1900
1914
public function testLazyAutowireAttribute ()
0 commit comments