Completed
Push — develop ( dac91a...dc8379 )
by Novikov
9s
created

CronTest::invalidMonthes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Tests\FOA\CronBundle\Manager;
4
5
use FOA\CronBundle\Manager\Cron;
6
use InvalidArgumentException;
7
use PHPUnit\Framework\TestCase;
8
9
class CronTest extends TestCase
10
{
11
    public function testAdd()
12
    {
13
        $cron = new Cron();
14
        $cron->setCommand('my_command');
15
        $this->assertEquals('my_command', $cron->getCommand());
16
    }
17
18
    public function testParseValidCron()
19
    {
20
        $cron = Cron::parse('1 2 3 4 5 my_command');
21
        $this->assertEquals('1', $cron->getMinute());
22
        $this->assertEquals('2', $cron->getHour());
23
        $this->assertEquals('3', $cron->getDayOfMonth());
24
        $this->assertEquals('4', $cron->getMonth());
25
        $this->assertEquals('5', $cron->getDayOfWeek());
26
        $this->assertEquals('my_command', $cron->getCommand());
27
        $this->assertEquals(null, $cron->getLogFile());
28
    }
29
30
    public function invalidMinutes()
31
    {
32
        return [
33
            ['-1 * * * * my_command'],
34
            ['60 * * * * my_command'],
35
        ];
36
    }
37
38
    /**
39
     * @dataProvider invalidMinutes
40
     * @expectedException InvalidArgumentException
41
     *
42
     * @param string $cronString
43
     */
44
    public function testParseInvalidMinute($cronString)
45
    {
46
        $this->expectExceptionCode(Cron::ERROR_MINUTE);
47
        Cron::parse($cronString);
48
    }
49
50
    public function invalidHours()
51
    {
52
        return [
53
            ['* -1 * * * my_command'],
54
            ['* 24 * * * my_command'],
55
        ];
56
    }
57
58
    /**
59
     * @dataProvider invalidHours
60
     * @expectedException InvalidArgumentException
61
     *
62
     * @param string $cronString
63
     */
64
    public function testParseInvalidHour($cronString)
65
    {
66
        $this->expectExceptionCode(Cron::ERROR_HOUR);
67
        Cron::parse($cronString);
68
    }
69
70
    public function invalidMonthDays()
71
    {
72
        return [
73
            ['* * 0 * * my_command'],
74
            ['* * 32 * * my_command'],
75
        ];
76
    }
77
78
    /**
79
     * @dataProvider invalidMonthDays
80
     * @expectedException InvalidArgumentException
81
     *
82
     * @param string $cronString
83
     */
84
    public function testParseInvalidDayOfMonth($cronString)
85
    {
86
        $this->expectExceptionCode(Cron::ERROR_DAY_OF_MONTH);
87
        Cron::parse($cronString);
88
    }
89
90
    public function invalidMonthes()
91
    {
92
        return [
93
            ['* * * 0 * my_command'],
94
            ['* * * 13 * my_command'],
95
        ];
96
    }
97
98
    /**
99
     * @dataProvider invalidMonthes
100
     * @expectedException InvalidArgumentException
101
     *
102
     * @param string $cronString
103
     */
104
    public function testParseInvalidMonth($cronString)
105
    {
106
        $this->expectExceptionCode(Cron::ERROR_MONTH);
107
        Cron::parse($cronString);
108
    }
109
110
    public function invalidWeekDays()
111
    {
112
        return [
113
            ['* * * * -1 my_command'],
114
            ['* * * * 8 my_command'],
115
        ];
116
    }
117
118
    /**
119
     * @dataProvider invalidWeekDays
120
     * @expectedException InvalidArgumentException
121
     *
122
     * @param string $cronString
123
     */
124
    public function testParseInvalidDayOfWeek($cronString)
125
    {
126
        $this->expectExceptionCode(Cron::ERROR_DAY_OF_WEEK);
127
        Cron::parse($cronString);
128
    }
129
}
130