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

CronTest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 121
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A testAdd() 0 6 1
A testParseValidCron() 0 11 1
A invalidMinutes() 0 7 1
A testParseInvalidMinute() 0 5 1
A invalidHours() 0 7 1
A testParseInvalidHour() 0 5 1
A invalidMonthDays() 0 7 1
A testParseInvalidDayOfMonth() 0 5 1
A invalidMonthes() 0 7 1
A testParseInvalidMonth() 0 5 1
A invalidWeekDays() 0 7 1
A testParseInvalidDayOfWeek() 0 5 1
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