phpunit: Cannot run a single test case with PHPStorm since 8.4.1
Q | A |
---|---|
PHPUnit version | 8.4.1 |
PHP version | PHP 7.3.9-1~deb10u1 (cli) (built: Sep 18 2019 10:33:23) ( NTS ) |
PHPStorm version | PhpStorm 2019.2.3, Build #PS-192.6817.20, built on September 25, 2019 |
Installation Method | Composer |
Summary
I’m using the mentioned PHP / PHPUnit setup in a Vagrant VirtualBox VM. Since PHPUnit 8.4.1 I cannot run a single test case from the context menu of PHPStorm without a fatal error.
Previous Behavior
Until 8.4.0 it was possible to run single test cases.
Current Behavior
Testing started at 9:27 PM ...
[vagrant:///path/to/project]:/usr/bin/php /vagrant/vendor/phpunit/phpunit/phpunit --configuration /vagrant/build/phpunit.xml Vendor\\ProjectNamespace\\Tests\\UnitTests\\SomeClassTest /vagrant/tests/UnitTests/SomeClassTest.php --teamcity
Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'Vendor\\ProjectNamespace\\Tests\\UnitTests\\SomeClassTest' could not be found in '/vagrant/tests/UnitTests/SomeClassTest.php'. in /vagrant/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php on line 69
PHPUnit\Runner\Exception: Class 'Vendor\\ProjectNamespace\\Tests\\UnitTests\\SomeClassTest' could not be found in '/vagrant/tests/UnitTests/SomeClassTest.php'. in /vagrant/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php on line 69
PHP Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'Vendor\\ProjectNamespace\\Tests\\UnitTests\\SomeClassTest' could not be found in '/vagrant/tests/UnitTests/SomeClassTest.php'. in /vagrant/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php:69
Stack trace:
Call Stack:
0.0001 398208 1. {main}() /vagrant/vendor/phpunit/phpunit/phpunit:0
0.0065 851376 2. PHPUnit\TextUI\Command::main() /vagrant/vendor/phpunit/phpunit/phpunit:61
#0 /vagrant/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(141): PHPUnit\Runner\StandardTestSuiteLoader->load('Vendor\\\\Pro...', '/vagrant/tests/...')
0.0065 851488 3. PHPUnit\TextUI\Command->run() /vagrant/vendor/phpunit/phpunit/src/TextUI/Command.php:159
#1 /vagrant/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(101): PHPUnit\Runner\BaseTestRunner->loadSuiteClass('Vendor\\\\Pro...', '/vagrant/tests/...')
0.0152 1546696 4. PHPUnit\TextUI\TestRunner->getTest() /vagrant/vendor/phpunit/phpunit/src/TextUI/Command.php:177
#2 /vagrant/vendor/phpunit/phpunit/src/TextUI/Command.php(177): PHPUnit\Runner\BaseTestRunner->getTest('Vendor\\\\Pro...', '/vagrant/tests/...', Array)
0.0152 1546696 5. PHPUnit\TextUI\TestRunner->loadSuiteClass() /vagrant/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:101
#3 /vagrant/vendor/phpunit/phpunit/src/TextUI/Command.php(159): PHPUnit\TextUI\Command->run(Array, true)
0.0165 1558304 6. PHPUnit\Runner\StandardTestSuiteLoader->load() /vagrant/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:141
#4 /vagrant/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main()
#5 {main}
thrown in /vagrant/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php on line 69
Process finished with exit code 255
Running all test cases from a folder context menu or running a single test from inside a test case are not affected. They still run as expected.
How to reproduce
Install PHPUnit 8.4.1 and select Run 'SomeClassTest (PHPUnit)'
.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 37 (16 by maintainers)
Commits related to this issue
- adds tests for regression #3904 — committed to realFlowControl/phpunit by realFlowControl 5 years ago
- adds tests for regression #3904 — committed to realFlowControl/phpunit by realFlowControl 5 years ago
- Add tests for regression #3904 — committed to realFlowControl/phpunit by realFlowControl 5 years ago
- Add tests for regression #3904 — committed to sebastianbergmann/phpunit by realFlowControl 5 years ago
- Add tests for regression #3904 — committed to sebastianbergmann/phpunit by realFlowControl 5 years ago
Hey @iranianpep, @oniice, @backstageel,
this is a problem with how PHPStorm executes PHPUnit, could you open a bug report with PHPStorm? If you do so, it would be nice if you post the link to the ticket here.
The problem is as @oniice spotted correct, that the class argument
Tests\HelperTest
was deprecated in PHPUnitv8.5
was removed in PHPUnitv9.0
. If you/they omit that argument, everything should work as expected./Flo
@codekandis Thank you. PHPUnit 8.4.2 will be released later today.
Related to PHPStorm bug https://youtrack.jetbrains.com/issue/WI-49193
Hi there,
I found a ticket for this in their issue tracker. Looks like the upcoming
2020.1
release will fix this./Flo
Thanks @flow-control! Glad it’s confirmed as a PHPStorm issue - they always seem a few steps behind world libs 🤦🏻♂️
Will get on that 😃
Also experiencing a similar issue with PHPStorm 2019.3.3 and PHPUnit 9.0.1.
Running a single method/class test appears to run this command
/usr/local/bin/php /Users/fredmyerscough/Code/laravel-sub-requests/vendor/phpunit/phpunit/phpunit --configuration /Users/fredmyerscough/Code/laravel-sub-requests/phpunit.xml --filter "/(::testHelperThrowsExceptionWithInvalidVerb)( .*)?$/" Tests\HelperTest /Users/fredmyerscough/Code/laravel-sub-requests/tests/HelperTest.php
Which fails saying
Cannot open file "Tests\HelperTest".
But manually running it as
/usr/local/bin/php /Users/fredmyerscough/Code/laravel-sub-requests/vendor/phpunit/phpunit/phpunit --configuration /Users/fredmyerscough/Code/laravel-sub-requests/phpunit.xml --filter "/(::testHelperThrowsExceptionWithInvalidVerb)( .*)?$/"
Seems to pass.
I have dropped back down to PHPUnit 8.5.2 and PHPStorm can run single method and class tests fine, and it still runs the same command.
I’ve had the same issue. It’s working with version PhpStorm
2019.3.3
+ PHPUnit8.5.2
but not9.0.1
. I haven’t tried EAP version though. It also works if I run the command directly in CLI without the filter.AFAIK this is fixed in the latest PhpStorm EAP version. I’m running it and it works, it didn’t with the latest 2019.3* version before.
I think it only happen with PHPStorm, I have same issue when I run my test from PHPStorm but when I copy the command to terminal it works fine.
[sftp://vagrant@yogapay.test:22]:/usr/bin/php /home/vagrant/code/yoga-pay/vendor/phpunit/phpunit/phpunit --configuration /home/vagrant/code/yoga-pay/phpunit.xml --filter "/(::test_nova_url)( .*)?$/" Tests\\Unit\\HelperTest /home/vagrant/code/yoga-pay/tests/Unit/HelperTest.php --teamcity
@flow-control I confirm it works.
Attached test scenario: phpunit-841-issue-testcase.zip
First I have to correct the version constraint: The error occurs since PHPUnit 8.4.0.
PHPStorm runs
This would result in a Vagrant SSH call
After some testing I focused on the escaped backslash namespace separator and I had minimized the tests to the following two IDE and Vagrant independent scenarios.
single backslash namespace separators
double backslash namespace separators
Conclusion
With the tests above it’s obvious now since PHPUnit 8.4.0 the esacped backslash namespace separators are interpreted differently.
To reproduce my tests change the PHPUnit version in the
composer.json
between8.3.5
or lower and8.4.0
or higher.