Netbeans中的ArrayCollection(原则2)初始化后,PHPUnit不再运行
我正在从事一个PHP项目,使用PHPUnit和Doctrine 2。我使用的是最新版本。我写了很多测试来测试所有的类、函数和行为。测试总是在运行。一切都很顺利。因为我使用了条令,所以我应用了最佳实践技巧并在构造函数中初始化了ArrayCollectionNetbeans中的ArrayCollection(原则2)初始化后,PHPUnit不再运行,php,unit-testing,doctrine-orm,phpunit,netbeans-7.1,Php,Unit Testing,Doctrine Orm,Phpunit,Netbeans 7.1,我正在从事一个PHP项目,使用PHPUnit和Doctrine 2。我使用的是最新版本。我写了很多测试来测试所有的类、函数和行为。测试总是在运行。一切都很顺利。因为我使用了条令,所以我应用了最佳实践技巧并在构造函数中初始化了ArrayCollection public function __construct($username, $eMail, $password1, $password2) { $this->quiz = new 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测试将不再运行
当我注释带有初始化的行时,所有测试都将再次运行。成员测验和会议是私人的。该应用程序通常是有效的
我是第二条和第二条的新手。到目前为止,我已经尝试了很多方法,比如在测试用例中加入不同的内容等等,但是没有任何效果。
也许我在测试箱里忘了什么。在ArrayCollection的步骤初始化和未初始化之间,我没有在testcase中更改任何内容
测试用例如下所示:
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文件夹位于测试用例的include路径上
您是否为您的应用程序自定义任何类装入器,因为您需要为您的测试执行相同的操作 我找到了解决这个问题的办法。我创建了一个名为bootstrap.php的文件,其中包含以下内容:
// Import the ClassLoader
use Doctrine\Common\ClassLoader;
// Autoloader for Doctrine
require '/../../php/PEAR/Doctrine/Common/ClassLoader.php';
// Autoloading for Doctrine
$doctrineClassLoader = new ClassLoader('Doctrine', realpath(__DIR__ . '/../../php/PEAR'));
$doctrineClassLoader->register();
该文件放在测试文件的主目录中,这是NetBeans项目中进行单元测试的部分。重要的是,在测试用例中没有什么可编辑的