Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'));
}
}