DateRangeTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 17
dl 0
loc 41
rs 10
c 2
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A provideDates() 0 6 1
A isConsideredEmptyOnlyIfNoneOfTheDatesIsSet() 0 7 1
A defaultConstructorSetDatesToNull() 0 6 1
A providedDatesAreSet() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Common\Util;
6
7
use Cake\Chronos\Chronos;
8
use PHPUnit\Framework\TestCase;
9
use Shlinkio\Shlink\Common\Util\DateRange;
10
11
class DateRangeTest extends TestCase
12
{
13
    /** @test */
14
    public function defaultConstructorSetDatesToNull(): void
15
    {
16
        $range = new DateRange();
17
        $this->assertNull($range->getStartDate());
18
        $this->assertNull($range->getEndDate());
19
        $this->assertTrue($range->isEmpty());
20
    }
21
22
    /** @test */
23
    public function providedDatesAreSet(): void
24
    {
25
        $startDate = Chronos::now();
26
        $endDate = Chronos::now();
27
        $range = new DateRange($startDate, $endDate);
28
        $this->assertSame($startDate, $range->getStartDate());
29
        $this->assertSame($endDate, $range->getEndDate());
30
        $this->assertFalse($range->isEmpty());
31
    }
32
33
    /**
34
     * @test
35
     * @dataProvider provideDates
36
     */
37
    public function isConsideredEmptyOnlyIfNoneOfTheDatesIsSet(
38
        ?Chronos $startDate,
39
        ?Chronos $endDate,
40
        bool $isEmpty
41
    ): void {
42
        $range = new DateRange($startDate, $endDate);
43
        $this->assertEquals($isEmpty, $range->isEmpty());
44
    }
45
46
    public function provideDates(): iterable
47
    {
48
        yield 'both are null' => [null, null, true];
49
        yield 'start is null' => [null, Chronos::now(), false];
50
        yield 'end is null' => [Chronos::now(), null, false];
51
        yield 'none are null' => [Chronos::now(), Chronos::now(), false];
52
    }
53
}
54