Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhpSession messing up with tests? #12

Open
bjmrey opened this issue Feb 3, 2017 · 8 comments
Open

PhpSession messing up with tests? #12

bjmrey opened this issue Feb 3, 2017 · 8 comments

Comments

@bjmrey
Copy link

bjmrey commented Feb 3, 2017

After upgrading to Laravel 5.4 running phpunit outputs the error below.

There was 1 error:

  1. Tests\Feature\ExampleTest::testBasicTest
    ErrorException: session_start(): Cannot send session cookie - headers already sent by (output started at /project/vendor/phpunit/phpunit/src/Util/Printer.php:114)

/project/vendor/pragmarx/support/src/PhpSession.php:23
/project/vendor/pragmarx/support/src/PhpSession.php:14
/project/vendor/pragmarx/tracker/src/Vendor/Laravel/ServiceProvider.php:268
...

I've solved it temporarily by adding @ before session_start() in src/PhpSession.php, but I'm not quite sure what's going on and whether the issue comes from this package or from my setup.

private function startSession()
{
	if ( ! $this->isStarted())
	{
		@session_start();
	}
}
@hktang
Copy link

hktang commented Aug 31, 2017

Thank you. I am having the same issue with Laravel 5.3.

Your temporary solution helps, at least the tests can run as usual.

@antonioribeiro
Copy link
Owner

antonioribeiro commented Aug 31, 2017

Could you please tell me what happens if you do a

private function startSession()
{
        dd(session_status());

        if ( ! $this->isStarted())
	{
		@session_start();
	}
}

?

@hktang
Copy link

hktang commented Aug 31, 2017

Hi @antonioribeiro, just run your code and get a return value 1.

@antonioribeiro
Copy link
Owner

antonioribeiro commented Aug 31, 2017

Sorry, I think we shoul also test:

private function startSession()
{

        if ( ! $this->isStarted())
	{
		dd(session_status());

		@session_start();
	}
}

@antonioribeiro
Copy link
Owner

Those are the values we are looking for

image

@hktang
Copy link

hktang commented Aug 31, 2017

Oops it seems I messed up with the tracker in both dev and production environment so I reverted the code to a previous commit. Will update you when I get back to the same state again..

@antonioribeiro
Copy link
Owner

Did you try to run it (locally) with dd()inside that if() ?

@javisr
Copy link

javisr commented Aug 15, 2018

Hi @antonioribeiro, I'm having the same issue.

I have a fresh 5.6 Laravel installation with your tracker package and the default example tests[1] and I get the same error when I run phpunit.

I've include dd(session_status()) inside the if() and the return is 1 in the browser and inside the phpunit test.

I hope it could help :)

[1]

public function testExample()
{
    $response = $this->get('/');
     $response->assertStatus(200);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants