mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-16 08:03:45 +03:00
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace ShlinkioTest\Shlink\Common\Util;
|
|
|
|
use Cake\Chronos\Chronos;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Shlinkio\Shlink\Common\Util\DateRange;
|
|
|
|
class DateRangeTest extends TestCase
|
|
{
|
|
/**
|
|
* @test
|
|
*/
|
|
public function defaultConstructorSetDatesToNull()
|
|
{
|
|
$range = new DateRange();
|
|
$this->assertNull($range->getStartDate());
|
|
$this->assertNull($range->getEndDate());
|
|
$this->assertTrue($range->isEmpty());
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function providedDatesAreSet()
|
|
{
|
|
$startDate = Chronos::now();
|
|
$endDate = Chronos::now();
|
|
$range = new DateRange($startDate, $endDate);
|
|
$this->assertSame($startDate, $range->getStartDate());
|
|
$this->assertSame($endDate, $range->getEndDate());
|
|
$this->assertFalse($range->isEmpty());
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
* @dataProvider provideDates
|
|
*/
|
|
public function isConsideredEmptyOnlyIfNoneOfTheDatesIsSet(?Chronos $startDate, ?Chronos $endDate, bool $isEmpty)
|
|
{
|
|
$range = new DateRange($startDate, $endDate);
|
|
$this->assertEquals($isEmpty, $range->isEmpty());
|
|
}
|
|
|
|
public function provideDates(): array
|
|
{
|
|
return [
|
|
[null, null, true],
|
|
[null, Chronos::now(), false],
|
|
[Chronos::now(), null, false],
|
|
[Chronos::now(), Chronos::now(), false],
|
|
];
|
|
}
|
|
}
|