123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- <?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\Helper\DialogHelper;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\HttpKernel\KernelInterface;
- use Mmoreram\GearmanBundle\Command\GearmanWorkerExecuteCommand;
- use Mmoreram\GearmanBundle\Service\GearmanClient;
- use Mmoreram\GearmanBundle\Service\GearmanDescriber;
- use Mmoreram\GearmanBundle\Service\GearmanExecute;
- /**
- * Class GearmanWorkerExecuteCommandTest
- */
- class GearmanWorkerExecuteCommandTest extends PHPUnit_Framework_TestCase
- {
- /**
- * @var GearmanWorkerExecuteCommand
- *
- * Command
- */
- protected $command;
- /**
- * @var InputInterface
- *
- * Input
- */
- protected $input;
- /**
- * @var OutputInterface
- *
- * Output
- */
- protected $output;
- /**
- * @var DialogHelper
- *
- * Dialog helper
- */
- protected $dialogHelper;
- /**
- * @var GearmanClient
- *
- * Gearman client
- */
- protected $gearmanClient;
- /**
- * @var GearmanDescriber
- *
- * Gearman describer
- */
- protected $gearmanDescriber;
- /**
- * @var GearmanExecute
- *
- * Gearman execute
- */
- protected $gearmanExecute;
- /**
- * @var KernelInterface
- *
- * Kernel
- */
- protected $kernel;
- /**
- * setup
- */
- public function setUp()
- {
- $this->command = $this
- ->getMockBuilder('Mmoreram\GearmanBundle\Command\GearmanWorkerExecuteCommand')
- ->setMethods(array(
- 'getHelperSet'
- ))
- ->getMock();
- $this->dialogHelper = $this
- ->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
- ->setMethods(array('askConfirmation'))
- ->getMock();
- $helperSet = $this
- ->getMockBuilder('Symfony\Component\Console\Helper\HelperSet')
- ->setMethods(array('get'))
- ->getMock();
- $helperSet
- ->expects($this->any())
- ->method('get')
- ->will($this->returnValue($this->dialogHelper));
- $this
- ->command
- ->expects($this->any())
- ->method('getHelperSet')
- ->will($this->returnValue($helperSet));
- $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(
- 'getWorker'
- ))
- ->getMock();
- $this->gearmanDescriber = $this
- ->getMockBuilder('Mmoreram\GearmanBundle\Service\GearmanDescriber')
- ->disableOriginalConstructor()
- ->setMethods(array(
- 'describeWorker'
- ))
- ->getMock();
- $this->gearmanExecute = $this
- ->getMockBuilder('Mmoreram\GearmanBundle\Service\GearmanExecute')
- ->disableOriginalConstructor()
- ->setMethods(array(
- 'executeWorker'
- ))
- ->getMock();
- $this->kernel
- ->expects($this->any())
- ->method('getEnvironment')
- ->will($this->returnValue('dev'));
- }
- /**
- * Test quietness
- *
- * @dataProvider dataQuietness
- */
- public function testQuietness(
- $quiet,
- $noInteraction,
- $confirmation,
- $countWriteln,
- $countDescriber,
- $countClient,
- $countExecute
- )
- {
- $this
- ->input
- ->expects($this->any())
- ->method('getOption')
- ->will($this->returnValueMap(array(
- array('quiet', $quiet),
- array('no-interaction', $noInteraction)
- )));
- $this
- ->dialogHelper
- ->expects($this->any())
- ->method('askConfirmation')
- ->will($this->returnValue($confirmation));
- $this
- ->output
- ->expects($countWriteln)
- ->method('writeln');
- $this
- ->gearmanDescriber
- ->expects($countDescriber)
- ->method('describeWorker');
- $this
- ->gearmanClient
- ->expects($countClient)
- ->method('getWorker')
- ->will($this->returnValue(array()));
- $this
- ->gearmanExecute
- ->expects($countExecute)
- ->method('executeWorker');
- $this->command
- ->setGearmanClient($this->gearmanClient)
- ->setGearmanDescriber($this->gearmanDescriber)
- ->setGearmanExecute($this->gearmanExecute)
- ->setKernel($this->kernel)
- ->run($this->input, $this->output);
- }
- /**
- * Data provider for testQuietness
- */
- public function dataQuietness()
- {
- return array(
- array(
- true,
- true,
- true,
- $this->never(),
- $this->never(),
- $this->atLeastOnce(),
- $this->atLeastOnce(),
- ),
- array(
- true,
- true,
- false,
- $this->never(),
- $this->never(),
- $this->atLeastOnce(),
- $this->atLeastOnce(),
- ),
- array(
- true,
- false,
- true,
- $this->never(),
- $this->never(),
- $this->atLeastOnce(),
- $this->atLeastOnce(),
- ),
- array(
- true,
- false,
- false,
- $this->never(),
- $this->never(),
- $this->never(),
- $this->never(),
- ),
- array(
- false,
- true,
- true,
- $this->atLeastOnce(),
- $this->atLeastOnce(),
- $this->atLeastOnce(),
- $this->atLeastOnce(),
- ),
- array(
- false,
- true,
- false,
- $this->atLeastOnce(),
- $this->atLeastOnce(),
- $this->atLeastOnce(),
- $this->atLeastOnce(),
- ),
- array(
- false,
- false,
- true,
- $this->atLeastOnce(),
- $this->atLeastOnce(),
- $this->atLeastOnce(),
- $this->atLeastOnce(),
- ),
- array(
- false,
- false,
- false,
- $this->any(),
- $this->any(),
- $this->never(),
- $this->never(),
- ),
- );
- }
- }
|