我正在学习如何使用 PHPUnit 4.3.5 / PHP 5.5.14 进行单元测试。一切都很顺利,直到我尝试获得代码覆盖率。我收到此错误:“尝试获取代码覆盖率时尝试 @cover 或 @use 不存在的方法“MyClass::__construct”。我尝试了其他答案,但无法修复它。任何想法我做错了什么? 谢谢!
/**
* Test constructor.
* @covers MyClass::__construct
* @group MyClassTest
*/
public function test_Can_Create_MyClass_Instance() {
$this->assertInstanceOf('MyClass', $this->_myClass);
}
如果您期望的是,您可能会得到相同的错误@covers
使用命名空间的注释use操作员。
以下代码将不起作用:
<?php
namespace MyCompany\MyBundle\Test\UnitTest\Service;
use MyCompany\MyBundle\Service\ClassToTest;
class MyAwesomeTest
{
/**
* @covers ClassToTest::someMethod()
*/
public function testSomeMethod()
{
// do your magic
}
}
像 PHPStorm 这样的智能 IDE 解决了ClassToTest::someMethod()
如果您按住 CTRL 键并单击注释,但 PHPUnit 会给您一个Trying to @cover or @use not existing method "ClassToTest::someMethod".
error.
这里有一个拉取请求:https://github.com/sebastianbergmann/phpunit/pull/1312 https://github.com/sebastianbergmann/phpunit/pull/1312
作为解决方法,只需使用完整的类名:
<?php
namespace MyCompany\MyBundle\Test\UnitTest\Service;
use MyCompany\MyBundle\Service\ClassToTest;
class MyAwesomeTest
{
/**
* @covers \MyCompany\MyBundle\Service\ClassToTest::someMethod()
*/
public function testSomeMethod()
{
// do your magic
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)