Completed
Pull Request — master (#20)
by Wachter
08:50 queued 06:29
created

DebugTasksCommandTest::testExecutePaginated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 9.4109
c 0
b 0
f 0
cc 1
eloc 30
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 Task\TaskBundle\Tests\Functional\Command;
13
14
use Task\Execution\TaskExecutionInterface;
15
use Task\TaskBundle\Command\DebugTasksCommand;
16
use Task\TaskBundle\Tests\Functional\BaseCommandTestCase;
17
use Task\TaskStatus;
18
19
/**
20
 * Tests for DebugTasksCommand.
21
 */
22
class DebugTasksCommandTest extends BaseCommandTestCase
23
{
24
    public function testExecute()
25
    {
26
        $task = $this->createTask('Test workload 1');
27
28
        /** @var TaskExecutionInterface[] $executions */
29
        $executions = [
30
            $this->createTaskExecution($task, new \DateTime('-1 hour'), TaskStatus::COMPLETE),
31
            $this->createTaskExecution($task, new \DateTime('-2 hour'), TaskStatus::COMPLETE),
32
        ];
33
34
        $executions[0]->setResult(strrev($executions[0]->getWorkload()));
35
        $executions[0]->setDuration(0.1);
36
        $executions[1]->setResult(strrev($executions[1]->getWorkload()));
37
        $executions[1]->setDuration(0.0001);
38
39
        $this->taskExecutionRepository->flush();
40
41
        $this->commandTester->execute(
42
            [
43
                'command' => $this->command->getName(),
44
            ]
45
        );
46
47
        $output = $this->commandTester->getDisplay();
48
        $this->assertContains($executions[0]->getUuid(), $output);
49
        $this->assertContains($executions[1]->getUuid(), $output);
50
        $this->assertContains('100000ms', $output);
51
        $this->assertContains('100ms', $output);
52
        $this->assertContains('completed', $output);
53
    }
54
55
    public function testExecutePaginated()
56
    {
57
        $task = $this->createTask('Test workload 1');
58
59
        /** @var TaskExecutionInterface[] $executions */
60
        $executions = [
61
            $this->createTaskExecution($task, new \DateTime('-1 hour')),
62
            $this->createTaskExecution($task, new \DateTime('-2 hour')),
63
            $this->createTaskExecution($task, new \DateTime('+1 hour')),
64
        ];
65
66
        $this->taskExecutionRepository->flush();
67
68
        $this->commandTester->execute(
69
            [
70
                'command' => $this->command->getName(),
71
                '--page-size' => 2,
72
            ]
73
        );
74
75
        $output = $this->commandTester->getDisplay();
76
        $this->assertContains($executions[0]->getUuid(), $output);
77
        $this->assertContains($executions[1]->getUuid(), $output);
78
        $this->assertNotContains($executions[2]->getUuid(), $output);
79
80
        $this->commandTester->execute(
81
            [
82
                'command' => $this->command->getName(),
83
                '--page' => 2,
84
                '--page-size' => 2,
85
            ]
86
        );
87
88
        $output = $this->commandTester->getDisplay();
89
        $this->assertNotContains($executions[0]->getUuid(), $output);
90
        $this->assertNotContains($executions[1]->getUuid(), $output);
91
        $this->assertContains($executions[2]->getUuid(), $output);
92
93
        $this->commandTester->execute(
94
            [
95
                'command' => $this->command->getName(),
96
                '--page' => 3,
97
                '--page-size' => 2,
98
            ]
99
        );
100
101
        $output = $this->commandTester->getDisplay();
102
        $this->assertNotContains($executions[0]->getUuid(), $output);
103
        $this->assertNotContains($executions[1]->getUuid(), $output);
104
        $this->assertNotContains($executions[2]->getUuid(), $output);
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    protected function getCommand()
111
    {
112
        return new DebugTasksCommand('debug:tasks', $this->taskExecutionRepository);
113
    }
114
}
115