gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 22:13:15 24 4
gpt4 key购买 nike

我正在开发一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com