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
Class not found #3889
Comments
Thank you for your report. Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting. Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue. |
Also please try with PHPUnit 8.4.1 and see if your problem still exists. |
EDIT: Found the issue. The reason is that the test class name did not exactly match the file name in which the test class is written. This mismatch was allowed in earlier versions, but causes a class load error in Not an issue with PHPUnit really, although behavior has changed. Original post below; Same problem for me with Only backtrace for now, will look into it later.
|
I have the same issue going from In 8.3.5 I could run a test directly with PHP Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'Class.test.php' could not be found in '/project/path/tests/path/to/Class.test.php'. in /project/path/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php:69
Stack trace:
#0 /project/path/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(141): PHPUnit\Runner\StandardTestSuiteLoader->load('Class.t...', '/project/path/dir...')
#1 /project/path/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(101): PHPUnit\Runner\BaseTestRunner->loadSuiteClass('tests/client-lm...', '/project/path/dir...')
#2 /project/path/vendor/phpunit/phpunit/src/TextUI/Command.php(177): PHPUnit\Runner\BaseTestRunner->getTest('tests/client-lm...', '/project/path/dir...', Array)
#3 /project/path/vendor/phpunit/phpunit/src/TextUI/Command.php(159): PHPUnit\TextUI\Command->run(Array, true)
#4 /project/path/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\ in /project/path/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php on line 69
Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'Class.test.php' could not be found in '/project/path/tests/path/to/Class.test.php'. in /project/path/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php:69
Stack trace:
#0 /project/path/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(141): PHPUnit\Runner\StandardTestSuiteLoader->load('Class.t...', '/project/path/dir...')
#1 /project/path/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(101): PHPUnit\Runner\BaseTestRunner->loadSuiteClass('tests/client-lm...', '/project/path/dir...')
#2 /project/path/vendor/phpunit/phpunit/src/TextUI/Command.php(177): PHPUnit\Runner\BaseTestRunner->getTest('tests/client-lm...', '/project/path/dir...', Array)
#3 /project/path/vendor/phpunit/phpunit/src/TextUI/Command.php(159): PHPUnit\TextUI\Command->run(Array, true)
#4 /project/path/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\ in /project/path/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php on line 69 |
An example for a file <?php
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
{
/**
* @test
*/
public function my_sample_test()
{
$this->assertTrue(true);
}
} and the testsuite would be defined in <testsuite name="sample">
<directory suffix=".test.php">./tests</directory>
</testsuite> I use this approach as I sometimes need php includes in the tests folders and don't want them to be considered tests |
File <?
class LoadTest extends PHPUnit\Framework\TestCase
{
// Doesn't matter, will not be loaded to begin with
} Obviously class and file name doesnt't match, but before it ran anyway. @flow-control |
I fixed that in #3891 by restoring a few lines i removed in #3830 I like to add, that naming your test class If the runner can not find a class with the name of the file (minus suffix) it checks all classes loaded from the given test file for not being abstract and being a subclass of |
@flow-control Can you please send a pull request that reverts #3891 (after I have merged it)? I would like to schedule that for PHPUnit 9 as I agree that this should not be supported. |
Thank you!
Understood
@sebastianbergmann does this mean I will be able to continue using a |
Hey @dmlogic, calling the test directly as you stated above with Calling the test file directly as you did will not be possible when reverting this pull request in version 9. What's your opinion on that @sebastianbergmann? /Flo |
Sounds like I need to move from thanks for your help. |
is this described in the breaking changes? I could not find it and we will have many test classes to rename (especially in older tests before namespaces were introduced, where for example we would have a class named (not a problem, but it would be nice to mention it in the breaking changes if it is not already the case) |
Hey there 🖖 this is stated in https://github.com/sebastianbergmann/phpunit/blob/9.1.0/ChangeLog-9.1.md at the bottom:
Maybe this could help you prepare for PHPUnit 10: https://github.com/rectorphp/rector/blob/master/docs/rector_rules_overview.md#pseudonamespacetonamespacerecto Hope I could help /Flo |
thanks a lot Flo, it did help. (I looked at the 9.0 changelog on the website and tried to find more on master, I did see a changelog for 8.5, 9.2 and 9.3, but not 9.1, and did not think to look at the tags) |
Hi, was planning our upgrade to 9.5.x when I saw these 2 lovely details in the PHP 9.1 release notes:
Basically this is going to "destroy" us. We both use a custom loader and custom naming. I'm sure there are good reasons to start adding all those restrictions, but they, specially together, will kill any other naming schema completely. For example, we call to our files: And we know where our tests are because the plugin defines it (and our custom loader knows about the structure). With this changes we are forced to call to the files like the testcases, which is horrible and also, all our custom loader abilities are gone. We "only" have 1146 test cases in core (files to rename that will make specially hard to backport things), but also have some good hundreds of plugins from 3rd parties, each one with their own test cases following the same schema. And everything has worked perfectly since we switched to PHPUnit, some good years ago. Note I'm not asking to reconsider the decision to increase the restrictions (although I must confess that I don't understand the "need" to do so) but, at very least, make it more prominent in current documentation, because phpunit 10 will bee too late for such a surprising and drastic change! Just my 2 cents, ciao :-) |
Summary
Trying to start test, got 'Process finished with exit code 0' with trace:
Class 'Tests\Service\ClassTest' could not be found in '/tests/Service/ClassTest.php'
Previous Behavior
It works in 8.3.5
Current Behavior
It's broken it 8.4.0
How to reproduce
Run test
The text was updated successfully, but these errors were encountered: