Completed
Pull Request — develop (#11)
by Alexandr
01:57
created

CronTest::testParseInvalidMinute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
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
        $cron = Cron::parse('1 2 3 4 15 my_command');
30
        $this->assertEquals('1', $cron->getMinute());
31
        $this->assertEquals('2', $cron->getHour());
32
        $this->assertEquals('3', $cron->getDayOfMonth());
33
        $this->assertEquals('4', $cron->getMonth());
34
        $this->assertEquals('15', $cron->getDayOfWeek());
35
        $this->assertEquals('my_command', $cron->getCommand());
36
        $this->assertEquals(null, $cron->getLogFile());
37
    }
38
39
    public function testParseInvalidMinute()
40
    {
41
        $this->expectException(InvalidArgumentException::class);
42
        $this->expectExceptionCode(Cron::ERROR_MINUTE);
43
        Cron::parse('80 * * * * my_command');
44
    }
45
46
    public function testParseInvalidHour()
47
    {
48
        $this->expectException(InvalidArgumentException::class);
49
        $this->expectExceptionCode(Cron::ERROR_HOUR);
50
        Cron::parse('* 35 * * * my_command');
51
    }
52
53
    public function testParseInvalidMonth()
54
    {
55
        $this->expectException(InvalidArgumentException::class);
56
        $this->expectExceptionCode(Cron::ERROR_MONTH);
57
        Cron::parse('* * * 14 * my_command');
58
    }
59
}
60