SomeDude SomeDude - 1 month ago 21
PHP Question

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 of which PHPUnit version you're using. After my own research and for the record, Symfony 3.1 still extends
\PHPUnit_Framework_TestCase
in its own
KernelTestCase
class that is the core of its own functional testing functions. To avoid breaking code, I'm going to play safe & extend the older
\PHPUnit_Framework_TestCase
when unit testing with Symfony specifically. These tests still work with PHPUnit 5.6 anyway

Answer

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