2012-04-10 9 views
3

PHPプロジェクトでPHPUnitとDoctrine 2を使用しています。最新のバージョンを使用しています。私はすべてのクラス、関数、および動作をテストするために多くのテストを書いた。テストは常に実行されています。すべてうまくいった。 Doctrineを使用しているので、私はベストプラクティスのヒントを適用し、コンストラクタでArrayCollectionを初期化しました。ザは、のArrayCollectionを含むNetBeansのArrayCollection(Doctrine 2)の初期化後にPHPUnitが動作しなくなる

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); 
} 

である:

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

私はこの問題の解決策を見つけました。ファイルはテストファイル、NetBeansプロジェクトにおけるユニットテストのための部品のホームディレクトリに置かれ

// 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(); 

:私は、次の内容の名前bootstrap.phpの持つファイルを作成しました。重要なことは、それはテストケースで編集するものではないということです。

0

PHPUnitを呼び出すときに、Doctrine \ Commonフォルダがテストケースのインクルードパスにあることを確認する必要があります。

テストで同じことを行う必要があるため、アプリケーションのクラスローダをカスタマイズしていますか。

関連する問題