Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public function setUser(User $user)
{
$this->set('user', $user);
}

public function hasUser()
{
return $this->has('user');
}

public function getUser()
{
return $this->get('user');
Expand Down
2 changes: 1 addition & 1 deletion example/example2.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function incrementCounter()
if (!$this->has('counter')) {
$this->set('counter', 0);
}

$this->set('counter', $this->get('counter') + 1);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/AbstractSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function __construct(SessionBackendInterface $backend)
{
$this->backend = $backend;
}

public function configure($name, $domain, $path = '/', $lifetime = 300, $isSecure = FALSE)
{
if ($this->isStarted()) {
Expand All @@ -124,7 +124,7 @@ public function configure($name, $domain, $path = '/', $lifetime = 300, $isSecur
$this->path = $path;
$this->domain = $domain;
$this->isSecure = $isSecure;

$this->isConfigured = TRUE;
}

Expand Down Expand Up @@ -187,7 +187,7 @@ final protected function has($key)
{
return isset($this->data[$key]);
}

/**
* Checks whether the session has already been started
*
Expand Down
8 changes: 4 additions & 4 deletions src/PhpSessionBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,24 @@ class PhpSessionBackend implements SessionBackendInterface
protected $domain;
protected $isSecure;

public function startSession($name, $lifetime, $path, $domain, $isSecure = FALSE)
public function startSession($name, $lifetime, $path, $domain, $isSecure = FALSE, $httpOnly = TRUE)
{
$this->name = $name;
$this->lifetime = $lifetime;
$this->path = $path;
$this->domain = $domain;
$this->isSecure = $isSecure;

session_set_cookie_params($lifetime, $path, $domain, $isSecure, TRUE);
session_set_cookie_params($lifetime, $path, $domain, $isSecure, $httpOnly);
session_name($name);
session_start();
}

public function getSessionId()
{
return session_id();
}

public function regenerateSessionId()
{
session_regenerate_id(TRUE);
Expand Down
38 changes: 19 additions & 19 deletions tests/AbstractSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,26 @@ class AbstractSessionTest extends PHPUnit_Framework_TestCase

/**
* @var string
*/
*/
protected $sessionName = 'a-session-name';

/**
* @var string
*/
*/
protected $sessionDomain = '.example.com';
/**
* @var string
*/
*/
protected $sessionId = 'a-session-id';

/**
* @var string
*/
*/
protected $newSessionId = 'a-new-session-id';

/**
* @var string
*/
*/
protected $value = 'a-value';

/**
Expand All @@ -96,7 +96,7 @@ protected function setUp()
$this->backend = $this->getMock('spriebsch\\session\\SessionBackendInterface');
$this->session = new ConcreteSession($this->backend);
}

/**
* Destroys the test fixture.
*
Expand Down Expand Up @@ -183,10 +183,10 @@ public function testStartStartsSessionInBackend()
$this->backend->expects($this->once())
->method('startSession')
->with($this->sessionName, 300, '/', '.example.com');

$this->session->configure($this->sessionName, $this->sessionDomain);
$this->session->start();

return $this->session;
}

Expand Down Expand Up @@ -343,7 +343,7 @@ public function testRegenerateIdRegeneratesSessionIdInBackend()
$this->session->configure($this->sessionName, $this->sessionDomain);
$this->session->start();
$this->session->regenerateId();

return $this->session;
}

Expand All @@ -363,7 +363,7 @@ public function testSessionIdChangesWhenIdIsRegenerated()

$this->session->configure($this->sessionName, $this->sessionDomain);
$this->session->start();

$this->assertEquals($this->newSessionId, $this->session->regenerateId());
}

Expand All @@ -375,21 +375,21 @@ public function testCommitThrowsExceptionWhenSessionIsNotStarted()
{
$this->session->commit();
}

/**
* @covers spriebsch\session\AbstractSession::commit
*/
public function testCommitWritesSessionData()
{
$this->session->configure($this->sessionName, $this->sessionDomain);
$this->session->start();
$this->session->setFoo('a-value');
$this->session->start();

$this->session->setFoo('a-value');

$this->backend->expects($this->once())
->method('write')
->with(array('foo' => 'a-value'));

$this->session->commit();
}

Expand All @@ -408,13 +408,13 @@ public function testDestroyThrowsExceptionWhenSessionIsNotStarted()
public function testDestroyCallsDestroyInBackend()
{
$this->session->configure($this->sessionName, $this->sessionDomain);
$this->session->start();
$this->session->setFoo('a-value');
$this->session->start();

$this->session->setFoo('a-value');

$this->backend->expects($this->once())
->method('destroy');

$this->session->destroy();
}
}
22 changes: 11 additions & 11 deletions tests/PhpSessionBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class PhpSessionBackendTest extends PHPUnit_Framework_TestCase
* @var spriebsch\session\SessionBackendInterface
*/
protected $backend;

protected $sessionName = 'a-session-name';

/**
Expand Down Expand Up @@ -92,7 +92,7 @@ protected function tearDown()
public function testStartSessionSetsSessionName()
{
$this->backend->startSession($this->sessionName, 300, '/', '.example.com');

$this->assertEquals($this->sessionName, session_name());
}

Expand All @@ -103,7 +103,7 @@ public function testStartSessionStartsASession()
{
$this->backend->startSession($this->sessionName, 300, '/', '.example.com');

$this->assertTrue(isset($_SESSION));
$this->assertTrue(isset($_SESSION));
$this->assertNotEmpty(session_id());
}

Expand All @@ -115,7 +115,7 @@ public function testStartSessionSetsCookie()
if (!in_array('xdebug', get_loaded_extensions())) {
$this->markTestSkipped('xdebug not available');
}

$this->backend->startSession($this->sessionName, 300, '/', '.example.com');

$headers = xdebug_get_headers();
Expand All @@ -130,7 +130,7 @@ public function testStartSessionSetsCookie()
public function testGetSessionIdReturnsSessionId()
{
$this->backend->startSession($this->sessionName, 300, '/', '.example.com');

$this->assertEquals(session_id(), $this->backend->getSessionId());
}

Expand All @@ -142,7 +142,7 @@ public function testRegenerateIdChangesSessionId()
$this->backend->startSession($this->sessionName, 300, '/', '.example.com');
$id = $this->backend->getSessionId();
$this->backend->regenerateSessionId();

$this->assertNotEquals(session_id(), $id);
}

Expand All @@ -156,7 +156,7 @@ public function testReadReadsFromSessionSuperglobal()

$this->assertEquals(array('foo' => 'a-foo'), $this->backend->read());
}

/**
* @covers spriebsch\session\PhpSessionBackend::write
*/
Expand All @@ -166,7 +166,7 @@ public function testWriteWritesToSessionSuperglobal()
$this->backend->write(array('foo' => 'another-foo'));

$this->assertEquals(array('foo' => 'another-foo'), $_SESSION);
}
}

/**
* @covers spriebsch\session\PhpSessionBackend::destroy
Expand All @@ -177,7 +177,7 @@ public function testDestroyDestroysSession()
$this->backend->destroy();

$this->assertEmpty(session_id());
}
}

/**
* @covers spriebsch\session\PhpSessionBackend::destroy
Expand All @@ -188,7 +188,7 @@ public function testDestroyUnsetsSessionSuperglobal()
$this->backend->destroy();

$this->assertFalse(isset($_SESSION));
}
}

/**
* @covers spriebsch\session\PhpSessionBackend::destroy
Expand All @@ -198,7 +198,7 @@ public function testDestroySetsCookie()
if (!in_array('xdebug', get_loaded_extensions())) {
$this->markTestSkipped('xdebug not available');
}

$this->backend->startSession($this->sessionName, 300, '/', '.example.com');
$this->backend->destroy();

Expand Down