Cannot send session cookie - headers already sent PHPUnit / Laravel

前端 未结 4 1392
小蘑菇
小蘑菇 2021-02-19 22:50

I have this strange problem when i call the parent::setUp() on my TestCase class for unit test a class when i run phpunit it throw me this error:

4条回答
  •  温柔的废话
    2021-02-19 23:21

    In Laravel I avoided the issue by checking the environment and avoiding problematic code for 'testing' environment.

    // Code working in Laravel 4.2
    if(App::environment() != 'testing') {
            // this will be skipped when testing
            setcookie('key', $val, time() + (86400 * 999), '/');
    }
    

    NOTE - Warning: this means you cannot test this piece of code!

提交回复
热议问题