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

testExecuteWithWorkloadAndInterval()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
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