1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Glooby\TaskBundle\Tests\Annotation\Schedule; |
4
|
|
|
|
5
|
|
|
use Glooby\TaskBundle\Annotation\Schedule; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Emil Kilhage |
9
|
|
|
*/ |
10
|
|
|
class ScheduleTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
View Code Duplication |
public function testSimple() |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
$schedule = new Schedule(['value' => '@daily']); |
15
|
|
|
|
16
|
|
|
$this->assertEquals('0 0 * * *', $schedule->runEvery); |
17
|
|
|
$this->assertTrue($schedule->active); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
View Code Duplication |
public function testInterval() |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$schedule = new Schedule(['runEvery' => '@daily']); |
23
|
|
|
|
24
|
|
|
$this->assertEquals('0 0 * * *', $schedule->runEvery); |
25
|
|
|
$this->assertTrue($schedule->active); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testIntervalActiveParams() |
29
|
|
|
{ |
30
|
|
|
$schedule = new Schedule([ |
31
|
|
|
'runEvery' => '@daily', |
32
|
|
|
'active' => false, |
33
|
|
|
'params' => [1], |
34
|
|
|
]); |
35
|
|
|
|
36
|
|
|
$this->assertEquals('0 0 * * *', $schedule->runEvery); |
37
|
|
|
$this->assertEquals([1], $schedule->params); |
38
|
|
|
$this->assertFalse($schedule->active); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testParamsNonArray() |
42
|
|
|
{ |
43
|
|
|
$this->setExpectedException('\InvalidArgumentException'); |
44
|
|
|
|
45
|
|
|
new Schedule([ |
46
|
|
|
'interval' => '@daily', |
47
|
|
|
'active' => false, |
48
|
|
|
'params' => 'foo', |
49
|
|
|
]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testInvalidProperty() |
53
|
|
|
{ |
54
|
|
|
$this->setExpectedException('\InvalidArgumentException'); |
55
|
|
|
|
56
|
|
|
new Schedule(['fooo' => '@daily']); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testInvalidInterval() |
60
|
|
|
{ |
61
|
|
|
$this->setExpectedException('\InvalidArgumentException'); |
62
|
|
|
|
63
|
|
|
new Schedule(['runEvery' => 'fdsfds fds']); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testMissingInvalid() |
67
|
|
|
{ |
68
|
|
|
$this->setExpectedException('\InvalidArgumentException'); |
69
|
|
|
|
70
|
|
|
new Schedule([]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testInvalidTimeout() |
74
|
|
|
{ |
75
|
|
|
$this->setExpectedException('\InvalidArgumentException'); |
76
|
|
|
|
77
|
|
|
new Schedule(['interval' => '@daily', 'timeout' => 'x']); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.