GearmanCacheClearCommandTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * Gearman Bundle for Symfony2
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * Feel free to edit as you please, and have fun.
  9. *
  10. * @author Marc Morera <yuhu@mmoreram.com>
  11. */
  12. namespace Mmoreram\GearmanBundle\Tests\Command;
  13. use PHPUnit_Framework_TestCase;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Output\OutputInterface;
  16. use Symfony\Component\HttpKernel\KernelInterface;
  17. use Mmoreram\GearmanBundle\Command\GearmanCacheClearCommand;
  18. use Mmoreram\GearmanBundle\Service\GearmanCacheWrapper;
  19. /**
  20. * Class GearmanCacheClearCommandTest
  21. */
  22. class GearmanCacheClearCommandTest extends PHPUnit_Framework_TestCase
  23. {
  24. /**
  25. * @var GearmanCacheClearCommand
  26. *
  27. * Command
  28. */
  29. protected $command;
  30. /**
  31. * @var InputInterface
  32. *
  33. * Input
  34. */
  35. protected $input;
  36. /**
  37. * @var OutputInterface
  38. *
  39. * Output
  40. */
  41. protected $output;
  42. /**
  43. * @var GearmanCacheWrapper
  44. *
  45. * Gearman Cache Wrapper
  46. */
  47. protected $gearmanCacheWrapper;
  48. /**
  49. * @var KernelInterface
  50. *
  51. * Kernel
  52. */
  53. protected $kernel;
  54. /**
  55. * Set up method
  56. */
  57. public function setUp()
  58. {
  59. $this->command = $this
  60. ->getMockBuilder('Mmoreram\GearmanBundle\Command\GearmanCacheClearCommand')
  61. ->setMethods(null)
  62. ->getMock();
  63. $this->input = $this
  64. ->getMockBuilder('Symfony\Component\Console\Input\InputInterface')
  65. ->disableOriginalConstructor()
  66. ->setMethods(array())
  67. ->getMock();
  68. $this->output = $this
  69. ->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')
  70. ->disableOriginalConstructor()
  71. ->setMethods(array())
  72. ->getMock();
  73. $this->kernel = $this
  74. ->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')
  75. ->disableOriginalConstructor()
  76. ->setMethods(array())
  77. ->getMock();
  78. $this->gearmanCacheWrapper = $this
  79. ->getMockBuilder('Mmoreram\GearmanBundle\Service\GearmanCacheWrapper')
  80. ->disableOriginalConstructor()
  81. ->setMethods(array(
  82. 'clear',
  83. ))
  84. ->getMock();
  85. $this
  86. ->gearmanCacheWrapper
  87. ->expects($this->once())
  88. ->method('clear');
  89. $this
  90. ->kernel
  91. ->expects($this->any())
  92. ->method('getEnvironment')
  93. ->will($this->returnValue('dev'));
  94. $this
  95. ->command
  96. ->setGearmanCacheWrapper($this->gearmanCacheWrapper)
  97. ->setKernel($this->kernel);
  98. }
  99. /**
  100. * Test run quietness
  101. */
  102. public function testRunQuiet()
  103. {
  104. $this
  105. ->input
  106. ->expects($this->any())
  107. ->method('getOption')
  108. ->will($this->returnValueMap(array(
  109. array('quiet', true)
  110. )));
  111. $this
  112. ->output
  113. ->expects($this->never())
  114. ->method('writeln');
  115. $this
  116. ->command
  117. ->run(
  118. $this->input,
  119. $this->output
  120. );
  121. }
  122. /**
  123. * Test run without quietness
  124. */
  125. public function testRunNonQuiet()
  126. {
  127. $this
  128. ->input
  129. ->expects($this->any())
  130. ->method('getOption')
  131. ->will($this->returnValueMap(array(
  132. array('quiet', false)
  133. )));
  134. $this
  135. ->output
  136. ->expects($this->any())
  137. ->method('writeln');
  138. $this
  139. ->command
  140. ->run(
  141. $this->input,
  142. $this->output
  143. );
  144. }
  145. }