Skip to content

Forward-compatible fixes for PHPUnit 10 #4047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 0 additions & 10 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@
beStrictAboutTodoAnnotatedTests="true"
verbose="false"
convertDeprecationsToExceptions="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="tests/tmp/clover.xml"/>
<text outputFile="php://stdout" showUncoveredFiles="true" showOnlySummary="true"/>
</report>
</coverage>

<testsuites>
<testsuite name="PHPStan">
<directory suffix="Test.php">tests/PHPStan</directory>
Expand Down
3 changes: 2 additions & 1 deletion src/Fixable/Patcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHPStan\File\FileReader;
use ReflectionClass;
use SebastianBergmann\Diff\Differ;
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
use function array_map;
use function count;
use function implode;
Expand All @@ -29,7 +30,7 @@ final class Patcher

public function __construct()
{
$this->differ = new Differ();
$this->differ = new Differ(new UnifiedDiffOutputBuilder());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testExtendingKnownClassWithCheck(): void
$errors = $this->runAnalyse(__DIR__ . '/data/extending-known-class-with-check.php');
$this->assertNoErrors($errors);

$reflectionProvider = $this->createReflectionProvider();
$reflectionProvider = self::createReflectionProvider();
$this->assertTrue($reflectionProvider->hasClass(Foo::class));
}

Expand Down Expand Up @@ -372,7 +372,7 @@ public function testBug4713(): void
$this->assertCount(1, $errors);
$this->assertSame('Method Bug4713\Service::createInstance() should return Bug4713\Service but returns object.', $errors[0]->getMessage());

$reflectionProvider = $this->createReflectionProvider();
$reflectionProvider = self::createReflectionProvider();
$class = $reflectionProvider->getClass(Service::class);
$parameter = $class->getNativeMethod('createInstance')->getOnlyVariant()->getParameters()[0];
$defaultValue = $parameter->getDefaultValue();
Expand All @@ -385,7 +385,7 @@ public function testBug4288(): void
$errors = $this->runAnalyse(__DIR__ . '/data/bug-4288.php');
$this->assertNoErrors($errors);

$reflectionProvider = $this->createReflectionProvider();
$reflectionProvider = self::createReflectionProvider();
$class = $reflectionProvider->getClass(MyClass::class);
$parameter = $class->getNativeMethod('paginate')->getOnlyVariant()->getParameters()[0];
$defaultValue = $parameter->getDefaultValue();
Expand Down
10 changes: 5 additions & 5 deletions tests/PHPStan/Analyser/AnalyserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function testIgnoreErrorMultiByPath(): void
$this->assertNoErrors($result);
}

public function dataIgnoreErrorByPathAndCount(): iterable
public static function dataIgnoreErrorByPathAndCount(): iterable
{
yield [
[
Expand Down Expand Up @@ -204,7 +204,7 @@ public function testIgnoreErrorByPathAndCount(array $ignoreErrors): void
$this->assertNoErrors($result);
}

public function dataTrueAndFalse(): array
public static function dataTrueAndFalse(): array
{
return [
[true],
Expand Down Expand Up @@ -422,7 +422,7 @@ public function testIgnoreErrorNotFoundInPathExplicitReportUnmatched(): void
$this->assertSame('Ignored error pattern #Fail\.# in path ' . __DIR__ . '/data/not-existent-path.php was not matched in reported errors.', $result[0]);
}

public function dataIgnoreErrorInTraitUsingClassFilePath(): array
public static function dataIgnoreErrorInTraitUsingClassFilePath(): array
{
return [
[
Expand Down Expand Up @@ -672,7 +672,7 @@ private function runAnalyser(
new IgnoreErrorExtensionProvider(new NetteContainer(new Container([]))),
self::getContainer()->getByType(RuleErrorTransformer::class),
$this->createScopeFactory(
$this->createReflectionProvider(),
self::createReflectionProvider(),
self::getContainer()->getService('typeSpecifier'),
),
new LocalIgnoresProcessor(),
Expand Down Expand Up @@ -700,7 +700,7 @@ private function createAnalyser(): Analyser
]);
$collectorRegistry = new CollectorRegistry([]);

$reflectionProvider = $this->createReflectionProvider();
$reflectionProvider = self::createReflectionProvider();
$fileHelper = $this->getFileHelper();

$typeSpecifier = self::getContainer()->getService('typeSpecifier');
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/AnonymousClassNameRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AnonymousClassNameRuleTest extends RuleTestCase

protected function getRule(): Rule
{
$reflectionProvider = $this->createReflectionProvider();
$reflectionProvider = self::createReflectionProvider();
return new AnonymousClassNameRule($reflectionProvider);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/ArgumentsNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class ArgumentsNormalizerTest extends PHPStanTestCase
{

public function dataReorderValid(): iterable
public static function dataReorderValid(): iterable
{
yield [
[
Expand Down Expand Up @@ -298,7 +298,7 @@ public function testReorderValid(
}
}

public function dataReorderInvalid(): iterable
public static function dataReorderInvalid(): iterable
{
yield [
[
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/AssertStubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class AssertStubTest extends TypeInferenceTestCase
{

public function dataFileAsserts(): iterable
public static function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/assert-stub.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/assert-stub.php');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/Bug10922Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class Bug10922Test extends TypeInferenceTestCase
{

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

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/Bug10980Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Bug10980Test extends TypeInferenceTestCase
{

public function dataFileAsserts(): iterable
public static function dataFileAsserts(): iterable
{
yield from self::gatherAssertTypes(__DIR__ . '/data/bug-10980.php');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/Bug11009Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class Bug11009Test extends TypeInferenceTestCase
{

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

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Bug9307CallMethodsRuleTest extends RuleTestCase

protected function getRule(): Rule
{
$reflectionProvider = $this->createReflectionProvider();
$reflectionProvider = self::createReflectionProvider();
$ruleLevelHelper = new RuleLevelHelper($reflectionProvider, true, false, true, true, false, false, true);
return new CallMethodsRule(
new MethodCallCheck($reflectionProvider, $ruleLevelHelper, true, true),
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/Bug9307Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class Bug9307Test extends TypeInferenceTestCase
{

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

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/ClassConstantStubFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class ClassConstantStubFileTest extends TypeInferenceTestCase
{

public function dataFileAsserts(): iterable
public static function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/class-constant-stub-files.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/class-constant-stub-files.php');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class ConditionalReturnTypeFromMethodStubTest extends TypeInferenceTestCase
{

public function dataFileAsserts(): iterable
public static function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/conditional-return-type-stub.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/conditional-return-type-stub.php');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/DoNotPolluteScopeWithBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class DoNotPolluteScopeWithBlockTest extends TypeInferenceTestCase
{

public function dataFileAsserts(): iterable
public static function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/do-not-pollute-scope-with-block.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/do-not-pollute-scope-with-block.php');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class DoNotRememberPossiblyImpureFunctionValuesTest extends TypeInferenceTestCase
{

public function dataAsserts(): iterable
public static function dataAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/do-not-remember-possibly-impure-function-values.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/do-not-remember-possibly-impure-function-values.php');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
class DynamicMethodThrowTypeExtensionTest extends TypeInferenceTestCase
{

public function dataFileAsserts(): iterable
public static function dataFileAsserts(): iterable
{
if (PHP_VERSION_ID < 80000) {
return [];
}

yield from $this->gatherAssertTypes(__DIR__ . '/data/dynamic-method-throw-type-extension.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/dynamic-method-throw-type-extension-named-args-fixture.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/dynamic-method-throw-type-extension.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/dynamic-method-throw-type-extension-named-args-fixture.php');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
class DynamicReturnTypeExtensionTypeInferenceTest extends TypeInferenceTestCase
{

public function dataAsserts(): iterable
public static function dataAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/dynamic-method-return-types.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/dynamic-method-return-types.php');

if (PHP_VERSION_ID >= 80000) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/dynamic-method-return-types-named-args.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/dynamic-method-return-types-named-args.php');
}

yield from $this->gatherAssertTypes(__DIR__ . '/data/dynamic-method-return-compound-types.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7344.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7391b.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/dynamic-method-return-compound-types.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/bug-7344.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/bug-7391b.php');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testError(): void
$this->assertSame(10, $error->getLine());
}

public function dataValidIdentifier(): iterable
public static function dataValidIdentifier(): iterable
{
yield ['a'];
yield ['aa'];
Expand All @@ -37,7 +37,7 @@ public function testValidIdentifier(string $identifier): void
$this->assertTrue(Error::validateIdentifier($identifier));
}

public function dataInvalidIdentifier(): iterable
public static function dataInvalidIdentifier(): iterable
{
yield [''];
yield [' '];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class ExpressionTypeResolverExtensionTest extends TypeInferenceTestCase
{

public function dataFileAsserts(): iterable
public static function dataFileAsserts(): iterable
{
yield from self::gatherAssertTypes(__DIR__ . '/data/expression-type-resolver-extension.php');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/Ignore/IgnoreLexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class IgnoreLexerTest extends PHPStanTestCase
{

public function dataTokenize(): iterable
public static function dataTokenize(): iterable
{
yield [
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
class ImmediatelyCalledFunctionWithoutImplicitThrowTest extends TypeInferenceTestCase
{

public function dataFileAsserts(): iterable
public static function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/immediately-called-function-without-implicit-throw.php');
yield from self::gatherAssertTypes(__DIR__ . '/data/immediately-called-function-without-implicit-throw.php');
}

/**
Expand Down
Loading
Loading