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