Completed
Push — master ( c2e487...7ac6a5 )
by Wachter
07:39
created

ScheduleTaskCommandTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 5
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testConfigure() 0 9 1
A runProvider() 0 7 1
B testRun() 0 24 1
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