Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[DoctrineBundle] Stop the cache warmer if proxies are auto-generated …
…anyways.
  • Loading branch information
beberlei authored and fabpot committed Jan 26, 2011
1 parent 5700be7 commit 3eadf73
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Expand Up @@ -49,6 +49,7 @@ public function isOptional()

public function warmUp($cacheDir)
{
// we need the directory no matter the proxy cache generation strategy.
$proxyCacheDir = $this->container->getParameter('doctrine.orm.proxy_dir');
if (!file_exists($proxyCacheDir)) {
if (false === @mkdir($proxyCacheDir, 0777, true)) {
Expand All @@ -58,6 +59,11 @@ public function warmUp($cacheDir)
throw new \RuntimeException(sprintf('Doctrine Proxy directory (%s) is not writeable for the current system user.', $proxyCacheDir));
}

// if proxys are autogenerated we don't need to generate them in the cache warmer.
if ($this->container->getParameter('doctrine.orm.auto_generate_proxy_classes') === true) {
return;
}

$entityManagers = $this->container->getParameter('doctrine.orm.entity_managers');
foreach ($entityManagers AS $entityManagerName) {
$em = $this->container->get(sprintf('doctrine.orm.%s_entity_manager', $entityManagerName));
Expand Down
Expand Up @@ -28,20 +28,25 @@ public function testWarmCache()
$testManager = $this->createTestEntityManager(array(
__DIR__ . "/../DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Entity")
);

$container = $this->getMock('Symfony\Component\DependencyInjection\Container');
$container->expects($this->at(0))
->method('getParameter')
->with($this->equalTo('doctrine.orm.proxy_dir'))
->will($this->returnValue(sys_get_temp_dir()));
$container->expects($this->at(1))
->method('getParameter')
->with($this->equalTo('doctrine.orm.auto_generate_proxy_classes'))
->will($this->returnValue( false ));
$container->expects($this->at(2))
->method('getParameter')
->with($this->equalTo('doctrine.orm.entity_managers'))
->will($this->returnValue(array('default', 'foo')));
$container->expects($this->at(2))
$container->expects($this->at(3))
->method('get')
->with($this->equalTo('doctrine.orm.default_entity_manager'))
->will($this->returnValue($testManager));
$container->expects($this->at(3))
$container->expects($this->at(4))
->method('get')
->with($this->equalTo('doctrine.orm.foo_entity_manager'))
->will($this->returnValue($testManager));
Expand All @@ -50,6 +55,32 @@ public function testWarmCache()
$cacheWarmer->warmUp(sys_get_temp_dir());
}

public function testSkipWhenProxiesAreAutoGenerated()
{
$testManager = $this->createTestEntityManager(array(
__DIR__ . "/../DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Entity")
);

$container = $this->getMock('Symfony\Component\DependencyInjection\Container');
$container->expects($this->at(0))
->method('getParameter')
->with($this->equalTo('doctrine.orm.proxy_dir'))
->will($this->returnValue(sys_get_temp_dir()));
$container->expects($this->at(1))
->method('getParameter')
->with($this->equalTo('doctrine.orm.auto_generate_proxy_classes'))
->will($this->returnValue( true ));
$container->expects($this->at(2))
->method('getParameter')
->with($this->equalTo('assertion'))
->will($this->returnValue( true ));

$cacheWarmer = new ProxyCacheWarmer($container);
$cacheWarmer->warmUp(sys_get_temp_dir());

$container->getParameter('assertion'); // check that the assertion is really the third call.
}

public function testProxyCacheWarmingIsNotOptional()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\Container');
Expand Down

0 comments on commit 3eadf73

Please sign in to comment.