Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use \PHPUnit_Framework_TestCase or ..\TestCase

Stupid question... In the Symfony docs, unit test classes extend \PHPUnit_Framework_TestCase but in PHPUnit docs, test classes extend PHPUnit\Framework\TestCase. Is there a difference, are they the same, or am I missing a subtle PHP feature where _ is equivalent to \?

Short of actually testing it out myself, can I use either, or just one in Symfony?

Update: It's been helpfully explained to me that these two classes are just a difference between PHPUnit versions. After my own research and for the record, Symfony 3.1 still extends \PHPUnit_Framework_TestCase in its own KernelTestCase class that powers Symfony's functional testing. To avoid breaking code, I'm going to play safe & extend WebTestCase that inherits from \PHPUnit_Framework_TestCase when unit testing with Symfony specifically. Such unit tests still work with PHPUnit 5.6 anyway

like image 967
SomeDude Avatar asked Oct 30 '22 17:10

SomeDude


1 Answers

These are the same but since PHPUnit 5.4 it's recommended to use TestCase. However, it's not a problem if you stay with PHPUnit_Framework_TestCase.

See a very similar question: PHPUnit can't found the "TestCase" class

like image 137
martin Avatar answered Nov 10 '22 05:11

martin