Completed
Push — master ( 67e465...aa77c9 )
by Alejandro
13s queued 10s
created

isConsideredEmptyOnlyIfNoneOfTheDatesIsSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Common\Util;
5
6
use Cake\Chronos\Chronos;
7
use PHPUnit\Framework\TestCase;
8
use Shlinkio\Shlink\Common\Util\DateRange;
9
10
class DateRangeTest extends TestCase
11
{
12
    /**
13
     * @test
14
     */
15
    public function defaultConstructorSetDatesToNull()
16
    {
17
        $range = new DateRange();
18
        $this->assertNull($range->getStartDate());
19
        $this->assertNull($range->getEndDate());
20
        $this->assertTrue($range->isEmpty());
21
    }
22
23
    /**
24
     * @test
25
     */
26
    public function providedDatesAreSet()
27
    {
28
        $startDate = Chronos::now();
29
        $endDate = Chronos::now();
30
        $range = new DateRange($startDate, $endDate);
31
        $this->assertSame($startDate, $range->getStartDate());
32
        $this->assertSame($endDate, $range->getEndDate());
33
        $this->assertFalse($range->isEmpty());
34
    }
35
36
    /**
37
     * @test
38
     * @dataProvider provideDates
39
     */
40
    public function isConsideredEmptyOnlyIfNoneOfTheDatesIsSet(?Chronos $startDate, ?Chronos $endDate, bool $isEmpty)
41
    {
42
        $range = new DateRange($startDate, $endDate);
43
        $this->assertEquals($isEmpty, $range->isEmpty());
44
    }
45
46
    public function provideDates(): array
47
    {
48
        return [
49
            [null, null, true],
50
            [null, Chronos::now(), false],
51
            [Chronos::now(), null, false],
52
            [Chronos::now(), Chronos::now(), false],
53
        ];
54
    }
55
}
56