Skip to content

Commit 7ea3d4d

Browse files
phpstan-botclaude
andcommitted
Add regression tests for #13061 and #7259
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f178bf5 commit 7ea3d4d

2 files changed

Lines changed: 141 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug13061;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
interface ScenarioInterface {}
8+
9+
class ScenarioNode implements ScenarioInterface {}
10+
class OutlineNode implements ScenarioInterface {}
11+
12+
class FeatureNode
13+
{
14+
/**
15+
* @param ScenarioInterface[] $scenarios
16+
*/
17+
public function __construct(
18+
public readonly ?string $title,
19+
public readonly array $scenarios,
20+
) {
21+
}
22+
}
23+
24+
/**
25+
* @phpstan-type TFeatureHash array{title?: string|null, scenarios?: array<int, TScenarioHash|TOutlineHash>}
26+
* @phpstan-type TScenarioHash array{type?: 'scenario', title?: string|null}
27+
* @phpstan-type TOutlineHash array{type: 'outline', title?: string|null, examples?: array<array-key, TExampleTableHash>}
28+
* @phpstan-type TExampleTableHash array<int, list<string>>
29+
*/
30+
abstract class GherkinArrayLoader
31+
{
32+
/**
33+
* @phpstan-param TFeatureHash $hash
34+
*/
35+
protected function loadFeatureHash(array $hash, int $line = 0): FeatureNode
36+
{
37+
$hash = array_merge(
38+
[
39+
'title' => null,
40+
'scenarios' => [],
41+
],
42+
$hash
43+
);
44+
45+
$scenarios = [];
46+
foreach ((array) $hash['scenarios'] as $scenarioIterator => $scenarioHash) {
47+
if (isset($scenarioHash['type']) && $scenarioHash['type'] === 'outline') {
48+
assertType("array{type: 'outline', title?: string|null, examples?: array<array<int, list<string>>>}", $scenarioHash);
49+
$scenarios[] = $this->loadOutlineHash($scenarioHash, $scenarioIterator);
50+
} else {
51+
assertType("array{type?: 'scenario', title?: string|null}", $scenarioHash);
52+
$scenarios[] = $this->loadScenarioHash($scenarioHash, $scenarioIterator);
53+
}
54+
}
55+
56+
return new FeatureNode($hash['title'], $scenarios);
57+
}
58+
59+
/**
60+
* @phpstan-param TScenarioHash $hash
61+
*/
62+
abstract protected function loadScenarioHash(array $hash, int $line = 0): ScenarioNode;
63+
64+
/**
65+
* @phpstan-param TOutlineHash $hash
66+
*/
67+
abstract protected function loadOutlineHash(array $hash, int $line = 0): OutlineNode;
68+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug7259;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorldNullable
8+
{
9+
public function __construct(
10+
private ?\DateTimeImmutable $from,
11+
private ?\DateTimeImmutable $till,
12+
)
13+
{
14+
$newFrom = $this->from;
15+
$newTill = $this->till;
16+
17+
if ($newFrom !== null || $newTill !== null) {
18+
if ($newFrom !== null && $newTill === null) {
19+
$newFrom = $newFrom->setTime(0, 0);
20+
$newTill = new \DateTimeImmutable('2300-12-31 23:59:59');
21+
}
22+
23+
if ($newTill !== null && $newFrom === null) {
24+
$newTill = $newTill->setTime(23, 59, 59, 999999);
25+
$newFrom = new \DateTimeImmutable('1970-01-01 00:00:00');
26+
}
27+
28+
assertType('DateTimeImmutable', $newFrom);
29+
assertType('DateTimeImmutable', $newTill);
30+
$this->checkDates($newFrom, $newTill);
31+
}
32+
}
33+
34+
private function checkDates(
35+
\DateTimeImmutable $from,
36+
\DateTimeImmutable $till,
37+
): void
38+
{
39+
}
40+
}
41+
42+
class HelloWorldStringInt
43+
{
44+
public function __construct(
45+
private string|int $from,
46+
private string|int $till,
47+
)
48+
{
49+
$newFrom = $this->from;
50+
$newTill = $this->till;
51+
52+
if (is_string($newFrom) || is_string($newTill)) {
53+
if (is_string($newFrom) && is_string($newTill) === false) {
54+
$newTill = 'test';
55+
}
56+
57+
if (is_string($newTill) && is_string($newFrom) === false) {
58+
$newFrom = 'test2';
59+
}
60+
61+
assertType('string', $newFrom);
62+
assertType('string', $newTill);
63+
$this->checkDates($newFrom, $newTill);
64+
}
65+
}
66+
67+
private function checkDates(
68+
string $from,
69+
string $till,
70+
): void
71+
{
72+
}
73+
}

0 commit comments

Comments
 (0)