4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
+
7
8
namespace Magento\Framework\Crontab\Test\Unit;
8
9
9
10
use Magento\Framework\Crontab\CrontabManager;
16
17
use Magento\Framework\Filesystem\Directory\ReadInterface;
17
18
use Magento\Framework\Filesystem\DriverPool;
18
19
20
+ /**
21
+ * Tests crontab manager functionality.
22
+ */
19
23
class CrontabManagerTest extends \PHPUnit\Framework\TestCase
20
24
{
21
25
/**
@@ -58,7 +62,7 @@ public function testGetTasksNoCrontab()
58
62
59
63
$this->shellMock->expects($this->once())
60
64
->method('execute')
61
- ->with('crontab -l', [])
65
+ ->with('crontab -l 2>/dev/null ', [])
62
66
->willThrowException($localizedException);
63
67
64
68
$this->assertEquals([], $this->crontabManager->getTasks());
@@ -74,7 +78,7 @@ public function testGetTasks($content, $tasks)
74
78
{
75
79
$this->shellMock->expects($this->once())
76
80
->method('execute')
77
- ->with('crontab -l', [])
81
+ ->with('crontab -l 2>/dev/null ', [])
78
82
->willReturn($content);
79
83
80
84
$this->assertEquals($tasks, $this->crontabManager->getTasks());
@@ -88,17 +92,17 @@ public function getTasksDataProvider()
88
92
return [
89
93
[
90
94
'content' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
91
- . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5( BP) . PHP_EOL
95
+ . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . hash("sha256", BP) . PHP_EOL
92
96
. '* * * * * /bin/php /var/www/magento/bin/magento cron:run' . PHP_EOL
93
- . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5( BP) . PHP_EOL,
97
+ . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . hash("sha256", BP) . PHP_EOL,
94
98
'tasks' => ['* * * * * /bin/php /var/www/magento/bin/magento cron:run'],
95
99
],
96
100
[
97
101
'content' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
98
- . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5( BP) . PHP_EOL
102
+ . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . hash("sha256", BP) . PHP_EOL
99
103
. '* * * * * /bin/php /var/www/magento/bin/magento cron:run' . PHP_EOL
100
104
. '* * * * * /bin/php /var/www/magento/bin/magento setup:cron:run' . PHP_EOL
101
- . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5( BP) . PHP_EOL,
105
+ . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . hash("sha256", BP) . PHP_EOL,
102
106
'tasks' => [
103
107
'* * * * * /bin/php /var/www/magento/bin/magento cron:run',
104
108
'* * * * * /bin/php /var/www/magento/bin/magento setup:cron:run',
@@ -127,7 +131,7 @@ public function testRemoveTasksWithException()
127
131
128
132
$this->shellMock->expects($this->at(0))
129
133
->method('execute')
130
- ->with('crontab -l', [])
134
+ ->with('crontab -l 2>/dev/null ', [])
131
135
->willReturn('');
132
136
133
137
$this->shellMock->expects($this->at(1))
@@ -148,7 +152,7 @@ public function testRemoveTasks($contentBefore, $contentAfter)
148
152
{
149
153
$this->shellMock->expects($this->at(0))
150
154
->method('execute')
151
- ->with('crontab -l', [])
155
+ ->with('crontab -l 2>/dev/null ', [])
152
156
->willReturn($contentBefore);
153
157
154
158
$this->shellMock->expects($this->at(1))
@@ -166,17 +170,17 @@ public function removeTasksDataProvider()
166
170
return [
167
171
[
168
172
'contentBefore' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
169
- . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5( BP) . PHP_EOL
173
+ . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . hash("sha256", BP) . PHP_EOL
170
174
. '* * * * * /bin/php /var/www/magento/bin/magento cron:run' . PHP_EOL
171
- . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5( BP) . PHP_EOL,
175
+ . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . hash("sha256", BP) . PHP_EOL,
172
176
'contentAfter' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
173
177
],
174
178
[
175
179
'contentBefore' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
176
- . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5( BP) . PHP_EOL
180
+ . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . hash("sha256", BP) . PHP_EOL
177
181
. '* * * * * /bin/php /var/www/magento/bin/magento cron:run' . PHP_EOL
178
182
. '* * * * * /bin/php /var/www/magento/bin/magento setup:cron:run' . PHP_EOL
179
- . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5( BP) . PHP_EOL,
183
+ . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . hash("sha256", BP) . PHP_EOL,
180
184
'contentAfter' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
181
185
],
182
186
[
@@ -276,7 +280,7 @@ public function testSaveTasks($tasks, $content, $contentToSave)
276
280
277
281
$this->shellMock->expects($this->at(0))
278
282
->method('execute')
279
- ->with('crontab -l', [])
283
+ ->with('crontab -l 2>/dev/null ', [])
280
284
->willReturn($content);
281
285
282
286
$this->shellMock->expects($this->at(1))
@@ -292,9 +296,9 @@ public function testSaveTasks($tasks, $content, $contentToSave)
292
296
public function saveTasksDataProvider()
293
297
{
294
298
$content = '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
295
- . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5( BP) . PHP_EOL
299
+ . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . hash("sha256", BP) . PHP_EOL
296
300
. '* * * * * /bin/php /var/www/magento/bin/magento cron:run' . PHP_EOL
297
- . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5( BP) . PHP_EOL;
301
+ . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . hash("sha256", BP) . PHP_EOL;
298
302
299
303
return [
300
304
[
@@ -303,52 +307,52 @@ public function saveTasksDataProvider()
303
307
],
304
308
'content' => $content,
305
309
'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
306
- . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5( BP) . PHP_EOL
310
+ . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . hash("sha256", BP) . PHP_EOL
307
311
. '* * * * * ' . PHP_BINARY . ' run.php' . PHP_EOL
308
- . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5( BP) . PHP_EOL,
312
+ . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . hash("sha256", BP) . PHP_EOL,
309
313
],
310
314
[
311
315
'tasks' => [
312
316
['expression' => '1 2 3 4 5', 'command' => 'run.php']
313
317
],
314
318
'content' => $content,
315
319
'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
316
- . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5( BP) . PHP_EOL
320
+ . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . hash("sha256", BP) . PHP_EOL
317
321
. '1 2 3 4 5 ' . PHP_BINARY . ' run.php' . PHP_EOL
318
- . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5( BP) . PHP_EOL,
322
+ . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . hash("sha256", BP) . PHP_EOL,
319
323
],
320
324
[
321
325
'tasks' => [
322
326
['command' => '{magentoRoot}run.php >> {magentoLog}cron.log']
323
327
],
324
328
'content' => $content,
325
329
'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
326
- . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5( BP) . PHP_EOL
330
+ . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . hash("sha256", BP) . PHP_EOL
327
331
. '* * * * * ' . PHP_BINARY . ' /var/www/magento2/run.php >>'
328
332
. ' /var/www/magento2/var/log/cron.log' . PHP_EOL
329
- . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5( BP) . PHP_EOL,
333
+ . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . hash("sha256", BP) . PHP_EOL,
330
334
],
331
335
[
332
336
'tasks' => [
333
337
['command' => '{magentoRoot}run.php % cron:run | grep -v "Ran \'jobs\' by schedule"']
334
338
],
335
339
'content' => $content,
336
340
'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
337
- . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5( BP) . PHP_EOL
341
+ . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . hash("sha256", BP) . PHP_EOL
338
342
. '* * * * * ' . PHP_BINARY . ' /var/www/magento2/run.php'
339
343
. ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL
340
- . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5( BP) . PHP_EOL,
344
+ . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . hash("sha256", BP) . PHP_EOL,
341
345
],
342
346
[
343
347
'tasks' => [
344
348
['command' => '{magentoRoot}run.php % cron:run | grep -v "Ran \'jobs\' by schedule"']
345
349
],
346
350
'content' => '* * * * * /bin/php /var/www/cron.php',
347
351
'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
348
- . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5( BP) . PHP_EOL
352
+ . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . hash("sha256", BP) . PHP_EOL
349
353
. '* * * * * ' . PHP_BINARY . ' /var/www/magento2/run.php'
350
354
. ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL
351
- . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5( BP) . PHP_EOL,
355
+ . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . hash("sha256", BP) . PHP_EOL,
352
356
],
353
357
];
354
358
}
0 commit comments