2016-07-30 18:45:48 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-30 18:45:48 +03:00
|
|
|
namespace ShlinkioTest\Shlink\Common\Util;
|
|
|
|
|
2018-09-29 13:52:32 +03:00
|
|
|
use Cake\Chronos\Chronos;
|
2017-03-24 22:34:18 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-07-30 18:45:48 +03:00
|
|
|
use Shlinkio\Shlink\Common\Util\DateRange;
|
|
|
|
|
|
|
|
class DateRangeTest extends TestCase
|
|
|
|
{
|
2019-02-17 22:28:34 +03:00
|
|
|
/** @test */
|
2016-07-30 18:45:48 +03:00
|
|
|
public function defaultConstructorSetDatesToNull()
|
|
|
|
{
|
|
|
|
$range = new DateRange();
|
|
|
|
$this->assertNull($range->getStartDate());
|
|
|
|
$this->assertNull($range->getEndDate());
|
|
|
|
$this->assertTrue($range->isEmpty());
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:28:34 +03:00
|
|
|
/** @test */
|
2016-07-30 18:45:48 +03:00
|
|
|
public function providedDatesAreSet()
|
|
|
|
{
|
2018-09-29 13:52:32 +03:00
|
|
|
$startDate = Chronos::now();
|
|
|
|
$endDate = Chronos::now();
|
2016-07-30 18:45:48 +03:00
|
|
|
$range = new DateRange($startDate, $endDate);
|
|
|
|
$this->assertSame($startDate, $range->getStartDate());
|
|
|
|
$this->assertSame($endDate, $range->getEndDate());
|
|
|
|
$this->assertFalse($range->isEmpty());
|
|
|
|
}
|
2018-11-17 21:23:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideDates
|
|
|
|
*/
|
2019-02-17 22:28:34 +03:00
|
|
|
public function isConsideredEmptyOnlyIfNoneOfTheDatesIsSet(
|
|
|
|
?Chronos $startDate,
|
|
|
|
?Chronos $endDate,
|
|
|
|
bool $isEmpty
|
|
|
|
): void {
|
2018-11-17 21:23:25 +03:00
|
|
|
$range = new DateRange($startDate, $endDate);
|
|
|
|
$this->assertEquals($isEmpty, $range->isEmpty());
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:28:34 +03:00
|
|
|
public function provideDates(): iterable
|
2018-11-17 21:23:25 +03:00
|
|
|
{
|
2019-02-17 22:28:34 +03:00
|
|
|
yield 'both are null' => [null, null, true];
|
|
|
|
yield 'start is null' => [null, Chronos::now(), false];
|
|
|
|
yield 'end is null' => [Chronos::now(), null, false];
|
|
|
|
yield 'none are null' => [Chronos::now(), Chronos::now(), false];
|
2018-11-17 21:23:25 +03:00
|
|
|
}
|
2016-07-30 18:45:48 +03:00
|
|
|
}
|