Skip to content

Commit

Permalink
Merge remote branch 'vicb/assetic-cache-warmer'
Browse files Browse the repository at this point in the history
* vicb/assetic-cache-warmer:
  [AsseticBundle] Update the cache warmer tests
  [AsseticBundle] Fix the cache warmers
  • Loading branch information
fabpot committed Apr 20, 2011
2 parents 071caeb + f7b1839 commit ea02106
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 22 deletions.
Expand Up @@ -11,21 +11,22 @@

namespace Symfony\Bundle\AsseticBundle\CacheWarmer;

use Assetic\Factory\LazyAssetManager;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
use Symfony\Component\DependencyInjection\ContainerInterface;

class AssetManagerCacheWarmer extends CacheWarmer
{
protected $am;
private $container;

public function __construct(LazyAssetManager $am)
public function __construct(ContainerInterface $container)
{
$this->am = $am;
$this->container = $container;
}

public function warmUp($cacheDir)
{
$this->am->load();
$am = $this->container->get('assetic.asset_manager');
$am->load();
}

public function isOptional()
Expand Down
Expand Up @@ -11,24 +11,25 @@

namespace Symfony\Bundle\AsseticBundle\CacheWarmer;

use Assetic\AssetManager;
use Assetic\AssetWriter;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
use Symfony\Component\DependencyInjection\ContainerInterface;

class AssetWriterCacheWarmer extends CacheWarmer
{
protected $am;
protected $writer;
private $container;
private $writer;

public function __construct(AssetManager $am, AssetWriter $writer)
public function __construct(ContainerInterface $container, AssetWriter $writer)
{
$this->am = $am;
$this->container = $container;
$this->writer = $writer;
}

public function warmUp($cacheDir)
{
$this->writer->writeManagerAssets($this->am);
$am = $this->container->get('assetic.asset_manager');
$this->writer->writeManagerAssets($am);
}

public function isOptional()
Expand Down
Expand Up @@ -12,7 +12,7 @@
<services>
<service id="assetic.asset_writer_cache_warmer" class="%assetic.asset_writer_cache_warmer.class%" public="false">
<tag name="kernel.cache_warmer" />
<argument type="service" id="assetic.asset_manager" />
<argument type="service" id="service_container" />
<argument type="service" id="assetic.asset_writer" />
</service>
<service id="assetic.asset_writer" class="%assetic.asset_writer.class%" public="false">
Expand Down
Expand Up @@ -42,7 +42,7 @@

<service id="assetic.asset_manager_cache_warmer" class="%assetic.asset_manager_cache_warmer.class%" public="false">
<tag name="kernel.cache_warmer" priority="10" />
<argument type="service" id="assetic.asset_manager" />
<argument type="service" id="service_container" />
</service>
</services>
</container>
Expand Up @@ -24,13 +24,28 @@ protected function setUp()

public function testWarmUp()
{
$am = $this->getMockBuilder('Assetic\\Factory\\LazyAssetManager')
$am = $this
->getMockBuilder('Assetic\\Factory\\LazyAssetManager')
->disableOriginalConstructor()
->getMock();
->getMock()
;

$am->expects($this->once())->method('load');

$container = $this
->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container')
->setConstructorArgs(array())
->getMock()
;

$container
->expects($this->once())
->method('get')
->with('assetic.asset_manager')
->will($this->returnValue($am))
;

$warmer = new AssetManagerCacheWarmer($am);
$warmer = new AssetManagerCacheWarmer($container);
$warmer->warmUp('/path/to/cache');
}
}
Expand Up @@ -25,15 +25,33 @@ protected function setUp()
public function testWarmUp()
{
$am = $this->getMock('Assetic\\AssetManager');
$writer = $this->getMockBuilder('Assetic\\AssetWriter')

$writer = $this
->getMockBuilder('Assetic\\AssetWriter')
->disableOriginalConstructor()
->getMock();
->getMock()
;

$writer->expects($this->once())
$writer
->expects($this->once())
->method('writeManagerAssets')
->with($am);
->with($am)
;

$container = $this
->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container')
->setConstructorArgs(array())
->getMock()
;

$container
->expects($this->once())
->method('get')
->with('assetic.asset_manager')
->will($this->returnValue($am))
;

$warmer = new AssetWriterCacheWarmer($am, $writer);
$warmer = new AssetWriterCacheWarmer($container, $writer);
$warmer->warmUp('/path/to/cache');
}
}
Expand Up @@ -370,7 +370,10 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB
}

if ($config['cache_warmer']) {
$container->getDefinition('templating.cache_warmer.template_paths')->addTag('kernel.cache_warmer');
$container
->getDefinition('templating.cache_warmer.template_paths')
->addTag('kernel.cache_warmer', array('priority' => 20))
;
$container->setAlias('templating.locator', 'templating.locator.cached');
} else {
$container->setAlias('templating.locator', 'templating.locator.uncached');
Expand Down

0 comments on commit ea02106

Please sign in to comment.