Skip to content

Commit 8097948

Browse files
authored
Merge pull request PHP-DI#868 from radar3301/fix-write-proxies-regression
Fix write proxies regression
2 parents bb5dd2a + 266d2a3 commit 8097948

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/ContainerBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function writeProxiesToFile(bool $writeToFile, string $proxyDirectory = n
247247
'The proxy directory must be specified if you want to write proxies on disk'
248248
);
249249
}
250-
$this->proxyDirectory = $proxyDirectory;
250+
$this->proxyDirectory = $writeToFile ? $proxyDirectory : null;
251251

252252
return $this;
253253
}

tests/UnitTest/ContainerBuilderTest.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@
2121
class 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

Comments
 (0)