Skip to content

Commit

Permalink
fix tests for < PHP 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
canvural committed May 24, 2024
1 parent ea44946 commit 134fb44
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php declare(strict_types = 1);

namespace PHPStan\Analyser;

use PHPStan\Testing\TypeInferenceTestCase;
use const PHP_VERSION_ID;

class ClosureTypeChangingExtensionArrowFunctionTest extends TypeInferenceTestCase
{

public function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/closure-type-changing-extension-arrow-function.php');
}

/**
* @dataProvider dataFileAsserts
* @param mixed ...$args
*/
public function testFileAsserts(
string $assertType,
string $file,
...$args,
): void
{
if (PHP_VERSION_ID < 70400) {
$this->markTestSkipped('Test requires PHP 7.4.');
}

$this->assertFileAsserts($assertType, $file, ...$args);
}

public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/closure-type-changing-extension-arrow-function.neon',
];
}

}
7 changes: 0 additions & 7 deletions tests/PHPStan/Analyser/ClosureTypeChangingExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@
namespace PHPStan\Analyser;

use PHPStan\Testing\TypeInferenceTestCase;
use const PHP_VERSION_ID;

class ClosureTypeChangingExtensionTest extends TypeInferenceTestCase
{

public function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/closure-type-changing-extension.php');

if (PHP_VERSION_ID < 80000) {
return;
}

yield from $this->gatherAssertTypes(__DIR__ . '/data/closure-type-changing-extension-arrow-function.php');
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
-
class: CallableTypeChangingExtensionArrowFunction\FunctionClosureTypeChangingExtension
tags:
- phpstan.functionClosureTypeChangingExtension

-
class: CallableTypeChangingExtensionArrowFunction\MethodClosureTypeChangingExtension
tags:
- phpstan.methodClosureTypeChangingExtension

-
class: CallableTypeChangingExtensionArrowFunction\StaticMethodClosureTypeChangingExtension
tags:
- phpstan.staticMethodClosureTypeChangingExtension

15 changes: 0 additions & 15 deletions tests/PHPStan/Analyser/closure-type-changing-extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,3 @@ services:
class: ClosureTypeChangingExtension\StaticMethodClosureTypeChangingExtension
tags:
- phpstan.staticMethodClosureTypeChangingExtension
-
class: CallableTypeChangingExtensionArrowFunction\FunctionClosureTypeChangingExtension
tags:
- phpstan.functionClosureTypeChangingExtension

-
class: CallableTypeChangingExtensionArrowFunction\MethodClosureTypeChangingExtension
tags:
- phpstan.methodClosureTypeChangingExtension

-
class: CallableTypeChangingExtensionArrowFunction\StaticMethodClosureTypeChangingExtension
tags:
- phpstan.staticMethodClosureTypeChangingExtension

Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,14 @@ function functionWithCallable(int $foo, callable $callback)

}

/**
* @param class-string<Foo> $fooString
*/
function test(Foo $foo, string $fooString): void
function test(Foo $foo): void
{

$foo->methodWithCallable(1, fn ($i) => assertType('int', $i->getValue()));

(new Foo)->methodWithCallable(2, fn (Generic $i) => assertType('string', $i->getValue()));

Foo::staticMethodWithCallable(fn ($i) => assertType('float', $i));

$fooString::staticMethodWithCallable(fn ($i) => assertType('float', $i));
}

functionWithCallable(1, fn ($i) => assertType('int', $i->getValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,7 @@ function functionWithClosure(int $foo, Closure $callback)

}

/**
* @param class-string<Foo> $fooString
*/
function test(Foo $foo, string $fooString): void
function test(Foo $foo): void
{
$foo->methodWithClosure(1, function ($i) {
assertType('int', $i->getValue());
Expand All @@ -212,10 +209,6 @@ function test(Foo $foo, string $fooString): void
Foo::staticMethodWithClosure(function ($i) {
assertType('float', $i);
});

$fooString::staticMethodWithClosure(function ($i) {
assertType('float', $i);
});
}

functionWithClosure(1, function ($i) {
Expand Down

0 comments on commit 134fb44

Please sign in to comment.