【发布时间】:2015-11-13 12:25:44
【问题描述】:
我正在为一个使用 apigility 的项目编写单元测试,但由于某种原因,测试类无法识别真实类的 que 命名空间。
这是一个测试类:
namespace Testzfnewsite\V1\Rest\SendEmail\Entity\DAO;
use PHPUnit_Framework_TestCase;
class GenericDAOTest extends PHPUnit_Framework_TestCase {
public function test_verifica_se_a_classe_existe(){
$classe = class_exists('\\zfnewsite\\V1\\Rest\\SendEmail\\Entity\\DAO\\GenericDAO');
$this->assertTrue($classe);
}
}
在这个例子中,class_exists函数的结果总是假的,我检查了命名空间和类名是正确的,可以看出这个测试类没有看到真正应用程序的命名空间。
这是 zfnewsite 模块的结构。
_zfnewsite
|
|_config
|
|_src
| |
| |_zfnewsite
| |
| |_V1
| | |
| | |_Rest
| | | |
| | | |_SendEmail
| | | | |
| | | | |_Entity
| | | | | |
| | | | | |_DAO
| | | | | |
| | | | | |_GenericDAO.php
| | | | | |_GenericDAOImpl.php
| | | | |
| | | | |_Service
| | | |
| | | |_Status
| | |
| | |_Rcp
| |
| |_Module.php
|
|_test
| |
| |_zfnewsite
| |
| |_V1
| | |
| | |_Rest
| | | |
| | | |_SendEmail
| | | | |
| | | | |_Entity
| | | | | |
| | | | | |_DAO
| | | | | |
| | | | | |_GenericDAOTest.php
| | | | | |_GenericDAOImplTest.php
| | | | |
| | | | |_Service
| | | |
| | | |_Status
| | |
| | |_Rcp
| |
| |_Bootstrap.php
|
|_Module.php
我需要帮助找出这个测试环境有什么问题,正常的 zf2 应用程序和 apigility 的测试有区别吗?
这是 GenericDAO 类的代码:
namespace zfnewsite\V1\Rest\SendEmail\Entity\DAO;
interface GenericDAO
{
public function save($data);
public function update($id, $data);
public function findOneBy(array $where);
public function findById($id);
public function findAll();
public function delete($id);
}
【问题讨论】:
-
你能显示
GenericDAO类定义吗? -
你试过
$classe = class_exists('zfnewsite\\V1\\Rest\\SendEmail\\Entity\\DAO\\GenericDAO');吗? -
是的,我试过“zfnewsite\\V1\\Rest\\SendEmail\\Entity\\DAO\\GenericDAO”,也试过“GenericDAO”和“\\DAO\\GenericDAO” ",它们都不起作用。
标签: php namespaces zend-framework2 phpunit laminas-api-tools