-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Can't run non-first test class in test file #4030
Comments
@flow-control Could this be related to the changes you made? |
Might be, though i did not (at least not on purpose) change something on how the |
I tried in various versions between $ php phpunit --no-configuration --filter TestSecond MyTests.php
PHPUnit 8.1.6 by Sebastian Bergmann and contributors.
Time: 16 ms, Memory: 6.00 MB
No tests executed! |
This is what happens in $ php phpunit --no-configuration --filter TestSecond MyTests.php
Class 'MyTests' could not be found in '/home/bowman/Work/flow-control/phpunit/MyTests.php'. |
I found out another info. It has only worked this way in the past, by using the class name in CLI: $ php phpunit --no-configuration --filter TestSecond TestSecond MyTests.php This feature has been depreacted in @sebastianbergmann I think i could make this work technically, by "just" passing the |
@flow-control but according to #3860 (comment) and https://phpunit.readthedocs.io/en/8.5/textui.html#textui-examples-filter-patterns |
@isfedorov exactly, but the difference is in that case, that the class in the file had the exact same name as the filename (without the The "problem" is, that the suite loader does not load the test class (as there is no test class in that file named OTOH what is working is the following scenario. $ ls test/
MyTests.php
$ php phpunit --no-configuration --filter TestSecond --test-suffix Tests.php test/
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 17 ms, Memory: 6.00 MB
OK (1 test, 1 assertion) You only need the |
TBH, there should only ever be one (test) class declared in a file. I think I will deprecate support for multiple test case classes declared in a source file in PHPUnit 9 and remove support for it in PHPUnit 10. This should make things even simpler. |
In ./phpunit --no-configuration MyTests.php This will only succeed if there is a class named |
Even better. :) |
Hi all, we have applied the suggestion with In the case when test class is named following the conventions ( https://phpunit.readthedocs.io/en/9.0/writing-tests-for-phpunit.html) and located in the file named as FirstTest.php:
Output of the following command is still "No tests executed!"
Could you please advise me on how I can avoid such behavior. |
Hey @bzixilu, I assume the /Flo |
@flow-control sorry, forgot to mention it, I've tried a few PHPUnit versions: 8.5.2, 7.5.0, 9.0.0 |
Hi again @bzixilu, prior to PHPUnit /usr/bin/php ../vendor/phpunit/phpunit/phpunit --no-configuration --filter "/(SecondTest::testTwo)( .*)?$/" FirstTest.php This should work up to /usr/bin/php ../vendor/phpunit/phpunit/phpunit --no-configuration --filter "/(SecondTest::testTwo)( .*)?$/" /path/to/test/2/ (this is using another test case class loader which still uses this fallback) For PHPUnit So your best bet is to refactor your test suite to have only on test case class per file. Hope I could help /Flo |
I see the problem ... I will check later today, maybe i find something to help you with this. But just as a reminder: the possibility for multiple test case classes in a single file and naming the test case class different from the filename is/will be deprecated and will be removed vor |
@flow-control Thank you for the support! |
Hey @bzixilu, I have looked it up and the only way to have this working was prior to PHPUnit When you change the <?php
use PHPUnit\Framework\TestCase;
class FooFirstTest extends TestCase
{
public function testOne()
{
static::assertTrue(true);
}
}
class SecondTest extends TestCase
{
public function testTwo()
{
$this->assertTrue(false);
}
} then your command works as expected: $ ./phpunit --no-configuration --filter "/(SecondTest::testTwo)( .*)?$/" --test-suffix FirstTest.php 2
PHPUnit 8.2.5 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 38 ms, Memory: 6.00 MB
There was 1 failure:
1) SecondTest::testTwo
Failed asserting that false is true.
/home/bowman/Work/flowcontrol/phpunit/2/FirstTest.php:17
FAILURES!
Tests: 1, Assertions: 1, Failures: 1. With the branch $ ./phpunit --no-configuration --filter "/(SecondTest::testTwo)( .*)?$/" --test-suffix FirstTest.php 2
PHPUnit 9.0-gb87137081 by Sebastian Bergmann and contributors.
Warning: Test case class not matching filename is deprecated
in /home/bowman/Work/flowcontrol/phpunit/2/FirstTest.php
class name was 'FooFirstTest', expected 'FirstTest', see #4105
Warning: Test case class not matching filename is deprecated
in /home/bowman/Work/flowcontrol/phpunit/2/FirstTest.php
class name was 'SecondTest', expected 'FirstTest', see #4105
Warning: Multiple test case classes per file is deprecated
in /home/bowman/Work/flowcontrol/phpunit/2/FirstTest.php, see #4105
F 1 / 1 (100%)
Time: 45 ms, Memory: 6.00 MB
There was 1 failure:
1) SecondTest::testTwo
Failed asserting that false is true.
/home/bowman/Work/flowcontrol/phpunit/2/FirstTest.php:17
FAILURES!
Tests: 1, Assertions: 1, Failures: 1. So, I know you can't change it, but this means, that as stated in the ChangeLog-9.0.md it is from PHPUnit With PHPUnit @sebastianbergmann should we do something about this? This not a bug, but the only trick that allowed to run the test case /Flo |
I do not think that there is anything we should do here but better communicate what was deprecated in PHPUnit 8.5, what was removed in PHPUnit 9.0, what is deprecated now, and what will be removed in PHPUnit 10.0. |
Please give me some hints about "Test case class not matching filename is deprecated" This does not make sence for me for a test tool. |
Summary
No tests executed when try to run non-first test class in a test file
Current behavior
"No tests executed!" result message
How to reproduce
Create file MyTest.php with several test classes like
Run command from cli
/usr/bin/php vendor/phpunit/phpunit/phpunit --no-configuration --filter TestSecond MyTests.php
Expected behavior
TestSecond test should be run
The text was updated successfully, but these errors were encountered: