PHPUnit and Sessions
Posted: Tue Oct 31, 2006 9:23 am
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?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
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'));
}
}