You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey everyone! Thank you so much for all your work on Patchwork. I use it for most of the tests I write, either through https://github.com/10up/wp_mock or using Patchwork's API directly.
Recently I started experimenting with the new-keyword-redefinable and ran into an issue. It seems that Patchwork is unable to resolve some namespaces correctly and as a result trying to run any test file fails with something like:
Fatal error: Uncaught ReflectionException: Class "PHPUnit\TextUI\Timer" does not exist in vendor/antecedent/patchwork/src/CallRerouting.php:597
I was able to reproduce that particular error on a fresh project using Patchwork and PHPUnit only. You can follow these steps to give it a try:
Run vendor/bin/phpunit --bootstrap=tests/bootstrap.php tests
You should see the error now
Then, if you change new-keyword-redefinable to false and run the phpunit command again, tests run normally.
The correct namespace for the Timer class is SebastianBergmann\Timer\Timer. PHPUnit\TextUI is the namespace of the TestRunner class, the one that instantiates a Timer.
I did some debugging and I think it all happens in the resolveName() function:
Thank you; it seems that you got to the root of the issue! This seems to be related to #120#104. Since that update, qualified names now come as single tokens, breaking the resolution mechanism that you described.
Hey everyone! Thank you so much for all your work on Patchwork. I use it for most of the tests I write, either through https://github.com/10up/wp_mock or using Patchwork's API directly.
Recently I started experimenting with the
new-keyword-redefinable
and ran into an issue. It seems that Patchwork is unable to resolve some namespaces correctly and as a result trying to run any test file fails with something like:I was able to reproduce that particular error on a fresh project using Patchwork and PHPUnit only. You can follow these steps to give it a try:
composer install
vendor/bin/phpunit --bootstrap=tests/bootstrap.php tests
Then, if you change
new-keyword-redefinable
tofalse
and run thephpunit
command again, tests run normally.The correct namespace for the
Timer
class isSebastianBergmann\Timer\Timer
.PHPUnit\TextUI
is the namespace of theTestRunner
class, the one that instantiates aTimer
.I did some debugging and I think it all happens in the
resolveName()
function:patchwork/src/CodeManipulation/Actions/Namespaces.php
Line 31 in 36e656b
At that point I can see
SebastianBergmann\Timer\Timer
in the$uses
array:However, the
resolveName()
function has no way to retrieve that value. Should the array have[Timer] => SebastianBergmann\Timer\Timer
instead?If that's the case then maybe the problem is somewhere in
collectUseDeclarations()
but I didn't get to explore those functions.I'm running PHP 8.1. Please let me know if I can provide any additional information.
The text was updated successfully, but these errors were encountered: