PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/symfony/assetic-bundle/Symfony/Bundle/AsseticBundle/Tests/Command/DumpCommandTest.php

https://bitbucket.org/renta/jobeet2.loc
PHP | 202 lines | 171 code | 23 blank | 8 comment | 5 complexity | 8c85340145ad68422dc424528f60c4a4 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0, LGPL-2.1, BSD-2-Clause, Apache-2.0, CC-BY-3.0
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Bundle\AsseticBundle\Tests\Command;
  11. use Symfony\Bundle\AsseticBundle\Command\DumpCommand;
  12. use Symfony\Component\Console\Input\ArrayInput;
  13. use Symfony\Component\Console\Input\InputOption;
  14. use Symfony\Component\Console\Output\NullOutput;
  15. class DumpCommandTest extends \PHPUnit_Framework_TestCase
  16. {
  17. private $writeTo;
  18. private $application;
  19. private $definition;
  20. private $kernel;
  21. private $container;
  22. private $am;
  23. protected function setUp()
  24. {
  25. if (!class_exists('Assetic\\AssetManager')) {
  26. $this->markTestSkipped('Assetic is not available.');
  27. }
  28. $this->writeTo = sys_get_temp_dir().'/assetic_dump';
  29. $this->application = $this->getMockBuilder('Symfony\\Bundle\\FrameworkBundle\\Console\\Application')
  30. ->disableOriginalConstructor()
  31. ->getMock();
  32. $this->definition = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\InputDefinition')
  33. ->disableOriginalConstructor()
  34. ->getMock();
  35. $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
  36. $this->helperSet = $this->getMock('Symfony\\Component\\Console\\Helper\\HelperSet');
  37. $this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
  38. $this->am = $this->getMockBuilder('Assetic\\Factory\\LazyAssetManager')
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $this->application->expects($this->any())
  42. ->method('getDefinition')
  43. ->will($this->returnValue($this->definition));
  44. $this->definition->expects($this->any())
  45. ->method('getArguments')
  46. ->will($this->returnValue(array()));
  47. $this->definition->expects($this->any())
  48. ->method('getOptions')
  49. ->will($this->returnValue(array(
  50. new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
  51. new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'),
  52. new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'),
  53. )));
  54. $this->application->expects($this->any())
  55. ->method('getKernel')
  56. ->will($this->returnValue($this->kernel));
  57. $this->application->expects($this->once())
  58. ->method('getHelperSet')
  59. ->will($this->returnValue($this->helperSet));
  60. $this->kernel->expects($this->any())
  61. ->method('getContainer')
  62. ->will($this->returnValue($this->container));
  63. $writeTo = $this->writeTo;
  64. $this->container->expects($this->any())
  65. ->method('getParameter')
  66. ->will($this->returnCallback(function($p) use($writeTo) {
  67. if ('assetic.write_to' === $p) {
  68. return $writeTo;
  69. } else if ('assetic.variables' === $p) {
  70. return array();
  71. }
  72. throw new \RuntimeException(sprintf('Unknown parameter "%s".', $p));
  73. }));
  74. $this->container->expects($this->once())
  75. ->method('get')
  76. ->with('assetic.asset_manager')
  77. ->will($this->returnValue($this->am));
  78. $this->command = new DumpCommand();
  79. $this->command->setApplication($this->application);
  80. }
  81. protected function tearDown()
  82. {
  83. if (is_dir($this->writeTo)) {
  84. array_map('unlink', glob($this->writeTo.'/*'));
  85. rmdir($this->writeTo);
  86. }
  87. }
  88. public function testEmptyAssetManager()
  89. {
  90. $this->am->expects($this->once())
  91. ->method('getNames')
  92. ->will($this->returnValue(array()));
  93. $this->command->run(new ArrayInput(array()), new NullOutput());
  94. }
  95. public function testDumpOne()
  96. {
  97. $asset = $this->getMock('Assetic\\Asset\\AssetInterface');
  98. $this->am->expects($this->once())
  99. ->method('getNames')
  100. ->will($this->returnValue(array('test_asset')));
  101. $this->am->expects($this->once())
  102. ->method('get')
  103. ->with('test_asset')
  104. ->will($this->returnValue($asset));
  105. $this->am->expects($this->once())
  106. ->method('getFormula')
  107. ->with('test_asset')
  108. ->will($this->returnValue(array()));
  109. $this->am->expects($this->exactly(2))
  110. ->method('isDebug')
  111. ->will($this->returnValue(false));
  112. $asset->expects($this->once())
  113. ->method('getTargetPath')
  114. ->will($this->returnValue('test_asset.css'));
  115. $asset->expects($this->once())
  116. ->method('dump')
  117. ->will($this->returnValue('/* test_asset */'));
  118. $asset->expects($this->any())
  119. ->method('getVars')
  120. ->will($this->returnValue(array()));
  121. $asset->expects($this->any())
  122. ->method('getValues')
  123. ->will($this->returnValue(array()));
  124. $this->command->run(new ArrayInput(array()), new NullOutput());
  125. $this->assertFileExists($this->writeTo.'/test_asset.css');
  126. $this->assertEquals('/* test_asset */', file_get_contents($this->writeTo.'/test_asset.css'));
  127. }
  128. public function testDumpDebug()
  129. {
  130. $asset = $this->getMock('Assetic\\Asset\\AssetCollection');
  131. $leaf = $this->getMock('Assetic\\Asset\\AssetInterface');
  132. $this->am->expects($this->once())
  133. ->method('getNames')
  134. ->will($this->returnValue(array('test_asset')));
  135. $this->am->expects($this->once())
  136. ->method('get')
  137. ->with('test_asset')
  138. ->will($this->returnValue($asset));
  139. $this->am->expects($this->once())
  140. ->method('getFormula')
  141. ->with('test_asset')
  142. ->will($this->returnValue(array()));
  143. $this->am->expects($this->exactly(2))
  144. ->method('isDebug')
  145. ->will($this->returnValue(true));
  146. $asset->expects($this->once())
  147. ->method('getTargetPath')
  148. ->will($this->returnValue('test_asset.css'));
  149. $asset->expects($this->once())
  150. ->method('dump')
  151. ->will($this->returnValue('/* test_asset */'));
  152. $asset->expects($this->once())
  153. ->method('getIterator')
  154. ->will($this->returnValue(new \ArrayIterator(array($leaf))));
  155. $asset->expects($this->any())
  156. ->method('getVars')
  157. ->will($this->returnValue(array()));
  158. $asset->expects($this->any())
  159. ->method('getValues')
  160. ->will($this->returnValue(array()));
  161. $leaf->expects($this->once())
  162. ->method('getTargetPath')
  163. ->will($this->returnValue('test_leaf.css'));
  164. $leaf->expects($this->once())
  165. ->method('dump')
  166. ->will($this->returnValue('/* test_leaf */'));
  167. $leaf->expects($this->any())
  168. ->method('getVars')
  169. ->will($this->returnValue(array()));
  170. $leaf->expects($this->any())
  171. ->method('getValues')
  172. ->will($this->returnValue(array()));
  173. $this->command->run(new ArrayInput(array()), new NullOutput());
  174. $this->assertFileExists($this->writeTo.'/test_asset.css');
  175. $this->assertFileExists($this->writeTo.'/test_leaf.css');
  176. $this->assertEquals('/* test_asset */', file_get_contents($this->writeTo.'/test_asset.css'));
  177. $this->assertEquals('/* test_leaf */', file_get_contents($this->writeTo.'/test_leaf.css'));
  178. }
  179. }