Skip to content

Commit 1d283fc

Browse files
VincentLangletondrejmirtes
authored andcommitted
Add non regression tests
1 parent c610c27 commit 1d283fc

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,14 @@ public function testBug6649(): void
601601
$this->assertNoErrors($errors);
602602
}
603603

604+
public function testBug6842(): void
605+
{
606+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6842.php');
607+
$this->assertCount(1, $errors);
608+
$this->assertSame('Generator expects value type T of DateTimeInterface, DateTime|DateTimeImmutable|T of DateTimeInterface given.', $errors[0]->getMessage());
609+
$this->assertSame(28, $errors[0]->getLine());
610+
}
611+
604612
/**
605613
* @param string[]|null $allAnalysedFiles
606614
* @return Error[]

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ public function dataFileAsserts(): iterable
815815
yield from $this->gatherAssertTypes(__DIR__ . '/data/value-of-enum.php');
816816
}
817817

818+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6576.php');
818819
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6584.php');
819820
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6439.php');
820821
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6748.php');
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Bug6576;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param array<int|string, mixed> $arr
9+
*/
10+
function alreadyWorks(array $arr): void {
11+
foreach ($arr as $key => $value) {
12+
assertType('int|string', $key);
13+
}
14+
}
15+
16+
/**
17+
* @template ArrType of array<int|string, mixed>
18+
*
19+
* @param ArrType $arr
20+
*/
21+
function shouldWork(array $arr): void {
22+
foreach ($arr as $key => $value) {
23+
assertType('int|string', $key);
24+
}
25+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug6842;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @template T of \DateTimeInterface|\DateTime|\DateTimeImmutable
9+
*
10+
* @param T $startDate
11+
* @param T $endDate
12+
*
13+
* @return \Iterator<T>
14+
*/
15+
public function getScheduledEvents(
16+
\DateTimeInterface $startDate,
17+
\DateTimeInterface $endDate
18+
): \Iterator {
19+
$interval = \DateInterval::createFromDateString('1 day');
20+
21+
/** @var \Iterator<T> $datePeriod */
22+
$datePeriod = new \DatePeriod($startDate, $interval, $endDate);
23+
24+
foreach ($datePeriod as $dateTime) {
25+
$scheduledEvent = $this->createScheduledEventFromSchedule($dateTime);
26+
27+
if ($scheduledEvent >= $startDate) {
28+
yield $scheduledEvent;
29+
}
30+
}
31+
}
32+
33+
/**
34+
* @template T of \DateTimeInterface
35+
*
36+
* @param T|\DateTime|\DateTimeImmutable $dateTime
37+
*
38+
* @return T|\DateTime|\DateTimeImmutable
39+
*/
40+
protected function createScheduledEventFromSchedule(
41+
\DateTimeInterface $dateTime
42+
): \DateTimeInterface {
43+
return $dateTime;
44+
}
45+
}

0 commit comments

Comments
 (0)