Skip to content

Fix PHPUnit warnings, notices and deprecations - #1107

Open
lyrixx wants to merge 1 commit into
symfony:2.xfrom
lyrixx:fix-phpunit-warnings
Open

lyrixx wants to merge 1 commit into
symfony:2.xfrom
lyrixx:fix-phpunit-warnings

Conversation

@lyrixx

@lyrixx lyrixx commented Oct 14, 2026 •

Copy link
Copy Markdown
Member
Q A
Bug fix? no
New feature? no
Deprecations? no
Issues —
License MIT

The CI is currently red on PHP 8.1 to 8.4 (see #1106), and Fabbot fails on every PR that touches a test file. This PR fixes both, as well as the other issues reported by PHPUnit.

CI failure

stat(): stat failed for tests/Fixtures/symfony.lock
Triggered by: Symfony\Flex\Tests\FlexTest::testContribRecipeNotApprovedIsRemovedFromLock

Composer's Filesystem now calls stat() on the target file when writing it, through Silencer. PHPUnit only considers errors silenced with @ as suppressed, so it reports it, and failOnWarning makes the build fail. This test only checks the lock in memory, so it now uses new Lock('php://memory'), which JsonFile writes without touching the disk (supported since Composer 2.1).

Other PHPUnit issues

  • 3 PHPUnit deprecations, "Using with*() on a test stub has no effect": these mocks were turned into stubs when upgrading to PHPUnit 12, so their with() did not check anything anymore (ScriptExecutorTest::testMemoryLimit was not testing anything). They are mocks with expects($this->once()) again;
  • 2 PHPUnit notices, "No expectations were configured for the mock object": createStub() is used instead;
  • 1 PHP 8.5 deprecation, "Using null as an array offset": a useless blob was registered for a new file in RecipePatcherTest.

Tested with PHPUnit 10, 11 and 12.

Fabbot

Fabbot's PHP-CS-Fixer step adds : void to test methods (void_return from @Symfony:risky), while its next step requires test methods not to have a return type. The PHP-CS-Fixer config now disables void_return in tests/, like symfony/symfony does.

@lyrixx
lyrixx force-pushed the fix-phpunit-warnings branch from 64974f4 to c717182 Compare October 14, 2026 07:51
@lyrixx
lyrixx force-pushed the fix-phpunit-warnings branch from c717182 to a78351c Compare October 14, 2026 07:56

@GromNaN GromNaN left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @lyrixx

Comment thread .php-cs-fixer.dist.php
{
return [
// test methods must not have a return type
'void_return' => static fn (SplFileInfo $file) => !str_starts_with($file->getPathname(), __DIR__.'/tests/'),

@GromNaN GromNaN Oct 14, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fabbot's PHP-CS-Fixer step adds : void to test methods (void_return from @symfony:risky), while its next step requires test methods not to have a return type. The PHP-CS-Fixer config now disables void_return in tests/, like symfony/symfony does.

Great but complex fix! We have the same issue on other MakerBundle and MonologBundle.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FYI Twig and Symfony UX do not follow this rule anymore, ref: symfony-tools/fabbot#18

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah :/

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.

3 participants