I am having trouble writing unit tests for a simple session wrapper.
The class itself has some basic functions set , get , exists , etc. All these functions have an assertSessionStart check, which performs the following actions:
protected static function assertStarted() { if (strlen(session_id()) < 1) { throw new Exception("Some text here"); } return; }
When writing sets of units, I have the following setUp and tearDown . I have this because I want each test to work with a new session environment.
protected function setUp() { session_start(); } protected function tearDown() { session_destroy(); }
Now in front of the problem, I want the testing method to fail when I try to use set when I have no session. To do this, I will have to destroy the session running in setUp . Like this:
public function testGetWithoutSession() { session_destroy(); $this->setExpectedException('Exception'); ESL_Session::set('set', 'value'); session_start(); }
However, this raises the warning "Attempt to destroy an uninitialized session." When I put echo session_id() right in front of session_destroy , though - it shows me that I have a live session.
Does anyone have experienced testing for session wrappers?
Additional information :
source share