私はPHPプロジェクトに取り組んでおり、PHPUnitとDoctrine2を使用しています。最新バージョンを使用しています。私はすべてのクラス、関数、動作をテストするためにたくさんのテストを書きました。テストは常に実行されています。すべてがうまくいきました。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テストは実行されなくなります。
初期化の行にコメントすると、すべてのテストが再度実行されます。メンバーのクイズとセッションは非公開です。アプリケーションは一般的に機能します。
Doctrine2と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);
}
今のところ、何が問題なのか本当にわかりません。たぶん、誰かがすでに同じことを経験したか、何が問題になる可能性があるかについて何か考えを持っています。
助けてくれてありがとう。