|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Unit\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Prophecy\Argument; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
8
|
|
|
use Task\SchedulerInterface; |
|
9
|
|
|
use Task\TaskBuilderInterface; |
|
10
|
|
|
use Task\TaskBundle\Command\ScheduleTaskCommand; |
|
11
|
|
|
|
|
12
|
|
|
class ScheduleTaskCommandTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testConfigure() |
|
15
|
|
|
{ |
|
16
|
|
|
$scheduler = $this->prophesize(SchedulerInterface::class); |
|
17
|
|
|
$command = new ScheduleTaskCommand($scheduler->reveal()); |
|
18
|
|
|
|
|
19
|
|
|
$this->assertEquals('task:schedule:task', $command->getName()); |
|
20
|
|
|
$this->assertTrue($command->getDefinition()->hasArgument('handler')); |
|
21
|
|
|
$this->assertTrue($command->getDefinition()->hasArgument('workload')); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function runProvider() |
|
25
|
|
|
{ |
|
26
|
|
|
return [ |
|
27
|
|
|
['test-handler', 'test-workload'], |
|
28
|
|
|
['test-handler-1', 'test-workload-1'], |
|
29
|
|
|
]; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @dataProvider runProvider |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testRun($handler, $workload) |
|
36
|
|
|
{ |
|
37
|
|
|
$taskBuilder = $this->prophesize(TaskBuilderInterface::class); |
|
38
|
|
|
|
|
39
|
|
|
$input = $this->prophesize(InputInterface::class); |
|
40
|
|
|
$output = $this->prophesize(OutputInterface::class); |
|
41
|
|
|
|
|
42
|
|
|
$input->bind(Argument::any())->willReturn(true); |
|
43
|
|
|
$input->validate()->willReturn(true); |
|
44
|
|
|
$input->isInteractive()->willReturn(false); |
|
45
|
|
|
$input->hasArgument('command')->willReturn(false); |
|
46
|
|
|
|
|
47
|
|
|
$input->getArgument('handler')->willReturn($handler); |
|
48
|
|
|
$input->getArgument('workload')->willReturn($workload); |
|
49
|
|
|
|
|
50
|
|
|
$scheduler = $this->prophesize(SchedulerInterface::class); |
|
51
|
|
|
$command = new ScheduleTaskCommand($scheduler->reveal()); |
|
52
|
|
|
|
|
53
|
|
|
$scheduler->createTask($handler, $workload)->shouldBeCalledTimes(1)->willReturn($taskBuilder->reveal()); |
|
54
|
|
|
|
|
55
|
|
|
$command->run($input->reveal(), $output->reveal()); |
|
56
|
|
|
|
|
57
|
|
|
$taskBuilder->schedule()->shouldBeCalledTimes(1); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|