Skip to content

Commit

Permalink
[AsseticBundle] added test of dumping one asset
Browse files Browse the repository at this point in the history
  • Loading branch information
kriswallsmith committed May 7, 2011
1 parent 6f03a08 commit 520941d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Symfony/Bundle/AsseticBundle/Tests/Command/DumpCommandTest.php
Expand Up @@ -17,6 +17,7 @@

class DumpCommandTest extends \PHPUnit_Framework_TestCase
{
private $writeTo;
private $application;
private $definition;
private $kernel;
Expand All @@ -29,6 +30,8 @@ protected function setUp()
$this->markTestSkipped('Assetic is not available.');
}

$this->writeTo = sys_get_temp_dir().'/assetic_dump';

$this->application = $this->getMockBuilder('Symfony\\Bundle\\FrameworkBundle\\Console\\Application')
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -56,6 +59,10 @@ protected function setUp()
$this->kernel->expects($this->any())
->method('getContainer')
->will($this->returnValue($this->container));
$this->container->expects($this->any())
->method('getParameter')
->with('assetic.write_to')
->will($this->returnValue($this->writeTo));
$this->container->expects($this->once())
->method('get')
->with('assetic.asset_manager')
Expand All @@ -65,6 +72,14 @@ protected function setUp()
$this->command->setApplication($this->application);
}

protected function tearDown()
{
if (is_dir($this->writeTo)) {
array_map('unlink', glob($this->writeTo.'/*'));
rmdir($this->writeTo);
}
}

public function testEmptyAssetManager()
{
$this->am->expects($this->once())
Expand All @@ -73,4 +88,35 @@ public function testEmptyAssetManager()

$this->command->run(new ArrayInput(array()), new NullOutput());
}

public function testDumpOne()
{
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');

$this->am->expects($this->once())
->method('getNames')
->will($this->returnValue(array('test_asset')));
$this->am->expects($this->once())
->method('get')
->with('test_asset')
->will($this->returnValue($asset));
$this->am->expects($this->once())
->method('getFormula')
->with('test_asset')
->will($this->returnValue(array()));
$this->am->expects($this->once())
->method('isDebug')
->will($this->returnValue(false));
$asset->expects($this->once())
->method('getTargetUrl')
->will($this->returnValue('test_asset.css'));
$asset->expects($this->once())
->method('dump')
->will($this->returnValue('/* test_asset */'));

$this->command->run(new ArrayInput(array()), new NullOutput());

$this->assertFileExists($this->writeTo.'/test_asset.css');
$this->assertEquals('/* test_asset */', file_get_contents($this->writeTo.'/test_asset.css'));
}
}

0 comments on commit 520941d

Please sign in to comment.