1<?php
2
3namespace Cron\Tests;
4
5use Cron\DayOfWeekField;
6use PHPUnit_Framework_TestCase;
7
8/**
9 * @author Michael Dowling <mtdowling@gmail.com>
10 */
11class AbstractFieldTest extends PHPUnit_Framework_TestCase
12{
13    /**
14     * @covers Cron\AbstractField::isRange
15     */
16    public function testTestsIfRange()
17    {
18        $f = new DayOfWeekField();
19        $this->assertTrue($f->isRange('1-2'));
20        $this->assertFalse($f->isRange('2'));
21    }
22
23    /**
24     * @covers Cron\AbstractField::isIncrementsOfRanges
25     */
26    public function testTestsIfIncrementsOfRanges()
27    {
28        $f = new DayOfWeekField();
29        $this->assertFalse($f->isIncrementsOfRanges('1-2'));
30        $this->assertTrue($f->isIncrementsOfRanges('1/2'));
31        $this->assertTrue($f->isIncrementsOfRanges('*/2'));
32        $this->assertTrue($f->isIncrementsOfRanges('3-12/2'));
33    }
34
35    /**
36     * @covers Cron\AbstractField::isInRange
37     */
38    public function testTestsIfInRange()
39    {
40        $f = new DayOfWeekField();
41        $this->assertTrue($f->isInRange('1', '1-2'));
42        $this->assertTrue($f->isInRange('2', '1-2'));
43        $this->assertTrue($f->isInRange('5', '4-12'));
44        $this->assertFalse($f->isInRange('3', '4-12'));
45        $this->assertFalse($f->isInRange('13', '4-12'));
46    }
47
48    /**
49     * @covers Cron\AbstractField::isInIncrementsOfRanges
50     */
51    public function testTestsIfInIncrementsOfRanges()
52    {
53        $f = new DayOfWeekField();
54        $this->assertTrue($f->isInIncrementsOfRanges('3', '3-59/2'));
55        $this->assertTrue($f->isInIncrementsOfRanges('13', '3-59/2'));
56        $this->assertTrue($f->isInIncrementsOfRanges('15', '3-59/2'));
57        $this->assertTrue($f->isInIncrementsOfRanges('14', '*/2'));
58        $this->assertFalse($f->isInIncrementsOfRanges('2', '3-59/13'));
59        $this->assertFalse($f->isInIncrementsOfRanges('14', '*/13'));
60        $this->assertFalse($f->isInIncrementsOfRanges('14', '3-59/2'));
61        $this->assertFalse($f->isInIncrementsOfRanges('3', '2-59'));
62        $this->assertFalse($f->isInIncrementsOfRanges('3', '2'));
63        $this->assertFalse($f->isInIncrementsOfRanges('3', '*'));
64        $this->assertFalse($f->isInIncrementsOfRanges('0', '*/0'));
65        $this->assertFalse($f->isInIncrementsOfRanges('1', '*/0'));
66
67        $this->assertTrue($f->isInIncrementsOfRanges('4', '4/10'));
68        $this->assertTrue($f->isInIncrementsOfRanges('14', '4/10'));
69        $this->assertTrue($f->isInIncrementsOfRanges('34', '4/10'));
70    }
71
72    /**
73     * @covers Cron\AbstractField::isSatisfied
74     */
75    public function testTestsIfSatisfied()
76    {
77        $f = new DayOfWeekField();
78        $this->assertTrue($f->isSatisfied('12', '3-13'));
79        $this->assertTrue($f->isSatisfied('15', '3-59/12'));
80        $this->assertTrue($f->isSatisfied('12', '*'));
81        $this->assertTrue($f->isSatisfied('12', '12'));
82        $this->assertFalse($f->isSatisfied('12', '3-11'));
83        $this->assertFalse($f->isSatisfied('12', '3-59/13'));
84        $this->assertFalse($f->isSatisfied('12', '11'));
85    }
86}
87