10-27-2019, 12:05 AM
Hello,
I'm trying to test an "Auth" library I created. Obviously, that library uses the session.
My first test looks like this:
See the line where I ask if $_SESSION['user'] does not exist? That line produces an error:
If I understand it correctly, that means "session_start()" hasn't been called before the first "echo".
I see two possibilities:
Thanks in advance!
I'm trying to test an "Auth" library I created. Obviously, that library uses the session.
My first test looks like this:
PHP Code:
public function testConstructor()
{
$auth = new Auth();
$this->assertInstanceOf(\App\Libraries\Auth\Auth::class, $auth);
$this->assertNull(service('session')->get('user'));
}
See the line where I ask if $_SESSION['user'] does not exist? That line produces an error:
Code:
ErrorException: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
If I understand it correctly, that means "session_start()" hasn't been called before the first "echo".
I see two possibilities:
- Call session_start() myself, although I don't know where (in setUp() is also too late).
- Use mocks. I saw a "Mocking Services" chapter in the userguide, but I didn't understand how to use it.
Thanks in advance!