【问题标题】:Test with symfony2, error in charge entities用 symfony2 测试,收费实体出错
【发布时间】:2014-03-06 13:46:53
【问题描述】:

我有一个这样的单元测试:

namespace My\WebBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use My\WebBundle\Controller\SynMCController;
use My\WebBundle\Entity\Users;

class MyControllerTest extends \PHPUnit_Framework_TestCase
{
public function testFunction()
    {
        $user1 = new Users();
        ...
    }
}

但是当我尝试用 PHP Unit 测试它时,我得到了这个错误:

类'My\WebBundle\Entity\Users;'在第 13 行的 ...\MyControllerTest.php 中找不到

第 13 行是:

$user1 = new Users();

¿在我的测试用例中使用实体有什么问题?当然我的实体用户在这条路径中,我在很多类中都使用过这条路径。

谢谢!!!

【问题讨论】:

  • 您确定您的实体没有被称为User 而不是Users
  • 谢谢,但是是的,有“s”的用户。

标签: php unit-testing symfony testing phpunit


【解决方案1】:

确保您的phpunit.xml 文件定义明确,尤其是bootstrap 属性。它应该指向 app/bootstrap.php.cache 负责使用正确自动加载器的文件

require_once __DIR__.'/autoload.php';

【讨论】:

  • 谢谢,但其他测试工作正常,但在这个测试中我使用了我的实体用户,而且 phpunit 对测试的收费很好,因为阅读了代码,如果我删除这个实体工作正常(但显然我需要这个实体来测试这个案例)
猜你喜欢
  • 2011-10-23
  • 1970-01-01
  • 1970-01-01
  • 2017-01-14
  • 1970-01-01
  • 1970-01-01
  • 2014-08-25
  • 1970-01-01
  • 2023-03-12
相关资源
最近更新 更多