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

DateRangeTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultConstructorSetDatesToNull() 0 6 1
A providedDatesAreSet() 0 8 1
A provideDates() 0 7 1
A isConsideredEmptyOnlyIfNoneOfTheDatesIsSet() 0 4 1
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