From df5d6d1e306630eb73607b5572fdbb6218d747f3 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Tue, 19 Nov 2024 16:38:48 +0100 Subject: [PATCH 01/10] Fix subtracting enums inside in_array when const set is used --- ...InArrayFunctionTypeSpecifyingExtension.php | 2 +- .../Analyser/AnalyserIntegrationTest.php | 6 +++++ tests/PHPStan/Analyser/data/enum-in-array.php | 22 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/PHPStan/Analyser/data/enum-in-array.php diff --git a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php index 62c022c8e1..b4c16e786a 100644 --- a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php @@ -110,7 +110,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n $context->true() || ( $context->false() - && count($arrayValueType->getFiniteTypes()) === 1 + && count($arrayValueType->getFiniteTypes()) > 0 ) ) { $specifiedTypes = $this->typeSpecifier->create( diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 37a92688b7..69252b4940 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1480,6 +1480,12 @@ public function testBug11913(): void $this->assertNoErrors($errors); } + public function testBug12083InArrayEnum(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/enum-in-array.php'); + $this->assertNoErrors($errors); + } + /** * @param string[]|null $allAnalysedFiles * @return Error[] diff --git a/tests/PHPStan/Analyser/data/enum-in-array.php b/tests/PHPStan/Analyser/data/enum-in-array.php new file mode 100644 index 0000000000..1729e70f5b --- /dev/null +++ b/tests/PHPStan/Analyser/data/enum-in-array.php @@ -0,0 +1,22 @@ + Date: Wed, 20 Nov 2024 12:12:28 +0100 Subject: [PATCH 02/10] Fix broken edge-case, few more test cases --- ...InArrayFunctionTypeSpecifyingExtension.php | 25 +++++++ tests/PHPStan/Analyser/data/enum-in-array.php | 66 +++++++++++++++++-- 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php index b4c16e786a..ff3f9f4c39 100644 --- a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php @@ -15,9 +15,14 @@ use PHPStan\Reflection\FunctionReflection; use PHPStan\Type\Accessory\NonEmptyArrayType; use PHPStan\Type\ArrayType; +use PHPStan\Type\Enum\EnumCaseObjectType; use PHPStan\Type\FunctionTypeSpecifyingExtension; +use PHPStan\Type\IntersectionType; use PHPStan\Type\MixedType; +use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; +use PHPStan\Type\TypeTraverser; +use PHPStan\Type\UnionType; use function count; use function strtolower; @@ -111,6 +116,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n || ( $context->false() && count($arrayValueType->getFiniteTypes()) > 0 + && $this->isEnumCasesArray($arrayValueType) // avoid eliminating all enum cases in edge case like in_array(Enum, list, true) ) ) { $specifiedTypes = $this->typeSpecifier->create( @@ -162,4 +168,23 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n return $specifiedTypes; } + private function isEnumCasesArray(Type $type): bool + { + $containsOnlyEnumCases = true; + + TypeTraverser::map($type, static function (Type $type, callable $traverse) use (&$containsOnlyEnumCases): Type { + if ($type instanceof UnionType || $type instanceof IntersectionType) { + return $traverse($type); + } + + if (!$type instanceof EnumCaseObjectType) { + $containsOnlyEnumCases = false; + } + + return $type; + }); + + return $containsOnlyEnumCases; + } + } diff --git a/tests/PHPStan/Analyser/data/enum-in-array.php b/tests/PHPStan/Analyser/data/enum-in-array.php index 1729e70f5b..1950b44175 100644 --- a/tests/PHPStan/Analyser/data/enum-in-array.php +++ b/tests/PHPStan/Analyser/data/enum-in-array.php @@ -1,5 +1,7 @@ */ + private array $list = []; - if (in_array($enum, MyEnum::SET1, true)) { + public function doFoo(MyEnum $enum): void + { + if (in_array($enum, $this->list, true)) { + return; + } - } else { - \PHPStan\Testing\assertType('*NEVER*', $enum); + assertType(MyEnum::class, $enum); } + } From b4ed66b21fd24e2c83d342da29a33d0f14f88ef8 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Wed, 20 Nov 2024 12:35:01 +0100 Subject: [PATCH 03/10] Fix for other finite types --- ...InArrayFunctionTypeSpecifyingExtension.php | 26 +------- .../Analyser/AnalyserIntegrationTest.php | 8 ++- tests/PHPStan/Analyser/data/enum-in-array.php | 59 ++++++++++++++++++- 3 files changed, 64 insertions(+), 29 deletions(-) diff --git a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php index ff3f9f4c39..cfa9b32d57 100644 --- a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php @@ -15,14 +15,9 @@ use PHPStan\Reflection\FunctionReflection; use PHPStan\Type\Accessory\NonEmptyArrayType; use PHPStan\Type\ArrayType; -use PHPStan\Type\Enum\EnumCaseObjectType; use PHPStan\Type\FunctionTypeSpecifyingExtension; -use PHPStan\Type\IntersectionType; use PHPStan\Type\MixedType; -use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; -use PHPStan\Type\TypeTraverser; -use PHPStan\Type\UnionType; use function count; use function strtolower; @@ -116,7 +111,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n || ( $context->false() && count($arrayValueType->getFiniteTypes()) > 0 - && $this->isEnumCasesArray($arrayValueType) // avoid eliminating all enum cases in edge case like in_array(Enum, list, true) + && TypeCombinator::union(...$arrayValueType->getFiniteTypes())->equals($arrayValueType) ) ) { $specifiedTypes = $this->typeSpecifier->create( @@ -168,23 +163,4 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n return $specifiedTypes; } - private function isEnumCasesArray(Type $type): bool - { - $containsOnlyEnumCases = true; - - TypeTraverser::map($type, static function (Type $type, callable $traverse) use (&$containsOnlyEnumCases): Type { - if ($type instanceof UnionType || $type instanceof IntersectionType) { - return $traverse($type); - } - - if (!$type instanceof EnumCaseObjectType) { - $containsOnlyEnumCases = false; - } - - return $type; - }); - - return $containsOnlyEnumCases; - } - } diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 69252b4940..e9f79293a5 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1483,7 +1483,13 @@ public function testBug11913(): void public function testBug12083InArrayEnum(): void { $errors = $this->runAnalyse(__DIR__ . '/data/enum-in-array.php'); - $this->assertNoErrors($errors); + + $this->assertCount(2, $errors); + + $this->assertSame('Call to function in_array() with arguments \'c\', array{\'c\'} and true will always evaluate to true.', $errors[0]->getMessage()); + $this->assertSame(92, $errors[0]->getLine()); + $this->assertSame('Call to function in_array() with arguments \'c\', array{\'c\'} and true will always evaluate to true.', $errors[1]->getMessage()); + $this->assertSame(124, $errors[1]->getLine()); } /** diff --git a/tests/PHPStan/Analyser/data/enum-in-array.php b/tests/PHPStan/Analyser/data/enum-in-array.php index 1950b44175..c0e7ce30ec 100644 --- a/tests/PHPStan/Analyser/data/enum-in-array.php +++ b/tests/PHPStan/Analyser/data/enum-in-array.php @@ -15,7 +15,7 @@ enum MyEnum: string public function test1(): void { - foreach (MyEnum::cases() as $enum) { + foreach (self::cases() as $enum) { if (in_array($enum, MyEnum::SET_AB, true)) { assertType('MyEnum::A|MyEnum::B', $enum); } elseif (in_array($enum, MyEnum::SET_C, true)) { @@ -28,7 +28,7 @@ public function test1(): void public function test2(): void { - foreach (MyEnum::cases() as $enum) { + foreach (self::cases() as $enum) { if (in_array($enum, MyEnum::SET_ABC, true)) { assertType('MyEnum::A|MyEnum::B|MyEnum::C', $enum); } else { @@ -39,7 +39,7 @@ public function test2(): void public function test3(): void { - foreach (MyEnum::cases() as $enum) { + foreach (self::cases() as $enum) { if (in_array($enum, MyEnum::SET_C, true)) { assertType('MyEnum::C', $enum); } else { @@ -76,3 +76,56 @@ public function doFoo(MyEnum $enum): void } } + + +class InArrayOtherFiniteType { + + const SET_AB = ['a', 'b']; + const SET_C = ['c']; + const SET_ABC = ['a', 'b', 'c']; + + public function test1(): void + { + foreach (['a', 'b', 'c'] as $item) { + if (in_array($item, self::SET_AB, true)) { + assertType("'a'|'b'", $item); + } elseif (in_array($item, self::SET_C, true)) { + assertType("'c'", $item); + } else { + assertType('*NEVER*', $item); + } + } + } + + public function test2(): void + { + foreach (['a', 'b', 'c'] as $item) { + if (in_array($item, self::SET_ABC, true)) { + assertType("'a'|'b'|'c'", $item); + } else { + assertType('*NEVER*', $item); + } + } + } + + public function test3(): void + { + foreach (['a', 'b', 'c'] as $item) { + if (in_array($item, self::SET_C, true)) { + assertType("'c'", $item); + } else { + assertType("'a'|'b'", $item); + } + } + } + public function test4(): void + { + foreach (['c'] as $item) { + if (in_array($item, self::SET_C, true)) { + assertType("'c'", $item); + } else { + assertType('*NEVER*', $item); + } + } + } +} From 6681e4a1e0dcbb8dd8d8354d11984e2aafbc9680 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Wed, 20 Nov 2024 12:38:54 +0100 Subject: [PATCH 04/10] Fix lint old php --- tests/PHPStan/Analyser/data/enum-in-array.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PHPStan/Analyser/data/enum-in-array.php b/tests/PHPStan/Analyser/data/enum-in-array.php index c0e7ce30ec..f90f5dcd58 100644 --- a/tests/PHPStan/Analyser/data/enum-in-array.php +++ b/tests/PHPStan/Analyser/data/enum-in-array.php @@ -1,4 +1,4 @@ -= 8.1 use function PHPStan\Testing\assertType; From d9442c87de65f4ab58aa9965e1d3f312a5910885 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Wed, 20 Nov 2024 12:53:32 +0100 Subject: [PATCH 05/10] Better tests --- ...InArrayFunctionTypeSpecifyingExtension.php | 2 +- .../Analyser/AnalyserIntegrationTest.php | 9 ++-- tests/PHPStan/Analyser/data/enum-in-array.php | 42 ++++++++++++++++++- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php index cfa9b32d57..f23bd1fbd8 100644 --- a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php @@ -111,7 +111,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n || ( $context->false() && count($arrayValueType->getFiniteTypes()) > 0 - && TypeCombinator::union(...$arrayValueType->getFiniteTypes())->equals($arrayValueType) + && TypeCombinator::union(...$arrayValueType->getFiniteTypes())->equals($arrayValueType) // avoid edge-case of in_array(Enum, list, true) ) ) { $specifiedTypes = $this->typeSpecifier->create( diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index e9f79293a5..911cbfa4cf 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -11,6 +11,7 @@ use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Constant\ConstantStringType; +use function array_filter; use function extension_loaded; use function restore_error_handler; use function sprintf; @@ -1484,12 +1485,10 @@ public function testBug12083InArrayEnum(): void { $errors = $this->runAnalyse(__DIR__ . '/data/enum-in-array.php'); - $this->assertCount(2, $errors); + $filteredErrors = array_filter($errors, static fn (Error $error): bool => $error->getIdentifier() !== 'function.alreadyNarrowedType' + && $error->getIdentifier() !== 'function.impossibleType'); - $this->assertSame('Call to function in_array() with arguments \'c\', array{\'c\'} and true will always evaluate to true.', $errors[0]->getMessage()); - $this->assertSame(92, $errors[0]->getLine()); - $this->assertSame('Call to function in_array() with arguments \'c\', array{\'c\'} and true will always evaluate to true.', $errors[1]->getMessage()); - $this->assertSame(124, $errors[1]->getLine()); + $this->assertNoErrors($filteredErrors); } /** diff --git a/tests/PHPStan/Analyser/data/enum-in-array.php b/tests/PHPStan/Analyser/data/enum-in-array.php index f90f5dcd58..725590f73e 100644 --- a/tests/PHPStan/Analyser/data/enum-in-array.php +++ b/tests/PHPStan/Analyser/data/enum-in-array.php @@ -58,6 +58,37 @@ public function test4(): void } } + public function testNegative1(): void + { + foreach (self::cases() as $enum) { + if (!in_array($enum, MyEnum::SET_AB, true)) { + assertType('MyEnum::C', $enum); + } else { + assertType('MyEnum::A|MyEnum::B', $enum); + } + } + } + + public function testNegative2(): void + { + foreach (self::cases() as $enum) { + if (!in_array($enum, MyEnum::SET_AB, true)) { + assertType('MyEnum::C', $enum); + } elseif (!in_array($enum, MyEnum::SET_AB, true)) { + assertType('*NEVER*', $enum); + } + } + } + + public function testNegative3(): void + { + foreach ([MyEnum::C] as $enum) { + if (!in_array($enum, MyEnum::SET_C, true)) { + assertType('*NEVER*', $enum); + } + } + } + } class InArrayEnum @@ -66,7 +97,7 @@ class InArrayEnum /** @var list */ private array $list = []; - public function doFoo(MyEnum $enum): void + public function testPositive(MyEnum $enum): void { if (in_array($enum, $this->list, true)) { return; @@ -75,6 +106,15 @@ public function doFoo(MyEnum $enum): void assertType(MyEnum::class, $enum); } + public function testNegative(MyEnum $enum): void + { + if (!in_array($enum, $this->list, true)) { + return; + } + + assertType(MyEnum::class, $enum); + } + } From 9a0afded71c83c8380aff16b36737b0ef758c3a9 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Wed, 20 Nov 2024 13:20:51 +0100 Subject: [PATCH 06/10] Fix even second part not working with enums --- .../Php/InArrayFunctionTypeSpecifyingExtension.php | 2 +- tests/PHPStan/Analyser/data/enum-in-array.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php index f23bd1fbd8..73f2fa0b91 100644 --- a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php @@ -134,7 +134,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n $context->true() || ( $context->false() - && count($needleType->getFiniteTypes()) === 1 + && count($needleType->getFiniteTypes()) > 0 ) ) { if ($context->true()) { diff --git a/tests/PHPStan/Analyser/data/enum-in-array.php b/tests/PHPStan/Analyser/data/enum-in-array.php index 725590f73e..381866c8fe 100644 --- a/tests/PHPStan/Analyser/data/enum-in-array.php +++ b/tests/PHPStan/Analyser/data/enum-in-array.php @@ -47,6 +47,7 @@ public function test3(): void } } } + public function test4(): void { foreach ([MyEnum::C] as $enum) { @@ -89,6 +90,18 @@ public function testNegative3(): void } } + /** + * @param array $array + */ + public function testNegative4(MyEnum $enum, array $array): void + { + if (!in_array($enum, $array, true)) { + assertType('array', $array); + } else { + assertType('non-empty-array', $array); + } + } + } class InArrayEnum From 45acbeb9ee7132860747c9c7bba5bf76fa2296aa Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Wed, 20 Nov 2024 13:26:13 +0100 Subject: [PATCH 07/10] Few more asserts --- tests/PHPStan/Analyser/data/enum-in-array.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/PHPStan/Analyser/data/enum-in-array.php b/tests/PHPStan/Analyser/data/enum-in-array.php index 381866c8fe..528d8f88cc 100644 --- a/tests/PHPStan/Analyser/data/enum-in-array.php +++ b/tests/PHPStan/Analyser/data/enum-in-array.php @@ -96,8 +96,10 @@ public function testNegative3(): void public function testNegative4(MyEnum $enum, array $array): void { if (!in_array($enum, $array, true)) { + assertType('MyEnum', $enum); assertType('array', $array); } else { + assertType('MyEnum', $enum); assertType('non-empty-array', $array); } } @@ -107,25 +109,26 @@ public function testNegative4(MyEnum $enum, array $array): void class InArrayEnum { - /** @var list */ - private array $list = []; - - public function testPositive(MyEnum $enum): void + /** @param list $list */ + public function testPositive(MyEnum $enum, array $list): void { - if (in_array($enum, $this->list, true)) { + if (in_array($enum, $list, true)) { return; } assertType(MyEnum::class, $enum); + assertType('list<*NEVER*>&list', $list); } - public function testNegative(MyEnum $enum): void + /** @param list $list */ + public function testNegative(MyEnum $enum, array $list): void { - if (!in_array($enum, $this->list, true)) { + if (!in_array($enum, $list, true)) { return; } assertType(MyEnum::class, $enum); + assertType('non-empty-list', $list); } } From aa9cc3f8f537152111efb3b6e15ec541cb2332f2 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 20 Nov 2024 13:56:19 +0100 Subject: [PATCH 08/10] Better fix --- src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php | 5 +++-- tests/PHPStan/Analyser/data/enum-in-array.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php index 73f2fa0b91..997cfea752 100644 --- a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php @@ -111,7 +111,8 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n || ( $context->false() && count($arrayValueType->getFiniteTypes()) > 0 - && TypeCombinator::union(...$arrayValueType->getFiniteTypes())->equals($arrayValueType) // avoid edge-case of in_array(Enum, list, true) + && count($needleType->getFiniteTypes()) > 0 + && $arrayType->isIterableAtLeastOnce()->yes() ) ) { $specifiedTypes = $this->typeSpecifier->create( @@ -134,7 +135,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n $context->true() || ( $context->false() - && count($needleType->getFiniteTypes()) > 0 + && count($needleType->getFiniteTypes()) === 1 ) ) { if ($context->true()) { diff --git a/tests/PHPStan/Analyser/data/enum-in-array.php b/tests/PHPStan/Analyser/data/enum-in-array.php index 528d8f88cc..ca34261bc8 100644 --- a/tests/PHPStan/Analyser/data/enum-in-array.php +++ b/tests/PHPStan/Analyser/data/enum-in-array.php @@ -97,7 +97,7 @@ public function testNegative4(MyEnum $enum, array $array): void { if (!in_array($enum, $array, true)) { assertType('MyEnum', $enum); - assertType('array', $array); + assertType('array', $array); } else { assertType('MyEnum', $enum); assertType('non-empty-array', $array); @@ -117,7 +117,7 @@ public function testPositive(MyEnum $enum, array $list): void } assertType(MyEnum::class, $enum); - assertType('list<*NEVER*>&list', $list); + assertType('list', $list); } /** @param list $list */ From d8bbaf8dda971fd3d7cfca8909750f0383771aaf Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 20 Nov 2024 14:13:38 +0100 Subject: [PATCH 09/10] Fix test --- tests/PHPStan/Analyser/AnalyserIntegrationTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 911cbfa4cf..8cad9df792 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1483,6 +1483,10 @@ public function testBug11913(): void public function testBug12083InArrayEnum(): void { + if (PHP_VERSION_ID < 80100) { + $this->markTestSkipped('Test requires PHP 8.1.'); + } + $errors = $this->runAnalyse(__DIR__ . '/data/enum-in-array.php'); $filteredErrors = array_filter($errors, static fn (Error $error): bool => $error->getIdentifier() !== 'function.alreadyNarrowedType' From 258095cbb728a80f98778bc4c8fa770f67a1b2c4 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 20 Nov 2024 14:16:35 +0100 Subject: [PATCH 10/10] This should have been in /nsrt/ from the start --- .../PHPStan/Analyser/AnalyserIntegrationTest.php | 15 --------------- .../Analyser/{data => nsrt}/enum-in-array.php | 0 2 files changed, 15 deletions(-) rename tests/PHPStan/Analyser/{data => nsrt}/enum-in-array.php (100%) diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 8cad9df792..37a92688b7 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -11,7 +11,6 @@ use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Constant\ConstantStringType; -use function array_filter; use function extension_loaded; use function restore_error_handler; use function sprintf; @@ -1481,20 +1480,6 @@ public function testBug11913(): void $this->assertNoErrors($errors); } - public function testBug12083InArrayEnum(): void - { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - - $errors = $this->runAnalyse(__DIR__ . '/data/enum-in-array.php'); - - $filteredErrors = array_filter($errors, static fn (Error $error): bool => $error->getIdentifier() !== 'function.alreadyNarrowedType' - && $error->getIdentifier() !== 'function.impossibleType'); - - $this->assertNoErrors($filteredErrors); - } - /** * @param string[]|null $allAnalysedFiles * @return Error[] diff --git a/tests/PHPStan/Analyser/data/enum-in-array.php b/tests/PHPStan/Analyser/nsrt/enum-in-array.php similarity index 100% rename from tests/PHPStan/Analyser/data/enum-in-array.php rename to tests/PHPStan/Analyser/nsrt/enum-in-array.php