GearmanWorkerListCommandTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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\GearmanWorkerListCommand;
  18. use Mmoreram\GearmanBundle\Service\GearmanClient;
  19. /**
  20. * Class GearmanWorkerListCommandTest
  21. */
  22. class GearmanWorkerListCommandTest extends PHPUnit_Framework_TestCase
  23. {
  24. /**
  25. * @var GearmanWorkerListCommand
  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 GearmanClient
  44. *
  45. * Gearman client
  46. */
  47. protected $gearmanClient;
  48. /**
  49. * @var KernelInterface
  50. *
  51. * Kernel
  52. */
  53. protected $kernel;
  54. /**
  55. * setup
  56. */
  57. public function setUp()
  58. {
  59. $this->command = $this
  60. ->getMockBuilder('Mmoreram\GearmanBundle\Command\GearmanWorkerListCommand')
  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->gearmanClient = $this
  79. ->getMockBuilder('Mmoreram\GearmanBundle\Service\GearmanClient')
  80. ->disableOriginalConstructor()
  81. ->setMethods(array(
  82. 'getWorkers',
  83. ))
  84. ->getMock();
  85. $this->gearmanClient
  86. ->expects($this->any())
  87. ->method('getWorkers')
  88. ->will($this->returnValue(array(
  89. array(
  90. 'className' => '',
  91. 'callableName' => '',
  92. 'jobs' => array()
  93. ),
  94. )));
  95. $this->kernel
  96. ->expects($this->any())
  97. ->method('getEnvironment')
  98. ->will($this->returnValue('dev'));
  99. }
  100. /**
  101. * Test quietness
  102. *
  103. * @dataProvider dataQuietness
  104. */
  105. public function testQuietness(
  106. $quiet,
  107. $countWriteln
  108. )
  109. {
  110. $this
  111. ->input
  112. ->expects($this->any())
  113. ->method('getOption')
  114. ->will($this->returnValueMap(array(
  115. array('quiet', $quiet)
  116. )));
  117. $this
  118. ->output
  119. ->expects($countWriteln)
  120. ->method('writeln');
  121. $this->command
  122. ->setGearmanClient($this->gearmanClient)
  123. ->setKernel($this->kernel)
  124. ->run($this->input, $this->output);
  125. }
  126. /**
  127. * Data provider for testQuietness
  128. */
  129. public function dataQuietness()
  130. {
  131. return array(
  132. array(
  133. true,
  134. $this->never(),
  135. ),
  136. array(
  137. false,
  138. $this->atLeastOnce(),
  139. ),
  140. );
  141. }
  142. }