11
11
use Task \Storage \TaskExecutionRepositoryInterface ;
12
12
use Task \TaskBundle \Builder \TaskBuilder ;
13
13
use Task \TaskBundle \Command \ScheduleSystemTasksCommand ;
14
+ use Task \TaskBundle \Entity \Task ;
14
15
use Task \TaskBundle \Entity \TaskRepository ;
15
16
use Task \TaskBundle \Tests \Functional \TestHandler ;
16
- use Task \TaskInterface ;
17
17
use Task \TaskStatus ;
18
18
19
19
class ScheduleSystemTasksCommandTest extends \PHPUnit_Framework_TestCase
@@ -69,9 +69,14 @@ public function testExecute()
69
69
]
70
70
);
71
71
72
+ $ task = $ this ->prophesize (Task::class);
73
+ $ task ->getSystemKey ()->willReturn ('testing ' );
74
+
72
75
$ taskBuilder = $ this ->prophesize (TaskBuilder::class);
73
76
74
77
$ this ->taskRepository ->findBySystemKey ('testing ' )->willReturn (null );
78
+ $ this ->taskRepository ->findSystemTasks ()->willReturn ([$ task ->reveal ()]);
79
+
75
80
$ this ->scheduler ->createTask (TestHandler::class, 'test ' )->shouldBeCalled ()->willReturn ($ taskBuilder ->reveal ());
76
81
77
82
$ taskBuilder ->setSystemKey ('testing ' )->shouldBeCalled ();
@@ -103,17 +108,27 @@ public function testExecuteMultiple()
103
108
]
104
109
);
105
110
111
+ $ task1 = $ this ->prophesize (Task::class);
112
+ $ task1 ->getSystemKey ()->willReturn ('testing-1 ' );
113
+ $ task2 = $ this ->prophesize (Task::class);
114
+ $ task2 ->getSystemKey ()->willReturn ('testing-2 ' );
115
+
106
116
$ this ->taskRepository ->findBySystemKey ('testing-1 ' )->willReturn (null );
107
117
$ this ->taskRepository ->findBySystemKey ('testing-2 ' )->willReturn (null );
118
+ $ this ->taskRepository ->findSystemTasks ()->willReturn ([$ task1 ->reveal (), $ task2 ->reveal ()]);
108
119
109
120
$ taskBuilder1 = $ this ->prophesize (TaskBuilder::class);
110
- $ this ->scheduler ->createTask (TestHandler::class, 'test-1 ' )->shouldBeCalled ()->willReturn ($ taskBuilder1 ->reveal ());
121
+ $ this ->scheduler ->createTask (TestHandler::class, 'test-1 ' )->shouldBeCalled ()->willReturn (
122
+ $ taskBuilder1 ->reveal ()
123
+ );
111
124
$ taskBuilder1 ->setSystemKey ('testing-1 ' )->shouldBeCalled ();
112
125
$ taskBuilder1 ->cron ('* * * * * ' )->shouldBeCalled ();
113
126
$ taskBuilder1 ->schedule ()->shouldBeCalled ();
114
127
115
128
$ taskBuilder2 = $ this ->prophesize (TaskBuilder::class);
116
- $ this ->scheduler ->createTask (TestHandler::class, 'test-2 ' )->shouldBeCalled ()->willReturn ($ taskBuilder2 ->reveal ());
129
+ $ this ->scheduler ->createTask (TestHandler::class, 'test-2 ' )->shouldBeCalled ()->willReturn (
130
+ $ taskBuilder2 ->reveal ()
131
+ );
117
132
$ taskBuilder2 ->setSystemKey ('testing-2 ' )->shouldBeCalled ();
118
133
$ taskBuilder2 ->cron ('* * * * * ' )->shouldBeCalled ();
119
134
$ taskBuilder2 ->schedule ()->shouldBeCalled ();
@@ -137,9 +152,10 @@ public function testExecuteDisable()
137
152
]
138
153
);
139
154
140
- $ task = $ this ->prophesize (TaskInterface ::class);
155
+ $ task = $ this ->prophesize (Task ::class);
141
156
$ task ->getInterval ()->willReturn (CronExpression::factory ('* * * * * ' ));
142
157
$ task ->getFirstExecution ()->willReturn (new \DateTime ());
158
+ $ task ->getSystemKey ()->willReturn ('testing ' );
143
159
144
160
$ task ->setInterval (
145
161
$ task ->reveal ()->getInterval (),
@@ -152,6 +168,7 @@ function ($date) {
152
168
)->shouldBeCalled ();
153
169
154
170
$ this ->taskRepository ->findBySystemKey ('testing ' )->willReturn ($ task ->reveal ());
171
+ $ this ->taskRepository ->findSystemTasks ()->willReturn ([$ task ->reveal ()]);
155
172
156
173
$ execution = $ this ->prophesize (TaskExecutionInterface::class);
157
174
$ execution ->setStatus (TaskStatus::ABORTED );
@@ -178,16 +195,18 @@ public function testExecuteUpdate()
178
195
]
179
196
);
180
197
181
- $ task = $ this ->prophesize (TaskInterface::class);
198
+ $ task = $ this ->prophesize (Task::class);
199
+ $ task ->getSystemKey ()->willReturn ('testing ' );
182
200
$ task ->getHandlerClass ()->willReturn (TestHandler::class);
183
201
$ task ->getWorkload ()->willReturn ('test ' );
184
202
$ task ->getInterval ()->willReturn (CronExpression::factory ('@daily ' ));
185
203
$ task ->getFirstExecution ()->willReturn (new \DateTime ());
186
204
187
- $ task ->setInterval (CronExpression::factory ('* * * * * ' ), $ task ->reveal ()->getFirstExecution ())
188
- -> shouldBeCalled ( );
205
+ $ task ->setInterval (CronExpression::factory ('* * * * * ' ), $ task ->reveal ()->getFirstExecution ())-> shouldBeCalled (
206
+ );
189
207
190
208
$ this ->taskRepository ->findBySystemKey ('testing ' )->willReturn ($ task ->reveal ());
209
+ $ this ->taskRepository ->findSystemTasks ()->willReturn ([$ task ->reveal ()]);
191
210
192
211
$ execution = $ this ->prophesize (TaskExecutionInterface::class);
193
212
$ execution ->setStatus (TaskStatus::ABORTED );
@@ -216,7 +235,8 @@ public function testExecuteUpdateNotSupported()
216
235
]
217
236
);
218
237
219
- $ task = $ this ->prophesize (TaskInterface::class);
238
+ $ task = $ this ->prophesize (Task::class);
239
+ $ task ->getSystemKey ()->willReturn ('testing ' );
220
240
$ task ->getHandlerClass ()->willReturn ('not-existing ' );
221
241
$ task ->getWorkload ()->willReturn ('new-workload ' );
222
242
$ task ->getInterval ()->willReturn (CronExpression::factory ('@daily ' ));
@@ -225,6 +245,7 @@ public function testExecuteUpdateNotSupported()
225
245
$ task ->setInterval (Argument::cetera ())->shouldNotBeCalled ();
226
246
227
247
$ this ->taskRepository ->findBySystemKey ('testing ' )->willReturn ($ task ->reveal ());
248
+ $ this ->taskRepository ->findSystemTasks ()->willReturn ([$ task ->reveal ()]);
228
249
229
250
$ this ->taskExecutionRepository ->save (Argument::cetera ())->shouldNotBeCalled ();
230
251
@@ -235,4 +256,38 @@ public function testExecuteUpdateNotSupported()
235
256
$ this ->prophesize (OutputInterface::class)->reveal ()
236
257
);
237
258
}
259
+
260
+ public function testExecuteRemove ()
261
+ {
262
+ $ command = $ this ->createCommand ([]);
263
+
264
+ $ task = $ this ->prophesize (Task::class);
265
+ $ task ->getInterval ()->willReturn (CronExpression::factory ('* * * * * ' ));
266
+ $ task ->getFirstExecution ()->willReturn (new \DateTime ());
267
+ $ task ->getSystemKey ()->willReturn ('testing ' );
268
+
269
+ $ task ->setInterval (
270
+ $ task ->reveal ()->getInterval (),
271
+ $ task ->reveal ()->getFirstExecution (),
272
+ Argument::that (
273
+ function ($ date ) {
274
+ return $ date <= new \DateTime ('+1 Minute ' );
275
+ }
276
+ )
277
+ )->shouldBeCalled ();
278
+
279
+ $ this ->taskRepository ->findBySystemKey ('testing ' )->willReturn ($ task ->reveal ());
280
+ $ this ->taskRepository ->findSystemTasks ()->willReturn ([$ task ->reveal ()]);
281
+
282
+ $ execution = $ this ->prophesize (TaskExecutionInterface::class);
283
+ $ execution ->setStatus (TaskStatus::ABORTED );
284
+
285
+ $ this ->taskExecutionRepository ->findPending ($ task ->reveal ())->willReturn ($ execution ->reveal ());
286
+ $ this ->taskExecutionRepository ->save ($ execution ->reveal ())->shouldBeCalled ();
287
+
288
+ $ command ->run (
289
+ $ this ->prophesize (InputInterface::class)->reveal (),
290
+ $ this ->prophesize (OutputInterface::class)->reveal ()
291
+ );
292
+ }
238
293
}
0 commit comments