Completed
Pull Request — master (#20)
by Wachter
02:52
created

ScheduleTaskCommandTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 7
dl 0
loc 83
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecute() 0 14 1
A testExecuteWithWorkload() 0 16 1
A testExecuteWithWorkloadAndInterval() 0 18 1
A testExecuteWithWorkloadAndIntervalAndEndDate() 0 21 1
A getCommand() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of php-task library.
5
 *
6
 * (c) php-task
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Functional\Command;
13
14
use Task\TaskBundle\Tests\Functional\BaseCommandTestCase;
15
use Task\TaskBundle\Tests\Functional\TestHandler;
16
17
/**
18
 * Tests for ScheduleTaskCommand.
19
 */
20
class ScheduleTaskCommandTest extends BaseCommandTestCase
21
{
22
    public function testExecute()
23
    {
24
        $this->commandTester->execute(
25
            [
26
                'command' => $this->command->getName(),
27
                'handlerClass' => TestHandler::class,
28
            ]
29
        );
30
31
        $tasks = $this->taskRepository->findAll();
32
        $this->assertCount(1, $tasks);
33
34
        $this->assertEquals(TestHandler::class, $tasks[0]->getHandlerClass());
35
    }
36
37
    public function testExecuteWithWorkload()
38
    {
39
        $this->commandTester->execute(
40
            [
41
                'command' => $this->command->getName(),
42
                'handlerClass' => TestHandler::class,
43
                'workload' => 'Test workload 1',
44
            ]
45
        );
46
47
        $tasks = $this->taskRepository->findAll();
48
        $this->assertCount(1, $tasks);
49
50
        $this->assertEquals(TestHandler::class, $tasks[0]->getHandlerClass());
51
        $this->assertEquals('Test workload 1', $tasks[0]->getWorkload());
52
    }
53
54
    public function testExecuteWithWorkloadAndInterval()
55
    {
56
        $this->commandTester->execute(
57
            [
58
                'command' => $this->command->getName(),
59
                'handlerClass' => TestHandler::class,
60
                'workload' => 'Test workload 1',
61
                '--cron-expression' => '0 * * * *',
62
            ]
63
        );
64
65
        $tasks = $this->taskRepository->findAll();
66
        $this->assertCount(1, $tasks);
67
68
        $this->assertEquals(TestHandler::class, $tasks[0]->getHandlerClass());
69
        $this->assertEquals('Test workload 1', $tasks[0]->getWorkload());
70
        $this->assertEquals('0 * * * *', $tasks[0]->getInterval());
71
    }
72
73
    public function testExecuteWithWorkloadAndIntervalAndEndDate()
74
    {
75
        $date = new \DateTime('+1 day');
76
        $this->commandTester->execute(
77
            [
78
                'command' => $this->command->getName(),
79
                'handlerClass' => TestHandler::class,
80
                'workload' => 'Test workload 1',
81
                '--cron-expression' => '0 * * * *',
82
                '--end-date' => $date->format(\DateTime::RFC3339),
83
            ]
84
        );
85
86
        $tasks = $this->taskRepository->findAll();
87
        $this->assertCount(1, $tasks);
88
89
        $this->assertEquals(TestHandler::class, $tasks[0]->getHandlerClass());
90
        $this->assertEquals('Test workload 1', $tasks[0]->getWorkload());
91
        $this->assertEquals('0 * * * *', $tasks[0]->getInterval());
92
        $this->assertEquals($date, $tasks[0]->getLastExecution());
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    protected function getCommand()
99
    {
100
        return self::$kernel->getContainer()->get('task.command.schedule_task');
101
    }
102
}
103