PHPUnit 在 Netbeans 中的 ArrayCollection(Doctrine 2)初始化后不再运行

标签 php unit-testing doctrine-orm phpunit netbeans-7.1

我正在开发一个 PHP 项目并使用 PHPUnit 和 Doctrine 2。我使用的是最新版本。我写了很多测试来测试所有的类、函数和行为。测试始终在运行。一切正常。由于我使用 Doctrine,我应用了最佳实践技巧并在构造函数中初始化 ArrayCollection。

public function __construct($username, $eMail, $password1, $password2) {
    $this->quiz = new ArrayCollection();
    $this->sessions = new ArrayCollection();
    $this->setUsername($username);
    $this->setEMail($eMail);
    $this->setPassword('', $password1, $password2);
}

ArrayCollection 的包含是:

use Doctrine\Common\Collections\ArrayCollection;

此后,PHPUnit 测试不再运行。

当我再次评论初始化所有测试运行的行时。成员(member)测验和 session 是私有(private)的。该应用程序通常可以正常工作。

我是 Doctrine 2 和 PHPUnit 的新手。到目前为止,我已经尝试了很多事情,比如测试用例中的不同包含等。但没有任何帮助。 也许我在测试用例中忘记了一些东西。在 ArrayCollection 的步骤初始化和未初始化之间,我没有对测试用例进行任何更改。

测试用例如下所示:

namespace Model;

require_once dirname(__FILE__) . '/../../Model/User.php';

/**
 * Test class for User.
 * Generated by PHPUnit on 2012-04-03 at 14:48:39.
 */
class UserTest extends \PHPUnit_Framework_TestCase {

    /**
     * @var User
     */
    protected $user;

    // constructor of the test suite
    function UserTest($name) {
        $this->PHPUnit_TestCase($name);
    }

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp() {
        $username = 'musteruser';
        $eMail = 'must@muster.ch';
        $pw = 'muster.muster';
        $this->user = new User($username, $eMail, $pw, $pw);
    }

    /**
     * Tears down the fixture, for example, closes a network connection.
     * This method is called after a test is executed.
     */
    protected function tearDown() {
        unset($this->user);
    }

现在我真的不知道可能是什么问题。也许有人已经经历过同样的事情,或者知道可能是什么问题。

感谢您的帮助。

最佳答案

当您调用 PHPUnit 时,您可能需要确保 Doctrine\Common 文件夹位于测试用例的包含路径中。

您是否为您的应用程序定制了任何类加载器,因为您需要为您的测试做同样的事情。

关于PHPUnit 在 Netbeans 中的 ArrayCollection(Doctrine 2)初始化后不再运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10085030/

相关文章:

doctrine - Doctrine 2 何时会在使用复合键时出错?

php - Laravel,我需要多个数据库表来对不同模型进行投票吗

java - jUnit 模拟 ModelMapper

php - 学说 DQL : DQL Join between 4 entities

angular - karma 测试运行器在完成后不关闭

c# - ReSharper 单元测试未在 bin 目录中运行

php - 根据第二个非相关连接进行连接,原则 2

php - 如何修复完整性约束违规 : 1062 Duplicate entry '1-1' for key 'PRIMARY: Laravel Pivot Table

php - 条件广告会伤害我的网页排名或 "confuse"网络爬虫

php - 在 PHPUnit 提供程序中使用工厂失败