Skip to content

[PHPUnit 9] Rename assertRegExp/assertNotRegExp to assertMatchesRegularExpression/assertDoesNotMatchRegularExpression on phpunit 90 set#666

Merged
TomasVotruba merged 1 commit intomainfrom
assert-reg-not-reg
Apr 1, 2026
Merged

[PHPUnit 9] Rename assertRegExp/assertNotRegExp to assertMatchesRegularExpression/assertDoesNotMatchRegularExpression on phpunit 90 set#666
TomasVotruba merged 1 commit intomainfrom
assert-reg-not-reg

Conversation

@samsonasik
Copy link
Copy Markdown
Member

ok, on phpunit v8, assertMatchesRegularExpression and assertDoesNotMatchRegularExpression doesn't exists yet, so needs to apply on phpunit 9 set.

Fixes rectorphp/rector#9714

…arExpression/assertDoesNotMatchRegularExpression
@samsonasik samsonasik changed the title [PHPUnit 9] Rename assertRegExp/assertNotRegExp to assertMatchesRegularExpression/assertDoesNotMatchRegularExpression [PHPUnit 9] Rename assertRegExp/assertNotRegExp to assertMatchesRegularExpression/assertDoesNotMatchRegularExpression on phpunit 90 set Apr 1, 2026
@samsonasik
Copy link
Copy Markdown
Member Author

Fixed 🎉 /cc @mvhirsch this should work with use phpunit 9 set so the assertRegExp will be renamed on version up to phpunit 9.

@samsonasik samsonasik requested a review from TomasVotruba April 1, 2026 05:33
@samsonasik
Copy link
Copy Markdown
Member Author

@TomasVotruba ready 👍

@TomasVotruba
Copy link
Copy Markdown
Member

👍

@TomasVotruba TomasVotruba merged commit 034f8a1 into main Apr 1, 2026
7 checks passed
@TomasVotruba TomasVotruba deleted the assert-reg-not-reg branch April 1, 2026 08:57
@mvhirsch
Copy link
Copy Markdown

mvhirsch commented Apr 1, 2026

Fixed 🎉 /cc @mvhirsch this should work with use phpunit 9 set so the assertRegExp will be renamed on version up to phpunit 9.

@samsonasik I'm using PHPUnit v10 that's why it failed in first place (rectorphp/rector#9714) 😊

Thank you!

@mvhirsch
Copy link
Copy Markdown

mvhirsch commented Apr 1, 2026

@samsonasik but I wonder how this is going to fix AssertRegExpRector when running standalone as showcased in my reproducer rectorphp/rector#9714?

I'm not using LevelSet updates, I'm just using this in my rector.dist.php:

->withPreparedSets(deadCode: true, codeQuality: true, typeDeclarations: true, privatization: true, earlyReturn: true, phpunitCodeQuality: true, doctrineCodeQuality: true, symfonyCodeQuality: true)

$node->name = new Identifier('assertRegExp');

@samsonasik
Copy link
Copy Markdown
Member Author

samsonasik commented Apr 1, 2026

You should can use ->withComposerBased(phpunit: true) or use ->withSets([\Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_90])

The target method only exists in phpunit 9+ so use the composer based or use the setlist to update the name.

@mvhirsch
Copy link
Copy Markdown

mvhirsch commented Apr 1, 2026

The target method only exists in phpunit 9+

The target method is assertMatchesRegularExpression, but AssertRegExpRector hard-codes assertRegExp which was removed in v10.

So if I understand you correctly, by using ->withPreparedSets(phpunitCodeQuality: true) I'm implicitely forced to use ->withComposerBased(phpunit: true) (or ->withSets(/* .. */)) in order to tell Rector to use a non-removed method name of PHPUnit since years? I remember a blog post of @TomasVotruba using sets all the time is just a waste of time: running Set upgrades just once, while running quality of life fixes all the time. Maybe that knowledge is outdated? 🤔

I'm not familiar with internals of Rector. Is it common to use the old/deprecated method names in Rectors and rector them with level-sets afterwards on second iteration?

@samsonasik
Copy link
Copy Markdown
Member Author

I think the AssertRegExpRector can be moved to phpunit 9 rule set, and refactor to change regex function assert to rename to assertMatchesRegularExpression, @mvhirsch could you create PR for it? Thank you.

@mvhirsch
Copy link
Copy Markdown

mvhirsch commented Apr 1, 2026

@mvhirsch could you create PR for it?

No, sorry.

@samsonasik
Copy link
Copy Markdown
Member Author

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.

Incorrect behavior of AssertRegExpRector

3 participants