123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- /**
- * Gearman Bundle for Symfony2
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- *
- * Feel free to edit as you please, and have fun.
- *
- * @author Marc Morera <yuhu@mmoreram.com>
- */
- namespace Mmoreram\GearmanBundle\Tests\Command;
- use PHPUnit_Framework_TestCase;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\HttpKernel\KernelInterface;
- use Mmoreram\GearmanBundle\Command\GearmanWorkerListCommand;
- use Mmoreram\GearmanBundle\Service\GearmanClient;
- /**
- * Class GearmanWorkerListCommandTest
- */
- class GearmanWorkerListCommandTest extends PHPUnit_Framework_TestCase
- {
- /**
- * @var GearmanWorkerListCommand
- *
- * Command
- */
- protected $command;
- /**
- * @var InputInterface
- *
- * Input
- */
- protected $input;
- /**
- * @var OutputInterface
- *
- * Output
- */
- protected $output;
- /**
- * @var GearmanClient
- *
- * Gearman client
- */
- protected $gearmanClient;
- /**
- * @var KernelInterface
- *
- * Kernel
- */
- protected $kernel;
- /**
- * setup
- */
- public function setUp()
- {
- $this->command = $this
- ->getMockBuilder('Mmoreram\GearmanBundle\Command\GearmanWorkerListCommand')
- ->setMethods(null)
- ->getMock();
- $this->input = $this
- ->getMockBuilder('Symfony\Component\Console\Input\InputInterface')
- ->disableOriginalConstructor()
- ->setMethods(array())
- ->getMock();
- $this->output = $this
- ->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')
- ->disableOriginalConstructor()
- ->setMethods(array())
- ->getMock();
- $this->kernel = $this
- ->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')
- ->disableOriginalConstructor()
- ->setMethods(array())
- ->getMock();
- $this->gearmanClient = $this
- ->getMockBuilder('Mmoreram\GearmanBundle\Service\GearmanClient')
- ->disableOriginalConstructor()
- ->setMethods(array(
- 'getWorkers',
- ))
- ->getMock();
- $this->gearmanClient
- ->expects($this->any())
- ->method('getWorkers')
- ->will($this->returnValue(array(
- array(
- 'className' => '',
- 'callableName' => '',
- 'jobs' => array()
- ),
- )));
- $this->kernel
- ->expects($this->any())
- ->method('getEnvironment')
- ->will($this->returnValue('dev'));
- }
- /**
- * Test quietness
- *
- * @dataProvider dataQuietness
- */
- public function testQuietness(
- $quiet,
- $countWriteln
- )
- {
- $this
- ->input
- ->expects($this->any())
- ->method('getOption')
- ->will($this->returnValueMap(array(
- array('quiet', $quiet)
- )));
- $this
- ->output
- ->expects($countWriteln)
- ->method('writeln');
- $this->command
- ->setGearmanClient($this->gearmanClient)
- ->setKernel($this->kernel)
- ->run($this->input, $this->output);
- }
- /**
- * Data provider for testQuietness
- */
- public function dataQuietness()
- {
- return array(
- array(
- true,
- $this->never(),
- ),
- array(
- false,
- $this->atLeastOnce(),
- ),
- );
- }
- }
|