Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
61
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php
vendored
Normal file
61
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @requires PHP 7.0
|
||||
*/
|
||||
class AbstractSessionHandlerTest extends TestCase
|
||||
{
|
||||
private static $server;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$spec = array(
|
||||
1 => array('file', '/dev/null', 'w'),
|
||||
2 => array('file', '/dev/null', 'w'),
|
||||
);
|
||||
if (!self::$server = @proc_open('exec php -S localhost:8053', $spec, $pipes, __DIR__.'/Fixtures')) {
|
||||
self::markTestSkipped('PHP server unable to start.');
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
if (self::$server) {
|
||||
proc_terminate(self::$server);
|
||||
proc_close(self::$server);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideSession
|
||||
*/
|
||||
public function testSession($fixture)
|
||||
{
|
||||
$context = array('http' => array('header' => "Cookie: sid=123abc\r\n"));
|
||||
$context = stream_context_create($context);
|
||||
$result = file_get_contents(sprintf('http://localhost:8053/%s.php', $fixture), false, $context);
|
||||
|
||||
$this->assertStringEqualsFile(__DIR__.sprintf('/Fixtures/%s.expected', $fixture), $result);
|
||||
}
|
||||
|
||||
public function provideSession()
|
||||
{
|
||||
foreach (glob(__DIR__.'/Fixtures/*.php') as $file) {
|
||||
yield array(pathinfo($file, PATHINFO_FILENAME));
|
||||
}
|
||||
}
|
||||
}
|
151
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/common.inc
vendored
Normal file
151
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/common.inc
vendored
Normal file
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
|
||||
|
||||
$parent = __DIR__;
|
||||
while (!@file_exists($parent.'/vendor/autoload.php')) {
|
||||
if (!@file_exists($parent)) {
|
||||
// open_basedir restriction in effect
|
||||
break;
|
||||
}
|
||||
if ($parent === dirname($parent)) {
|
||||
echo "vendor/autoload.php not found\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$parent = dirname($parent);
|
||||
}
|
||||
|
||||
require $parent.'/vendor/autoload.php';
|
||||
|
||||
error_reporting(-1);
|
||||
ini_set('html_errors', 0);
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('session.gc_probability', 0);
|
||||
ini_set('session.serialize_handler', 'php');
|
||||
ini_set('session.cookie_lifetime', 0);
|
||||
ini_set('session.cookie_domain', '');
|
||||
ini_set('session.cookie_secure', '');
|
||||
ini_set('session.cookie_httponly', '');
|
||||
ini_set('session.use_cookies', 1);
|
||||
ini_set('session.use_only_cookies', 1);
|
||||
ini_set('session.cache_expire', 180);
|
||||
ini_set('session.cookie_path', '/');
|
||||
ini_set('session.cookie_domain', '');
|
||||
ini_set('session.cookie_secure', 1);
|
||||
ini_set('session.cookie_httponly', 1);
|
||||
ini_set('session.use_strict_mode', 1);
|
||||
ini_set('session.lazy_write', 1);
|
||||
ini_set('session.name', 'sid');
|
||||
ini_set('session.save_path', __DIR__);
|
||||
ini_set('session.cache_limiter', '');
|
||||
|
||||
header_remove('X-Powered-By');
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
|
||||
register_shutdown_function(function () {
|
||||
echo "\n";
|
||||
session_write_close();
|
||||
print_r(headers_list());
|
||||
echo "shutdown\n";
|
||||
});
|
||||
ob_start();
|
||||
|
||||
class TestSessionHandler extends AbstractSessionHandler
|
||||
{
|
||||
private $data;
|
||||
|
||||
public function __construct($data = '')
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function open($path, $name)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return parent::open($path, $name);
|
||||
}
|
||||
|
||||
public function validateId($sessionId)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return parent::validateId($sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($sessionId)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return parent::read($sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateTimestamp($sessionId, $data)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($sessionId, $data)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return parent::write($sessionId, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return parent::destroy($sessionId);
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function gc($maxLifetime)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function doRead($sessionId)
|
||||
{
|
||||
echo __FUNCTION__.': ', $this->data, "\n";
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
protected function doWrite($sessionId, $data)
|
||||
{
|
||||
echo __FUNCTION__.': ', $data, "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function doDestroy($sessionId)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
17
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/empty_destroys.expected
vendored
Normal file
17
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/empty_destroys.expected
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
|
||||
write
|
||||
destroy
|
||||
doDestroy
|
||||
close
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=10800, private, must-revalidate
|
||||
[2] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
|
||||
)
|
||||
shutdown
|
8
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/empty_destroys.php
vendored
Normal file
8
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/empty_destroys.php
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
|
||||
session_start();
|
||||
|
||||
unset($_SESSION['abc']);
|
14
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/read_only.expected
vendored
Normal file
14
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/read_only.expected
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
123
|
||||
updateTimestamp
|
||||
close
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=10800, private, must-revalidate
|
||||
)
|
||||
shutdown
|
8
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/read_only.php
vendored
Normal file
8
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/read_only.php
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
|
||||
session_start();
|
||||
|
||||
echo $_SESSION['abc'];
|
24
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/regenerate.expected
vendored
Normal file
24
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/regenerate.expected
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
destroy
|
||||
doDestroy
|
||||
close
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
|
||||
write
|
||||
doWrite: abc|i:123;
|
||||
close
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=10800, private, must-revalidate
|
||||
[2] => Set-Cookie: sid=random_session_id; path=/; secure; HttpOnly
|
||||
)
|
||||
shutdown
|
10
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/regenerate.php
vendored
Normal file
10
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/regenerate.php
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
|
||||
session_start();
|
||||
|
||||
session_regenerate_id(true);
|
||||
|
||||
ob_start(function ($buffer) { return str_replace(session_id(), 'random_session_id', $buffer); });
|
20
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/storage.expected
vendored
Normal file
20
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/storage.expected
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
open
|
||||
validateId
|
||||
read
|
||||
doRead:
|
||||
read
|
||||
Array
|
||||
(
|
||||
[0] => bar
|
||||
)
|
||||
$_SESSION is not empty
|
||||
write
|
||||
destroy
|
||||
close
|
||||
$_SESSION is not empty
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=0, private, must-revalidate
|
||||
)
|
||||
shutdown
|
24
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/storage.php
vendored
Normal file
24
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/storage.php
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
|
||||
$storage = new NativeSessionStorage();
|
||||
$storage->setSaveHandler(new TestSessionHandler());
|
||||
$flash = new FlashBag();
|
||||
$storage->registerBag($flash);
|
||||
$storage->start();
|
||||
|
||||
$flash->add('foo', 'bar');
|
||||
|
||||
print_r($flash->get('foo'));
|
||||
echo empty($_SESSION) ? '$_SESSION is empty' : '$_SESSION is not empty';
|
||||
echo "\n";
|
||||
|
||||
$storage->save();
|
||||
|
||||
echo empty($_SESSION) ? '$_SESSION is empty' : '$_SESSION is not empty';
|
||||
|
||||
ob_start(function ($buffer) { return str_replace(session_id(), 'random_session_id', $buffer); });
|
15
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/with_cookie.expected
vendored
Normal file
15
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/with_cookie.expected
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
|
||||
updateTimestamp
|
||||
close
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=10800, private, must-revalidate
|
||||
[2] => Set-Cookie: abc=def
|
||||
)
|
||||
shutdown
|
8
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/with_cookie.php
vendored
Normal file
8
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/with_cookie.php
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
|
||||
session_start();
|
||||
|
||||
setcookie('abc', 'def');
|
|
@ -0,0 +1,24 @@
|
|||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
updateTimestamp
|
||||
close
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
|
||||
write
|
||||
destroy
|
||||
doDestroy
|
||||
close
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=10800, private, must-revalidate
|
||||
[2] => Set-Cookie: abc=def
|
||||
)
|
||||
shutdown
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
setcookie('abc', 'def');
|
||||
|
||||
session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
|
||||
session_start();
|
||||
session_write_close();
|
||||
session_start();
|
||||
|
||||
$_SESSION['abc'] = 234;
|
||||
unset($_SESSION['abc']);
|
135
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php
vendored
Normal file
135
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler;
|
||||
|
||||
/**
|
||||
* @requires extension memcache
|
||||
* @group time-sensitive
|
||||
* @group legacy
|
||||
*/
|
||||
class MemcacheSessionHandlerTest extends TestCase
|
||||
{
|
||||
const PREFIX = 'prefix_';
|
||||
const TTL = 1000;
|
||||
|
||||
/**
|
||||
* @var MemcacheSessionHandler
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
protected $memcache;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('PHPUnit_MockObject cannot mock the Memcache class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289');
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
$this->memcache = $this->getMockBuilder('Memcache')->getMock();
|
||||
$this->storage = new MemcacheSessionHandler(
|
||||
$this->memcache,
|
||||
array('prefix' => self::PREFIX, 'expiretime' => self::TTL)
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->memcache = null;
|
||||
$this->storage = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testOpenSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->open('', ''));
|
||||
}
|
||||
|
||||
public function testCloseSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->close());
|
||||
}
|
||||
|
||||
public function testReadSession()
|
||||
{
|
||||
$this->memcache
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with(self::PREFIX.'id')
|
||||
;
|
||||
|
||||
$this->assertEquals('', $this->storage->read('id'));
|
||||
}
|
||||
|
||||
public function testWriteSession()
|
||||
{
|
||||
$this->memcache
|
||||
->expects($this->once())
|
||||
->method('set')
|
||||
->with(self::PREFIX.'id', 'data', 0, $this->equalTo(time() + self::TTL, 2))
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$this->assertTrue($this->storage->write('id', 'data'));
|
||||
}
|
||||
|
||||
public function testDestroySession()
|
||||
{
|
||||
$this->memcache
|
||||
->expects($this->once())
|
||||
->method('delete')
|
||||
->with(self::PREFIX.'id')
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$this->assertTrue($this->storage->destroy('id'));
|
||||
}
|
||||
|
||||
public function testGcSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->gc(123));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getOptionFixtures
|
||||
*/
|
||||
public function testSupportedOptions($options, $supported)
|
||||
{
|
||||
try {
|
||||
new MemcacheSessionHandler($this->memcache, $options);
|
||||
$this->assertTrue($supported);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertFalse($supported);
|
||||
}
|
||||
}
|
||||
|
||||
public function getOptionFixtures()
|
||||
{
|
||||
return array(
|
||||
array(array('prefix' => 'session'), true),
|
||||
array(array('expiretime' => 100), true),
|
||||
array(array('prefix' => 'session', 'expiretime' => 200), true),
|
||||
array(array('expiretime' => 100, 'foo' => 'bar'), false),
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetConnection()
|
||||
{
|
||||
$method = new \ReflectionMethod($this->storage, 'getMemcache');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertInstanceOf('\Memcache', $method->invoke($this->storage));
|
||||
}
|
||||
}
|
139
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php
vendored
Normal file
139
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler;
|
||||
|
||||
/**
|
||||
* @requires extension memcached
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class MemcachedSessionHandlerTest extends TestCase
|
||||
{
|
||||
const PREFIX = 'prefix_';
|
||||
const TTL = 1000;
|
||||
|
||||
/**
|
||||
* @var MemcachedSessionHandler
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
protected $memcached;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('PHPUnit_MockObject cannot mock the Memcached class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289');
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
|
||||
if (version_compare(phpversion('memcached'), '2.2.0', '>=') && version_compare(phpversion('memcached'), '3.0.0b1', '<')) {
|
||||
$this->markTestSkipped('Tests can only be run with memcached extension 2.1.0 or lower, or 3.0.0b1 or higher');
|
||||
}
|
||||
|
||||
$this->memcached = $this->getMockBuilder('Memcached')->getMock();
|
||||
$this->storage = new MemcachedSessionHandler(
|
||||
$this->memcached,
|
||||
array('prefix' => self::PREFIX, 'expiretime' => self::TTL)
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->memcached = null;
|
||||
$this->storage = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testOpenSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->open('', ''));
|
||||
}
|
||||
|
||||
public function testCloseSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->close());
|
||||
}
|
||||
|
||||
public function testReadSession()
|
||||
{
|
||||
$this->memcached
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with(self::PREFIX.'id')
|
||||
;
|
||||
|
||||
$this->assertEquals('', $this->storage->read('id'));
|
||||
}
|
||||
|
||||
public function testWriteSession()
|
||||
{
|
||||
$this->memcached
|
||||
->expects($this->once())
|
||||
->method('set')
|
||||
->with(self::PREFIX.'id', 'data', $this->equalTo(time() + self::TTL, 2))
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$this->assertTrue($this->storage->write('id', 'data'));
|
||||
}
|
||||
|
||||
public function testDestroySession()
|
||||
{
|
||||
$this->memcached
|
||||
->expects($this->once())
|
||||
->method('delete')
|
||||
->with(self::PREFIX.'id')
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$this->assertTrue($this->storage->destroy('id'));
|
||||
}
|
||||
|
||||
public function testGcSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->gc(123));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getOptionFixtures
|
||||
*/
|
||||
public function testSupportedOptions($options, $supported)
|
||||
{
|
||||
try {
|
||||
new MemcachedSessionHandler($this->memcached, $options);
|
||||
$this->assertTrue($supported);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertFalse($supported);
|
||||
}
|
||||
}
|
||||
|
||||
public function getOptionFixtures()
|
||||
{
|
||||
return array(
|
||||
array(array('prefix' => 'session'), true),
|
||||
array(array('expiretime' => 100), true),
|
||||
array(array('prefix' => 'session', 'expiretime' => 200), true),
|
||||
array(array('expiretime' => 100, 'foo' => 'bar'), false),
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetConnection()
|
||||
{
|
||||
$method = new \ReflectionMethod($this->storage, 'getMemcached');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertInstanceOf('\Memcached', $method->invoke($this->storage));
|
||||
}
|
||||
}
|
333
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php
vendored
Normal file
333
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,333 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler;
|
||||
|
||||
/**
|
||||
* @author Markus Bachmann <markus.bachmann@bachi.biz>
|
||||
* @group time-sensitive
|
||||
* @group legacy
|
||||
*/
|
||||
class MongoDbSessionHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $mongo;
|
||||
private $storage;
|
||||
public $options;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (\extension_loaded('mongodb')) {
|
||||
if (!class_exists('MongoDB\Client')) {
|
||||
$this->markTestSkipped('The mongodb/mongodb package is required.');
|
||||
}
|
||||
} elseif (!\extension_loaded('mongo')) {
|
||||
$this->markTestSkipped('The Mongo or MongoDB extension is required.');
|
||||
}
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$mongoClass = 'MongoDB\Client';
|
||||
} else {
|
||||
$mongoClass = version_compare(phpversion('mongo'), '1.3.0', '<') ? 'Mongo' : 'MongoClient';
|
||||
}
|
||||
|
||||
$this->mongo = $this->getMockBuilder($mongoClass)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->options = array(
|
||||
'id_field' => '_id',
|
||||
'data_field' => 'data',
|
||||
'time_field' => 'time',
|
||||
'expiry_field' => 'expires_at',
|
||||
'database' => 'sf2-test',
|
||||
'collection' => 'session-test',
|
||||
);
|
||||
|
||||
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testConstructorShouldThrowExceptionForInvalidMongo()
|
||||
{
|
||||
new MongoDbSessionHandler(new \stdClass(), $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testConstructorShouldThrowExceptionForMissingOptions()
|
||||
{
|
||||
new MongoDbSessionHandler($this->mongo, array());
|
||||
}
|
||||
|
||||
public function testOpenMethodAlwaysReturnTrue()
|
||||
{
|
||||
$this->assertTrue($this->storage->open('test', 'test'), 'The "open" method should always return true');
|
||||
}
|
||||
|
||||
public function testCloseMethodAlwaysReturnTrue()
|
||||
{
|
||||
$this->assertTrue($this->storage->close(), 'The "close" method should always return true');
|
||||
}
|
||||
|
||||
public function testRead()
|
||||
{
|
||||
$collection = $this->createMongoCollectionMock();
|
||||
|
||||
$this->mongo->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
// defining the timeout before the actual method call
|
||||
// allows to test for "greater than" values in the $criteria
|
||||
$testTimeout = time() + 1;
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method('findOne')
|
||||
->will($this->returnCallback(function ($criteria) use ($testTimeout) {
|
||||
$this->assertArrayHasKey($this->options['id_field'], $criteria);
|
||||
$this->assertEquals($criteria[$this->options['id_field']], 'foo');
|
||||
|
||||
$this->assertArrayHasKey($this->options['expiry_field'], $criteria);
|
||||
$this->assertArrayHasKey('$gte', $criteria[$this->options['expiry_field']]);
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$this->options['expiry_field']]['$gte']);
|
||||
$this->assertGreaterThanOrEqual(round((string) $criteria[$this->options['expiry_field']]['$gte'] / 1000), $testTimeout);
|
||||
} else {
|
||||
$this->assertInstanceOf('MongoDate', $criteria[$this->options['expiry_field']]['$gte']);
|
||||
$this->assertGreaterThanOrEqual($criteria[$this->options['expiry_field']]['$gte']->sec, $testTimeout);
|
||||
}
|
||||
|
||||
$fields = array(
|
||||
$this->options['id_field'] => 'foo',
|
||||
);
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$fields[$this->options['data_field']] = new \MongoDB\BSON\Binary('bar', \MongoDB\BSON\Binary::TYPE_OLD_BINARY);
|
||||
$fields[$this->options['id_field']] = new \MongoDB\BSON\UTCDateTime(time() * 1000);
|
||||
} else {
|
||||
$fields[$this->options['data_field']] = new \MongoBinData('bar', \MongoBinData::BYTE_ARRAY);
|
||||
$fields[$this->options['id_field']] = new \MongoDate();
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}));
|
||||
|
||||
$this->assertEquals('bar', $this->storage->read('foo'));
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$collection = $this->createMongoCollectionMock();
|
||||
|
||||
$this->mongo->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$data = array();
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'updateOne' : 'update';
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method($methodName)
|
||||
->will($this->returnCallback(function ($criteria, $updateData, $options) use (&$data) {
|
||||
$this->assertEquals(array($this->options['id_field'] => 'foo'), $criteria);
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertEquals(array('upsert' => true), $options);
|
||||
} else {
|
||||
$this->assertEquals(array('upsert' => true, 'multiple' => false), $options);
|
||||
}
|
||||
|
||||
$data = $updateData['$set'];
|
||||
}));
|
||||
|
||||
$expectedExpiry = time() + (int) ini_get('session.gc_maxlifetime');
|
||||
$this->assertTrue($this->storage->write('foo', 'bar'));
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertEquals('bar', $data[$this->options['data_field']]->getData());
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['time_field']]);
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['expiry_field']]);
|
||||
$this->assertGreaterThanOrEqual($expectedExpiry, round((string) $data[$this->options['expiry_field']] / 1000));
|
||||
} else {
|
||||
$this->assertEquals('bar', $data[$this->options['data_field']]->bin);
|
||||
$this->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
|
||||
$this->assertInstanceOf('MongoDate', $data[$this->options['expiry_field']]);
|
||||
$this->assertGreaterThanOrEqual($expectedExpiry, $data[$this->options['expiry_field']]->sec);
|
||||
}
|
||||
}
|
||||
|
||||
public function testWriteWhenUsingExpiresField()
|
||||
{
|
||||
$this->options = array(
|
||||
'id_field' => '_id',
|
||||
'data_field' => 'data',
|
||||
'time_field' => 'time',
|
||||
'database' => 'sf2-test',
|
||||
'collection' => 'session-test',
|
||||
'expiry_field' => 'expiresAt',
|
||||
);
|
||||
|
||||
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
|
||||
|
||||
$collection = $this->createMongoCollectionMock();
|
||||
|
||||
$this->mongo->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$data = array();
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'updateOne' : 'update';
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method($methodName)
|
||||
->will($this->returnCallback(function ($criteria, $updateData, $options) use (&$data) {
|
||||
$this->assertEquals(array($this->options['id_field'] => 'foo'), $criteria);
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertEquals(array('upsert' => true), $options);
|
||||
} else {
|
||||
$this->assertEquals(array('upsert' => true, 'multiple' => false), $options);
|
||||
}
|
||||
|
||||
$data = $updateData['$set'];
|
||||
}));
|
||||
|
||||
$this->assertTrue($this->storage->write('foo', 'bar'));
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertEquals('bar', $data[$this->options['data_field']]->getData());
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['time_field']]);
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['expiry_field']]);
|
||||
} else {
|
||||
$this->assertEquals('bar', $data[$this->options['data_field']]->bin);
|
||||
$this->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
|
||||
$this->assertInstanceOf('MongoDate', $data[$this->options['expiry_field']]);
|
||||
}
|
||||
}
|
||||
|
||||
public function testReplaceSessionData()
|
||||
{
|
||||
$collection = $this->createMongoCollectionMock();
|
||||
|
||||
$this->mongo->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$data = array();
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'updateOne' : 'update';
|
||||
|
||||
$collection->expects($this->exactly(2))
|
||||
->method($methodName)
|
||||
->will($this->returnCallback(function ($criteria, $updateData, $options) use (&$data) {
|
||||
$data = $updateData;
|
||||
}));
|
||||
|
||||
$this->storage->write('foo', 'bar');
|
||||
$this->storage->write('foo', 'foobar');
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertEquals('foobar', $data['$set'][$this->options['data_field']]->getData());
|
||||
} else {
|
||||
$this->assertEquals('foobar', $data['$set'][$this->options['data_field']]->bin);
|
||||
}
|
||||
}
|
||||
|
||||
public function testDestroy()
|
||||
{
|
||||
$collection = $this->createMongoCollectionMock();
|
||||
|
||||
$this->mongo->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'deleteOne' : 'remove';
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method($methodName)
|
||||
->with(array($this->options['id_field'] => 'foo'));
|
||||
|
||||
$this->assertTrue($this->storage->destroy('foo'));
|
||||
}
|
||||
|
||||
public function testGc()
|
||||
{
|
||||
$collection = $this->createMongoCollectionMock();
|
||||
|
||||
$this->mongo->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'deleteMany' : 'remove';
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method($methodName)
|
||||
->will($this->returnCallback(function ($criteria) {
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$this->options['expiry_field']]['$lt']);
|
||||
$this->assertGreaterThanOrEqual(time() - 1, round((string) $criteria[$this->options['expiry_field']]['$lt'] / 1000));
|
||||
} else {
|
||||
$this->assertInstanceOf('MongoDate', $criteria[$this->options['expiry_field']]['$lt']);
|
||||
$this->assertGreaterThanOrEqual(time() - 1, $criteria[$this->options['expiry_field']]['$lt']->sec);
|
||||
}
|
||||
}));
|
||||
|
||||
$this->assertTrue($this->storage->gc(1));
|
||||
}
|
||||
|
||||
public function testGetConnection()
|
||||
{
|
||||
$method = new \ReflectionMethod($this->storage, 'getMongo');
|
||||
$method->setAccessible(true);
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$mongoClass = 'MongoDB\Client';
|
||||
} else {
|
||||
$mongoClass = version_compare(phpversion('mongo'), '1.3.0', '<') ? 'Mongo' : 'MongoClient';
|
||||
}
|
||||
|
||||
$this->assertInstanceOf($mongoClass, $method->invoke($this->storage));
|
||||
}
|
||||
|
||||
private function createMongoCollectionMock()
|
||||
{
|
||||
$collectionClass = 'MongoCollection';
|
||||
if (phpversion('mongodb')) {
|
||||
$collectionClass = 'MongoDB\Collection';
|
||||
}
|
||||
|
||||
$collection = $this->getMockBuilder($collectionClass)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
77
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php
vendored
Normal file
77
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for NativeFileSessionHandler.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class NativeFileSessionHandlerTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir()));
|
||||
|
||||
$this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
|
||||
$this->assertEquals('user', ini_get('session.save_handler'));
|
||||
|
||||
$this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
|
||||
$this->assertEquals('TESTING', ini_get('session.name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider savePathDataProvider
|
||||
*/
|
||||
public function testConstructSavePath($savePath, $expectedSavePath, $path)
|
||||
{
|
||||
$handler = new NativeFileSessionHandler($savePath);
|
||||
$this->assertEquals($expectedSavePath, ini_get('session.save_path'));
|
||||
$this->assertTrue(is_dir(realpath($path)));
|
||||
|
||||
rmdir($path);
|
||||
}
|
||||
|
||||
public function savePathDataProvider()
|
||||
{
|
||||
$base = sys_get_temp_dir();
|
||||
|
||||
return array(
|
||||
array("$base/foo", "$base/foo", "$base/foo"),
|
||||
array("5;$base/foo", "5;$base/foo", "$base/foo"),
|
||||
array("5;0600;$base/foo", "5;0600;$base/foo", "$base/foo"),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testConstructException()
|
||||
{
|
||||
$handler = new NativeFileSessionHandler('something;invalid;with;too-many-args');
|
||||
}
|
||||
|
||||
public function testConstructDefault()
|
||||
{
|
||||
$path = ini_get('session.save_path');
|
||||
$storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler());
|
||||
|
||||
$this->assertEquals($path, ini_get('session.save_path'));
|
||||
}
|
||||
}
|
38
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php
vendored
Normal file
38
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
|
||||
|
||||
/**
|
||||
* Test class for NativeSessionHandler.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @group legacy
|
||||
*/
|
||||
class NativeSessionHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedDeprecation The Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler class is deprecated since Symfony 3.4 and will be removed in 4.0. Use the \SessionHandler class instead.
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$handler = new NativeSessionHandler();
|
||||
|
||||
$this->assertInstanceOf('SessionHandler', $handler);
|
||||
$this->assertTrue($handler instanceof NativeSessionHandler);
|
||||
}
|
||||
}
|
59
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/NullSessionHandlerTest.php
vendored
Normal file
59
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/NullSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for NullSessionHandler.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class NullSessionHandlerTest extends TestCase
|
||||
{
|
||||
public function testSaveHandlers()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
$this->assertEquals('user', ini_get('session.save_handler'));
|
||||
}
|
||||
|
||||
public function testSession()
|
||||
{
|
||||
session_id('nullsessionstorage');
|
||||
$storage = $this->getStorage();
|
||||
$session = new Session($storage);
|
||||
$this->assertNull($session->get('something'));
|
||||
$session->set('something', 'unique');
|
||||
$this->assertEquals('unique', $session->get('something'));
|
||||
}
|
||||
|
||||
public function testNothingIsPersisted()
|
||||
{
|
||||
session_id('nullsessionstorage');
|
||||
$storage = $this->getStorage();
|
||||
$session = new Session($storage);
|
||||
$session->start();
|
||||
$this->assertEquals('nullsessionstorage', $session->getId());
|
||||
$this->assertNull($session->get('something'));
|
||||
}
|
||||
|
||||
public function getStorage()
|
||||
{
|
||||
return new NativeSessionStorage(array(), new NullSessionHandler());
|
||||
}
|
||||
}
|
411
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php
vendored
Normal file
411
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,411 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
|
||||
|
||||
/**
|
||||
* @requires extension pdo_sqlite
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class PdoSessionHandlerTest extends TestCase
|
||||
{
|
||||
private $dbFile;
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// make sure the temporary database file is deleted when it has been created (even when a test fails)
|
||||
if ($this->dbFile) {
|
||||
@unlink($this->dbFile);
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
protected function getPersistentSqliteDsn()
|
||||
{
|
||||
$this->dbFile = tempnam(sys_get_temp_dir(), 'sf2_sqlite_sessions');
|
||||
|
||||
return 'sqlite:'.$this->dbFile;
|
||||
}
|
||||
|
||||
protected function getMemorySqlitePdo()
|
||||
{
|
||||
$pdo = new \PDO('sqlite::memory:');
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$storage = new PdoSessionHandler($pdo);
|
||||
$storage->createTable();
|
||||
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testWrongPdoErrMode()
|
||||
{
|
||||
$pdo = $this->getMemorySqlitePdo();
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT);
|
||||
|
||||
$storage = new PdoSessionHandler($pdo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testInexistentTable()
|
||||
{
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo(), array('db_table' => 'inexistent_table'));
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('id');
|
||||
$storage->write('id', 'data');
|
||||
$storage->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testCreateTableTwice()
|
||||
{
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
|
||||
$storage->createTable();
|
||||
}
|
||||
|
||||
public function testWithLazyDsnConnection()
|
||||
{
|
||||
$dsn = $this->getPersistentSqliteDsn();
|
||||
|
||||
$storage = new PdoSessionHandler($dsn);
|
||||
$storage->createTable();
|
||||
$storage->open('', 'sid');
|
||||
$data = $storage->read('id');
|
||||
$storage->write('id', 'data');
|
||||
$storage->close();
|
||||
$this->assertSame('', $data, 'New session returns empty string data');
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$data = $storage->read('id');
|
||||
$storage->close();
|
||||
$this->assertSame('data', $data, 'Written value can be read back correctly');
|
||||
}
|
||||
|
||||
public function testWithLazySavePathConnection()
|
||||
{
|
||||
$dsn = $this->getPersistentSqliteDsn();
|
||||
|
||||
// Open is called with what ini_set('session.save_path', $dsn) would mean
|
||||
$storage = new PdoSessionHandler(null);
|
||||
$storage->open($dsn, 'sid');
|
||||
$storage->createTable();
|
||||
$data = $storage->read('id');
|
||||
$storage->write('id', 'data');
|
||||
$storage->close();
|
||||
$this->assertSame('', $data, 'New session returns empty string data');
|
||||
|
||||
$storage->open($dsn, 'sid');
|
||||
$data = $storage->read('id');
|
||||
$storage->close();
|
||||
$this->assertSame('data', $data, 'Written value can be read back correctly');
|
||||
}
|
||||
|
||||
public function testReadWriteReadWithNullByte()
|
||||
{
|
||||
$sessionData = 'da'."\0".'ta';
|
||||
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
|
||||
$storage->open('', 'sid');
|
||||
$readData = $storage->read('id');
|
||||
$storage->write('id', $sessionData);
|
||||
$storage->close();
|
||||
$this->assertSame('', $readData, 'New session returns empty string data');
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$readData = $storage->read('id');
|
||||
$storage->close();
|
||||
$this->assertSame($sessionData, $readData, 'Written value can be read back correctly');
|
||||
}
|
||||
|
||||
public function testReadConvertsStreamToString()
|
||||
{
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('PHPUnit_MockObject cannot mock the PDOStatement class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289');
|
||||
}
|
||||
|
||||
$pdo = new MockPdo('pgsql');
|
||||
$pdo->prepareResult = $this->getMockBuilder('PDOStatement')->getMock();
|
||||
|
||||
$content = 'foobar';
|
||||
$stream = $this->createStream($content);
|
||||
|
||||
$pdo->prepareResult->expects($this->once())->method('fetchAll')
|
||||
->will($this->returnValue(array(array($stream, 42, time()))));
|
||||
|
||||
$storage = new PdoSessionHandler($pdo);
|
||||
$result = $storage->read('foo');
|
||||
|
||||
$this->assertSame($content, $result);
|
||||
}
|
||||
|
||||
public function testReadLockedConvertsStreamToString()
|
||||
{
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('PHPUnit_MockObject cannot mock the PDOStatement class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289');
|
||||
}
|
||||
if (ini_get('session.use_strict_mode')) {
|
||||
$this->markTestSkipped('Strict mode needs no locking for new sessions.');
|
||||
}
|
||||
|
||||
$pdo = new MockPdo('pgsql');
|
||||
$selectStmt = $this->getMockBuilder('PDOStatement')->getMock();
|
||||
$insertStmt = $this->getMockBuilder('PDOStatement')->getMock();
|
||||
|
||||
$pdo->prepareResult = function ($statement) use ($selectStmt, $insertStmt) {
|
||||
return 0 === strpos($statement, 'INSERT') ? $insertStmt : $selectStmt;
|
||||
};
|
||||
|
||||
$content = 'foobar';
|
||||
$stream = $this->createStream($content);
|
||||
$exception = null;
|
||||
|
||||
$selectStmt->expects($this->atLeast(2))->method('fetchAll')
|
||||
->will($this->returnCallback(function () use (&$exception, $stream) {
|
||||
return $exception ? array(array($stream, 42, time())) : array();
|
||||
}));
|
||||
|
||||
$insertStmt->expects($this->once())->method('execute')
|
||||
->will($this->returnCallback(function () use (&$exception) {
|
||||
throw $exception = new \PDOException('', '23');
|
||||
}));
|
||||
|
||||
$storage = new PdoSessionHandler($pdo);
|
||||
$result = $storage->read('foo');
|
||||
|
||||
$this->assertSame($content, $result);
|
||||
}
|
||||
|
||||
public function testReadingRequiresExactlySameId()
|
||||
{
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
|
||||
$storage->open('', 'sid');
|
||||
$storage->write('id', 'data');
|
||||
$storage->write('test', 'data');
|
||||
$storage->write('space ', 'data');
|
||||
$storage->close();
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$readDataCaseSensitive = $storage->read('ID');
|
||||
$readDataNoCharFolding = $storage->read('tést');
|
||||
$readDataKeepSpace = $storage->read('space ');
|
||||
$readDataExtraSpace = $storage->read('space ');
|
||||
$storage->close();
|
||||
|
||||
$this->assertSame('', $readDataCaseSensitive, 'Retrieval by ID should be case-sensitive (collation setting)');
|
||||
$this->assertSame('', $readDataNoCharFolding, 'Retrieval by ID should not do character folding (collation setting)');
|
||||
$this->assertSame('data', $readDataKeepSpace, 'Retrieval by ID requires spaces as-is');
|
||||
$this->assertSame('', $readDataExtraSpace, 'Retrieval by ID requires spaces as-is');
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates session_regenerate_id(true) which will require an INSERT or UPDATE (replace).
|
||||
*/
|
||||
public function testWriteDifferentSessionIdThanRead()
|
||||
{
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('id');
|
||||
$storage->destroy('id');
|
||||
$storage->write('new_id', 'data_of_new_session_id');
|
||||
$storage->close();
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$data = $storage->read('new_id');
|
||||
$storage->close();
|
||||
|
||||
$this->assertSame('data_of_new_session_id', $data, 'Data of regenerated session id is available');
|
||||
}
|
||||
|
||||
public function testWrongUsageStillWorks()
|
||||
{
|
||||
// wrong method sequence that should no happen, but still works
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
|
||||
$storage->write('id', 'data');
|
||||
$storage->write('other_id', 'other_data');
|
||||
$storage->destroy('inexistent');
|
||||
$storage->open('', 'sid');
|
||||
$data = $storage->read('id');
|
||||
$otherData = $storage->read('other_id');
|
||||
$storage->close();
|
||||
|
||||
$this->assertSame('data', $data);
|
||||
$this->assertSame('other_data', $otherData);
|
||||
}
|
||||
|
||||
public function testSessionDestroy()
|
||||
{
|
||||
$pdo = $this->getMemorySqlitePdo();
|
||||
$storage = new PdoSessionHandler($pdo);
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('id');
|
||||
$storage->write('id', 'data');
|
||||
$storage->close();
|
||||
$this->assertEquals(1, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn());
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('id');
|
||||
$storage->destroy('id');
|
||||
$storage->close();
|
||||
$this->assertEquals(0, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn());
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$data = $storage->read('id');
|
||||
$storage->close();
|
||||
$this->assertSame('', $data, 'Destroyed session returns empty string');
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testSessionGC()
|
||||
{
|
||||
$previousLifeTime = ini_set('session.gc_maxlifetime', 1000);
|
||||
$pdo = $this->getMemorySqlitePdo();
|
||||
$storage = new PdoSessionHandler($pdo);
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('id');
|
||||
$storage->write('id', 'data');
|
||||
$storage->close();
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('gc_id');
|
||||
ini_set('session.gc_maxlifetime', -1); // test that you can set lifetime of a session after it has been read
|
||||
$storage->write('gc_id', 'data');
|
||||
$storage->close();
|
||||
$this->assertEquals(2, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn(), 'No session pruned because gc not called');
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$data = $storage->read('gc_id');
|
||||
$storage->gc(-1);
|
||||
$storage->close();
|
||||
|
||||
ini_set('session.gc_maxlifetime', $previousLifeTime);
|
||||
|
||||
$this->assertSame('', $data, 'Session already considered garbage, so not returning data even if it is not pruned yet');
|
||||
$this->assertEquals(1, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn(), 'Expired session is pruned');
|
||||
}
|
||||
|
||||
public function testGetConnection()
|
||||
{
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
|
||||
|
||||
$method = new \ReflectionMethod($storage, 'getConnection');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertInstanceOf('\PDO', $method->invoke($storage));
|
||||
}
|
||||
|
||||
public function testGetConnectionConnectsIfNeeded()
|
||||
{
|
||||
$storage = new PdoSessionHandler('sqlite::memory:');
|
||||
|
||||
$method = new \ReflectionMethod($storage, 'getConnection');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertInstanceOf('\PDO', $method->invoke($storage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideUrlDsnPairs
|
||||
*/
|
||||
public function testUrlDsn($url, $expectedDsn, $expectedUser = null, $expectedPassword = null)
|
||||
{
|
||||
$storage = new PdoSessionHandler($url);
|
||||
|
||||
$this->assertAttributeEquals($expectedDsn, 'dsn', $storage);
|
||||
|
||||
if (null !== $expectedUser) {
|
||||
$this->assertAttributeEquals($expectedUser, 'username', $storage);
|
||||
}
|
||||
|
||||
if (null !== $expectedPassword) {
|
||||
$this->assertAttributeEquals($expectedPassword, 'password', $storage);
|
||||
}
|
||||
}
|
||||
|
||||
public function provideUrlDsnPairs()
|
||||
{
|
||||
yield array('mysql://localhost/test', 'mysql:host=localhost;dbname=test;');
|
||||
yield array('mysql://localhost:56/test', 'mysql:host=localhost;port=56;dbname=test;');
|
||||
yield array('mysql2://root:pwd@localhost/test', 'mysql:host=localhost;dbname=test;', 'root', 'pwd');
|
||||
yield array('postgres://localhost/test', 'pgsql:host=localhost;dbname=test;');
|
||||
yield array('postgresql://localhost:5634/test', 'pgsql:host=localhost;port=5634;dbname=test;');
|
||||
yield array('postgres://root:pwd@localhost/test', 'pgsql:host=localhost;dbname=test;', 'root', 'pwd');
|
||||
yield 'sqlite relative path' => array('sqlite://localhost/tmp/test', 'sqlite:tmp/test');
|
||||
yield 'sqlite absolute path' => array('sqlite://localhost//tmp/test', 'sqlite:/tmp/test');
|
||||
yield 'sqlite relative path without host' => array('sqlite:///tmp/test', 'sqlite:tmp/test');
|
||||
yield 'sqlite absolute path without host' => array('sqlite3:////tmp/test', 'sqlite:/tmp/test');
|
||||
yield array('sqlite://localhost/:memory:', 'sqlite::memory:');
|
||||
yield array('mssql://localhost/test', 'sqlsrv:server=localhost;Database=test');
|
||||
yield array('mssql://localhost:56/test', 'sqlsrv:server=localhost,56;Database=test');
|
||||
}
|
||||
|
||||
private function createStream($content)
|
||||
{
|
||||
$stream = tmpfile();
|
||||
fwrite($stream, $content);
|
||||
fseek($stream, 0);
|
||||
|
||||
return $stream;
|
||||
}
|
||||
}
|
||||
|
||||
class MockPdo extends \PDO
|
||||
{
|
||||
public $prepareResult;
|
||||
private $driverName;
|
||||
private $errorMode;
|
||||
|
||||
public function __construct($driverName = null, $errorMode = null)
|
||||
{
|
||||
$this->driverName = $driverName;
|
||||
$this->errorMode = null !== $errorMode ?: \PDO::ERRMODE_EXCEPTION;
|
||||
}
|
||||
|
||||
public function getAttribute($attribute)
|
||||
{
|
||||
if (\PDO::ATTR_ERRMODE === $attribute) {
|
||||
return $this->errorMode;
|
||||
}
|
||||
|
||||
if (\PDO::ATTR_DRIVER_NAME === $attribute) {
|
||||
return $this->driverName;
|
||||
}
|
||||
|
||||
return parent::getAttribute($attribute);
|
||||
}
|
||||
|
||||
public function prepare($statement, $driverOptions = array())
|
||||
{
|
||||
return \is_callable($this->prepareResult)
|
||||
? \call_user_func($this->prepareResult, $statement, $driverOptions)
|
||||
: $this->prepareResult;
|
||||
}
|
||||
|
||||
public function beginTransaction()
|
||||
{
|
||||
}
|
||||
|
||||
public function rollBack()
|
||||
{
|
||||
}
|
||||
}
|
189
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php
vendored
Normal file
189
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
|
||||
|
||||
class StrictSessionHandlerTest extends TestCase
|
||||
{
|
||||
public function testOpen()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('open')
|
||||
->with('path', 'name')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertInstanceOf('SessionUpdateTimestampHandlerInterface', $proxy);
|
||||
$this->assertInstanceOf(AbstractSessionHandler::class, $proxy);
|
||||
$this->assertTrue($proxy->open('path', 'name'));
|
||||
}
|
||||
|
||||
public function testCloseSession()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('close')
|
||||
->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->close());
|
||||
}
|
||||
|
||||
public function testValidateIdOK()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('data');
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->validateId('id'));
|
||||
}
|
||||
|
||||
public function testValidateIdKO()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('');
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertFalse($proxy->validateId('id'));
|
||||
}
|
||||
|
||||
public function testRead()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('data');
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertSame('data', $proxy->read('id'));
|
||||
}
|
||||
|
||||
public function testReadWithValidateIdOK()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('data');
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->validateId('id'));
|
||||
$this->assertSame('data', $proxy->read('id'));
|
||||
}
|
||||
|
||||
public function testReadWithValidateIdMismatch()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->exactly(2))->method('read')
|
||||
->withConsecutive(array('id1'), array('id2'))
|
||||
->will($this->onConsecutiveCalls('data1', 'data2'));
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->validateId('id1'));
|
||||
$this->assertSame('data2', $proxy->read('id2'));
|
||||
}
|
||||
|
||||
public function testUpdateTimestamp()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('write')
|
||||
->with('id', 'data')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->updateTimestamp('id', 'data'));
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('write')
|
||||
->with('id', 'data')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->write('id', 'data'));
|
||||
}
|
||||
|
||||
public function testWriteEmptyNewSession()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('');
|
||||
$handler->expects($this->never())->method('write');
|
||||
$handler->expects($this->once())->method('destroy')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertFalse($proxy->validateId('id'));
|
||||
$this->assertSame('', $proxy->read('id'));
|
||||
$this->assertTrue($proxy->write('id', ''));
|
||||
}
|
||||
|
||||
public function testWriteEmptyExistingSession()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('data');
|
||||
$handler->expects($this->never())->method('write');
|
||||
$handler->expects($this->once())->method('destroy')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertSame('data', $proxy->read('id'));
|
||||
$this->assertTrue($proxy->write('id', ''));
|
||||
}
|
||||
|
||||
public function testDestroy()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('destroy')
|
||||
->with('id')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->destroy('id'));
|
||||
}
|
||||
|
||||
public function testDestroyNewSession()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('');
|
||||
$handler->expects($this->once())->method('destroy')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertSame('', $proxy->read('id'));
|
||||
$this->assertTrue($proxy->destroy('id'));
|
||||
}
|
||||
|
||||
public function testDestroyNonEmptyNewSession()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('');
|
||||
$handler->expects($this->once())->method('write')
|
||||
->with('id', 'data')->willReturn(true);
|
||||
$handler->expects($this->once())->method('destroy')
|
||||
->with('id')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertSame('', $proxy->read('id'));
|
||||
$this->assertTrue($proxy->write('id', 'data'));
|
||||
$this->assertTrue($proxy->destroy('id'));
|
||||
}
|
||||
|
||||
public function testGc()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('gc')
|
||||
->with(123)->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->gc(123));
|
||||
}
|
||||
}
|
97
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/WriteCheckSessionHandlerTest.php
vendored
Normal file
97
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/WriteCheckSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler;
|
||||
|
||||
/**
|
||||
* @author Adrien Brault <adrien.brault@gmail.com>
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
class WriteCheckSessionHandlerTest extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->once())
|
||||
->method('close')
|
||||
->with()
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$this->assertTrue($writeCheckSessionHandler->close());
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->once())
|
||||
->method('write')
|
||||
->with('foo', 'bar')
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$this->assertTrue($writeCheckSessionHandler->write('foo', 'bar'));
|
||||
}
|
||||
|
||||
public function testSkippedWrite()
|
||||
{
|
||||
$wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->once())
|
||||
->method('read')
|
||||
->with('foo')
|
||||
->will($this->returnValue('bar'))
|
||||
;
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->never())
|
||||
->method('write')
|
||||
;
|
||||
|
||||
$this->assertEquals('bar', $writeCheckSessionHandler->read('foo'));
|
||||
$this->assertTrue($writeCheckSessionHandler->write('foo', 'bar'));
|
||||
}
|
||||
|
||||
public function testNonSkippedWrite()
|
||||
{
|
||||
$wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->once())
|
||||
->method('read')
|
||||
->with('foo')
|
||||
->will($this->returnValue('bar'))
|
||||
;
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->once())
|
||||
->method('write')
|
||||
->with('foo', 'baZZZ')
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$this->assertEquals('bar', $writeCheckSessionHandler->read('foo'));
|
||||
$this->assertTrue($writeCheckSessionHandler->write('foo', 'baZZZ'));
|
||||
}
|
||||
}
|
Reference in a new issue