Skip to content

Commit 507fdca

Browse files
committed
Fix tests
1 parent d0824eb commit 507fdca

File tree

6 files changed

+45
-14
lines changed

6 files changed

+45
-14
lines changed

tests/PHPStan/Rules/Functions/ArrowFunctionReturnTypeRuleTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,20 @@ public function testRule(): void
3939
'Anonymous function should return int but returns string.',
4040
14,
4141
],
42+
43+
]);
44+
}
45+
46+
public function testRuleNever(): void
47+
{
48+
if (PHP_VERSION_ID < 80100) {
49+
self::markTestSkipped('Test requires PHP 8.1.');
50+
}
51+
52+
$this->analyse([__DIR__ . '/data/arrow-function-never-return.php'], [
4253
[
4354
'Anonymous function should never return but return statement found.',
44-
44,
55+
12,
4556
],
4657
]);
4758
}

tests/PHPStan/Rules/Functions/ExistingClassesInArrowFunctionTypehintsRuleTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,14 @@ public function testIntersectionTypes(int $phpVersion, array $errors): void
289289
public function testNever(): void
290290
{
291291
$errors = [];
292-
if (PHP_VERSION_ID < 80200) {
292+
if (PHP_VERSION_ID < 80100) {
293+
$errors = [
294+
[
295+
'Anonymous function has invalid return type ArrowFunctionNever\never.',
296+
6,
297+
],
298+
];
299+
} elseif (PHP_VERSION_ID < 80200) {
293300
$errors = [
294301
[
295302
'Never return type in arrow function is supported only on PHP 8.2 and later.',
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php // lint >= 8.1
2+
3+
namespace ArrowFunctionNeverReturn;
4+
5+
class Baz
6+
{
7+
8+
public function doFoo(): void
9+
{
10+
$f = fn () => throw new \Exception();
11+
$g = fn (): never => throw new \Exception();
12+
$g = fn (): never => 1;
13+
}
14+
15+
}

tests/PHPStan/Rules/Functions/data/arrow-functions-return-type.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,3 @@ public function doBar(): void
3333
}
3434

3535
static fn (int $value): iterable => yield $value;
36-
37-
class Baz
38-
{
39-
40-
public function doFoo(): void
41-
{
42-
$f = fn () => throw new \Exception();
43-
$g = fn (): never => throw new \Exception();
44-
$g = fn (): never => 1;
45-
}
46-
47-
}

tests/PHPStan/Rules/Playground/FunctionNeverRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPStan\Rules\Rule;
66
use PHPStan\Testing\RuleTestCase;
7+
use const PHP_VERSION_ID;
78

89
/**
910
* @extends RuleTestCase<FunctionNeverRule>
@@ -18,6 +19,10 @@ protected function getRule(): Rule
1819

1920
public function testRule(): void
2021
{
22+
if (PHP_VERSION_ID < 80100) {
23+
self::markTestSkipped('Test requires PHP 8.1 or greater.');
24+
}
25+
2126
$this->analyse([__DIR__ . '/data/function-never.php'], [
2227
[
2328
'Function FunctionNever\doBar() always throws an exception, it should have return type "never".',

tests/PHPStan/Rules/Playground/MethodNeverRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPStan\Rules\Rule;
66
use PHPStan\Testing\RuleTestCase;
7+
use const PHP_VERSION_ID;
78

89
/**
910
* @extends RuleTestCase<MethodNeverRule>
@@ -18,6 +19,10 @@ protected function getRule(): Rule
1819

1920
public function testRule(): void
2021
{
22+
if (PHP_VERSION_ID < 80100) {
23+
self::markTestSkipped('Test requires PHP 8.1 or greater.');
24+
}
25+
2126
$this->analyse([__DIR__ . '/data/method-never.php'], [
2227
[
2328
'Method MethodNever\Foo::doBar() always throws an exception, it should have return type "never".',

0 commit comments

Comments
 (0)