shlink/module/Common/test/Util/DateRangeTest.php

56 lines
1.4 KiB
PHP
Raw Normal View History

2016-07-30 17:45:48 +02:00
<?php
2017-10-12 10:13:20 +02:00
declare(strict_types=1);
2016-07-30 17:45:48 +02:00
namespace ShlinkioTest\Shlink\Common\Util;
use Cake\Chronos\Chronos;
2017-03-24 20:34:18 +01:00
use PHPUnit\Framework\TestCase;
2016-07-30 17:45:48 +02:00
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();
2016-07-30 17:45:48 +02:00
$range = new DateRange($startDate, $endDate);
$this->assertSame($startDate, $range->getStartDate());
$this->assertSame($endDate, $range->getEndDate());
$this->assertFalse($range->isEmpty());
}
2018-11-17 19:23:25 +01:00
/**
* @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],
];
}
2016-07-30 17:45:48 +02:00
}