1<?php
2
3namespace Cron\Tests;
4
5use Cron\DayOfMonthField;
6use DateTime;
7use PHPUnit_Framework_TestCase;
8
9/**
10 * @author Michael Dowling <mtdowling@gmail.com>
11 */
12class DayOfMonthFieldTest extends PHPUnit_Framework_TestCase
13{
14    /**
15     * @covers Cron\DayOfMonthField::validate
16     */
17    public function testValidatesField()
18    {
19        $f = new DayOfMonthField();
20        $this->assertTrue($f->validate('1'));
21        $this->assertTrue($f->validate('*'));
22        $this->assertTrue($f->validate('5W,L'));
23        $this->assertFalse($f->validate('1.'));
24    }
25
26    /**
27     * @covers Cron\DayOfMonthField::isSatisfiedBy
28     */
29    public function testChecksIfSatisfied()
30    {
31        $f = new DayOfMonthField();
32        $this->assertTrue($f->isSatisfiedBy(new DateTime(), '?'));
33    }
34
35    /**
36     * @covers Cron\DayOfMonthField::increment
37     */
38    public function testIncrementsDate()
39    {
40        $d = new DateTime('2011-03-15 11:15:00');
41        $f = new DayOfMonthField();
42        $f->increment($d);
43        $this->assertEquals('2011-03-16 00:00:00', $d->format('Y-m-d H:i:s'));
44
45        $d = new DateTime('2011-03-15 11:15:00');
46        $f->increment($d, true);
47        $this->assertEquals('2011-03-14 23:59:00', $d->format('Y-m-d H:i:s'));
48    }
49
50    /**
51     * Day of the month cannot accept a 0 value, it must be between 1 and 31
52     * See Github issue #120
53     *
54     * @since 2017-01-22
55     */
56    public function testDoesNotAccept0Date()
57    {
58        $f = new DayOfMonthField();
59        $this->assertFalse($f->validate(0));
60    }
61}
62