File: SpecTest.php

package info (click to toggle)
php-nesbot-carbon 2.73.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 19,940 kB
  • sloc: php: 158,741; xml: 99; makefile: 32; sh: 14
file content (99 lines) | stat: -rw-r--r-- 2,469 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php

declare(strict_types=1);

/**
 * This file is part of the Carbon package.
 *
 * (c) Brian Nesbitt <brian@nesbot.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Tests\CarbonInterval;

use Carbon\CarbonInterval;
use DateInterval;
use Tests\AbstractTestCase;

class SpecTest extends AbstractTestCase
{
    public function testZeroInterval()
    {
        $ci = new CarbonInterval(0, 0, 0, 0, 0, 0, 0);
        $this->assertSame('PT0S', $ci->spec());
    }

    public function testYearInterval()
    {
        $ci = new CarbonInterval();
        $this->assertSame('P1Y', $ci->spec());
    }

    public function testMonthInterval()
    {
        $ci = new CarbonInterval(0, 1);
        $this->assertSame('P1M', $ci->spec());
    }

    public function testWeekInterval()
    {
        $ci = new CarbonInterval(0, 0, 1);
        $this->assertSame('P7D', $ci->spec());
    }

    public function testDayInterval()
    {
        $ci = new CarbonInterval(0, 0, 0, 1);
        $this->assertSame('P1D', $ci->spec());
    }

    public function testMixedDateInterval()
    {
        $ci = new CarbonInterval(1, 2, 0, 3);
        $this->assertSame('P1Y2M3D', $ci->spec());
    }

    public function testHourInterval()
    {
        $ci = new CarbonInterval(0, 0, 0, 0, 1);
        $this->assertSame('PT1H', $ci->spec());
    }

    public function testMinuteInterval()
    {
        $ci = new CarbonInterval(0, 0, 0, 0, 0, 1);
        $this->assertSame('PT1M', $ci->spec());
    }

    public function testSecondInterval()
    {
        $ci = new CarbonInterval(0, 0, 0, 0, 0, 0, 1);
        $this->assertSame('PT1S', $ci->spec());
    }

    public function testMicrosecondsInterval()
    {
        $ci = new CarbonInterval(0, 0, 0, 0, 0, 0, 0, 12300);
        $this->assertSame('PT0.012300S', $ci->spec(true));
    }

    public function testMixedTimeInterval()
    {
        $ci = new CarbonInterval(0, 0, 0, 0, 1, 2, 3);
        $this->assertSame('PT1H2M3S', $ci->spec());
    }

    public function testMixedDateAndTimeInterval()
    {
        $ci = new CarbonInterval(1, 2, 0, 3, 4, 5, 6);
        $this->assertSame('P1Y2M3DT4H5M6S', $ci->spec());
    }

    public function testCreatingInstanceEquals()
    {
        $ci = new CarbonInterval(1, 2, 0, 3, 4, 5, 6);
        $this->assertEquals($ci, CarbonInterval::instance(new DateInterval($ci->spec())));
    }
}