forked from symfony/symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HttpFoundation] Add tests and some CS/docblocks.
- Loading branch information
Drak
committed
Mar 14, 2012
1 parent
a6a9280
commit cb873b2
Showing
10 changed files
with
147 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,5 +65,4 @@ protected function setOptions(array $options) | |
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
|
||
/** | ||
* AbstractProxy. | ||
* | ||
* @author Drak <[email protected]> | ||
*/ | ||
abstract class AbstractProxy | ||
{ | ||
|
@@ -43,9 +45,14 @@ public function getSaveHandlerName() | |
return $this->saveHandlerName; | ||
} | ||
|
||
/** | ||
* Is this proxy handler and instance of \SessionHandlerInterface. | ||
* | ||
* @return boolean | ||
*/ | ||
public function isSessionHandlerInterface() | ||
{ | ||
return (bool)($this instanceof \SessionHandlerInterface); | ||
return ($this instanceof \SessionHandlerInterface); | ||
} | ||
|
||
/** | ||
|
@@ -75,6 +82,6 @@ public function isActive() | |
*/ | ||
public function setActive($flag) | ||
{ | ||
$this->active = (bool)$flag; | ||
$this->active = (bool) $flag; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,21 +15,17 @@ | |
* NativeProxy. | ||
* | ||
* This proxy is built-in session handlers in PHP 5.3.x | ||
* | ||
* @author Drak <[email protected]> | ||
*/ | ||
class NativeProxy extends AbstractProxy | ||
{ | ||
/** | ||
* Constructor. | ||
* | ||
* @param $handler | ||
*/ | ||
public function __construct($handler) | ||
public function __construct() | ||
{ | ||
if (version_compare(phpversion(), '5.4.0', '>=') && $handler instanceof \SessionHandlerInterface) { | ||
throw new \InvalidArgumentException('This proxy is only for PHP 5.3 and not for instances of \SessionHandler or \SessionHandlerInterface'); | ||
} | ||
|
||
$this->handler = $handler; | ||
// this makes an educated guess as to what the handler is since it should already be set. | ||
$this->saveHandlerName = ini_get('session.save_handler'); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
|
||
/** | ||
* SessionHandler proxy. | ||
* | ||
* @author Drak <[email protected]> | ||
*/ | ||
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface | ||
{ | ||
|
@@ -29,7 +31,7 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf | |
public function __construct(\SessionHandlerInterface $handler) | ||
{ | ||
$this->handler = $handler; | ||
$this->wrapper = (bool)(class_exists('SessionHandler') && $handler instanceof \SessionHandler); | ||
$this->wrapper = ($handler instanceof \SessionHandler); | ||
$this->saveHandlerName = $this->wrapper ? ini_get('session.save_handler') : 'user'; | ||
} | ||
|
||
|
@@ -38,7 +40,7 @@ public function __construct(\SessionHandlerInterface $handler) | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
function open($savePath, $sessionName) | ||
public function open($savePath, $sessionName) | ||
{ | ||
$return = (bool)$this->handler->open($savePath, $sessionName); | ||
|
||
|
@@ -52,42 +54,42 @@ function open($savePath, $sessionName) | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
function close() | ||
public function close() | ||
{ | ||
$this->active = false; | ||
|
||
return (bool)$this->handler->close(); | ||
return (bool) $this->handler->close(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
function read($id) | ||
public function read($id) | ||
{ | ||
return (string)$this->handler->read($id); | ||
return (string) $this->handler->read($id); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
function write($id, $data) | ||
public function write($id, $data) | ||
{ | ||
return (bool)$this->handler->write($id, $data); | ||
return (bool) $this->handler->write($id, $data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
function destroy($id) | ||
public function destroy($id) | ||
{ | ||
return (bool)$this->handler->destroy($id); | ||
return (bool) $this->handler->destroy($id); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
function gc($maxlifetime) | ||
public function gc($maxlifetime) | ||
{ | ||
return (bool)$this->handler->gc($maxlifetime); | ||
return (bool) $this->handler->gc($maxlifetime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,44 @@ | |
|
||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy; | ||
|
||
// Note until PHPUnit_Mock_Objects 1.2 is released you cannot mock abstracts due to | ||
// https://github.com/sebastianbergmann/phpunit-mock-objects/issues/73 | ||
class ConcreteProxy extends AbstractProxy | ||
{ | ||
|
||
} | ||
|
||
class ConcreteSessionHandlerInterfaceProxy extends AbstractProxy implements \SessionHandlerInterface | ||
{ | ||
public function open($savePath, $sessionName) | ||
{ | ||
} | ||
|
||
public function close() | ||
{ | ||
} | ||
|
||
public function read($id) | ||
{ | ||
} | ||
|
||
public function write($id, $data) | ||
{ | ||
} | ||
|
||
public function destroy($id) | ||
{ | ||
} | ||
|
||
public function gc($maxlifetime) | ||
{ | ||
} | ||
} | ||
|
||
/** | ||
* Test class for AbstractProxy. | ||
* | ||
* @runTestsInSeparateProcesses | ||
* @author Drak <[email protected]> | ||
*/ | ||
class AbstractProxyTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
@@ -23,7 +52,7 @@ class AbstractProxyTest extends \PHPUnit_Framework_TestCase | |
|
||
protected function setUp() | ||
{ | ||
$this->proxy = new ConcreteProxy; | ||
$this->proxy = new ConcreteProxy(); | ||
} | ||
|
||
protected function tearDown() | ||
|
@@ -33,37 +62,31 @@ protected function tearDown() | |
|
||
public function testGetSaveHandlerName() | ||
{ | ||
$this->markTestIncomplete( | ||
'This test has not been implemented yet.' | ||
); | ||
$this->assertNull($this->proxy->getSaveHandlerName()); | ||
} | ||
|
||
public function testIsSessionHandlerInterface() | ||
{ | ||
$this->markTestIncomplete( | ||
'This test has not been implemented yet.' | ||
); | ||
$this->assertFalse($this->proxy->isSessionHandlerInterface()); | ||
$sh = new ConcreteSessionHandlerInterfaceProxy(); | ||
$this->assertTrue($sh->isSessionHandlerInterface()); | ||
} | ||
|
||
public function testIsWrapper() | ||
{ | ||
$this->markTestIncomplete( | ||
'This test has not been implemented yet.' | ||
); | ||
$this->assertFalse($this->proxy->isWrapper()); | ||
} | ||
|
||
public function testIsActive() | ||
{ | ||
$this->markTestIncomplete( | ||
'This test has not been implemented yet.' | ||
); | ||
$this->assertFalse($this->proxy->isActive()); | ||
} | ||
|
||
public function testSetActive() | ||
{ | ||
$this->markTestIncomplete( | ||
'This test has not been implemented yet.' | ||
); | ||
$this->proxy->setActive(true); | ||
$this->assertTrue($this->proxy->isActive()); | ||
$this->proxy->setActive(false); | ||
$this->assertFalse($this->proxy->isActive()); | ||
} | ||
|
||
} |
30 changes: 0 additions & 30 deletions
30
tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/Proxy/NativeProxyPHP54Test.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,27 +8,20 @@ | |
/** | ||
* Test class for NativeProxy. | ||
* | ||
* @runTestsInSeparateProcesses | ||
* @author Drak <[email protected]> | ||
*/ | ||
class NativeProxyPHP53Test extends \PHPUnit_Framework_TestCase | ||
class NativeProxyTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
if (version_compare(phpversion(), '5.4.0', '>=')) { | ||
$this->markTestSkipped('Test skipped, only for PHP 5.3'); | ||
} | ||
} | ||
|
||
public function testIsWrapper() | ||
{ | ||
$proxy = new NativeProxy(new NativeFileSessionHandler()); | ||
$proxy = new NativeProxy(); | ||
$this->assertFalse($proxy->isWrapper()); | ||
} | ||
|
||
public function testGetSaveHandlerName() | ||
{ | ||
$name = ini_get('session.save_handler'); | ||
$proxy = new NativeProxy(new NativeFileSessionHandler()); | ||
$proxy = new NativeProxy(); | ||
$this->assertEquals($name, $proxy->getSaveHandlerName()); | ||
} | ||
} |
Oops, something went wrong.