Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run a single test case with PHPStorm since 8.4.1 #3904

Closed
codekandis opened this issue Oct 18, 2019 · 37 comments
Closed

Cannot run a single test case with PHPStorm since 8.4.1 #3904

codekandis opened this issue Oct 18, 2019 · 37 comments
Labels
type/bug Something is broken

Comments

@codekandis
Copy link

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)'.

@codekandis codekandis added type/backward-compatibility Something will be/is intentionally broken type/bug Something is broken labels Oct 18, 2019
@sebastianbergmann sebastianbergmann removed the type/backward-compatibility Something will be/is intentionally broken label Oct 18, 2019
@sebastianbergmann
Copy link
Owner

This issue tracker is for the Open Source project that provides the PHPUnit testing framework as well as the CLI tool for executing tests.

Please report issues with regards to IDE integration to the vendor of your IDE.

That being said, please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting and that does not involve PhpStorm, Vagrant, VirtualBox, etc.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

@sebastianbergmann sebastianbergmann added the status/waiting-for-feedback Waiting for feedback from original reporter label Oct 18, 2019
@codekandis codekandis reopened this Oct 18, 2019
@codekandis
Copy link
Author

codekandis commented Oct 18, 2019

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

/usr/bin/php /vagrant/vendor/phpunit/phpunit/phpunit --configuration /vagrant/phpunit.xml Vendor\\ProjectNamespace\\UnitTests\\AnotherTest /vagrant/tests/UnitTests/AnotherTest.php --teamcity

This would result in a Vagrant SSH call

vagrant ssh --command "/usr/bin/php /vagrant/vendor/phpunit/phpunit/phpunit --configuration /vagrant/phpunit.xml Vendor\\ProjectNamespace\\UnitTests\\AnotherTest /vagrant/tests/UnitTests/AnotherTest.php --teamcity"

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

/usr/bin/php vendor/phpunit/phpunit/phpunit --configuration phpunit.xml Vendor\ProjectNamespace\UnitTests\AnotherTest tests/UnitTests/AnotherTest.php --teamcity
PHPUnit version Test Result
<= 8.3.5 success
>= 8.4.0 success

double backslash namespace separators

/usr/bin/php vendor/phpunit/phpunit/phpunit --configuration phpunit.xml Vendor\\ProjectNamespace\\UnitTests\\AnotherTest tests/UnitTests/AnotherTest.php --teamcity
PHPUnit version Test Result
<= 8.3.5 success
>= 8.4.0 fatal error

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 between 8.3.5 or lower and 8.4.0 or higher.

@sebastianbergmann sebastianbergmann removed the status/waiting-for-feedback Waiting for feedback from original reporter label Oct 18, 2019
@sebastianbergmann
Copy link
Owner

@flow-control Is this yet another side effect of (y)our cleanup?

@realFlowControl
Copy link
Contributor

realFlowControl commented Oct 19, 2019

@sebastianbergmann could totally be. I will check this weekend if I can find the cause to this regression. There are so much special cases, time to get #3859 done 😉

@realFlowControl
Copy link
Contributor

@codekandis thanks for reporting the issue. Could you do me a favour and try the call without the class name and namespace?

/usr/bin/php vendor/phpunit/phpunit/phpunit --configuration phpunit.xml tests/UnitTests/AnotherTest.php --teamcity

@codekandis
Copy link
Author

@flow-control I confirm it works.

@realFlowControl
Copy link
Contributor

Hey @codekandis,

i tried to break this down to simple example, but could not reproduce.

Test.php

<?php declare(strict_types=1);
/*
 * This file is part of PHPUnit.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Test\Foo\Bar;

use PHPUnit\Framework\TestCase;

final class Test extends TestCase
{
    public function testOne(): void
    {
        $this->assertTrue(true);
    }
}

and then run phpunit with

$ ./phpunit Test\\Foo\\Bar\\Test Test.php

gives me

PHPUnit 8.4.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.3.10 with Xdebug 2.7.2
Configuration: /home/bowman/Work/flow-control/phpunit/phpunit.xml

.                                                                   1 / 1 (100%)

Time: 22 ms, Memory: 6.00 MB

OK (1 test, 1 assertion)

same with PHPUnit 8.4.1.

The only thing i could find is that if i misspell the namespace or class name it will not work in 8.4.0 to 8.4.1 due to #3889 (comment), which is already merged to 8.4 and may be released 8.4.2 i guess.

Could you double check that the namespace and class name is correct? Or could you create and paste here a minimal test file that reproduces the behavior you have experienced?

Kind regards
Florian

@dadrych
Copy link

dadrych commented Oct 22, 2019

Hey @flow-control ,

I reproduced this bug in my project. You have to use 4 times backslash as separator in cli.

Clone my project https://github.com/dadrych/phpunit_8_4_1_bug, run composer install and php vendor/phpunit/phpunit/phpunit --configuration=phpunit.xml --filter "/(::testFoo)( .*)?$/" App\\\\Tests\\\\FooTest tests/FooTest.php

@realFlowControl
Copy link
Contributor

realFlowControl commented Oct 22, 2019

Hey @dadrych,

you should use two backslashes, otherwise PHPUnit will get the string App\\Tests\\FooTest passed as the class name to look for, which is invalid. If you call it with just two backslashes, it will work:

$ php vendor/phpunit/phpunit/phpunit --configuration=phpunit.xml --filter "/(::testFoo)( .*)?$/" App\\Tests\\FooTest tests/FooTest.php
PHPUnit 8.4.1 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.3.10 with Xdebug 2.7.2
Configuration: /home/bowman/Work/phpunit_8_4_1_bug/phpunit.xml

.                                                                   1 / 1 (100%)

Time: 28 ms, Memory: 4.00 MB

OK (1 test, 1 assertion)

This is a feature that in < 8.4.0 the StandardTestSuiteLoader falling back to finding a class that extends the TestCase, if it can not find the class name you passed it via CLI. This feautre was removed in 8.4.0 and due to another regression it will be there again in 8.4.2 but finally be removed in 9. (at least to my knowledge, as i prepared the pull requests).

This #3889 (comment) explains it pretty well

/Flo

@jacksontong
Copy link

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

@dadrych
Copy link

dadrych commented Oct 22, 2019

Related to PHPStorm bug https://youtrack.jetbrains.com/issue/WI-49193

@codekandis
Copy link
Author

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.

Please take a look at the both scenarios I posted above. The are two commands I've run on the CLI of my standard /usr/bin/bash (not at the PHPStorm terminal). And the one with the double backslash does not work.

The focus has been on IDE independent and VM independent scenarios. So it's definitely not PHPStorm related.

@codekandis
Copy link
Author

@flow-control Try without using the filter.

@realFlowControl
Copy link
Contributor

Hey @codekandis,

i tried without the filter:

[bowman@localhost phpunit_8_4_1_bug]$ php vendor/phpunit/phpunit/phpunit --configuration=phpunit.xml App\\Tests\\FooTest tests/FooTest.php
PHPUnit 8.4.1 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.3.10 with Xdebug 2.7.2
Configuration: /tmp/phpunit_8_4_1_bug/phpunit.xml

.                                                                   1 / 1 (100%)

Time: 17 ms, Memory: 4.00 MB

OK (1 test, 1 assertion)

Works as expceted

Kind regards
Florian

@codekandis
Copy link
Author

Ok, so however. It's definitely not PHPStorm related.

@sebastianbergmann
Copy link
Owner

@codekandis Can you please try the current state of 8.4 (which will soon be released as 8.4.2)?

@codekandis
Copy link
Author

codekandis commented Oct 28, 2019

@sebastianbergmann I can confirm it's working in "phpunit/phpunit": "8.4.x-dev". If you want it tested explicitely with the GitHub Repo in branch 8.4 then tell me.

@sebastianbergmann
Copy link
Owner

@codekandis Thank you. PHPUnit 8.4.2 will be released later today.

@codekandis
Copy link
Author

@sebastianbergmann I updated PHPUnit and 8.4.2 works fine though. Thx.

@danijelk
Copy link

danijelk commented Oct 30, 2019

We have the oposite side-effect, where it doesn't work in 8.4.2 but works in <=8.4.1

8.4.2

/usr/local/bin/php /Volumes/c/development/pr/vendor/phpunit/phpunit/phpunit --configuration /Volumes/c/development/pr/phpunit.xml --filter "/(::make_sure_branding_works)( .*)?$/" Tests\UnitTest\Reports\GraphExport\GraphExportEmailTest /Volumes/c/development/pr/tests/UnitTests/Reports/GraphExport/GraphExportEmailTest.php --teamcity
PHPUnit 8.4.2 by Sebastian Bergmann and contributors.

Time: 114 ms, Memory: 14.00 MB

No tests executed!
Process finished with exit code 0

reverting to 8.4.1

/usr/local/bin/php /Volumes/c/development/pr/vendor/phpunit/phpunit/phpunit --configuration /Volumes/c/development/pr/phpunit.xml --filter "/::make_sure_branding_works( .*)?$/" Tests\UnitTest\Reports\GraphExport\GraphExportEmailTest /Volumes/c/development/pr/tests/UnitTests/Reports/GraphExport/GraphExportEmailTest.php --teamcity
PHPUnit 8.4.1 by Sebastian Bergmann and contributors.

Time: 629 ms, Memory: 30.00 MB

OK (1 test, 1 assertion)
Process finished with exit code 0

As I see it, the only diff is the added brackets on the filter option. Do I need to open a new ticket for this @flow-control?

@realFlowControl
Copy link
Contributor

Hey @danijelk,

this looks like another problem to me, because the test files seems to be found, but no tests in that file are matching the filter option. Could you try calling without the brackets in PHPUnit 8.4.2 and share a minimal self-contained example of a test class and how you call it?

/Flo

@danijelk
Copy link

Without brackets gives us some useful debug info

PHPUnit 8.4.2 by Sebastian Bergmann and contributors.


##teamcity[testCount count='1' flowId='7079']

##teamcity[testSuiteStarted name='Tests\UnitTest\Mail\MailTracking' locationHint='php_qn:///Volumes/c/development/pr/tests/UnitTests/Mail/MailTracking.php::\Tests\UnitTest\Mail\MailTracking' flowId='7079']

##teamcity[testStarted name='Warning' locationHint='php_qn:///Volumes/c/development/pr/vendor/phpunit/phpunit/src/Framework/WarningTestCase.php::\PHPUnit\Framework\WarningTestCase::Warning' flowId='7079']

##teamcity[testFailed name='Warning' message='No tests found in class "Tests\UnitTest\Mail\MailTracking".' details=' ' duration='5' flowId='7079']

##teamcity[testFinished name='Warning' duration='5' flowId='7079']

##teamcity[testSuiteFinished name='Tests\UnitTest\Mail\MailTracking' flowId='7079']


Time: 118 ms, Memory: 14.00 MB

I narrowed down the cause. I have 2 files, 1 test class (GraphExportEmailTest), and one class that other test classes extend (MailTracking) which extends TestCase. So the 8.4.2 seems to just scan the parent MailTracking class and not the actual test class itself as it did in 8.4.1.

Hope this helps. Else let me know and I'll try to make a self contained example if you cannot replicate with an extended class.

@sebastianbergmann
Copy link
Owner

@flow-control I think we have reached a point where we should at least consider to revert all changes we made here for PHPUnit 8.4 and then take the time needed to figure out the effects of these changes. Then we can decide on a case by case basis whether we want that effect (and (possibly) break BC) or not.

@realFlowControl
Copy link
Contributor

@sebastianbergmann i think so, too. I will prepare a pull request
@danijelk if you could create that testcase, that would be awesome, so i can add that to the tests and we are safe from this regression in the future ;-)
and out of curiosity, could you try calling your test on PHPUnit 8.4.2 with:

/usr/local/bin/php /Volumes/c/development/pr/vendor/phpunit/phpunit/phpunit --configuration /Volumes/c/development/pr/phpunit.xml --filter "/(::make_sure_branding_works)( .*)?$/" Tests\\UnitTest\\Reports\\GraphExport\\GraphExportEmailTest /Volumes/c/development/pr/tests/UnitTests/Reports/GraphExport/GraphExportEmailTest.php --teamcity

I just only changed to using two backslashes (one is for escaping the other). To me it looks like there is another fallback somewhere after the StandardSuiteLoader and it would help me better understand that problem.
Thank you.

@danijelk
Copy link

@sebastianbergmann i think so, too. I will prepare a pull request
@danijelk if you could create that testcase, that would be awesome, so i can add that to the tests and we are safe from this regression in the future ;-)
and out of curiosity, could you try calling your test on PHPUnit 8.4.2 with:

/usr/local/bin/php /Volumes/c/development/pr/vendor/phpunit/phpunit/phpunit --configuration /Volumes/c/development/pr/phpunit.xml --filter "/(::make_sure_branding_works)( .*)?$/" Tests\\UnitTest\\Reports\\GraphExport\\GraphExportEmailTest /Volumes/c/development/pr/tests/UnitTests/Reports/GraphExport/GraphExportEmailTest.php --teamcity

I just only changed to using two backslashes (one is for escaping the other). To me it looks like there is another fallback somewhere after the StandardSuiteLoader and it would help me better understand that problem.
Thank you.

Same issue with your command.

Here is the repo for the failed test https://github.com/danijelk/phpunit_8_4_2_bug

Let me know if there is anything more I can do.

@realFlowControl
Copy link
Contributor

Thanks very much, i found out why this is not working in 8.4.2, i have yet to find out why it was working in < 8.4.1, as it shouldn't have worked 😉

One hint i have found while debugging this: on the bash or similar terminals, you need to use two backslashes, because the backslash is the escape character. If you call PHPUnit with only one backslash on the cli, what the bash passes along to PHPUnit is string(15) "AppTestsFooTest". If you use App\\Tests\\FooTest on bash it will result to string(17) "App\Tests\FooTest". That PHPUnit is not using this class is another story 😉

Thanks again, i will add that example to the test pipeline, while reverting the cleanup.

realFlowControl added a commit to realFlowControl/phpunit that referenced this issue Oct 30, 2019
realFlowControl added a commit to realFlowControl/phpunit that referenced this issue Oct 30, 2019
realFlowControl added a commit to realFlowControl/phpunit that referenced this issue Oct 31, 2019
@kczereczon
Copy link

kczereczon commented Feb 8, 2020

I have issue with PHPStorm and WSL:

PHPStrom execute this command:

/usr/bin/php /mnt/c/projects/wivest/vendor/phpunit/phpunit/phpunit --configuration /mnt/c/projects/wivest/phpunit.xml --filter Tests\\Feature\\ExampleTest /mnt/c/projects/wivest/tests/Feature/ExampleTest.php --teamcity --cache-result-file=/mnt/c/projects/wivest/.phpunit.result.cache

After that I have result:

PHPUnit 8.5.2 by Sebastian Bergmann and contributors.

Time: 252 ms, Memory: 6.00 MB

No tests executed!
Process finished with exit code 0

But when I remove --filter everything work

@realFlowControl
Copy link
Contributor

Hey there,

could you provide that test file?

Kind regards
Florian

@kczereczon
Copy link

kczereczon commented Feb 8, 2020

@flow-control

This is simple Laravel's example test:

<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
}

I've used vscode before and Better PHPUnit generate this command.

/home/kczereczon/projects/wivest/vendor/bin/phpunit /home/kczereczon/projects/wivest/tests/Feature/ExampleTest.php --filter '^.*::testBasicTest( .*)?$' 

And this commad works properly.

@mfn
Copy link

mfn commented Feb 8, 2020

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.

@kczereczon
Copy link

@mfn Yes, I've just downloaded EAP version and it works perfectly.

@iranianpep
Copy link

I've had the same issue. It's working with version PhpStorm 2019.3.3 + PHPUnit 8.5.2 but not 9.0.1. I haven't tried EAP version though. It also works if I run the command directly in CLI without the filter.

@oniice
Copy link

oniice commented Mar 6, 2020

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.

@backstageel
Copy link

@oniice same issue here with with PHPStorm 2019.3.3 and PHPUnit 9.0.1.

@realFlowControl
Copy link
Contributor

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 PHPUnit v8.5 was removed in PHPUnit v9.0. If you/they omit that argument, everything should work as expected.

/Flo

@oniice
Copy link

oniice commented Mar 17, 2020

Thanks @flow-control! Glad it's confirmed as a PHPStorm issue - they always seem a few steps behind world libs 🤦🏻‍♂️

Will get on that :)

@realFlowControl
Copy link
Contributor

Hi there,

I found a ticket for this in their issue tracker. Looks like the upcoming 2020.1 release will fix this.

/Flo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

No branches or pull requests