1

私はphpunitを使用しています。基本的に HTTP ヘッダーからパラメーターを取得し、それを使用して後続の操作を実行するコードをテストしたいと考えています。

ただし、ヘッダーのテスト中は null です。

コードがパラメーターにアクセスするときにその値を取得するようにヘッダーを設定する方法はありますか (ブートストラップ ファイルにある可能性があります)。

更新:この質問 で提案されているように、以下のコードを試しました:

class Action_UserTest extends PHPUnit_Framework_TestCase {

    /**
     * @runInSeparateProcess
     */
    public function testBar()
    {
        header('Location : foo');
    }

    /**
     * @covers Action_User::executePut
     * @todo   Implement testExecutePut().
     */
    public function testExecutePut() {

        ob_start();
        $this->testBar();
        $headers_list = headers_list();
        $this->assertNotEmpty($headers_list);
        $this->assertContains('Location: foo', $headers_list);
        header_remove();
        ob_clean();
    } 
}

しかし、エラーが発生します:

Action_UserTest::testExecutePut()
Cannot modify header information - headers already sent by (output started at /usr/lib/php/PHPUnit/Util/Printer.php:172)
4

1 に答える 1