AssetWriterTest.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2011 OpenSky Project Inc
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Assetic\Test;
  11. use Assetic\AssetWriter;
  12. class AssetWriterTest extends \PHPUnit_Framework_TestCase
  13. {
  14. protected function setUp()
  15. {
  16. $this->dir = sys_get_temp_dir().'/assetic_tests_'.rand(11111, 99999);
  17. mkdir($this->dir);
  18. $this->writer = new AssetWriter($this->dir);
  19. }
  20. protected function tearDown()
  21. {
  22. array_map('unlink', glob($this->dir.'/*'));
  23. rmdir($this->dir);
  24. }
  25. public function testWriteManagerAssets()
  26. {
  27. $asset = $this->getMock('Assetic\\Asset\\AssetInterface');
  28. $am = $this->getMock('Assetic\\AssetManager');
  29. $am->expects($this->once())
  30. ->method('getNames')
  31. ->will($this->returnValue(array('foo')));
  32. $am->expects($this->once())
  33. ->method('get')
  34. ->with('foo')
  35. ->will($this->returnValue($asset));
  36. $asset->expects($this->once())
  37. ->method('getTargetPath')
  38. ->will($this->returnValue('target_url'));
  39. $asset->expects($this->once())
  40. ->method('dump')
  41. ->will($this->returnValue('content'));
  42. $this->writer->writeManagerAssets($am);
  43. $this->assertFileExists($this->dir.'/target_url');
  44. $this->assertEquals('content', file_get_contents($this->dir.'/target_url'));
  45. }
  46. }