From 3b85c3b8a72b6747b8acf7b6acb06a37e8584929 Mon Sep 17 00:00:00 2001 From: radar3301 Date: Tue, 31 Oct 2023 16:18:43 -0600 Subject: [PATCH 1/2] Fix WriteProxiesToFile regression --- src/ContainerBuilder.php | 2 +- tests/UnitTest/ContainerBuilderTest.php | 39 ++++++++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/ContainerBuilder.php b/src/ContainerBuilder.php index 92d72bf4..7a7285c7 100644 --- a/src/ContainerBuilder.php +++ b/src/ContainerBuilder.php @@ -247,7 +247,7 @@ public function writeProxiesToFile(bool $writeToFile, string $proxyDirectory = n 'The proxy directory must be specified if you want to write proxies on disk' ); } - $this->proxyDirectory = $proxyDirectory; + $this->proxyDirectory = $writeToFile ? $proxyDirectory : null; return $this; } diff --git a/tests/UnitTest/ContainerBuilderTest.php b/tests/UnitTest/ContainerBuilderTest.php index 1a863cb7..ee37a230 100644 --- a/tests/UnitTest/ContainerBuilderTest.php +++ b/tests/UnitTest/ContainerBuilderTest.php @@ -21,18 +21,19 @@ class ContainerBuilderTest extends TestCase { use EasyMock; + + private static function getProperty(object $object, string $propertyName) + { + return (function (string $propertyName) { + return $this->$propertyName; + })->bindTo($object, $object)($propertyName); + } /** * @test */ public function should_configure_for_development_by_default() { - $getProperty = function (object $object, string $propertyName) { - return (function (string $propertyName) { - return $this->$propertyName; - })->bindTo($object, $object)($propertyName); - }; - // Make the ContainerBuilder use our fake class to catch constructor parameters $builder = new ContainerBuilder(FakeContainer::class); /** @var FakeContainer $container */ @@ -41,7 +42,7 @@ public function should_configure_for_development_by_default() // Not compiled $this->assertNotInstanceOf(CompiledContainer::class, $container); // Proxies evaluated in memory - $this->assertNull($getProperty($container->proxyFactory, 'proxyDirectory')); + $this->assertNull(self::getProperty($container->proxyFactory, 'proxyDirectory')); } /** @@ -248,4 +249,28 @@ public function should_throw_if_modified_after_building_a_container() $builder->addDefinitions([]); } + + /** + * @test + */ + public function should_create_proxies() + { + $builder = new ContainerBuilder(FakeContainer::class); + $builder->writeProxiesToFile(true, 'somedir'); + $container = $builder->build(); + + $this->assertSame('somedir', self::getProperty($container->proxyFactory, 'proxyDirectory')); + } + + /** + * @test + */ + public function should_not_create_proxies() + { + $builder = new ContainerBuilder(FakeContainer::class); + $builder->writeProxiesToFile(false, 'somedir'); + $container = $builder->build(); + + $this->assertNull(self::getProperty($container->proxyFactory, 'proxyDirectory')); + } } From 266d2a3d0e7033adfe167087b714e9b31b3f3705 Mon Sep 17 00:00:00 2001 From: radar3301 Date: Tue, 31 Oct 2023 16:21:50 -0600 Subject: [PATCH 2/2] Fix coding style typos --- tests/UnitTest/ContainerBuilderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/UnitTest/ContainerBuilderTest.php b/tests/UnitTest/ContainerBuilderTest.php index ee37a230..c88062e7 100644 --- a/tests/UnitTest/ContainerBuilderTest.php +++ b/tests/UnitTest/ContainerBuilderTest.php @@ -256,7 +256,7 @@ public function should_throw_if_modified_after_building_a_container() public function should_create_proxies() { $builder = new ContainerBuilder(FakeContainer::class); - $builder->writeProxiesToFile(true, 'somedir'); + $builder->writeProxiesToFile(true, 'somedir'); $container = $builder->build(); $this->assertSame('somedir', self::getProperty($container->proxyFactory, 'proxyDirectory')); @@ -268,7 +268,7 @@ public function should_create_proxies() public function should_not_create_proxies() { $builder = new ContainerBuilder(FakeContainer::class); - $builder->writeProxiesToFile(false, 'somedir'); + $builder->writeProxiesToFile(false, 'somedir'); $container = $builder->build(); $this->assertNull(self::getProperty($container->proxyFactory, 'proxyDirectory'));