Skip to content

Commit

Permalink
Add DatePeriod test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alban-io committed Jan 30, 2022
1 parent a170986 commit 89d17c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stubs/date.stub
Expand Up @@ -20,15 +20,15 @@ class DatePeriod
/**
* @return TEnd
*/
public function getEndDate()
public function getEndDate(): ?DateTimeInterface
{

}

/**
* @return TRecurrences
*/
public function getRecurrences()
public function getRecurrences(): ?int
{

}
Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Analyser/data/date-period-return-types.php
Expand Up @@ -8,14 +8,24 @@
$recurrences = 4;
$iso = 'R4/2012-07-01T00:00:00Z/P7D';

$datePeriodList = [];

$datePeriod = new DatePeriod($start, $interval, $end);
assertType(\DateTimeInterface::class, $datePeriod->getEndDate());
assertType('null', $datePeriod->getRecurrences());
$datePeriodList[] = $datePeriod;

$datePeriod = new DatePeriod($start, $interval, $recurrences);
assertType('null', $datePeriod->getEndDate());
assertType('int', $datePeriod->getRecurrences());
$datePeriodList[] = $datePeriod;

$datePeriod = new DatePeriod($iso);
assertType('null', $datePeriod->getEndDate());
assertType('int', $datePeriod->getRecurrences());
$datePeriodList[] = $datePeriod;

/** @var DatePeriod $datePeriod */
$datePeriod = $datePeriodList[random_int(0, 2)];
assertType(\DateTimeInterface::class . '|null', $datePeriod->getEndDate());
assertType('int|null', $datePeriod->getRecurrences());

0 comments on commit 89d17c7

Please sign in to comment.