ログインシステムの単体テストを作成していますが、Zend_Session_Namespaceオブジェクトとの対話に問題があります。PHPUnitフレームワーク(ZF 1.10、PHPUnit 3.4.5)のZend_Test拡張機能を使用しています
テスト
public function testAuthFailure()
{
$request = $this->getRequest();
$request->setMethod("POST");
$request->setPost("username", "testUser");
$request->setPost("password", "testPassword");
$this->dispatch("/auth/login");
$this->assertModule("auth");
$this->assertController("login");
$this->assertAction("validate");
$loginSession = new Zend_Session_Namespace("login");
$this->assertFalse(is_null($loginSession));
$this->assertObjectHasAttribute("messages", $loginSession);
$this->assertFalse(empty($loginSession->messages));
$this->arrayHasKey("error", $loginSession->messages["error"]);
$this->assertEquals($loginSession->messages["error"], "Could not log you in with that username and/or password");
}
現在のコントローラー/アクションコード
public function validateAction()
{
$loginSession = new Zend_Session_Namespace("login");
if (!$this->buildForm()->isValid($this->getRequest()->getPost())) {
$loginSession->messages["error"][] = "Please enter your username and password";
}
$loginSession->messages["error"][] = "Could not contact the authentication server";
$this->getResponse()
->setHttpResponseCode(303)
->setHeader("Location", "/auth/login");
}
私の単体テストは$this->assertObjectHasAttribute("messages", $loginSession);
-で失敗していますが、メッセージの実際の内容では失敗すると予想されます。
phpunitブートストラップに次の行があります。
Zend_Session::$_unitTestEnabled = true;
Zend_Session::start();
セッションメッセージが正しく設定されていることを確認するにはどうすればよいですか?