Skip to content

Conversation

@GromNaN
Copy link
Member

@GromNaN GromNaN commented Jan 7, 2026

  • Run tests with PHPUnit 11
  • Add PHPUnit attributes, in addition to annotations

Making all the data providers static require to make many other methods static in the tests directory.

The main point is the MakerTestCase that is part of the API and is extended in other projects. Creating a new class is the only way to change abstract methods from non-static to static in a BC way.

self::assertEquals(1, substr_count($haystack, $needle), \sprintf('Found more than %d occurrences of "%s" in "%s"', $count, $needle, $haystack));
}

private static function getMakerInstance(string $makerClass): MakerInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be static. The maker instance should be created inside the test, so that it is coming from the containing booted for that test.

Data providers are executed before all tests, so all your cases are currently using the same container instance, breaking test isolation.

I think the retrieval of the maker instance from the service locator (introduced in #1771) should be moved to the test itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an excellent point. By delaying the retrieval of the maker in the test body, there are far fewer methods that need to be made static. It's no longer necessary to create a new class for MakerTestCase.

@GromNaN GromNaN force-pushed the phpunit-11 branch 2 times, most recently from 3688847 to 02dbbfd Compare January 9, 2026 21:22
use Symfony\Component\Process\Process;

/**
* @method static iterable<array{0: MakerTestDetails}> getTestDetails()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By removing the abstract method declaration, moved to a PHPDoc, I avoid the breaking change.
We have have to be careful to not add the abstract static method declaration in 1.x, but only in 2.x.

*/
protected function createMakerTest(): MakerTestDetails
{
trigger_deprecation('symfony/maker-bundle', '1.66.0', 'The "%s()" method is deprecated. Use "self::newMakerTest()" instead.', __METHOD__, self::class);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is renamed because it needs to be static. We don't want to introduce a breaking change in case this method is overridden.

* @return void
*/
protected function assertContainsCount(string $needle, string $haystack, int $count)
protected static function assertContainsCount(string $needle, string $haystack, int $count)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change, but there is no reason to override this method. And all assertion methods are usually static.

self::assertEquals(1, substr_count($haystack, $needle), \sprintf('Found more than %d occurrences of "%s" in "%s"', $count, $needle, $haystack));
}

private static function getMakerInstance(string $makerClass): MakerInterface
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an excellent point. By delaying the retrieval of the maker in the test body, there are far fewer methods that need to be made static. It's no longer necessary to create a new class for MakerTestCase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants