4
4

More than 5 years have passed since last update.

PHPUnitで複数回session_start()してしまうエラーを回避する方法。

Last updated at Posted at 2013-05-30
 A session had already been started - ignoring session_start()

PHPUnitテストコードのsetUp()を以下の様にする。

xxx_Test.php
protected function setUp(){
    if(!isset($_SESSION)){
        $_SESSION=array(  );
    }
}

$_SESSIONはarray()なので、空の配列をそのまま入れる。

tearDown()でsession_destroy()してもいいのかもしれないけど、
自分の場合、別途影響が出て、うまく行かなかったのと、
Stack Overflowに同様の対処方法があった上記を採用しました。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4