Skip to content

Commit

Permalink
Merge pull request PHP-DI#868 from radar3301/fix-write-proxies-regres…
Browse files Browse the repository at this point in the history
…sion

Fix write proxies regression
  • Loading branch information
mnapoli authored Nov 2, 2023
2 parents bb5dd2a + 266d2a3 commit 8097948
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
39 changes: 32 additions & 7 deletions tests/UnitTest/ContainerBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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'));
}

/**
Expand Down Expand Up @@ -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'));
}
}

0 comments on commit 8097948

Please sign in to comment.