@@ -7,50 +7,50 @@ |
||
7 | 7 | class TaskFinderTest extends TestCase |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * |
|
12 | - * @var \Queue\Shell\QueueShell|\PHPUnit_Framework_MockObject_MockObject |
|
13 | - */ |
|
14 | - public $QueueShell; |
|
15 | - |
|
16 | - /** |
|
17 | - * |
|
18 | - * @var \Queue\Queue\TaskFinder |
|
19 | - */ |
|
20 | - protected $taskFinder; |
|
21 | - |
|
22 | - /** |
|
23 | - * Fixtures to load |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - public $fixtures = [ |
|
28 | - 'plugin.Queue.QueuedTasks', |
|
29 | - ]; |
|
30 | - |
|
31 | - /** |
|
32 | - * Setup Defaults |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function setUp() |
|
37 | - { |
|
38 | - parent::setUp(); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - public function testAllAppAndPluginTasks() |
|
46 | - { |
|
47 | - $this->taskFinder = new TaskFinder(); |
|
48 | - |
|
49 | - $result = $this->taskFinder->allAppAndPluginTasks(); |
|
50 | - $this->assertCount(1, $result); |
|
51 | - $this->assertArraySubset([ |
|
52 | - 'Queue.QueueExample' |
|
53 | - ], $result); |
|
54 | - $this->assertTrue(!in_array('Foo.QueueFoo', $result)); |
|
55 | - } |
|
10 | + /** |
|
11 | + * |
|
12 | + * @var \Queue\Shell\QueueShell|\PHPUnit_Framework_MockObject_MockObject |
|
13 | + */ |
|
14 | + public $QueueShell; |
|
15 | + |
|
16 | + /** |
|
17 | + * |
|
18 | + * @var \Queue\Queue\TaskFinder |
|
19 | + */ |
|
20 | + protected $taskFinder; |
|
21 | + |
|
22 | + /** |
|
23 | + * Fixtures to load |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + public $fixtures = [ |
|
28 | + 'plugin.Queue.QueuedTasks', |
|
29 | + ]; |
|
30 | + |
|
31 | + /** |
|
32 | + * Setup Defaults |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function setUp() |
|
37 | + { |
|
38 | + parent::setUp(); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + public function testAllAppAndPluginTasks() |
|
46 | + { |
|
47 | + $this->taskFinder = new TaskFinder(); |
|
48 | + |
|
49 | + $result = $this->taskFinder->allAppAndPluginTasks(); |
|
50 | + $this->assertCount(1, $result); |
|
51 | + $this->assertArraySubset([ |
|
52 | + 'Queue.QueueExample' |
|
53 | + ], $result); |
|
54 | + $this->assertTrue(!in_array('Foo.QueueFoo', $result)); |
|
55 | + } |
|
56 | 56 | } |
@@ -19,292 +19,292 @@ |
||
19 | 19 | class QueuedTasksTableTest extends TestCase |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * |
|
24 | - * @var \Queue\Model\Table\QueuedTasksTable |
|
25 | - */ |
|
26 | - protected $QueuedTasks; |
|
22 | + /** |
|
23 | + * |
|
24 | + * @var \Queue\Model\Table\QueuedTasksTable |
|
25 | + */ |
|
26 | + protected $QueuedTasks; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Fixtures |
|
30 | - * |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - public $fixtures = [ |
|
34 | - 'plugin.Queue.QueuedTasks' |
|
35 | - ]; |
|
28 | + /** |
|
29 | + * Fixtures |
|
30 | + * |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + public $fixtures = [ |
|
34 | + 'plugin.Queue.QueuedTasks' |
|
35 | + ]; |
|
36 | 36 | |
37 | - /** |
|
38 | - * setUp method |
|
39 | - * |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public function setUp() |
|
43 | - { |
|
44 | - parent::setUp(); |
|
45 | - $config = TableRegistry::getTableLocator()->exists('QueuedTasks') ? [] : [ |
|
46 | - 'className' => QueuedTasksTable::class |
|
47 | - ]; |
|
48 | - $this->QueuedTasks = TableRegistry::getTableLocator()->get('QueuedTasks', $config); |
|
49 | - } |
|
37 | + /** |
|
38 | + * setUp method |
|
39 | + * |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public function setUp() |
|
43 | + { |
|
44 | + parent::setUp(); |
|
45 | + $config = TableRegistry::getTableLocator()->exists('QueuedTasks') ? [] : [ |
|
46 | + 'className' => QueuedTasksTable::class |
|
47 | + ]; |
|
48 | + $this->QueuedTasks = TableRegistry::getTableLocator()->get('QueuedTasks', $config); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Basic Instance test |
|
53 | - * |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public function testQueueInstance() |
|
57 | - { |
|
58 | - $this->assertInstanceOf(QueuedTasksTable::class, $this->QueuedTasks); |
|
59 | - } |
|
51 | + /** |
|
52 | + * Basic Instance test |
|
53 | + * |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public function testQueueInstance() |
|
57 | + { |
|
58 | + $this->assertInstanceOf(QueuedTasksTable::class, $this->QueuedTasks); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Test the basic create and length evaluation functions. |
|
63 | - * |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - public function testCreateAndCount() |
|
67 | - { |
|
68 | - // at first, the queue should contain 0 items. |
|
69 | - $this->assertSame(0, $this->QueuedTasks->getLength()); |
|
61 | + /** |
|
62 | + * Test the basic create and length evaluation functions. |
|
63 | + * |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + public function testCreateAndCount() |
|
67 | + { |
|
68 | + // at first, the queue should contain 0 items. |
|
69 | + $this->assertSame(0, $this->QueuedTasks->getLength()); |
|
70 | 70 | |
71 | - // create a job |
|
72 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('test1', [ |
|
73 | - 'some' => 'random', |
|
74 | - 'test' => 'data' |
|
75 | - ])); |
|
71 | + // create a job |
|
72 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('test1', [ |
|
73 | + 'some' => 'random', |
|
74 | + 'test' => 'data' |
|
75 | + ])); |
|
76 | 76 | |
77 | - // test if queue Length is 1 now. |
|
78 | - $this->assertSame(1, $this->QueuedTasks->getLength()); |
|
77 | + // test if queue Length is 1 now. |
|
78 | + $this->assertSame(1, $this->QueuedTasks->getLength()); |
|
79 | 79 | |
80 | - // create some more jobs |
|
81 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('test2', [ |
|
82 | - 'some' => 'random', |
|
83 | - 'test' => 'data2' |
|
84 | - ])); |
|
85 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('test2', [ |
|
86 | - 'some' => 'random', |
|
87 | - 'test' => 'data3' |
|
88 | - ])); |
|
89 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('test3', [ |
|
90 | - 'some' => 'random', |
|
91 | - 'test' => 'data4' |
|
92 | - ])); |
|
80 | + // create some more jobs |
|
81 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('test2', [ |
|
82 | + 'some' => 'random', |
|
83 | + 'test' => 'data2' |
|
84 | + ])); |
|
85 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('test2', [ |
|
86 | + 'some' => 'random', |
|
87 | + 'test' => 'data3' |
|
88 | + ])); |
|
89 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('test3', [ |
|
90 | + 'some' => 'random', |
|
91 | + 'test' => 'data4' |
|
92 | + ])); |
|
93 | 93 | |
94 | - // overall queueLength shpould now be 4 |
|
95 | - $this->assertSame(4, $this->QueuedTasks->getLength()); |
|
94 | + // overall queueLength shpould now be 4 |
|
95 | + $this->assertSame(4, $this->QueuedTasks->getLength()); |
|
96 | 96 | |
97 | - // there should be 1 task of type 'test1', one of type 'test3' and 2 of type 'test2' |
|
98 | - $this->assertSame(1, $this->QueuedTasks->getLength('test1')); |
|
99 | - $this->assertSame(2, $this->QueuedTasks->getLength('test2')); |
|
100 | - $this->assertSame(1, $this->QueuedTasks->getLength('test3')); |
|
101 | - } |
|
97 | + // there should be 1 task of type 'test1', one of type 'test3' and 2 of type 'test2' |
|
98 | + $this->assertSame(1, $this->QueuedTasks->getLength('test1')); |
|
99 | + $this->assertSame(2, $this->QueuedTasks->getLength('test2')); |
|
100 | + $this->assertSame(1, $this->QueuedTasks->getLength('test3')); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Test the basic create and fetch functions. |
|
105 | - * |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - public function testCreateAndFetch() |
|
109 | - { |
|
110 | - $this->_needsConnection(); |
|
103 | + /** |
|
104 | + * Test the basic create and fetch functions. |
|
105 | + * |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function testCreateAndFetch() |
|
109 | + { |
|
110 | + $this->_needsConnection(); |
|
111 | 111 | |
112 | - // $capabilities is a list of tasks the worker can run. |
|
113 | - $capabilities = [ |
|
114 | - 'task1' => [ |
|
115 | - 'name' => 'task1', |
|
116 | - 'timeout' => 100, |
|
117 | - 'retries' => 2 |
|
118 | - ] |
|
119 | - ]; |
|
120 | - $testData = [ |
|
121 | - 'x1' => 'y1', |
|
122 | - 'x2' => 'y2', |
|
123 | - 'x3' => 'y3', |
|
124 | - 'x4' => 'y4' |
|
125 | - ]; |
|
112 | + // $capabilities is a list of tasks the worker can run. |
|
113 | + $capabilities = [ |
|
114 | + 'task1' => [ |
|
115 | + 'name' => 'task1', |
|
116 | + 'timeout' => 100, |
|
117 | + 'retries' => 2 |
|
118 | + ] |
|
119 | + ]; |
|
120 | + $testData = [ |
|
121 | + 'x1' => 'y1', |
|
122 | + 'x2' => 'y2', |
|
123 | + 'x3' => 'y3', |
|
124 | + 'x4' => 'y4' |
|
125 | + ]; |
|
126 | 126 | |
127 | - // start off empty. |
|
128 | - $this->assertSame([], $this->QueuedTasks->find() |
|
129 | - ->toArray()); |
|
130 | - // at first, the queue should contain 0 items. |
|
131 | - $this->assertSame(0, $this->QueuedTasks->getLength()); |
|
132 | - // there are no jobs, so we cant fetch any. |
|
133 | - $this->assertNull($this->QueuedTasks->requestJob($capabilities)); |
|
134 | - // insert one job. |
|
135 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', $testData)); |
|
127 | + // start off empty. |
|
128 | + $this->assertSame([], $this->QueuedTasks->find() |
|
129 | + ->toArray()); |
|
130 | + // at first, the queue should contain 0 items. |
|
131 | + $this->assertSame(0, $this->QueuedTasks->getLength()); |
|
132 | + // there are no jobs, so we cant fetch any. |
|
133 | + $this->assertNull($this->QueuedTasks->requestJob($capabilities)); |
|
134 | + // insert one job. |
|
135 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', $testData)); |
|
136 | 136 | |
137 | - // fetch and check the first job. |
|
138 | - $job = $this->QueuedTasks->requestJob($capabilities); |
|
139 | - $this->assertSame(1, $job->id); |
|
140 | - $this->assertSame('task1', $job->task); |
|
141 | - $this->assertSame(0, $job->failed_count); |
|
142 | - $this->assertNull($job->completed); |
|
143 | - $this->assertSame($testData, unserialize($job->data)); |
|
137 | + // fetch and check the first job. |
|
138 | + $job = $this->QueuedTasks->requestJob($capabilities); |
|
139 | + $this->assertSame(1, $job->id); |
|
140 | + $this->assertSame('task1', $job->task); |
|
141 | + $this->assertSame(0, $job->failed_count); |
|
142 | + $this->assertNull($job->completed); |
|
143 | + $this->assertSame($testData, unserialize($job->data)); |
|
144 | 144 | |
145 | - // after this job has been fetched, it may not be reassigned. |
|
146 | - $result = $this->QueuedTasks->requestJob($capabilities); |
|
147 | - $this->assertNull($result); |
|
145 | + // after this job has been fetched, it may not be reassigned. |
|
146 | + $result = $this->QueuedTasks->requestJob($capabilities); |
|
147 | + $this->assertNull($result); |
|
148 | 148 | |
149 | - // queue length is still 1 since the first job did not finish. |
|
150 | - $this->assertSame(1, $this->QueuedTasks->getLength()); |
|
149 | + // queue length is still 1 since the first job did not finish. |
|
150 | + $this->assertSame(1, $this->QueuedTasks->getLength()); |
|
151 | 151 | |
152 | - // Now mark Task1 as done |
|
153 | - $this->assertTrue($this->QueuedTasks->markJobDone($job)); |
|
152 | + // Now mark Task1 as done |
|
153 | + $this->assertTrue($this->QueuedTasks->markJobDone($job)); |
|
154 | 154 | |
155 | - // Should be 0 again. |
|
156 | - $this->assertSame(0, $this->QueuedTasks->getLength()); |
|
157 | - } |
|
155 | + // Should be 0 again. |
|
156 | + $this->assertSame(0, $this->QueuedTasks->getLength()); |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Test the delivery of jobs in sequence, skipping fetched but not completed tasks. |
|
161 | - * |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - public function testSequence() |
|
165 | - { |
|
166 | - $this->_needsConnection(); |
|
159 | + /** |
|
160 | + * Test the delivery of jobs in sequence, skipping fetched but not completed tasks. |
|
161 | + * |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + public function testSequence() |
|
165 | + { |
|
166 | + $this->_needsConnection(); |
|
167 | 167 | |
168 | - // $capabilities is a list of tasks the worker can run. |
|
169 | - $capabilities = [ |
|
170 | - 'task1' => [ |
|
171 | - 'name' => 'task1', |
|
172 | - 'timeout' => 100, |
|
173 | - 'retries' => 2 |
|
174 | - ] |
|
175 | - ]; |
|
176 | - // at first, the queue should contain 0 items. |
|
177 | - $this->assertSame(0, $this->QueuedTasks->getLength()); |
|
178 | - // create some more jobs |
|
179 | - foreach (range(0, 9) as $num) { |
|
180 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
181 | - 'tasknum' => $num |
|
182 | - ])); |
|
183 | - } |
|
184 | - // 10 jobs in the queue. |
|
185 | - $this->assertSame(10, $this->QueuedTasks->getLength()); |
|
168 | + // $capabilities is a list of tasks the worker can run. |
|
169 | + $capabilities = [ |
|
170 | + 'task1' => [ |
|
171 | + 'name' => 'task1', |
|
172 | + 'timeout' => 100, |
|
173 | + 'retries' => 2 |
|
174 | + ] |
|
175 | + ]; |
|
176 | + // at first, the queue should contain 0 items. |
|
177 | + $this->assertSame(0, $this->QueuedTasks->getLength()); |
|
178 | + // create some more jobs |
|
179 | + foreach (range(0, 9) as $num) { |
|
180 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
181 | + 'tasknum' => $num |
|
182 | + ])); |
|
183 | + } |
|
184 | + // 10 jobs in the queue. |
|
185 | + $this->assertSame(10, $this->QueuedTasks->getLength()); |
|
186 | 186 | |
187 | - // jobs should be fetched in the original sequence. |
|
188 | - $array = []; |
|
189 | - foreach (range(0, 4) as $num) { |
|
190 | - $array[$num] = $this->QueuedTasks->requestJob($capabilities); |
|
191 | - $jobData = unserialize($array[$num]['data']); |
|
192 | - $this->assertSame($num, $jobData['tasknum']); |
|
193 | - } |
|
194 | - // now mark them as done |
|
195 | - foreach (range(0, 4) as $num) { |
|
196 | - $this->assertTrue($this->QueuedTasks->markJobDone($array[$num])); |
|
197 | - $this->assertSame(9 - $num, $this->QueuedTasks->getLength()); |
|
198 | - } |
|
187 | + // jobs should be fetched in the original sequence. |
|
188 | + $array = []; |
|
189 | + foreach (range(0, 4) as $num) { |
|
190 | + $array[$num] = $this->QueuedTasks->requestJob($capabilities); |
|
191 | + $jobData = unserialize($array[$num]['data']); |
|
192 | + $this->assertSame($num, $jobData['tasknum']); |
|
193 | + } |
|
194 | + // now mark them as done |
|
195 | + foreach (range(0, 4) as $num) { |
|
196 | + $this->assertTrue($this->QueuedTasks->markJobDone($array[$num])); |
|
197 | + $this->assertSame(9 - $num, $this->QueuedTasks->getLength()); |
|
198 | + } |
|
199 | 199 | |
200 | - // jobs should be fetched in the original sequence. |
|
201 | - foreach (range(5, 9) as $num) { |
|
202 | - $job = $this->QueuedTasks->requestJob($capabilities); |
|
203 | - $jobData = unserialize($job->data); |
|
204 | - $this->assertSame($num, $jobData['tasknum']); |
|
205 | - $this->assertTrue($this->QueuedTasks->markJobDone($job)); |
|
206 | - $this->assertSame(9 - $num, $this->QueuedTasks->getLength()); |
|
207 | - } |
|
208 | - } |
|
200 | + // jobs should be fetched in the original sequence. |
|
201 | + foreach (range(5, 9) as $num) { |
|
202 | + $job = $this->QueuedTasks->requestJob($capabilities); |
|
203 | + $jobData = unserialize($job->data); |
|
204 | + $this->assertSame($num, $jobData['tasknum']); |
|
205 | + $this->assertTrue($this->QueuedTasks->markJobDone($job)); |
|
206 | + $this->assertSame(9 - $num, $this->QueuedTasks->getLength()); |
|
207 | + } |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * Test creating Jobs to run close to a specified time, and strtotime parsing. |
|
212 | - * Using toUnixString() function to convert Time object to timestamp, instead of strtotime |
|
213 | - * |
|
214 | - * @return null |
|
215 | - */ |
|
216 | - public function testNotBefore() |
|
217 | - { |
|
218 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', null, '+ 1 Min')); |
|
219 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', null, '+ 1 Day')); |
|
220 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', null, '2009-07-01 12:00:00')); |
|
221 | - $data = $this->QueuedTasks->find('all')->toArray(); |
|
222 | - $this->assertWithinRange((new Time('+ 1 Min'))->toUnixString(), $data[0]['not_before']->toUnixString(), 60); |
|
223 | - $this->assertWithinRange((new Time('+ 1 Day'))->toUnixString(), $data[1]['not_before']->toUnixString(), 60); |
|
224 | - $this->assertWithinRange((new Time('2009-07-01 12:00:00'))->toUnixString(), $data[2]['not_before']->toUnixString(), 60); |
|
225 | - } |
|
210 | + /** |
|
211 | + * Test creating Jobs to run close to a specified time, and strtotime parsing. |
|
212 | + * Using toUnixString() function to convert Time object to timestamp, instead of strtotime |
|
213 | + * |
|
214 | + * @return null |
|
215 | + */ |
|
216 | + public function testNotBefore() |
|
217 | + { |
|
218 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', null, '+ 1 Min')); |
|
219 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', null, '+ 1 Day')); |
|
220 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', null, '2009-07-01 12:00:00')); |
|
221 | + $data = $this->QueuedTasks->find('all')->toArray(); |
|
222 | + $this->assertWithinRange((new Time('+ 1 Min'))->toUnixString(), $data[0]['not_before']->toUnixString(), 60); |
|
223 | + $this->assertWithinRange((new Time('+ 1 Day'))->toUnixString(), $data[1]['not_before']->toUnixString(), 60); |
|
224 | + $this->assertWithinRange((new Time('2009-07-01 12:00:00'))->toUnixString(), $data[2]['not_before']->toUnixString(), 60); |
|
225 | + } |
|
226 | 226 | |
227 | - /** |
|
228 | - * Test Job reordering depending on 'notBefore' field. |
|
229 | - * Jobs with an expired not_before field should be executed before any other job without specific timing info. |
|
230 | - * |
|
231 | - * @return void |
|
232 | - */ |
|
233 | - public function testNotBeforeOrder() |
|
234 | - { |
|
235 | - $this->_needsConnection(); |
|
227 | + /** |
|
228 | + * Test Job reordering depending on 'notBefore' field. |
|
229 | + * Jobs with an expired not_before field should be executed before any other job without specific timing info. |
|
230 | + * |
|
231 | + * @return void |
|
232 | + */ |
|
233 | + public function testNotBeforeOrder() |
|
234 | + { |
|
235 | + $this->_needsConnection(); |
|
236 | 236 | |
237 | - $capabilities = [ |
|
238 | - 'task1' => [ |
|
239 | - 'name' => 'task1', |
|
240 | - 'timeout' => 100, |
|
241 | - 'retries' => 2 |
|
242 | - ], |
|
243 | - 'dummytask' => [ |
|
244 | - 'name' => 'dummytask', |
|
245 | - 'timeout' => 100, |
|
246 | - 'retries' => 2 |
|
247 | - ] |
|
248 | - ]; |
|
249 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('dummytask')); |
|
250 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('dummytask')); |
|
251 | - // create a task with it's execution target some seconds in the past, so it should jump to the top of the testCreateAndFetchlist. |
|
252 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
253 | - 'three' |
|
254 | - ], '- 3 Seconds')); |
|
255 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
256 | - 'two' |
|
257 | - ], '- 5 Seconds')); |
|
258 | - $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
259 | - 'one' |
|
260 | - ], '- 7 Seconds')); |
|
237 | + $capabilities = [ |
|
238 | + 'task1' => [ |
|
239 | + 'name' => 'task1', |
|
240 | + 'timeout' => 100, |
|
241 | + 'retries' => 2 |
|
242 | + ], |
|
243 | + 'dummytask' => [ |
|
244 | + 'name' => 'dummytask', |
|
245 | + 'timeout' => 100, |
|
246 | + 'retries' => 2 |
|
247 | + ] |
|
248 | + ]; |
|
249 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('dummytask')); |
|
250 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('dummytask')); |
|
251 | + // create a task with it's execution target some seconds in the past, so it should jump to the top of the testCreateAndFetchlist. |
|
252 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
253 | + 'three' |
|
254 | + ], '- 3 Seconds')); |
|
255 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
256 | + 'two' |
|
257 | + ], '- 5 Seconds')); |
|
258 | + $this->assertTrue((bool)$this->QueuedTasks->createJob('task1', [ |
|
259 | + 'one' |
|
260 | + ], '- 7 Seconds')); |
|
261 | 261 | |
262 | - // when using requestJob, the jobs we just created should be delivered in this order, NOT the order in which they where created. |
|
263 | - $expected = [ |
|
264 | - [ |
|
265 | - 'name' => 'task1', |
|
266 | - 'data' => [ |
|
267 | - 'one' |
|
268 | - ] |
|
269 | - ], |
|
270 | - [ |
|
271 | - 'name' => 'task1', |
|
272 | - 'data' => [ |
|
273 | - 'two' |
|
274 | - ] |
|
275 | - ], |
|
276 | - [ |
|
277 | - 'name' => 'task1', |
|
278 | - 'data' => [ |
|
279 | - 'three' |
|
280 | - ] |
|
281 | - ], |
|
282 | - [ |
|
283 | - 'name' => 'dummytask', |
|
284 | - 'data' => null |
|
285 | - ], |
|
286 | - [ |
|
287 | - 'name' => 'dummytask', |
|
288 | - 'data' => null |
|
289 | - ] |
|
290 | - ]; |
|
262 | + // when using requestJob, the jobs we just created should be delivered in this order, NOT the order in which they where created. |
|
263 | + $expected = [ |
|
264 | + [ |
|
265 | + 'name' => 'task1', |
|
266 | + 'data' => [ |
|
267 | + 'one' |
|
268 | + ] |
|
269 | + ], |
|
270 | + [ |
|
271 | + 'name' => 'task1', |
|
272 | + 'data' => [ |
|
273 | + 'two' |
|
274 | + ] |
|
275 | + ], |
|
276 | + [ |
|
277 | + 'name' => 'task1', |
|
278 | + 'data' => [ |
|
279 | + 'three' |
|
280 | + ] |
|
281 | + ], |
|
282 | + [ |
|
283 | + 'name' => 'dummytask', |
|
284 | + 'data' => null |
|
285 | + ], |
|
286 | + [ |
|
287 | + 'name' => 'dummytask', |
|
288 | + 'data' => null |
|
289 | + ] |
|
290 | + ]; |
|
291 | 291 | |
292 | - foreach ($expected as $item) { |
|
293 | - $tmp = $this->QueuedTasks->requestJob($capabilities); |
|
292 | + foreach ($expected as $item) { |
|
293 | + $tmp = $this->QueuedTasks->requestJob($capabilities); |
|
294 | 294 | |
295 | - $this->assertSame($item['name'], $tmp['task']); |
|
296 | - $this->assertEquals($item['data'], unserialize($tmp['data'])); |
|
297 | - } |
|
298 | - } |
|
295 | + $this->assertSame($item['name'], $tmp['task']); |
|
296 | + $this->assertEquals($item['data'], unserialize($tmp['data'])); |
|
297 | + } |
|
298 | + } |
|
299 | 299 | |
300 | - /** |
|
301 | - * Helper method for skipping tests that need a real connection. |
|
302 | - * |
|
303 | - * @return void |
|
304 | - */ |
|
305 | - protected function _needsConnection() |
|
306 | - { |
|
307 | - $config = ConnectionManager::getConfig('test'); |
|
308 | - $this->skipIf(strpos($config['driver'], 'Mysql') === false, 'Only Mysql is working yet for this.'); |
|
309 | - } |
|
300 | + /** |
|
301 | + * Helper method for skipping tests that need a real connection. |
|
302 | + * |
|
303 | + * @return void |
|
304 | + */ |
|
305 | + protected function _needsConnection() |
|
306 | + { |
|
307 | + $config = ConnectionManager::getConfig('test'); |
|
308 | + $this->skipIf(strpos($config['driver'], 'Mysql') === false, 'Only Mysql is working yet for this.'); |
|
309 | + } |
|
310 | 310 | } |
@@ -11,187 +11,187 @@ |
||
11 | 11 | |
12 | 12 | class QueueShellTest extends TestCase |
13 | 13 | { |
14 | - use ToolsTestTrait; |
|
15 | - |
|
16 | - /** |
|
17 | - * |
|
18 | - * @var \Queue\Shell\QueueShell|\PHPUnit_Framework_MockObject_MockObject |
|
19 | - */ |
|
20 | - public $QueueShell; |
|
21 | - |
|
22 | - /** |
|
23 | - * |
|
24 | - * @var \Tools\TestSuite\ConsoleOutput |
|
25 | - */ |
|
26 | - public $out; |
|
27 | - |
|
28 | - /** |
|
29 | - * |
|
30 | - * @var \Tools\TestSuite\ConsoleOutput |
|
31 | - */ |
|
32 | - public $err; |
|
33 | - |
|
34 | - /** |
|
35 | - * Fixtures to load |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - public $fixtures = [ |
|
40 | - 'plugin.Queue.QueuedTasks' |
|
41 | - ]; |
|
42 | - |
|
43 | - /** |
|
44 | - * Setup Defaults |
|
45 | - * |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public function setUp() |
|
49 | - { |
|
50 | - parent::setUp(); |
|
51 | - |
|
52 | - $this->out = new ConsoleOutput(); |
|
53 | - $this->err = new ConsoleOutput(); |
|
54 | - $io = new ConsoleIo($this->out, $this->err); |
|
55 | - |
|
56 | - $this->QueueShell = $this->getMockBuilder(QueueShell::class) |
|
57 | - ->setMethods([ |
|
58 | - 'in', |
|
59 | - 'err', |
|
60 | - '_stop' |
|
61 | - ]) |
|
62 | - ->setConstructorArgs([ |
|
63 | - $io |
|
64 | - ]) |
|
65 | - ->getMock(); |
|
66 | - $this->QueueShell->initialize(); |
|
67 | - |
|
68 | - Configure::write('Queue', [ |
|
69 | - 'sleepTime' => 2, |
|
70 | - 'defaultWorkerTimeout' => 3, |
|
71 | - 'workerMaxRuntime' => 5, |
|
72 | - 'cleanupTimeout' => 10, |
|
73 | - 'exitWhenNothingToDo' => false, |
|
74 | - 'log' => false |
|
75 | - ]); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function testObject() |
|
83 | - { |
|
84 | - $this->assertTrue(is_object($this->QueueShell)); |
|
85 | - $this->assertInstanceOf(QueueShell::class, $this->QueueShell); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - public function testStats() |
|
93 | - { |
|
94 | - $this->_needsConnection(); |
|
95 | - |
|
96 | - $this->QueueShell->stats(); |
|
97 | - $this->assertContains('Total unfinished jobs: 0', $this->out->output()); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * |
|
102 | - * @return void |
|
103 | - */ |
|
104 | - public function testSettings() |
|
105 | - { |
|
106 | - $this->QueueShell->settings(); |
|
107 | - $this->assertContains('* cleanupTimeout: 10', $this->out->output()); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * |
|
112 | - * @return void |
|
113 | - */ |
|
114 | - public function testAddInexistent() |
|
115 | - { |
|
116 | - $this->QueueShell->args[] = 'FooBar'; |
|
117 | - $this->QueueShell->add(); |
|
118 | - $this->assertContains('Error: Task not found: FooBar', $this->out->output()); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function testAdd() |
|
126 | - { |
|
127 | - $this->QueueShell->args[] = 'Example'; |
|
128 | - $this->QueueShell->add(); |
|
129 | - |
|
130 | - $this->assertContains('OK, job created, now run the worker', $this->out->output(), print_r($this->out->output(), true)); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - public function testTimeNeeded() |
|
138 | - { |
|
139 | - $this->QueueShell = $this->getMockBuilder(QueueShell::class) |
|
140 | - ->setMethods([ |
|
141 | - '_time' |
|
142 | - ]) |
|
143 | - ->getMock(); |
|
144 | - |
|
145 | - $first = time(); |
|
146 | - $second = $first - HOUR + MINUTE; |
|
147 | - $this->QueueShell->expects($this->at(0)) |
|
148 | - ->method('_time') |
|
149 | - ->will($this->returnValue($first)); |
|
150 | - $this->QueueShell->expects($this->at(1)) |
|
151 | - ->method('_time') |
|
152 | - ->will($this->returnValue($second)); |
|
153 | - $this->QueueShell->expects($this->exactly(2)) |
|
154 | - ->method('_time') |
|
155 | - ->withAnyParameters(); |
|
156 | - |
|
157 | - $result = $this->invokeMethod($this->QueueShell, '_timeNeeded'); |
|
158 | - $this->assertSame('3540s', $result); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * |
|
163 | - * @return void |
|
164 | - */ |
|
165 | - public function testMemoryUsage() |
|
166 | - { |
|
167 | - $result = $this->invokeMethod($this->QueueShell, '_memoryUsage'); |
|
168 | - $this->assertRegExp('/^\d+MB/', $result, 'Should be e.g. `17MB` or `17MB/1GB` etc.'); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * |
|
173 | - * @return void |
|
174 | - */ |
|
175 | - public function testStringToArray() |
|
176 | - { |
|
177 | - $string = 'Foo,Bar,'; |
|
178 | - $result = $this->invokeMethod($this->QueueShell, '_stringToArray', [$string]); |
|
179 | - |
|
180 | - $expected = [ |
|
181 | - 'Foo', |
|
182 | - 'Bar' |
|
183 | - ]; |
|
184 | - $this->assertSame($expected, $result); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Helper method for skipping tests that need a real connection. |
|
189 | - * |
|
190 | - * @return void |
|
191 | - */ |
|
192 | - protected function _needsConnection() |
|
193 | - { |
|
194 | - $config = ConnectionManager::getConfig('test'); |
|
195 | - $this->skipIf(strpos($config['driver'], 'Mysql') === false, 'Only Mysql is working yet for this.'); |
|
196 | - } |
|
14 | + use ToolsTestTrait; |
|
15 | + |
|
16 | + /** |
|
17 | + * |
|
18 | + * @var \Queue\Shell\QueueShell|\PHPUnit_Framework_MockObject_MockObject |
|
19 | + */ |
|
20 | + public $QueueShell; |
|
21 | + |
|
22 | + /** |
|
23 | + * |
|
24 | + * @var \Tools\TestSuite\ConsoleOutput |
|
25 | + */ |
|
26 | + public $out; |
|
27 | + |
|
28 | + /** |
|
29 | + * |
|
30 | + * @var \Tools\TestSuite\ConsoleOutput |
|
31 | + */ |
|
32 | + public $err; |
|
33 | + |
|
34 | + /** |
|
35 | + * Fixtures to load |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + public $fixtures = [ |
|
40 | + 'plugin.Queue.QueuedTasks' |
|
41 | + ]; |
|
42 | + |
|
43 | + /** |
|
44 | + * Setup Defaults |
|
45 | + * |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public function setUp() |
|
49 | + { |
|
50 | + parent::setUp(); |
|
51 | + |
|
52 | + $this->out = new ConsoleOutput(); |
|
53 | + $this->err = new ConsoleOutput(); |
|
54 | + $io = new ConsoleIo($this->out, $this->err); |
|
55 | + |
|
56 | + $this->QueueShell = $this->getMockBuilder(QueueShell::class) |
|
57 | + ->setMethods([ |
|
58 | + 'in', |
|
59 | + 'err', |
|
60 | + '_stop' |
|
61 | + ]) |
|
62 | + ->setConstructorArgs([ |
|
63 | + $io |
|
64 | + ]) |
|
65 | + ->getMock(); |
|
66 | + $this->QueueShell->initialize(); |
|
67 | + |
|
68 | + Configure::write('Queue', [ |
|
69 | + 'sleepTime' => 2, |
|
70 | + 'defaultWorkerTimeout' => 3, |
|
71 | + 'workerMaxRuntime' => 5, |
|
72 | + 'cleanupTimeout' => 10, |
|
73 | + 'exitWhenNothingToDo' => false, |
|
74 | + 'log' => false |
|
75 | + ]); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function testObject() |
|
83 | + { |
|
84 | + $this->assertTrue(is_object($this->QueueShell)); |
|
85 | + $this->assertInstanceOf(QueueShell::class, $this->QueueShell); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + public function testStats() |
|
93 | + { |
|
94 | + $this->_needsConnection(); |
|
95 | + |
|
96 | + $this->QueueShell->stats(); |
|
97 | + $this->assertContains('Total unfinished jobs: 0', $this->out->output()); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * |
|
102 | + * @return void |
|
103 | + */ |
|
104 | + public function testSettings() |
|
105 | + { |
|
106 | + $this->QueueShell->settings(); |
|
107 | + $this->assertContains('* cleanupTimeout: 10', $this->out->output()); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * |
|
112 | + * @return void |
|
113 | + */ |
|
114 | + public function testAddInexistent() |
|
115 | + { |
|
116 | + $this->QueueShell->args[] = 'FooBar'; |
|
117 | + $this->QueueShell->add(); |
|
118 | + $this->assertContains('Error: Task not found: FooBar', $this->out->output()); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function testAdd() |
|
126 | + { |
|
127 | + $this->QueueShell->args[] = 'Example'; |
|
128 | + $this->QueueShell->add(); |
|
129 | + |
|
130 | + $this->assertContains('OK, job created, now run the worker', $this->out->output(), print_r($this->out->output(), true)); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + public function testTimeNeeded() |
|
138 | + { |
|
139 | + $this->QueueShell = $this->getMockBuilder(QueueShell::class) |
|
140 | + ->setMethods([ |
|
141 | + '_time' |
|
142 | + ]) |
|
143 | + ->getMock(); |
|
144 | + |
|
145 | + $first = time(); |
|
146 | + $second = $first - HOUR + MINUTE; |
|
147 | + $this->QueueShell->expects($this->at(0)) |
|
148 | + ->method('_time') |
|
149 | + ->will($this->returnValue($first)); |
|
150 | + $this->QueueShell->expects($this->at(1)) |
|
151 | + ->method('_time') |
|
152 | + ->will($this->returnValue($second)); |
|
153 | + $this->QueueShell->expects($this->exactly(2)) |
|
154 | + ->method('_time') |
|
155 | + ->withAnyParameters(); |
|
156 | + |
|
157 | + $result = $this->invokeMethod($this->QueueShell, '_timeNeeded'); |
|
158 | + $this->assertSame('3540s', $result); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * |
|
163 | + * @return void |
|
164 | + */ |
|
165 | + public function testMemoryUsage() |
|
166 | + { |
|
167 | + $result = $this->invokeMethod($this->QueueShell, '_memoryUsage'); |
|
168 | + $this->assertRegExp('/^\d+MB/', $result, 'Should be e.g. `17MB` or `17MB/1GB` etc.'); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * |
|
173 | + * @return void |
|
174 | + */ |
|
175 | + public function testStringToArray() |
|
176 | + { |
|
177 | + $string = 'Foo,Bar,'; |
|
178 | + $result = $this->invokeMethod($this->QueueShell, '_stringToArray', [$string]); |
|
179 | + |
|
180 | + $expected = [ |
|
181 | + 'Foo', |
|
182 | + 'Bar' |
|
183 | + ]; |
|
184 | + $this->assertSame($expected, $result); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Helper method for skipping tests that need a real connection. |
|
189 | + * |
|
190 | + * @return void |
|
191 | + */ |
|
192 | + protected function _needsConnection() |
|
193 | + { |
|
194 | + $config = ConnectionManager::getConfig('test'); |
|
195 | + $this->skipIf(strpos($config['driver'], 'Mysql') === false, 'Only Mysql is working yet for this.'); |
|
196 | + } |
|
197 | 197 | } |
@@ -6,57 +6,57 @@ |
||
6 | 6 | class Config |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * |
|
11 | - * @return int |
|
12 | - */ |
|
13 | - public static function defaultWorkerTimeout() |
|
14 | - { |
|
15 | - return Configure::read('Queue.defaultWorkerTimeout', 600); // 10min |
|
16 | - } |
|
17 | - |
|
18 | - /** |
|
19 | - * |
|
20 | - * @return int |
|
21 | - */ |
|
22 | - public static function workerMaxRuntime() |
|
23 | - { |
|
24 | - return Configure::read('Queue.workerMaxRuntime', 120); |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * |
|
29 | - * @return int |
|
30 | - */ |
|
31 | - public static function cleanupTimeout() |
|
32 | - { |
|
33 | - return Configure::read('Queue.cleanupTimeout', 2592000); // 30 days |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * |
|
38 | - * @return int |
|
39 | - */ |
|
40 | - public static function sleepTime() |
|
41 | - { |
|
42 | - return Configure::read('Queue.sleepTime', 10); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * |
|
47 | - * @return int |
|
48 | - */ |
|
49 | - public static function gcprob() |
|
50 | - { |
|
51 | - return Configure::read('Queue.gcprob', 10); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * |
|
56 | - * @return int |
|
57 | - */ |
|
58 | - public static function defaultWorkerRetries() |
|
59 | - { |
|
60 | - return Configure::read('Queue.defaultWorkerRetries', 1); |
|
61 | - } |
|
9 | + /** |
|
10 | + * |
|
11 | + * @return int |
|
12 | + */ |
|
13 | + public static function defaultWorkerTimeout() |
|
14 | + { |
|
15 | + return Configure::read('Queue.defaultWorkerTimeout', 600); // 10min |
|
16 | + } |
|
17 | + |
|
18 | + /** |
|
19 | + * |
|
20 | + * @return int |
|
21 | + */ |
|
22 | + public static function workerMaxRuntime() |
|
23 | + { |
|
24 | + return Configure::read('Queue.workerMaxRuntime', 120); |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * |
|
29 | + * @return int |
|
30 | + */ |
|
31 | + public static function cleanupTimeout() |
|
32 | + { |
|
33 | + return Configure::read('Queue.cleanupTimeout', 2592000); // 30 days |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * |
|
38 | + * @return int |
|
39 | + */ |
|
40 | + public static function sleepTime() |
|
41 | + { |
|
42 | + return Configure::read('Queue.sleepTime', 10); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * |
|
47 | + * @return int |
|
48 | + */ |
|
49 | + public static function gcprob() |
|
50 | + { |
|
51 | + return Configure::read('Queue.gcprob', 10); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * |
|
56 | + * @return int |
|
57 | + */ |
|
58 | + public static function defaultWorkerRetries() |
|
59 | + { |
|
60 | + return Configure::read('Queue.defaultWorkerRetries', 1); |
|
61 | + } |
|
62 | 62 | } |
@@ -15,115 +15,115 @@ |
||
15 | 15 | class SimpleQueueTransport extends AbstractTransport |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Send mail |
|
20 | - * |
|
21 | - * @param \Cake\Mailer\Email $email Email |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function send(Email $email) |
|
25 | - { |
|
26 | - if (!empty($this->_config['queue'])) { |
|
27 | - $this->_config = $this->_config['queue'] + $this->_config; |
|
28 | - $email->setConfig((array)$this->_config['queue'] + [ |
|
29 | - 'queue' => [] |
|
30 | - ]); |
|
31 | - unset($this->_config['queue']); |
|
32 | - } |
|
18 | + /** |
|
19 | + * Send mail |
|
20 | + * |
|
21 | + * @param \Cake\Mailer\Email $email Email |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function send(Email $email) |
|
25 | + { |
|
26 | + if (!empty($this->_config['queue'])) { |
|
27 | + $this->_config = $this->_config['queue'] + $this->_config; |
|
28 | + $email->setConfig((array)$this->_config['queue'] + [ |
|
29 | + 'queue' => [] |
|
30 | + ]); |
|
31 | + unset($this->_config['queue']); |
|
32 | + } |
|
33 | 33 | |
34 | - $settings = [ |
|
35 | - 'from' => [ |
|
36 | - $email->getFrom() |
|
37 | - ], |
|
38 | - 'to' => [ |
|
39 | - $email->getTo() |
|
40 | - ], |
|
41 | - 'cc' => [ |
|
42 | - $email->getCc() |
|
43 | - ], |
|
44 | - 'bcc' => [ |
|
45 | - $email->getBcc() |
|
46 | - ], |
|
47 | - 'charset' => [ |
|
48 | - $email->getCharset() |
|
49 | - ], |
|
50 | - 'replyTo' => [ |
|
51 | - $email->getReplyTo() |
|
52 | - ], |
|
53 | - 'readReceipt' => [ |
|
54 | - $email->getReadReceipt() |
|
55 | - ], |
|
56 | - 'returnPath' => [ |
|
57 | - $email->getReturnPath() |
|
58 | - ], |
|
59 | - 'messageId' => [ |
|
60 | - $email->getMessageId() |
|
61 | - ], |
|
62 | - 'domain' => [ |
|
63 | - $email->getDomain() |
|
64 | - ], |
|
65 | - 'headers' => [ |
|
66 | - $email->getHeaders() |
|
67 | - ], |
|
68 | - 'headerCharset' => [ |
|
69 | - $email->getHeaderCharset() |
|
70 | - ], |
|
71 | - 'theme' => [ |
|
72 | - $email->viewBuilder()->getTheme() |
|
73 | - ], |
|
74 | - 'profile' => [ |
|
75 | - $email->getProfile() |
|
76 | - ], |
|
77 | - 'emailFormat' => [ |
|
78 | - $email->getEmailFormat() |
|
79 | - ], |
|
80 | - 'subject' => method_exists($email, 'getOriginalSubject') ? [ |
|
81 | - $email->getOriginalSubject() |
|
82 | - ] : [ |
|
83 | - $email->getSubject() |
|
84 | - ], |
|
85 | - 'transport' => [ |
|
86 | - $this->_config['transport'] |
|
87 | - ], |
|
88 | - 'attachments' => [ |
|
89 | - $email->getAttachments() |
|
90 | - ], |
|
91 | - 'template' => [ |
|
92 | - $email->viewBuilder()->getTemplate() |
|
93 | - ], |
|
94 | - 'layout' => [ |
|
95 | - $email->viewBuilder()->getLayout() |
|
96 | - ], |
|
97 | - 'viewVars' => [ |
|
98 | - $email->getViewVars() |
|
99 | - ] |
|
100 | - ]; |
|
34 | + $settings = [ |
|
35 | + 'from' => [ |
|
36 | + $email->getFrom() |
|
37 | + ], |
|
38 | + 'to' => [ |
|
39 | + $email->getTo() |
|
40 | + ], |
|
41 | + 'cc' => [ |
|
42 | + $email->getCc() |
|
43 | + ], |
|
44 | + 'bcc' => [ |
|
45 | + $email->getBcc() |
|
46 | + ], |
|
47 | + 'charset' => [ |
|
48 | + $email->getCharset() |
|
49 | + ], |
|
50 | + 'replyTo' => [ |
|
51 | + $email->getReplyTo() |
|
52 | + ], |
|
53 | + 'readReceipt' => [ |
|
54 | + $email->getReadReceipt() |
|
55 | + ], |
|
56 | + 'returnPath' => [ |
|
57 | + $email->getReturnPath() |
|
58 | + ], |
|
59 | + 'messageId' => [ |
|
60 | + $email->getMessageId() |
|
61 | + ], |
|
62 | + 'domain' => [ |
|
63 | + $email->getDomain() |
|
64 | + ], |
|
65 | + 'headers' => [ |
|
66 | + $email->getHeaders() |
|
67 | + ], |
|
68 | + 'headerCharset' => [ |
|
69 | + $email->getHeaderCharset() |
|
70 | + ], |
|
71 | + 'theme' => [ |
|
72 | + $email->viewBuilder()->getTheme() |
|
73 | + ], |
|
74 | + 'profile' => [ |
|
75 | + $email->getProfile() |
|
76 | + ], |
|
77 | + 'emailFormat' => [ |
|
78 | + $email->getEmailFormat() |
|
79 | + ], |
|
80 | + 'subject' => method_exists($email, 'getOriginalSubject') ? [ |
|
81 | + $email->getOriginalSubject() |
|
82 | + ] : [ |
|
83 | + $email->getSubject() |
|
84 | + ], |
|
85 | + 'transport' => [ |
|
86 | + $this->_config['transport'] |
|
87 | + ], |
|
88 | + 'attachments' => [ |
|
89 | + $email->getAttachments() |
|
90 | + ], |
|
91 | + 'template' => [ |
|
92 | + $email->viewBuilder()->getTemplate() |
|
93 | + ], |
|
94 | + 'layout' => [ |
|
95 | + $email->viewBuilder()->getLayout() |
|
96 | + ], |
|
97 | + 'viewVars' => [ |
|
98 | + $email->getViewVars() |
|
99 | + ] |
|
100 | + ]; |
|
101 | 101 | |
102 | - foreach ($settings as $setting => $value) { |
|
103 | - if (array_key_exists(0, $value) && ($value[0] === null || $value[0] === [])) { |
|
104 | - unset($settings[$setting]); |
|
105 | - } |
|
106 | - } |
|
102 | + foreach ($settings as $setting => $value) { |
|
103 | + if (array_key_exists(0, $value) && ($value[0] === null || $value[0] === [])) { |
|
104 | + unset($settings[$setting]); |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - $QueuedJobs = $this->getQueuedJobsModel(); |
|
109 | - $result = $QueuedJobs->createJob('Email', [ |
|
110 | - 'settings' => $settings |
|
111 | - ]); |
|
112 | - $result['headers'] = ''; |
|
113 | - $result['message'] = ''; |
|
108 | + $QueuedJobs = $this->getQueuedJobsModel(); |
|
109 | + $result = $QueuedJobs->createJob('Email', [ |
|
110 | + 'settings' => $settings |
|
111 | + ]); |
|
112 | + $result['headers'] = ''; |
|
113 | + $result['message'] = ''; |
|
114 | 114 | |
115 | - return $result->toArray(); |
|
116 | - } |
|
115 | + return $result->toArray(); |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * |
|
120 | - * @return \Queue\Model\Table\QueuedTasksTable |
|
121 | - */ |
|
122 | - protected function getQueuedJobsModel() |
|
123 | - { |
|
124 | - /** @var \Queue\Model\Table\QueuedTasksTable $table */ |
|
125 | - $table = TableRegistry::getTableLocator()->get('Queue.QueuedTasks'); |
|
118 | + /** |
|
119 | + * |
|
120 | + * @return \Queue\Model\Table\QueuedTasksTable |
|
121 | + */ |
|
122 | + protected function getQueuedJobsModel() |
|
123 | + { |
|
124 | + /** @var \Queue\Model\Table\QueuedTasksTable $table */ |
|
125 | + $table = TableRegistry::getTableLocator()->get('Queue.QueuedTasks'); |
|
126 | 126 | |
127 | - return $table; |
|
128 | - } |
|
127 | + return $table; |
|
128 | + } |
|
129 | 129 | } |
@@ -15,34 +15,34 @@ |
||
15 | 15 | class QueueTransport extends AbstractTransport |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Send mail |
|
20 | - * |
|
21 | - * @param \Cake\Mailer\Email $email Email |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function send(Email $email) |
|
25 | - { |
|
26 | - if (!empty($this->_config['queue'])) { |
|
27 | - $this->_config = $this->_config['queue'] + $this->_config; |
|
28 | - $email->setConfig((array)$this->_config['queue'] + [ |
|
29 | - 'queue' => [] |
|
30 | - ]); |
|
31 | - unset($this->_config['queue']); |
|
32 | - } |
|
18 | + /** |
|
19 | + * Send mail |
|
20 | + * |
|
21 | + * @param \Cake\Mailer\Email $email Email |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function send(Email $email) |
|
25 | + { |
|
26 | + if (!empty($this->_config['queue'])) { |
|
27 | + $this->_config = $this->_config['queue'] + $this->_config; |
|
28 | + $email->setConfig((array)$this->_config['queue'] + [ |
|
29 | + 'queue' => [] |
|
30 | + ]); |
|
31 | + unset($this->_config['queue']); |
|
32 | + } |
|
33 | 33 | |
34 | - $transport = $this->_config['transport']; |
|
35 | - $email->setTransport($transport); |
|
34 | + $transport = $this->_config['transport']; |
|
35 | + $email->setTransport($transport); |
|
36 | 36 | |
37 | - /** @var \Queue\Model\Table\QueuedTasksTable $QueuedTasks */ |
|
38 | - $QueuedTasks = TableRegistry::getTableLocator()->get('Queue.QueuedTasks'); |
|
39 | - $result = $QueuedTasks->createJob('Email', [ |
|
40 | - 'transport' => $transport, |
|
41 | - 'settings' => $email |
|
42 | - ]); |
|
43 | - $result['headers'] = ''; |
|
44 | - $result['message'] = ''; |
|
37 | + /** @var \Queue\Model\Table\QueuedTasksTable $QueuedTasks */ |
|
38 | + $QueuedTasks = TableRegistry::getTableLocator()->get('Queue.QueuedTasks'); |
|
39 | + $result = $QueuedTasks->createJob('Email', [ |
|
40 | + 'transport' => $transport, |
|
41 | + 'settings' => $email |
|
42 | + ]); |
|
43 | + $result['headers'] = ''; |
|
44 | + $result['message'] = ''; |
|
45 | 45 | |
46 | - return $result->toArray(); |
|
47 | - } |
|
46 | + return $result->toArray(); |
|
47 | + } |
|
48 | 48 | } |
@@ -11,121 +11,121 @@ |
||
11 | 11 | class SimpleQueueTransportTest extends TestCase |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Fixtures to load |
|
16 | - * |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $fixtures = [ |
|
20 | - 'plugin.Queue.QueuedTasks' |
|
21 | - ]; |
|
14 | + /** |
|
15 | + * Fixtures to load |
|
16 | + * |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $fixtures = [ |
|
20 | + 'plugin.Queue.QueuedTasks' |
|
21 | + ]; |
|
22 | 22 | |
23 | - /** |
|
24 | - * |
|
25 | - * @var \Queue\Mailer\Transport\SimpleQueueTransport |
|
26 | - */ |
|
27 | - protected $QueueTransport; |
|
23 | + /** |
|
24 | + * |
|
25 | + * @var \Queue\Mailer\Transport\SimpleQueueTransport |
|
26 | + */ |
|
27 | + protected $QueueTransport; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Setup |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function setUp() |
|
35 | - { |
|
36 | - parent::setUp(); |
|
37 | - $this->QueueTransport = new SimpleQueueTransport(); |
|
38 | - } |
|
29 | + /** |
|
30 | + * Setup |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function setUp() |
|
35 | + { |
|
36 | + parent::setUp(); |
|
37 | + $this->QueueTransport = new SimpleQueueTransport(); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function testSendWithEmail() |
|
45 | - { |
|
46 | - $config = [ |
|
47 | - 'transport' => 'queue', |
|
48 | - 'charset' => 'utf-8', |
|
49 | - 'headerCharset' => 'utf-8' |
|
50 | - ]; |
|
40 | + /** |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function testSendWithEmail() |
|
45 | + { |
|
46 | + $config = [ |
|
47 | + 'transport' => 'queue', |
|
48 | + 'charset' => 'utf-8', |
|
49 | + 'headerCharset' => 'utf-8' |
|
50 | + ]; |
|
51 | 51 | |
52 | - $this->QueueTransport->setConfig($config); |
|
53 | - $Email = new Email($config); |
|
52 | + $this->QueueTransport->setConfig($config); |
|
53 | + $Email = new Email($config); |
|
54 | 54 | |
55 | - $Email->setFrom('[email protected]', 'CakePHP Test'); |
|
56 | - $Email->setTo('[email protected]', 'CakePHP'); |
|
57 | - $Email->setCc([ |
|
58 | - '[email protected]' => 'Mark Story', |
|
59 | - '[email protected]' => 'Juan Basso' |
|
60 | - ]); |
|
61 | - $Email->setBcc('[email protected]'); |
|
62 | - $Email->setSubject('Testing Message'); |
|
63 | - $Email->setAttachments([ |
|
64 | - 'wow.txt' => [ |
|
65 | - 'data' => 'much wow!', |
|
66 | - 'mimetype' => 'text/plain', |
|
67 | - 'contentId' => 'important' |
|
68 | - ] |
|
69 | - ]); |
|
55 | + $Email->setFrom('[email protected]', 'CakePHP Test'); |
|
56 | + $Email->setTo('[email protected]', 'CakePHP'); |
|
57 | + $Email->setCc([ |
|
58 | + '[email protected]' => 'Mark Story', |
|
59 | + '[email protected]' => 'Juan Basso' |
|
60 | + ]); |
|
61 | + $Email->setBcc('[email protected]'); |
|
62 | + $Email->setSubject('Testing Message'); |
|
63 | + $Email->setAttachments([ |
|
64 | + 'wow.txt' => [ |
|
65 | + 'data' => 'much wow!', |
|
66 | + 'mimetype' => 'text/plain', |
|
67 | + 'contentId' => 'important' |
|
68 | + ] |
|
69 | + ]); |
|
70 | 70 | |
71 | - $Email->viewBuilder()->setLayout('test_layout'); |
|
72 | - $Email->viewBuilder()->setTemplate('test_template'); |
|
73 | - $Email->setSubject("L'utilisateur n'a pas pu être enregistré"); |
|
74 | - $Email->setReplyTo('[email protected]'); |
|
75 | - $Email->setReadReceipt('[email protected]'); |
|
76 | - $Email->setReturnPath('[email protected]'); |
|
77 | - $Email->setDomain('cakephp.org'); |
|
78 | - $Email->viewBuilder()->setTheme('EuroTheme'); |
|
79 | - $Email->setEmailFormat('both'); |
|
80 | - $Email->set('var1', 1); |
|
81 | - $Email->set('var2', 2); |
|
71 | + $Email->viewBuilder()->setLayout('test_layout'); |
|
72 | + $Email->viewBuilder()->setTemplate('test_template'); |
|
73 | + $Email->setSubject("L'utilisateur n'a pas pu être enregistré"); |
|
74 | + $Email->setReplyTo('[email protected]'); |
|
75 | + $Email->setReadReceipt('[email protected]'); |
|
76 | + $Email->setReturnPath('[email protected]'); |
|
77 | + $Email->setDomain('cakephp.org'); |
|
78 | + $Email->viewBuilder()->setTheme('EuroTheme'); |
|
79 | + $Email->setEmailFormat('both'); |
|
80 | + $Email->set('var1', 1); |
|
81 | + $Email->set('var2', 2); |
|
82 | 82 | |
83 | - $result = $this->QueueTransport->send($Email); |
|
84 | - $this->assertSame('Email', $result['task']); |
|
85 | - $this->assertTrue(strlen($result['data']) < 10000); |
|
83 | + $result = $this->QueueTransport->send($Email); |
|
84 | + $this->assertSame('Email', $result['task']); |
|
85 | + $this->assertTrue(strlen($result['data']) < 10000); |
|
86 | 86 | |
87 | - $output = unserialize($result['data']); |
|
88 | - $emailReconstructed = new Email($config); |
|
87 | + $output = unserialize($result['data']); |
|
88 | + $emailReconstructed = new Email($config); |
|
89 | 89 | |
90 | - foreach ($output['settings'] as $method => $setting) { |
|
91 | - $callable = $emailReconstructed; |
|
92 | - if (in_array($method, [ |
|
93 | - 'theme', |
|
94 | - 'template', |
|
95 | - 'layout' |
|
96 | - ])) { |
|
97 | - $callable = $callable->viewBuilder(); |
|
98 | - } |
|
99 | - $setter = 'set' . ucfirst($method); |
|
100 | - call_user_func_array([ |
|
101 | - $callable, |
|
102 | - $setter |
|
103 | - ], (array)$setting); |
|
104 | - } |
|
90 | + foreach ($output['settings'] as $method => $setting) { |
|
91 | + $callable = $emailReconstructed; |
|
92 | + if (in_array($method, [ |
|
93 | + 'theme', |
|
94 | + 'template', |
|
95 | + 'layout' |
|
96 | + ])) { |
|
97 | + $callable = $callable->viewBuilder(); |
|
98 | + } |
|
99 | + $setter = 'set' . ucfirst($method); |
|
100 | + call_user_func_array([ |
|
101 | + $callable, |
|
102 | + $setter |
|
103 | + ], (array)$setting); |
|
104 | + } |
|
105 | 105 | |
106 | - $this->assertEquals($emailReconstructed->getFrom(), $Email->getFrom()); |
|
107 | - $this->assertEquals($emailReconstructed->getTo(), $Email->getTo()); |
|
108 | - $this->assertEquals($emailReconstructed->getCc(), $Email->getCc()); |
|
109 | - $this->assertEquals($emailReconstructed->getBcc(), $Email->getBcc()); |
|
110 | - $this->assertEquals($emailReconstructed->getSubject(), $Email->getSubject()); |
|
111 | - $this->assertEquals($emailReconstructed->getCharset(), $Email->getCharset()); |
|
112 | - $this->assertEquals($emailReconstructed->getHeaderCharset(), $Email->getHeaderCharset()); |
|
113 | - $this->assertEquals($emailReconstructed->getEmailFormat(), $Email->getEmailFormat()); |
|
114 | - $this->assertEquals($emailReconstructed->getReplyTo(), $Email->getReplyTo()); |
|
115 | - $this->assertEquals($emailReconstructed->getReadReceipt(), $Email->getReadReceipt()); |
|
116 | - $this->assertEquals($emailReconstructed->getReturnPath(), $Email->getReturnPath()); |
|
117 | - // $this->assertEquals($emailReconstructed->getMessageId(), $Email->getMessageId()); |
|
118 | - $this->assertEquals($emailReconstructed->getDomain(), $Email->getDomain()); |
|
119 | - $this->assertEquals($emailReconstructed->viewBuilder() |
|
120 | - ->getTheme(), $Email->viewBuilder() |
|
121 | - ->getTheme()); |
|
122 | - $this->assertEquals($emailReconstructed->getProfile(), $Email->getProfile()); |
|
123 | - $this->assertEquals($emailReconstructed->getViewVars(), $Email->getViewVars()); |
|
124 | - $this->assertEquals($emailReconstructed->viewBuilder() |
|
125 | - ->getTemplate(), $Email->viewBuilder() |
|
126 | - ->getTemplate()); |
|
127 | - $this->assertEquals($emailReconstructed->viewBuilder() |
|
128 | - ->getLayout(), $Email->viewBuilder() |
|
129 | - ->getLayout()); |
|
130 | - } |
|
106 | + $this->assertEquals($emailReconstructed->getFrom(), $Email->getFrom()); |
|
107 | + $this->assertEquals($emailReconstructed->getTo(), $Email->getTo()); |
|
108 | + $this->assertEquals($emailReconstructed->getCc(), $Email->getCc()); |
|
109 | + $this->assertEquals($emailReconstructed->getBcc(), $Email->getBcc()); |
|
110 | + $this->assertEquals($emailReconstructed->getSubject(), $Email->getSubject()); |
|
111 | + $this->assertEquals($emailReconstructed->getCharset(), $Email->getCharset()); |
|
112 | + $this->assertEquals($emailReconstructed->getHeaderCharset(), $Email->getHeaderCharset()); |
|
113 | + $this->assertEquals($emailReconstructed->getEmailFormat(), $Email->getEmailFormat()); |
|
114 | + $this->assertEquals($emailReconstructed->getReplyTo(), $Email->getReplyTo()); |
|
115 | + $this->assertEquals($emailReconstructed->getReadReceipt(), $Email->getReadReceipt()); |
|
116 | + $this->assertEquals($emailReconstructed->getReturnPath(), $Email->getReturnPath()); |
|
117 | + // $this->assertEquals($emailReconstructed->getMessageId(), $Email->getMessageId()); |
|
118 | + $this->assertEquals($emailReconstructed->getDomain(), $Email->getDomain()); |
|
119 | + $this->assertEquals($emailReconstructed->viewBuilder() |
|
120 | + ->getTheme(), $Email->viewBuilder() |
|
121 | + ->getTheme()); |
|
122 | + $this->assertEquals($emailReconstructed->getProfile(), $Email->getProfile()); |
|
123 | + $this->assertEquals($emailReconstructed->getViewVars(), $Email->getViewVars()); |
|
124 | + $this->assertEquals($emailReconstructed->viewBuilder() |
|
125 | + ->getTemplate(), $Email->viewBuilder() |
|
126 | + ->getTemplate()); |
|
127 | + $this->assertEquals($emailReconstructed->viewBuilder() |
|
128 | + ->getLayout(), $Email->viewBuilder() |
|
129 | + ->getLayout()); |
|
130 | + } |
|
131 | 131 | } |
@@ -11,57 +11,57 @@ |
||
11 | 11 | class QueueTransportTest extends TestCase |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Fixtures to load |
|
16 | - * |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $fixtures = [ |
|
20 | - 'plugin.Queue.QueuedTasks' |
|
21 | - ]; |
|
14 | + /** |
|
15 | + * Fixtures to load |
|
16 | + * |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $fixtures = [ |
|
20 | + 'plugin.Queue.QueuedTasks' |
|
21 | + ]; |
|
22 | 22 | |
23 | - /** |
|
24 | - * |
|
25 | - * @var \Queue\Mailer\Transport\QueueTransport |
|
26 | - */ |
|
27 | - protected $QueueTransport; |
|
23 | + /** |
|
24 | + * |
|
25 | + * @var \Queue\Mailer\Transport\QueueTransport |
|
26 | + */ |
|
27 | + protected $QueueTransport; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Setup |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function setUp() |
|
35 | - { |
|
36 | - parent::setUp(); |
|
37 | - $this->QueueTransport = new QueueTransport(); |
|
38 | - } |
|
29 | + /** |
|
30 | + * Setup |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function setUp() |
|
35 | + { |
|
36 | + parent::setUp(); |
|
37 | + $this->QueueTransport = new QueueTransport(); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * TestSend method |
|
42 | - * |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - public function testSendWithEmail() |
|
46 | - { |
|
47 | - $Email = new Email(); |
|
48 | - $Email->setFrom('[email protected]', 'CakePHP Test'); |
|
49 | - $Email->setTo('[email protected]', 'CakePHP'); |
|
50 | - $Email->setCc([ |
|
51 | - '[email protected]' => 'Mark Story', |
|
52 | - '[email protected]' => 'Juan Basso' |
|
53 | - ]); |
|
54 | - $Email->setBcc('[email protected]'); |
|
55 | - $Email->setSubject('Testing Message'); |
|
56 | - $Email->setTransport('queue'); |
|
57 | - $config = $Email->getConfig('default'); |
|
58 | - $this->QueueTransport->setConfig($config); |
|
40 | + /** |
|
41 | + * TestSend method |
|
42 | + * |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + public function testSendWithEmail() |
|
46 | + { |
|
47 | + $Email = new Email(); |
|
48 | + $Email->setFrom('[email protected]', 'CakePHP Test'); |
|
49 | + $Email->setTo('[email protected]', 'CakePHP'); |
|
50 | + $Email->setCc([ |
|
51 | + '[email protected]' => 'Mark Story', |
|
52 | + '[email protected]' => 'Juan Basso' |
|
53 | + ]); |
|
54 | + $Email->setBcc('[email protected]'); |
|
55 | + $Email->setSubject('Testing Message'); |
|
56 | + $Email->setTransport('queue'); |
|
57 | + $config = $Email->getConfig('default'); |
|
58 | + $this->QueueTransport->setConfig($config); |
|
59 | 59 | |
60 | - $result = $this->QueueTransport->send($Email); |
|
61 | - $this->assertSame('Email', $result['task']); |
|
62 | - $this->assertTrue(strlen($result['data']) < 10000); |
|
60 | + $result = $this->QueueTransport->send($Email); |
|
61 | + $this->assertSame('Email', $result['task']); |
|
62 | + $this->assertTrue(strlen($result['data']) < 10000); |
|
63 | 63 | |
64 | - // $output = unserialize($result['data']); |
|
65 | - // $this->assertEquals('Testing Message', $output['settings']['_subject']); |
|
66 | - } |
|
64 | + // $output = unserialize($result['data']); |
|
65 | + // $this->assertEquals('Testing Message', $output['settings']['_subject']); |
|
66 | + } |
|
67 | 67 | } |
@@ -8,80 +8,80 @@ |
||
8 | 8 | class TaskFinder |
9 | 9 | { |
10 | 10 | |
11 | - /** |
|
12 | - * |
|
13 | - * @var array|null |
|
14 | - */ |
|
15 | - protected $tasks; |
|
11 | + /** |
|
12 | + * |
|
13 | + * @var array|null |
|
14 | + */ |
|
15 | + protected $tasks; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Returns all possible Queue tasks. |
|
19 | - * |
|
20 | - * Makes sure that app tasks are prioritized over plugin ones. |
|
21 | - * |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function allAppAndPluginTasks() |
|
25 | - { |
|
26 | - if ($this->tasks !== null) { |
|
27 | - return $this->tasks; |
|
28 | - } |
|
17 | + /** |
|
18 | + * Returns all possible Queue tasks. |
|
19 | + * |
|
20 | + * Makes sure that app tasks are prioritized over plugin ones. |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function allAppAndPluginTasks() |
|
25 | + { |
|
26 | + if ($this->tasks !== null) { |
|
27 | + return $this->tasks; |
|
28 | + } |
|
29 | 29 | |
30 | - $paths = App::path('Shell/Task'); |
|
31 | - $this->tasks = []; |
|
30 | + $paths = App::path('Shell/Task'); |
|
31 | + $this->tasks = []; |
|
32 | 32 | |
33 | - foreach ($paths as $path) { |
|
34 | - $folder = new Folder($path); |
|
35 | - $this->tasks = $this->getAppPaths($folder); |
|
36 | - } |
|
37 | - $plugins = Plugin::loaded(); |
|
38 | - foreach ($plugins as $plugin) { |
|
39 | - $pluginPaths = App::path('Shell/Task', $plugin); |
|
40 | - foreach ($pluginPaths as $pluginPath) { |
|
41 | - $folder = new Folder($pluginPath); |
|
42 | - $pluginTasks = $this->getPluginPaths($folder, $plugin); |
|
43 | - $this->tasks = array_merge($this->tasks, $pluginTasks); |
|
44 | - } |
|
45 | - } |
|
33 | + foreach ($paths as $path) { |
|
34 | + $folder = new Folder($path); |
|
35 | + $this->tasks = $this->getAppPaths($folder); |
|
36 | + } |
|
37 | + $plugins = Plugin::loaded(); |
|
38 | + foreach ($plugins as $plugin) { |
|
39 | + $pluginPaths = App::path('Shell/Task', $plugin); |
|
40 | + foreach ($pluginPaths as $pluginPath) { |
|
41 | + $folder = new Folder($pluginPath); |
|
42 | + $pluginTasks = $this->getPluginPaths($folder, $plugin); |
|
43 | + $this->tasks = array_merge($this->tasks, $pluginTasks); |
|
44 | + } |
|
45 | + } |
|
46 | 46 | |
47 | - return $this->tasks; |
|
48 | - } |
|
47 | + return $this->tasks; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * |
|
52 | - * @param \Cake\Filesystem\Folder $folder The directory |
|
53 | - * |
|
54 | - * @return array |
|
55 | - */ |
|
56 | - protected function getAppPaths(Folder $folder) |
|
57 | - { |
|
58 | - $res = array_merge($this->tasks, $folder->find('Queue.+\.php')); |
|
59 | - foreach ($res as &$r) { |
|
60 | - $r = basename($r, 'Task.php'); |
|
61 | - } |
|
50 | + /** |
|
51 | + * |
|
52 | + * @param \Cake\Filesystem\Folder $folder The directory |
|
53 | + * |
|
54 | + * @return array |
|
55 | + */ |
|
56 | + protected function getAppPaths(Folder $folder) |
|
57 | + { |
|
58 | + $res = array_merge($this->tasks, $folder->find('Queue.+\.php')); |
|
59 | + foreach ($res as &$r) { |
|
60 | + $r = basename($r, 'Task.php'); |
|
61 | + } |
|
62 | 62 | |
63 | - return $res; |
|
64 | - } |
|
63 | + return $res; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * |
|
68 | - * @param \Cake\Filesystem\Folder $folder The directory |
|
69 | - * @param string $plugin The plugin name |
|
70 | - * |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - protected function getPluginPaths(Folder $folder, $plugin) |
|
74 | - { |
|
75 | - $res = $folder->find('Queue.+Task\.php'); |
|
76 | - foreach ($res as $key => $r) { |
|
77 | - $name = basename($r, 'Task.php'); |
|
78 | - if (in_array($name, $this->tasks)) { |
|
79 | - unset($res[$key]); |
|
80 | - continue; |
|
81 | - } |
|
82 | - $res[$key] = $plugin . '.' . $name; |
|
83 | - } |
|
66 | + /** |
|
67 | + * |
|
68 | + * @param \Cake\Filesystem\Folder $folder The directory |
|
69 | + * @param string $plugin The plugin name |
|
70 | + * |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + protected function getPluginPaths(Folder $folder, $plugin) |
|
74 | + { |
|
75 | + $res = $folder->find('Queue.+Task\.php'); |
|
76 | + foreach ($res as $key => $r) { |
|
77 | + $name = basename($r, 'Task.php'); |
|
78 | + if (in_array($name, $this->tasks)) { |
|
79 | + unset($res[$key]); |
|
80 | + continue; |
|
81 | + } |
|
82 | + $res[$key] = $plugin . '.' . $name; |
|
83 | + } |
|
84 | 84 | |
85 | - return $res; |
|
86 | - } |
|
85 | + return $res; |
|
86 | + } |
|
87 | 87 | } |