1
|
|
|
<?php |
2
|
|
|
App::uses('ConsoleOutput', 'Console'); |
3
|
|
|
App::uses('ConsoleInput', 'Console'); |
4
|
|
|
App::uses('ShellDispatcher', 'Console'); |
5
|
|
|
App::uses('Shell', 'Console'); |
6
|
|
|
App::uses('QueueShell', 'Queue.Console/Command'); |
7
|
|
|
App::uses('QueuedTask', 'Queue.Model'); |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* QueueShell Wrapper. |
11
|
|
|
* |
12
|
|
|
*/ |
13
|
|
|
class QueueShellWrapper extends QueueShell { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* A list with error messages. |
17
|
|
|
* |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
protected $_err = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* A list with out messages. |
24
|
|
|
* |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $_out = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Test double of `parent::err`. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function err($message = null, $newlines = 1) { |
35
|
|
|
$this->_err[] = $message; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Test double of `parent::out`. |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
public function out($message = null, $newlines = 1, $level = Shell::NORMAL) { |
|
|
|
|
44
|
|
|
$this->_out[] = $message; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Test double of `parent::_stop`. |
49
|
|
|
* |
50
|
|
|
* @return int |
51
|
|
|
*/ |
52
|
|
|
protected function _stop($status = 0) { |
53
|
|
|
return $status; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* QueueShell Test. |
60
|
|
|
* |
61
|
|
|
* @property QueueShellWrapper $QueueShell |
62
|
|
|
*/ |
63
|
|
|
class QueueShellTest extends CakeTestCase { |
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Fixtures. |
67
|
|
|
* |
68
|
|
|
* @var array |
69
|
|
|
*/ |
70
|
|
|
public $fixtures = ['plugin.queue.queued_task']; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* setUp method. |
74
|
|
|
* |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
public function setUp() { |
78
|
|
|
parent::setUp(); |
79
|
|
|
|
80
|
|
|
$out = $this->getMock('ConsoleOutput', [], [], '', false); |
81
|
|
|
$in = $this->getMock('ConsoleInput', [], [], '', false); |
82
|
|
|
|
83
|
|
|
$this->QueueShell = $this->getMock('QueueShellWrapper', |
84
|
|
|
['in'], |
85
|
|
|
[$out, $out, $in] |
86
|
|
|
); |
87
|
|
|
$this->QueueShell->initialize(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* tearDown method. |
92
|
|
|
* |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
|
|
public function tearDown() { |
96
|
|
|
parent::tearDown(); |
97
|
|
|
|
98
|
|
|
unset($this->QueueShell); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Tests `QueueShell` object type. |
103
|
|
|
* |
104
|
|
|
* @return void |
105
|
|
|
*/ |
106
|
|
|
public function testObject() { |
107
|
|
|
$this->assertTrue(is_object($this->QueueShell)); |
108
|
|
|
$this->assertInstanceOf('QueueShell', $this->QueueShell); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Tests `QueueShell::stats`. |
113
|
|
|
* |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
public function testStats() { |
117
|
|
|
$result = $this->QueueShell->stats(); |
|
|
|
|
118
|
|
|
|
119
|
|
|
$this->assertTrue(in_array(__d('queue', 'Total unfinished jobs: %s', 0), $this->QueueShell->_out)); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Tests `QueueShell::add`, non-existing |
124
|
|
|
* |
125
|
|
|
* @return void |
126
|
|
|
*/ |
127
|
|
|
public function testAddNonExistent() { |
128
|
|
|
$this->QueueShell->args[] = 'Foo'; |
129
|
|
|
$result = $this->QueueShell->add(); |
|
|
|
|
130
|
|
|
|
131
|
|
|
$this->assertTrue(in_array(__d('queue', 'Error: Task not Found: %s', 'Foo'), $this->QueueShell->_out)); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Tests `QueueShell::add`, existing |
136
|
|
|
* |
137
|
|
|
* @return void |
138
|
|
|
*/ |
139
|
|
|
public function testAdd() { |
140
|
|
|
$restore = Configure::read('Queue.exitWhenNothingToDo'); |
|
|
|
|
141
|
|
|
Configure::write('Queue.exitWhenNothingToDo', true); |
142
|
|
|
|
143
|
|
|
$this->QueueShell->args[] = 'Example'; |
144
|
|
|
$result = $this->QueueShell->add(); |
|
|
|
|
145
|
|
|
|
146
|
|
|
$this->assertEmpty($this->QueueShell->_out); |
147
|
|
|
|
148
|
|
|
$this->QueueShell->args[] = 'QueueExample'; |
149
|
|
|
$result = $this->QueueShell->add(); |
|
|
|
|
150
|
|
|
|
151
|
|
|
$this->assertEmpty($this->QueueShell->_out); |
152
|
|
|
|
153
|
|
|
$this->skipIf((php_sapi_name() !== 'cli'), 'This test can only be run from console.'); |
154
|
|
|
|
155
|
|
|
$result = $this->QueueShell->runworker(); |
|
|
|
|
156
|
|
|
|
157
|
|
|
$this->assertTrue(in_array(__d('queue', 'Running job of task \'%s\' \'%d\'.', 'Example', 5), $this->QueueShell->_out)); |
|
|
|
|
158
|
|
|
|
159
|
|
|
Configure::write('Queue.exitWhenNothingToDo', $restore); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Tests `QueueShell::runworker`. |
164
|
|
|
* |
165
|
|
|
* @return void |
166
|
|
|
*/ |
167
|
|
|
public function testRunworker() { |
168
|
|
|
$restore = Configure::read('Queue.exitWhenNothingToDo'); |
169
|
|
|
Configure::write('Queue.exitWhenNothingToDo', true); |
170
|
|
|
|
171
|
|
|
$this->skipIf((php_sapi_name() !== 'cli'), 'This test can only be run from console.'); |
172
|
|
|
|
173
|
|
|
$result = $this->QueueShell->runworker(); |
|
|
|
|
174
|
|
|
|
175
|
|
|
$this->assertTrue(in_array(__d('queue', 'Looking for a job.'), $this->QueueShell->_out)); |
|
|
|
|
176
|
|
|
|
177
|
|
|
Configure::write('Queue.exitWhenNothingToDo', $restore); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Tests `QueueShell::clean`. |
182
|
|
|
* |
183
|
|
|
* @return void |
184
|
|
|
*/ |
185
|
|
|
public function testClean() { |
186
|
|
|
$countBefore = $this->QueueShell->QueuedTask->find('count'); |
187
|
|
|
$result = $this->QueueShell->clean(); |
|
|
|
|
188
|
|
|
$expected = $countBefore - 2; |
189
|
|
|
$count = $this->QueueShell->QueuedTask->find('count'); |
190
|
|
|
$this->assertEquals($expected, $count); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
} |
194
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths