forked from MUlt1mate/cron-manager
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTaskManagerTest.php
56 lines (49 loc) · 1.9 KB
/
TaskManagerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace vm\cron_tests;
use vm\cron\TaskInterface;
use vm\cron\TaskManager;
/**
* @author mult1mate
* Date: 01.02.16
* Time: 0:48
*/
class TaskManagerTest extends \PHPUnit_Framework_TestCase
{
public function testEditTask()
{
$task = TaskMock::createNew();
$command = 'ActionMock::method()';
$task = TaskManager::editTask($task, '* * * * *', $command, TaskInterface::TASK_STATUS_ACTIVE, 'comment');
$this->assertEquals($command, $task->getCommand());
$command = 'wrong_command';
$task = TaskManager::editTask($task, '* * * * *', $command, TaskInterface::TASK_STATUS_ACTIVE, 'comment');
$this->assertNotEquals($command, $task->getCommand());
}
public function testValidateCommand()
{
$result = TaskManager::validateCommand('Class::method( arg1 , arg2 ) ');
$this->assertEquals($result, 'Class::method(arg1,arg2)');
$result = TaskManager::validateCommand('Class->method( arg1 , arg2 ) ');
$this->assertFalse($result);
}
public function testParseCrontab()
{
$task = TaskMock::createNew();
$cron = '
#comment
* * * * * cd path/; /usr/bin/php index.php controller method args 2>&1 > /dev/null
* * * * -1 cd path/; /usr/bin/php index.php controller method args 2>&1 > /dev/null
* * * * * cd path/; wrong expression';
TaskManager::parseCrontab($cron, $task);
}
public function testGetTaskCrontabLine()
{
$task = TaskMock::createNew();
$task->setStatus(TaskInterface::TASK_STATUS_INACTIVE);
$task->setCommand('Class::method()');
$task->setComment('comment');
$task->setTime('* * * * *');
$export = TaskManager::getTaskCrontabLine($task, 'path', 'php', 'index.php');
$this->assertEquals("#comment\n#* * * * * cd path; php index.php Class method 2>&1 > /dev/null\n", $export);
}
}