Cannot run PHPUnit Files due to --filter CLI argument

Hello,

1) When i try to run a PhpUnit Testfile with PhpStorm 2023.1.4 it generates the following command:

/bin/php -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host=127.0.0.1 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/phpunit --no-configuration --filter php\\models\\tests\\AddressTest --test-suffix AddressTest.php /home/gg/PhpStormProjects/MemberManagement/php/models/tests --teamcity --cache-result-file=/home/gg/PhpStormProjects/MemberManagement/.phpunit.result.cache

Which results in the follow error:

PHPUnit 10.3-dev by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.7

 

An error occurred inside PHPUnit.

Message:  preg_match(): Delimiter must not be alphanumeric, backslash, or NUL
Location: /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:68

#0 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/src/TextUI/Application.php(176): PHPUnit\TextUI\TestRunner->run()
#1 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/phpunit(99): PHPUnit\TextUI\Application->run()
#2 {main}

Caused by: /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/src/Runner/Filter/NameFilterIterator.php:75

#0 [internal function]: error_handler()
#1 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/src/Runner/Filter/NameFilterIterator.php(75): preg_match()
#2 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/src/Runner/Filter/NameFilterIterator.php(41): PHPUnit\Runner\Filter\NameFilterIterator->setFilter()
#3 [internal function]: PHPUnit\Runner\Filter\NameFilterIterator->__construct()
#4 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/src/Runner/Filter/Factory.php(53): ReflectionClass->newInstance()
#5 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/src/Framework/TestSuite.php(386): PHPUnit\Runner\Filter\Factory->factory()
#6 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/src/Framework/TestSuite.php(396): PHPUnit\Framework\TestSuite->getIterator()
#7 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/src/TextUI/TestSuiteFilterProcessor.php(81): PHPUnit\Framework\TestSuite->injectFilter()
#8 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(57): PHPUnit\TextUI\TestSuiteFilterProcessor->process()
#9 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/src/TextUI/Application.php(176): PHPUnit\TextUI\TestRunner->run()
#10 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/phpunit(99): PHPUnit\TextUI\Application->run()
#11 {main}

Process finished with exit code 255

2) Executed on the command line i get the same result.

3) However, if i mark a Single Test and execute it, it produces the following command:

/bin/php /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/phpunit --no-configuration --filter "/(php\\models\\tests\\AddressTest::testgetFullCity)( .*)?$/" --test-suffix AddressTest.php /home/gg/PhpStormProjects/MemberManagement/php/models/tests --teamcity --cache-result-file=/home/gg/PhpStormProjects/MemberManagement/.phpunit.result.cache

which runs as expected.

4) When i modify the first generated command to this one (remove the --filter) and run it in the command line:

/bin/php -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host=127.0.0.1 /home/gg/PhpStormProjects/MemberManagement/vendor/phpunit/phpunit/phpunit --no-configuration --test-suffix AddressTest.php /home/gg/PhpStormProjects/MemberManagement/php/models/tests --teamcity --cache-result-file=/home/gg/PhpStormProjects/MemberManagement/.phpunit.result.cache

...it works as expected and the whole testfile is tested on the command line.

5) What am i doing wrong and how am i supposed run complete testfiles in PhpStorm? Any advice is highly appreciated.

0
2 comments

Is there chance you are using a custom error handler? There is a similar ticket on YouTrack:
https://youtrack.jetbrains.com/issue/WI-71499

If this is the case, could you please try to install a freshly released PhpStorm 2023.2 and check if this issue is also reproducible there? 

0

Thanks for the quick response!

Yes you are right - i am using a custom error handler. When i disable the custom error handler, the test file runs through. Single tests keep working

Unfortunately a upgrade to 2023.2 does not resolve the issue (also my 30 day evaluation license is only valid for 2023.1.*). Yet still a disabled custom error handler solves it.

I may disable the custom error handler for now. I would love that issue to be resolved in an future release and use PhpStorm in my company. For further evaluation i can use the work-around of a disabled custom error handler.

Thank you Vasilly!

0

Please sign in to leave a comment.