Skip to content

Commit 1dee6dd

Browse files
herndlmondrejmirtes
authored andcommitted
Add regression test
1 parent 4ae9acf commit 1dee6dd

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

Diff for: phpstan-baseline.neon

+5
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ parameters:
99
message: "#^Accessing PHPStan\\\\Rules\\\\Comparison\\\\ImpossibleCheckTypeStaticMethodCallRule\\:\\:class is not covered by backward compatibility promise\\. The class might change in a minor PHPStan version\\.$#"
1010
count: 1
1111
path: tests/Type/WebMozartAssert/ImpossibleCheckTypeMethodCallRuleTest.php
12+
13+
-
14+
message: "#^Accessing PHPStan\\\\Rules\\\\Methods\\\\ReturnTypeRule\\:\\:class is not covered by backward compatibility promise\\. The class might change in a minor PHPStan version\\.$#"
15+
count: 1
16+
path: tests/Type/WebMozartAssert/MethodReturnTypeRuleTest.php

Diff for: tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function dataFileAsserts(): iterable
2020
yield from $this->gatherAssertTypes(__DIR__ . '/data/type.php');
2121

2222
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-18.php');
23+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-117.php');
2324
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-150.php');
2425
}
2526

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\WebMozartAssert;
4+
5+
use PHPStan\Rules\Methods\ReturnTypeRule;
6+
use PHPStan\Rules\Rule;
7+
use PHPStan\Testing\RuleTestCase;
8+
9+
/** @extends RuleTestCase<ReturnTypeRule> */
10+
class MethodReturnTypeRuleTest extends RuleTestCase
11+
{
12+
13+
protected function getRule(): Rule
14+
{
15+
return self::getContainer()->getByType(ReturnTypeRule::class);
16+
}
17+
18+
public function testBug117(): void
19+
{
20+
$this->analyse([__DIR__ . '/data/bug-117.php'], []);
21+
}
22+
23+
}

Diff for: tests/Type/WebMozartAssert/data/bug-117.php

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WebmozartAssertBug117;
6+
7+
use Webmozart\Assert\Assert;
8+
use function PHPStan\Testing\assertType;
9+
10+
class HelloWorld
11+
{
12+
/**
13+
* @param mixed[] $requestData
14+
*
15+
* @return array{
16+
* accountId: int,
17+
* errorColor: string|null,
18+
* theme: array{
19+
* backgroundColor: string|null,
20+
* textColor: string|null,
21+
* headerImage: array{id: int}|null,
22+
* },
23+
* }
24+
*/
25+
public function getData(int $accountId, array $requestData): array
26+
{
27+
Assert::keyExists($requestData, 'errorColor');
28+
Assert::nullOrString($requestData['errorColor']);
29+
30+
Assert::keyExists($requestData, 'theme');
31+
Assert::isArray($requestData['theme']);
32+
33+
Assert::keyExists($requestData['theme'], 'headerImage');
34+
Assert::nullOrIsArray($requestData['theme']['headerImage']);
35+
36+
if (null !== $requestData['theme']['headerImage']) {
37+
Assert::keyExists($requestData['theme']['headerImage'], 'id');
38+
Assert::integer($requestData['theme']['headerImage']['id']);
39+
}
40+
41+
Assert::keyExists($requestData, 'theme', 'backgroundColor');
42+
Assert::nullOrString($requestData['theme']['backgroundColor']);
43+
44+
Assert::keyExists($requestData, 'theme', 'textColor');
45+
Assert::nullOrString($requestData['theme']['textColor']);
46+
47+
$requestData['accountId'] = $accountId;
48+
49+
assertType("hasOffsetValue('accountId', int)&hasOffsetValue('errorColor', string|null)&hasOffsetValue('theme', array&hasOffsetValue('backgroundColor', string|null)&hasOffsetValue('headerImage', (array&hasOffsetValue('id', int))|null)&hasOffsetValue('textColor', string|null))&non-empty-array", $requestData);
50+
51+
return $requestData;
52+
}
53+
}

0 commit comments

Comments
 (0)