2012-04-10 69 views
3

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

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测试不再运行。

当我用初始化注释行时,所有的测试再次运行。成员测验和会议是私人的。该应用程序通常有效。

我是新的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 = '[email protected]'; 
     $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); 
    } 

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

感谢您的任何帮助。

回答

0

我找到了解决方案。我创建了一个名为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项目的一部分,单元测试的主目录。重要的是,这是测试用例中没有的东西。

0

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

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