Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 4, 2024
1 parent 88560b6 commit 069d6e9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,20 @@ public function testRule(): void
'Anonymous function should return int but returns string.',
14,
],

]);
}

public function testRuleNever(): void
{
if (PHP_VERSION_ID < 80100) {
self::markTestSkipped('Test requires PHP 8.1.');
}

$this->analyse([__DIR__ . '/data/arrow-function-never-return.php'], [
[
'Anonymous function should never return but return statement found.',
44,
12,
],
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,14 @@ public function testIntersectionTypes(int $phpVersion, array $errors): void
public function testNever(): void
{
$errors = [];
if (PHP_VERSION_ID < 80200) {
if (PHP_VERSION_ID < 80100) {
$errors = [
[
'Anonymous function has invalid return type ArrowFunctionNever\never.',
6,
],
];
} elseif (PHP_VERSION_ID < 80200) {
$errors = [
[
'Never return type in arrow function is supported only on PHP 8.2 and later.',
Expand Down
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Functions/data/arrow-function-never-return.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php // lint >= 8.1

namespace ArrowFunctionNeverReturn;

class Baz
{

public function doFoo(): void
{
$f = fn () => throw new \Exception();
$g = fn (): never => throw new \Exception();
$g = fn (): never => 1;
}

}
12 changes: 0 additions & 12 deletions tests/PHPStan/Rules/Functions/data/arrow-functions-return-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,3 @@ public function doBar(): void
}

static fn (int $value): iterable => yield $value;

class Baz
{

public function doFoo(): void
{
$f = fn () => throw new \Exception();
$g = fn (): never => throw new \Exception();
$g = fn (): never => 1;
}

}
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Playground/FunctionNeverRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use const PHP_VERSION_ID;

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

public function testRule(): void
{
if (PHP_VERSION_ID < 80100) {
self::markTestSkipped('Test requires PHP 8.1 or greater.');
}

$this->analyse([__DIR__ . '/data/function-never.php'], [
[
'Function FunctionNever\doBar() always throws an exception, it should have return type "never".',
Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Playground/MethodNeverRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use const PHP_VERSION_ID;

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

public function testRule(): void
{
if (PHP_VERSION_ID < 80100) {
self::markTestSkipped('Test requires PHP 8.1 or greater.');
}

$this->analyse([__DIR__ . '/data/method-never.php'], [
[
'Method MethodNever\Foo::doBar() always throws an exception, it should have return type "never".',
Expand Down

0 comments on commit 069d6e9

Please sign in to comment.