| Q | A
| --------------------| ---------------
| PHPUnit version | 5.7.21
| PHP version | 5.6.30
| Installation Method | Composer
Hi,
I have found a strange behavior in PHPUnit when I don't write my class name correctly. I think it's related to #731
Situation:
TestBase.php
file that contains a TestBase
class that does not end with _Test_ so that shouldn't be calledChildTest.php
file that contains a MyTest
class (wrong name then). When I do phpunit tests/
I get : No tests found in class "Edyan\MyPackage\Tests\TestBase"
and my tests contained in the class are well executed.If I set TestBase
as abstract
: no problem
If I rename MyTest
to ChildTest
: no problem
Any idea ?
Thanks
Since you're using composer, it uses a PSR-0/4 autoloader. According to PSR standard, a mismatching between class and file name is an error.
Thanks for your answer,
Does that mean that PHPUnit shouldn't load a class that has a different name than the file ? With composer if you try to load the class ABC
located into CDE.php
you'll get an error.
Thanks
Base classes such as your TestBase
class that do not contain any tests of their own should be declared abstract
. Then PHPUnit does not try to run their non-existant tests.
That's clear, thanks for the best practice
Most helpful comment
Base classes such as your
TestBase
class that do not contain any tests of their own should be declaredabstract
. Then PHPUnit does not try to run their non-existant tests.