2121class ContainerBuilderTest extends TestCase
2222{
2323 use EasyMock;
24+
25+ private static function getProperty (object $ object , string $ propertyName )
26+ {
27+ return (function (string $ propertyName ) {
28+ return $ this ->$ propertyName ;
29+ })->bindTo ($ object , $ object )($ propertyName );
30+ }
2431
2532 /**
2633 * @test
2734 */
2835 public function should_configure_for_development_by_default ()
2936 {
30- $ getProperty = function (object $ object , string $ propertyName ) {
31- return (function (string $ propertyName ) {
32- return $ this ->$ propertyName ;
33- })->bindTo ($ object , $ object )($ propertyName );
34- };
35-
3637 // Make the ContainerBuilder use our fake class to catch constructor parameters
3738 $ builder = new ContainerBuilder (FakeContainer::class);
3839 /** @var FakeContainer $container */
@@ -41,7 +42,7 @@ public function should_configure_for_development_by_default()
4142 // Not compiled
4243 $ this ->assertNotInstanceOf (CompiledContainer::class, $ container );
4344 // Proxies evaluated in memory
44- $ this ->assertNull ($ getProperty ($ container ->proxyFactory , 'proxyDirectory ' ));
45+ $ this ->assertNull (self :: getProperty ($ container ->proxyFactory , 'proxyDirectory ' ));
4546 }
4647
4748 /**
@@ -248,4 +249,28 @@ public function should_throw_if_modified_after_building_a_container()
248249
249250 $ builder ->addDefinitions ([]);
250251 }
252+
253+ /**
254+ * @test
255+ */
256+ public function should_create_proxies ()
257+ {
258+ $ builder = new ContainerBuilder (FakeContainer::class);
259+ $ builder ->writeProxiesToFile (true , 'somedir ' );
260+ $ container = $ builder ->build ();
261+
262+ $ this ->assertSame ('somedir ' , self ::getProperty ($ container ->proxyFactory , 'proxyDirectory ' ));
263+ }
264+
265+ /**
266+ * @test
267+ */
268+ public function should_not_create_proxies ()
269+ {
270+ $ builder = new ContainerBuilder (FakeContainer::class);
271+ $ builder ->writeProxiesToFile (false , 'somedir ' );
272+ $ container = $ builder ->build ();
273+
274+ $ this ->assertNull (self ::getProperty ($ container ->proxyFactory , 'proxyDirectory ' ));
275+ }
251276}
0 commit comments