PHPUnit and Sessions
Moderator: General Moderators
PHPUnit and Sessions
I'm having a bit of trouble testing my code for a system that requires authentication. Is there anyway to set session variables using PHPUnit 2.3.6?
what troubles do you have? have you tried something like this:
Code: Select all
class TestOfSomething extends UnitTestCase {
function testSomeMethodRequiringAuthenticationWhenLoggedOn() {
$_SESSION = array();
$_SESSION['user_id'] = 123;
$this->assertTrue(SomeFunctionRequiringAuthentication('asd', 'zxc'));
}
function testSomeMethodRequiringAuthenticationWhenNotLoggedOn() {
$_SESSION = array();
unset($_SESSION['user_id']);
$this->assertFalse(SomeFunctionRequiringAuthentication('asd', 'zxc'));
}
}