Skip to content

Commit

Permalink
Regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 16, 2024
1 parent e1b84b8 commit bf57ac0
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php declare(strict_types = 1);

namespace PHPStan\Analyser;

use PHPStan\Php\PhpVersion;
use PHPStan\Rules\FunctionCallParametersCheck;
use PHPStan\Rules\Methods\CallMethodsRule;
use PHPStan\Rules\Methods\MethodCallCheck;
use PHPStan\Rules\NullsafeCheck;
use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper;
use PHPStan\Rules\Properties\PropertyReflectionFinder;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use const PHP_VERSION_ID;

class Bug9307CallMethodsRuleTest extends RuleTestCase

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, ubuntu-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, ubuntu-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, windows-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, windows-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule

Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Class PHPStan\Analyser\Bug9307CallMethodsRuleTest extends generic class PHPStan\Testing\RuleTestCase but does not specify its types: TRule
{

protected function getRule(): Rule

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, ubuntu-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, ubuntu-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, windows-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, windows-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType

Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Method PHPStan\Analyser\Bug9307CallMethodsRuleTest::getRule() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType
{
$reflectionProvider = $this->createReflectionProvider();
$ruleLevelHelper = new RuleLevelHelper($reflectionProvider, true, false, true, true, false, true, false);
return new CallMethodsRule(
new MethodCallCheck($reflectionProvider, $ruleLevelHelper, true, true),
new FunctionCallParametersCheck($ruleLevelHelper, new NullsafeCheck(), new PhpVersion(PHP_VERSION_ID), new UnresolvableTypeHelper(), new PropertyReflectionFinder(), true, true, true, true, true),
);
}

protected function shouldTreatPhpDocTypesAsCertain(): bool
{
return false;
}

public function testRule(): void
{
$this->analyse([__DIR__ . '/data/bug-9307.php'], []);
}

}
36 changes: 36 additions & 0 deletions tests/PHPStan/Analyser/Bug9307Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php declare(strict_types = 1);

namespace PHPStan\Analyser;

use PHPStan\Testing\TypeInferenceTestCase;

class Bug9307Test extends TypeInferenceTestCase
{

public function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9307.php');
}

/**
* @dataProvider dataFileAsserts
* @param mixed ...$args
*/
public function testFileAsserts(
string $assertType,
string $file,
...$args,
): void
{
$this->assertFileAsserts($assertType, $file, ...$args);
}

public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/../../../conf/bleedingEdge.neon',
__DIR__ . '/bug-9307.neon',
];
}

}
2 changes: 2 additions & 0 deletions tests/PHPStan/Analyser/bug-9307.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
treatPhpDocTypesAsCertain: false
56 changes: 56 additions & 0 deletions tests/PHPStan/Analyser/data/bug-9307.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php declare(strict_types=1);

namespace Bug9307;

use function PHPStan\Testing\assertType;

class Item {
public int $id;
}

class Aaa
{
public function test(): void
{
$objects = [];
$itemCache = [];

foreach ($this->getIds() as $id) {
if (! array_key_exists($id, $itemCache)) {
$items = $this->getObjects();
$itemCache[$id] = $items;
} else {
$items = $itemCache[$id];
}

// It works when the following line is uncommented.
//$items = $this->getObjects();

foreach ($items as $item) {
$objects[$item->id] = $item;
}
}

assertType('array', $objects);

$this->acceptObjects($objects);
}

/** @return array<int> */
public function getIds(): array
{
return [];
}

/** @return array<int, Item> */
public function getObjects(): array
{
return [];
}

/** @param array<int, Item> $objects */
public function acceptObjects(array $objects): void
{

}
}

0 comments on commit bf57ac0

Please sign in to comment.