だから私はcodeigniter(https://github.com/ericbarnes/codeigniter-simpletest)で設定されたsimpletestを持っています
いくつかの簡単なテストを実行しましたが、問題はないようです。しかし、私はブロックを打っています。セッションデータを使用してテストする方法がわかりません。
問題は、テストがうまく機能しているということです。しかし、私はいくつかの例外を得ています。テストを個別に (つまり、simpletest の "all" タブ以外で) 実行しても、問題はありません。そして、「すべて」のテストを実行すると、次のエラーが発生します。
予期しない PHP エラー [ヘッダー情報を変更できません - 既に送信されたヘッダー ( */www/public/tests/simpletest/extensions/my_reporter.php:193 で出力開始)] 重大度 [E_WARNING] in [ * /www/system/libraries/ Session.php 408行目]ブロッククオート
今、私はすべてブラウザを使用してセッションを設定しており、最初のテストケースが完了した後にそれらを設定/設定解除できないと推測しています(私の場合、完了するユーザーモデルテストケースがあり、次に2番目のテストがあります)ケース (認証ライブラリ)、例外があります。
最初のテスト ケースが完了した後、ヘッダーは既に送信されていると思います。
<?php
class test_auth extends CodeIgniterUnitTestCase
{
public function __construct()
{
parent::__construct();
$this->UnitTestCase('Authorization Library');
$this->rand_good = rand(500,15000);
$this->rand_bad = rand(500,15000);
}
public function setUp()
{
$this->_ci->db->flush_cache();
$this->_ci->db->truncate('users');
$this->_ci->session->sess_destroy();
$this->_ci->session->unset_userdata('logged_in_id');
$u = new User();
$u->email = 'email' . $this->rand_good;
$u->password = 'pass' . $this->rand_good;
$u->confirm_password = 'pass' . $this->rand_good;
$u->save();
}
public function tearDown()
{
$u = new User();
$u->get();
foreach($u->all as $user)
{
$user->delete();
}
}
public function test_login_good_email_good_password()
{
$u = new User();
$u->email = 'email' . $this->rand_good;
$u->password = 'pass' . $this->rand_good;
$this->assertTrue($this->_ci->auth->login($u), 'login');
$this->assertTrue($this->_ci->auth->is_logged_in(), 'is logged in');
}
public function test_login_bad_email_bad_password()
{
$u = new User();
$u->email = 'email' . $this->rand_bad;
$u->password = 'pass' . $this->rand_bad;
$this->assertFalse($this->_ci->auth->login($u), 'login');
$this->assertFalse($this->_ci->auth->is_logged_in(), 'is logged in');
}
}
/* End of file test_auth.php */
これに影響を与える 2 つの行は、session->sess_destroy()
とsession->unset_userdata()
これらの行は、tearDown() または setUp() のいずれかで同じ問題を引き起こします。それぞれがヘッダー例外を引き起こします。
テストからブラウザーの部分を取り除き、simpletest で何らかの方法でそれをシミュレートできることを望んでいると思います。
これを解決するにはどうすればよいですか?