[英]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
. 愚蠢的问题......在Symfony文档中,单元测试类扩展了\\PHPUnit_Framework_TestCase
但在PHPUnit文档中,测试类扩展了PHPUnit\\Framework\\TestCase
。 Is there a difference, are they the same, or am I missing a subtle PHP feature where _
is equivalent to \\
? 有没有区别,它们是相同的,还是我错过了一个微妙的PHP功能,其中_
相当于\\
?
Short of actually testing it out myself, can I use either, or just one in Symfony? 没有实际测试它自己,我可以使用,或只在Symfony中使用一个?
Update : It's been helpfully explained to me that these two classes are just a difference between PHPUnit versions. 更新 :有人向我解释说,这两个类只是PHPUnit版本之间的区别。 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. 在我自己的研究和记录之后,Symfony 3.1仍在其自己的KernelTestCase
类中扩展\\PHPUnit_Framework_TestCase
,该类为Symfony的功能测试提供支持。 To avoid breaking code, I'm going to play safe & extend WebTestCase
that inherits from \\PHPUnit_Framework_TestCase
when unit testing with Symfony specifically. 为了避免破坏代码,在安装Symfony进行单元测试时,我将安全地播放并继承继承自\\PHPUnit_Framework_TestCase
WebTestCase
。 Such unit tests still work with PHPUnit 5.6 anyway 无论如何,这样的单元测试仍然适用于PHPUnit 5.6
These are the same but since PHPUnit 5.4 it's recommended to use TestCase
. 这些是相同的,但自PHPUnit 5.4以来,建议使用TestCase
。 However, it's not a problem if you stay with PHPUnit_Framework_TestCase
. 但是,如果你继续使用PHPUnit_Framework_TestCase
,这不是问题。
See a very similar question: PHPUnit can't found the "TestCase" class 看到一个非常相似的问题: PHPUnit找不到“TestCase”类
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.