Fix session test save path not being writable for vagrant user

The tests now try to write to /tmp and are skipped if this folder
is not writable. Also the test has been refactored a bit (comments,
assertion messages)

regs #4461
This commit is contained in:
Jannis Moßhammer 2013-08-02 15:35:05 +02:00
parent ce4ea10a0a
commit 5a82c37ed1

View File

@ -4,60 +4,80 @@
namespace Tests\Icinga\Authentication; namespace Tests\Icinga\Authentication;
require_once("../../library/Icinga/Authentication/Session.php"); require_once('../../library/Icinga/Authentication/Session.php');
require_once("../../library/Icinga/Authentication/PhpSession.php"); require_once('../../library/Icinga/Authentication/PhpSession.php');
require_once("../../library/Icinga/Application/Logger.php"); require_once('../../library/Icinga/Application/Logger.php');
require_once("../../library/Icinga/Exception/ConfigurationError.php"); require_once('../../library/Icinga/Exception/ConfigurationError.php');
require_once("Zend/Log.php"); require_once('Zend/Log.php');
use Icinga\Authentication\PhpSession as PhpSession; use Icinga\Authentication\PhpSession as PhpSession;
class PHPSessionTest extends \PHPUnit_Framework_TestCase class PHPSessionTest extends \PHPUnit_Framework_TestCase
{ {
private function getSession()
{
if (!is_writable('/tmp')) {
$this->markTestSkipped('Could not write to session directory');
return;
}
return new PhpSession(array(
'use_cookies' => false,
'save_path' => '/tmp'
));
}
/** /**
* @runInSeparateProcess * Test the creation of a PhpSession object
*
* @runInSeparateProcess
**/ **/
public function testSessionCreation() public function testSessionCreation()
{ {
$session = new PhpSession(); $this->getSession();
$session = new PhpSession(array("ssesion.use_cookies"=>false));
} }
/** /**
* @runInSeparateProcess * Test PhpSession::open()
**/ *
* @runInSeparateProcess
*/
public function testOpenSession() public function testOpenSession()
{ {
$this->assertEquals(session_id(), ''); $this->assertEquals(session_id(), '', 'Asserting test precondition: session not being setup yet ');
$session = new PhpSession(); $session = $this->getSession();
$session->open(); $session->open();
$this->assertNotEquals(session_id(), ''); $this->assertNotEquals(session_id(), '', 'Asserting a Session ID being available after PhpSession::open()');
} }
/** /**
* @runInSeparateProcess * Test a session being closed by PhpSession::close()
**/ *
* @runInSeparateProcess
**/
public function testCloseSession() public function testCloseSession()
{ {
$this->assertEquals(session_id(), '', 'Asserting test precondition: session not being setup yet ');
$this->assertEquals(session_id(), ''); $session = $this->getSession();
$session = new PhpSession();
$session->open(); $session->open();
$this->assertNotEquals(session_id(), ''); $this->assertNotEquals(session_id(), '', 'Asserting a Session ID being available after PhpSession::open()');
$session->close(); $session->close();
} }
/** /**
* @runInSeparateProcess * Test if a session is correctly purged when calling PhpSession::purge()
**/ *
* @runInSeparateProcess
*/
public function testPurgeSession() public function testPurgeSession()
{ {
$this->assertEquals(session_id(), ''); $this->assertEquals(session_id(), '', 'Asserting test precondition: session not being setup yet ');
$session = new PhpSession(); $session = $this->getSession();
$session->open(); $session->open();
$this->assertNotEquals(session_id(), ''); $this->assertNotEquals(session_id(), '', 'Asserting a Session ID being available after PhpSession::open()');
$session->purge(); $session->purge();
$this->assertEquals(session_id(), ''); $this->assertEquals(session_id(), '', 'Asserting no Session ID being available after PhpSession::purge()');
} }
} }