3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
-
6
+ declare (strict_types= 1 );
7
7
8
8
namespace Magento \Framework \Crontab \Test \Unit ;
9
9
10
+ use Magento \Framework \App \Filesystem \DirectoryList ;
10
11
use Magento \Framework \Crontab \CrontabManager ;
11
12
use Magento \Framework \Crontab \CrontabManagerInterface ;
12
- use Magento \Framework \ShellInterface ;
13
- use Magento \Framework \Phrase ;
14
13
use Magento \Framework \Exception \LocalizedException ;
15
14
use Magento \Framework \Filesystem ;
16
- use Magento \Framework \App \Filesystem \DirectoryList ;
17
15
use Magento \Framework \Filesystem \Directory \ReadInterface ;
18
16
use Magento \Framework \Filesystem \DriverPool ;
17
+ use Magento \Framework \Phrase ;
18
+ use Magento \Framework \ShellInterface ;
19
+ use PHPUnit \Framework \TestCase ;
20
+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
19
21
20
22
/**
21
23
* Tests crontab manager functionality.
22
24
*/
23
- class CrontabManagerTest extends \ PHPUnit \ Framework \ TestCase
25
+ class CrontabManagerTest extends TestCase
24
26
{
25
27
/**
26
- * @var ShellInterface|\PHPUnit_Framework_MockObject_MockObject
28
+ * @var ShellInterface|MockObject
27
29
*/
28
30
private $ shellMock ;
29
31
30
32
/**
31
- * @var Filesystem|\PHPUnit_Framework_MockObject_MockObject
33
+ * @var Filesystem|MockObject
32
34
*/
33
35
private $ filesystemMock ;
34
36
@@ -38,7 +40,7 @@ class CrontabManagerTest extends \PHPUnit\Framework\TestCase
38
40
private $ crontabManager ;
39
41
40
42
/**
41
- * @return void
43
+ * @inheritDoc
42
44
*/
43
45
protected function setUp ()
44
46
{
@@ -53,9 +55,11 @@ protected function setUp()
53
55
}
54
56
55
57
/**
58
+ * Verify get tasks without cronetab.
59
+ *
56
60
* @return void
57
61
*/
58
- public function testGetTasksNoCrontab ()
62
+ public function testGetTasksNoCrontab (): void
59
63
{
60
64
$ exception = new \Exception ('crontab: no crontab for user ' );
61
65
$ localizedException = new LocalizedException (new Phrase ('Some error ' ), $ exception );
@@ -69,12 +73,14 @@ public function testGetTasksNoCrontab()
69
73
}
70
74
71
75
/**
76
+ * Verify get tasks.
77
+ *
72
78
* @param string $content
73
79
* @param array $tasks
74
80
* @return void
75
81
* @dataProvider getTasksDataProvider
76
82
*/
77
- public function testGetTasks ($ content , $ tasks )
83
+ public function testGetTasks ($ content , $ tasks ): void
78
84
{
79
85
$ this ->shellMock ->expects ($ this ->once ())
80
86
->method ('execute ' )
@@ -85,9 +91,11 @@ public function testGetTasks($content, $tasks)
85
91
}
86
92
87
93
/**
94
+ * Data provider to get tasks.
95
+ *
88
96
* @return array
89
97
*/
90
- public function getTasksDataProvider ()
98
+ public function getTasksDataProvider (): array
91
99
{
92
100
return [
93
101
[
@@ -120,11 +128,13 @@ public function getTasksDataProvider()
120
128
}
121
129
122
130
/**
131
+ * Verify remove tasks with exception.
132
+ *
123
133
* @return void
124
134
* @expectedException \Magento\Framework\Exception\LocalizedException
125
135
* @expectedExceptionMessage Shell error
126
136
*/
127
- public function testRemoveTasksWithException ()
137
+ public function testRemoveTasksWithException (): void
128
138
{
129
139
$ exception = new \Exception ('Shell error ' );
130
140
$ localizedException = new LocalizedException (new Phrase ('Some error ' ), $ exception );
@@ -143,12 +153,14 @@ public function testRemoveTasksWithException()
143
153
}
144
154
145
155
/**
156
+ * Verify remove tasks.
157
+ *
146
158
* @param string $contentBefore
147
159
* @param string $contentAfter
148
160
* @return void
149
161
* @dataProvider removeTasksDataProvider
150
162
*/
151
- public function testRemoveTasks ($ contentBefore , $ contentAfter )
163
+ public function testRemoveTasks ($ contentBefore , $ contentAfter ): void
152
164
{
153
165
$ this ->shellMock ->expects ($ this ->at (0 ))
154
166
->method ('execute ' )
@@ -163,9 +175,11 @@ public function testRemoveTasks($contentBefore, $contentAfter)
163
175
}
164
176
165
177
/**
178
+ * Data provider to remove tasks.
179
+ *
166
180
* @return array
167
181
*/
168
- public function removeTasksDataProvider ()
182
+ public function removeTasksDataProvider (): array
169
183
{
170
184
return [
171
185
[
@@ -195,11 +209,13 @@ public function removeTasksDataProvider()
195
209
}
196
210
197
211
/**
212
+ * Verify save tasks with empty tasks list.
213
+ *
198
214
* @return void
199
215
* @expectedException \Magento\Framework\Exception\LocalizedException
200
216
* @expectedExceptionMessage The list of tasks is empty. Add tasks and try again.
201
217
*/
202
- public function testSaveTasksWithEmptyTasksList ()
218
+ public function testSaveTasksWithEmptyTasksList (): void
203
219
{
204
220
$ baseDirMock = $ this ->getMockBuilder (ReadInterface::class)
205
221
->getMockForAbstractClass ();
@@ -222,11 +238,13 @@ public function testSaveTasksWithEmptyTasksList()
222
238
}
223
239
224
240
/**
241
+ * Verify save tasks with out command.
242
+ *
225
243
* @return void
226
244
* @expectedException \Magento\Framework\Exception\LocalizedException
227
245
* @expectedExceptionMessage The command shouldn't be empty. Enter and try again.
228
246
*/
229
- public function testSaveTasksWithoutCommand ()
247
+ public function testSaveTasksWithoutCommand (): void
230
248
{
231
249
$ baseDirMock = $ this ->getMockBuilder (ReadInterface::class)
232
250
->getMockForAbstractClass ();
@@ -252,13 +270,15 @@ public function testSaveTasksWithoutCommand()
252
270
}
253
271
254
272
/**
273
+ * Verify sava task.
274
+ *
255
275
* @param array $tasks
256
276
* @param string $content
257
277
* @param string $contentToSave
258
278
* @return void
259
279
* @dataProvider saveTasksDataProvider
260
280
*/
261
- public function testSaveTasks ($ tasks , $ content , $ contentToSave )
281
+ public function testSaveTasks ($ tasks , $ content , $ contentToSave ): void
262
282
{
263
283
$ baseDirMock = $ this ->getMockBuilder (ReadInterface::class)
264
284
->getMockForAbstractClass ();
@@ -291,9 +311,11 @@ public function testSaveTasks($tasks, $content, $contentToSave)
291
311
}
292
312
293
313
/**
314
+ * Data provider to save tasks.
315
+ *
294
316
* @return array
295
317
*/
296
- public function saveTasksDataProvider ()
318
+ public function saveTasksDataProvider (): array
297
319
{
298
320
$ content = '* * * * * /bin/php /var/www/cron.php ' . PHP_EOL
299
321
. CrontabManagerInterface::TASKS_BLOCK_START . ' ' . hash ("sha256 " , BP ) . PHP_EOL
@@ -354,6 +376,17 @@ public function saveTasksDataProvider()
354
376
. ' %% cron:run | grep -v \"Ran \'jobs \' by schedule\" ' . PHP_EOL
355
377
. CrontabManagerInterface::TASKS_BLOCK_END . ' ' . hash ("sha256 " , BP ) . PHP_EOL ,
356
378
],
379
+ [
380
+ 'tasks ' => [
381
+ ['command ' => '{magentoRoot}run.php mysqldump db > db-$(date +%F).sql ' ]
382
+ ],
383
+ 'content ' => '* * * * * /bin/php /var/www/cron.php ' ,
384
+ 'contentToSave ' => '* * * * * /bin/php /var/www/cron.php ' . PHP_EOL
385
+ . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . hash ("sha256 " , BP ) . PHP_EOL
386
+ . '* * * * * ' . PHP_BINARY . ' /var/www/magento2/run.php '
387
+ . ' mysqldump db > db-\$(date +%%F).sql ' . PHP_EOL
388
+ . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . hash ("sha256 " , BP ) . PHP_EOL ,
389
+ ],
357
390
];
358
391
}
359
392
}
0 commit comments