mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-25 20:29:10 -04:00
ALPHA 3.0.2a
This commit is contained in:
@@ -208,6 +208,19 @@ class BinaryFileResponseTest extends ResponseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testUnpreparedResponseSendsFullFile()
|
||||
{
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200);
|
||||
|
||||
$data = file_get_contents(__DIR__.'/File/Fixtures/test.gif');
|
||||
|
||||
$this->expectOutputString($data);
|
||||
$response = clone $response;
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidRanges
|
||||
*/
|
||||
|
||||
@@ -154,6 +154,18 @@ class CookieTest extends TestCase
|
||||
$cookie = new Cookie('foo', 'bar', time() - 20);
|
||||
|
||||
$this->assertTrue($cookie->isCleared(), '->isCleared() returns true if the cookie has expired');
|
||||
|
||||
$cookie = new Cookie('foo', 'bar');
|
||||
|
||||
$this->assertFalse($cookie->isCleared());
|
||||
|
||||
$cookie = new Cookie('foo', 'bar', 0);
|
||||
|
||||
$this->assertFalse($cookie->isCleared());
|
||||
|
||||
$cookie = new Cookie('foo', 'bar', -1);
|
||||
|
||||
$this->assertFalse($cookie->isCleared());
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
namespace Symfony\Component\HttpFoundation\Tests\File\MimeType;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
||||
|
||||
/**
|
||||
* @requires extension fileinfo
|
||||
@@ -59,7 +59,7 @@ class MimeTypeTest extends TestCase
|
||||
|
||||
public function testGuessWithNonReadablePath()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
if ('\\' === \DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('Can not verify chmod operations on Windows');
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class UploadedFileTest extends TestCase
|
||||
|
||||
$this->assertEquals('application/octet-stream', $file->getClientMimeType());
|
||||
|
||||
if (extension_loaded('fileinfo')) {
|
||||
if (\extension_loaded('fileinfo')) {
|
||||
$this->assertEquals('image/gif', $file->getMimeType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ Array
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: no-cache, private
|
||||
[2] => Date: Sat, 12 Nov 1955 20:04:00 GMT
|
||||
[3] => Set-Cookie: %3F%2A%28%29%3A%40%26%2B%24%2F%25%23%5B%5D=%3F%2A%28%29%3A%40%26%2B%24%2F%25%23%5B%5D; path=/
|
||||
[3] => Set-Cookie: ?*():@&+$/%#[]=%3F%2A%28%29%3A%40%26%2B%24%2F%25%23%5B%5D; path=/
|
||||
[4] => Set-Cookie: ?*():@&+$/%#[]=%3F%2A%28%29%3A%40%26%2B%24%2F%25%23%5B%5D; path=/
|
||||
)
|
||||
shutdown
|
||||
|
||||
@@ -192,7 +192,7 @@ class HeaderBagTest extends TestCase
|
||||
$this->assertEquals(array($headers[$key]), $val);
|
||||
}
|
||||
|
||||
$this->assertEquals(count($headers), $i);
|
||||
$this->assertEquals(\count($headers), $i);
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
@@ -200,6 +200,6 @@ class HeaderBagTest extends TestCase
|
||||
$headers = array('foo' => 'bar', 'HELLO' => 'WORLD');
|
||||
$headerBag = new HeaderBag($headers);
|
||||
|
||||
$this->assertCount(count($headers), $headerBag);
|
||||
$this->assertCount(\count($headers), $headerBag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class IpUtilsTest extends TestCase
|
||||
*/
|
||||
public function testIpv6($matches, $remoteAddr, $cidr)
|
||||
{
|
||||
if (!defined('AF_INET6')) {
|
||||
if (!\defined('AF_INET6')) {
|
||||
$this->markTestSkipped('Only works when PHP is compiled without the option "disable-ipv6".');
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class IpUtilsTest extends TestCase
|
||||
*/
|
||||
public function testAnIpv6WithOptionDisabledIpv6()
|
||||
{
|
||||
if (defined('AF_INET6')) {
|
||||
if (\defined('AF_INET6')) {
|
||||
$this->markTestSkipped('Only works when PHP is compiled with the option "disable-ipv6".');
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ class ParameterBagTest extends TestCase
|
||||
$this->assertEquals($parameters[$key], $val);
|
||||
}
|
||||
|
||||
$this->assertEquals(count($parameters), $i);
|
||||
$this->assertEquals(\count($parameters), $i);
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
@@ -179,7 +179,7 @@ class ParameterBagTest extends TestCase
|
||||
$parameters = array('foo' => 'bar', 'hello' => 'world');
|
||||
$bag = new ParameterBag($parameters);
|
||||
|
||||
$this->assertCount(count($parameters), $bag);
|
||||
$this->assertCount(\count($parameters), $bag);
|
||||
}
|
||||
|
||||
public function testGetBoolean()
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\RequestMatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestMatcher;
|
||||
|
||||
class RequestMatcherTest extends TestCase
|
||||
{
|
||||
|
||||
110
vendor/symfony/http-foundation/Tests/RequestTest.php
vendored
110
vendor/symfony/http-foundation/Tests/RequestTest.php
vendored
@@ -13,9 +13,9 @@ namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
class RequestTest extends TestCase
|
||||
{
|
||||
@@ -854,6 +854,11 @@ class RequestTest extends TestCase
|
||||
$request->setMethod('POST');
|
||||
$request->headers->set('X-HTTP-METHOD-OVERRIDE', 'delete');
|
||||
$this->assertEquals('DELETE', $request->getMethod(), '->getMethod() returns the method from X-HTTP-Method-Override if defined and POST');
|
||||
|
||||
$request = new Request();
|
||||
$request->setMethod('POST');
|
||||
$request->query->set('_method', array('delete', 'patch'));
|
||||
$this->assertSame('POST', $request->getMethod(), '->getMethod() returns the request method if invalid type is defined in query');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -901,7 +906,7 @@ class RequestTest extends TestCase
|
||||
|
||||
public function getClientIpsProvider()
|
||||
{
|
||||
// $expected $remoteAddr $httpForwardedFor $trustedProxies
|
||||
// $expected $remoteAddr $httpForwardedFor $trustedProxies
|
||||
return array(
|
||||
// simple IPv4
|
||||
array(array('88.88.88.88'), '88.88.88.88', null, null),
|
||||
@@ -915,8 +920,8 @@ class RequestTest extends TestCase
|
||||
|
||||
// forwarded for with remote IPv4 addr not trusted
|
||||
array(array('127.0.0.1'), '127.0.0.1', '88.88.88.88', null),
|
||||
// forwarded for with remote IPv4 addr trusted
|
||||
array(array('88.88.88.88'), '127.0.0.1', '88.88.88.88', array('127.0.0.1')),
|
||||
// forwarded for with remote IPv4 addr trusted + comma
|
||||
array(array('88.88.88.88'), '127.0.0.1', '88.88.88.88,', array('127.0.0.1')),
|
||||
// forwarded for with remote IPv4 and all FF addrs trusted
|
||||
array(array('88.88.88.88'), '127.0.0.1', '88.88.88.88', array('127.0.0.1', '88.88.88.88')),
|
||||
// forwarded for with remote IPv4 range trusted
|
||||
@@ -1020,7 +1025,7 @@ class RequestTest extends TestCase
|
||||
'HTTP_X_FORWARDED_FOR' => $httpXForwardedFor,
|
||||
);
|
||||
|
||||
Request::setTrustedProxies(array('88.88.88.88'), Request::HEADER_X_FORWARDED_ALL);
|
||||
Request::setTrustedProxies(array('88.88.88.88'), -1);
|
||||
|
||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||
|
||||
@@ -1831,20 +1836,6 @@ class RequestTest extends TestCase
|
||||
public function iisRequestUriProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'X_ORIGINAL_URL' => '/foo/bar',
|
||||
),
|
||||
array(),
|
||||
'/foo/bar',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'X_REWRITE_URL' => '/foo/bar',
|
||||
),
|
||||
array(),
|
||||
'/foo/bar',
|
||||
),
|
||||
array(
|
||||
array(),
|
||||
array(
|
||||
@@ -1853,36 +1844,6 @@ class RequestTest extends TestCase
|
||||
),
|
||||
'/foo/bar',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'X_ORIGINAL_URL' => '/foo/bar',
|
||||
),
|
||||
array(
|
||||
'HTTP_X_ORIGINAL_URL' => '/foo/bar',
|
||||
),
|
||||
'/foo/bar',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'X_ORIGINAL_URL' => '/foo/bar',
|
||||
),
|
||||
array(
|
||||
'IIS_WasUrlRewritten' => '1',
|
||||
'UNENCODED_URL' => '/foo/bar',
|
||||
),
|
||||
'/foo/bar',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'X_ORIGINAL_URL' => '/foo/bar',
|
||||
),
|
||||
array(
|
||||
'HTTP_X_ORIGINAL_URL' => '/foo/bar',
|
||||
'IIS_WasUrlRewritten' => '1',
|
||||
'UNENCODED_URL' => '/foo/bar',
|
||||
),
|
||||
'/foo/bar',
|
||||
),
|
||||
array(
|
||||
array(),
|
||||
array(
|
||||
@@ -2192,6 +2153,55 @@ class RequestTest extends TestCase
|
||||
$this->assertEquals($expectedBaseUrl, $request->getBaseUrl());
|
||||
$this->assertEquals($expectedBasePath, $request->getBasePath());
|
||||
}
|
||||
|
||||
public function testTrustedHost()
|
||||
{
|
||||
Request::setTrustedProxies(array('1.1.1.1'), -1);
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('Forwarded', 'host=localhost:8080');
|
||||
$request->headers->set('X-Forwarded-Host', 'localhost:8080');
|
||||
|
||||
$this->assertSame('localhost:8080', $request->getHttpHost());
|
||||
$this->assertSame(8080, $request->getPort());
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('Forwarded', 'host="[::1]:443"');
|
||||
$request->headers->set('X-Forwarded-Host', '[::1]:443');
|
||||
$request->headers->set('X-Forwarded-Port', 443);
|
||||
|
||||
$this->assertSame('[::1]:443', $request->getHttpHost());
|
||||
$this->assertSame(443, $request->getPort());
|
||||
}
|
||||
|
||||
public function testTrustedPort()
|
||||
{
|
||||
Request::setTrustedProxies(array('1.1.1.1'), -1);
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('Forwarded', 'host=localhost:8080');
|
||||
$request->headers->set('X-Forwarded-Port', 8080);
|
||||
|
||||
$this->assertSame(8080, $request->getPort());
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('Forwarded', 'host=localhost');
|
||||
$request->headers->set('X-Forwarded-Port', 80);
|
||||
|
||||
$this->assertSame(80, $request->getPort());
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('Forwarded', 'host="[::1]"');
|
||||
$request->headers->set('X-Forwarded-Proto', 'https');
|
||||
$request->headers->set('X-Forwarded-Port', 443);
|
||||
|
||||
$this->assertSame(443, $request->getPort());
|
||||
}
|
||||
}
|
||||
|
||||
class RequestContentProxy extends Request
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
|
||||
@@ -126,7 +126,7 @@ class ResponseTest extends ResponseTestCase
|
||||
|
||||
public function testSetNotModified()
|
||||
{
|
||||
$response = new Response();
|
||||
$response = new Response('foo');
|
||||
$modified = $response->setNotModified();
|
||||
$this->assertObjectHasAttribute('headers', $modified);
|
||||
$this->assertObjectHasAttribute('content', $modified);
|
||||
@@ -135,6 +135,11 @@ class ResponseTest extends ResponseTestCase
|
||||
$this->assertObjectHasAttribute('statusText', $modified);
|
||||
$this->assertObjectHasAttribute('charset', $modified);
|
||||
$this->assertEquals(304, $modified->getStatusCode());
|
||||
|
||||
ob_start();
|
||||
$modified->sendContent();
|
||||
$string = ob_get_clean();
|
||||
$this->assertEmpty($string);
|
||||
}
|
||||
|
||||
public function testIsSuccessful()
|
||||
@@ -357,6 +362,11 @@ class ResponseTest extends ResponseTestCase
|
||||
$response->headers->set('Expires', -1);
|
||||
$response->expire();
|
||||
$this->assertNull($response->headers->get('Age'), '->expire() does not set the Age when the response is expired');
|
||||
|
||||
$response = new Response();
|
||||
$response->headers->set('Expires', date(DATE_RFC2822, time() + 600));
|
||||
$response->expire();
|
||||
$this->assertNull($response->headers->get('Expires'), '->expire() removes the Expires header when the response is fresh');
|
||||
}
|
||||
|
||||
public function testGetTtl()
|
||||
@@ -969,7 +979,7 @@ class ResponseTest extends ResponseTestCase
|
||||
*/
|
||||
public function ianaCodesReasonPhrasesProvider()
|
||||
{
|
||||
if (!in_array('https', stream_get_wrappers(), true)) {
|
||||
if (!\in_array('https', stream_get_wrappers(), true)) {
|
||||
$this->markTestSkipped('The "https" wrapper is not available');
|
||||
}
|
||||
|
||||
@@ -997,7 +1007,7 @@ class ResponseTest extends ResponseTestCase
|
||||
$value = $xpath->query('.//ns:value', $record)->item(0)->nodeValue;
|
||||
$description = $xpath->query('.//ns:description', $record)->item(0)->nodeValue;
|
||||
|
||||
if (in_array($description, array('Unassigned', '(Unused)'), true)) {
|
||||
if (\in_array($description, array('Unassigned', '(Unused)'), true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -176,11 +176,11 @@ class AttributeBagTest extends TestCase
|
||||
++$i;
|
||||
}
|
||||
|
||||
$this->assertEquals(count($this->array), $i);
|
||||
$this->assertEquals(\count($this->array), $i);
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$this->assertCount(count($this->array), $this->bag);
|
||||
$this->assertCount(\count($this->array), $this->bag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,17 @@ class NamespacedAttributeBagTest extends TestCase
|
||||
$this->assertEquals($exists, $this->bag->has($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider attributesProvider
|
||||
*/
|
||||
public function testHasNoSideEffect($key, $value, $expected)
|
||||
{
|
||||
$expected = json_encode($this->bag->all());
|
||||
$this->bag->has($key);
|
||||
|
||||
$this->assertEquals($expected, json_encode($this->bag->all()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider attributesProvider
|
||||
*/
|
||||
@@ -96,6 +107,17 @@ class NamespacedAttributeBagTest extends TestCase
|
||||
$this->assertEquals('default', $this->bag->get('user2.login', 'default'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider attributesProvider
|
||||
*/
|
||||
public function testGetNoSideEffect($key, $value, $expected)
|
||||
{
|
||||
$expected = json_encode($this->bag->all());
|
||||
$this->bag->get($key);
|
||||
|
||||
$this->assertEquals($expected, json_encode($this->bag->all()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider attributesProvider
|
||||
*/
|
||||
|
||||
@@ -74,6 +74,18 @@ class FlashBagTest extends TestCase
|
||||
$this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$tab = array('bar' => 'baz');
|
||||
$this->bag->add('string_message', 'lorem');
|
||||
$this->bag->add('object_message', new \stdClass());
|
||||
$this->bag->add('array_message', $tab);
|
||||
|
||||
$this->assertEquals(array('lorem'), $this->bag->get('string_message'));
|
||||
$this->assertEquals(array(new \stdClass()), $this->bag->get('object_message'));
|
||||
$this->assertEquals(array($tab), $this->bag->get('array_message'));
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$this->assertEquals(array(), $this->bag->get('non_existing'));
|
||||
@@ -112,6 +124,19 @@ class FlashBagTest extends TestCase
|
||||
$this->assertEquals(array('notice'), $this->bag->keys());
|
||||
}
|
||||
|
||||
public function testSetAll()
|
||||
{
|
||||
$this->bag->add('one_flash', 'Foo');
|
||||
$this->bag->add('another_flash', 'Bar');
|
||||
$this->assertTrue($this->bag->has('one_flash'));
|
||||
$this->assertTrue($this->bag->has('another_flash'));
|
||||
$this->bag->setAll(array('unique_flash' => 'FooBar'));
|
||||
$this->assertFalse($this->bag->has('one_flash'));
|
||||
$this->assertFalse($this->bag->has('another_flash'));
|
||||
$this->assertSame(array('unique_flash' => 'FooBar'), $this->bag->all());
|
||||
$this->assertSame(array(), $this->bag->all());
|
||||
}
|
||||
|
||||
public function testPeekAll()
|
||||
{
|
||||
$this->bag->set('notice', 'Foo');
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
/**
|
||||
@@ -206,7 +206,7 @@ class SessionTest extends TestCase
|
||||
++$i;
|
||||
}
|
||||
|
||||
$this->assertEquals(count($attributes), $i);
|
||||
$this->assertEquals(\count($attributes), $i);
|
||||
}
|
||||
|
||||
public function testGetCount()
|
||||
|
||||
@@ -32,11 +32,6 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
*/
|
||||
protected $redisClient;
|
||||
|
||||
/**
|
||||
* @var \Redis
|
||||
*/
|
||||
protected $validator;
|
||||
|
||||
/**
|
||||
* @return \Redis|\RedisArray|\RedisCluster|\Predis\Client
|
||||
*/
|
||||
@@ -46,15 +41,12 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!extension_loaded('redis')) {
|
||||
if (!\extension_loaded('redis')) {
|
||||
self::markTestSkipped('Extension redis required.');
|
||||
}
|
||||
|
||||
$host = getenv('REDIS_HOST') ?: 'localhost';
|
||||
|
||||
$this->validator = new \Redis();
|
||||
$this->validator->connect($host);
|
||||
|
||||
$this->redisClient = $this->createRedisClient($host);
|
||||
$this->storage = new RedisSessionHandler(
|
||||
$this->redisClient,
|
||||
@@ -82,8 +74,8 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
|
||||
public function testReadSession()
|
||||
{
|
||||
$this->setFixture(self::PREFIX.'id1', null);
|
||||
$this->setFixture(self::PREFIX.'id2', 'abc123');
|
||||
$this->redisClient->set(self::PREFIX.'id1', null);
|
||||
$this->redisClient->set(self::PREFIX.'id2', 'abc123');
|
||||
|
||||
$this->assertEquals('', $this->storage->read('id1'));
|
||||
$this->assertEquals('abc123', $this->storage->read('id2'));
|
||||
@@ -93,14 +85,14 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
{
|
||||
$this->assertTrue($this->storage->write('id', 'data'));
|
||||
|
||||
$this->assertTrue($this->hasFixture(self::PREFIX.'id'));
|
||||
$this->assertEquals('data', $this->getFixture(self::PREFIX.'id'));
|
||||
$this->assertTrue((bool) $this->redisClient->exists(self::PREFIX.'id'));
|
||||
$this->assertEquals('data', $this->redisClient->get(self::PREFIX.'id'));
|
||||
}
|
||||
|
||||
public function testUseSessionGcMaxLifetimeAsTimeToLive()
|
||||
{
|
||||
$this->storage->write('id', 'data');
|
||||
$ttl = $this->fixtureTtl(self::PREFIX.'id');
|
||||
$ttl = $this->redisClient->ttl(self::PREFIX.'id');
|
||||
|
||||
$this->assertLessThanOrEqual(ini_get('session.gc_maxlifetime'), $ttl);
|
||||
$this->assertGreaterThanOrEqual(0, $ttl);
|
||||
@@ -108,11 +100,11 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
|
||||
public function testDestroySession()
|
||||
{
|
||||
$this->setFixture(self::PREFIX.'id', 'foo');
|
||||
$this->redisClient->set(self::PREFIX.'id', 'foo');
|
||||
|
||||
$this->assertTrue($this->hasFixture(self::PREFIX.'id'));
|
||||
$this->assertTrue((bool) $this->redisClient->exists(self::PREFIX.'id'));
|
||||
$this->assertTrue($this->storage->destroy('id'));
|
||||
$this->assertFalse($this->hasFixture(self::PREFIX.'id'));
|
||||
$this->assertFalse((bool) $this->redisClient->exists(self::PREFIX.'id'));
|
||||
}
|
||||
|
||||
public function testGcSession()
|
||||
@@ -122,12 +114,12 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
|
||||
public function testUpdateTimestamp()
|
||||
{
|
||||
$lowTTL = 10;
|
||||
$lowTtl = 10;
|
||||
|
||||
$this->setFixture(self::PREFIX.'id', 'foo', $lowTTL);
|
||||
$this->redisClient->setex(self::PREFIX.'id', $lowTtl, 'foo');
|
||||
$this->storage->updateTimestamp('id', array());
|
||||
|
||||
$this->assertGreaterThan($lowTTL, $this->fixtureTtl(self::PREFIX.'id'));
|
||||
$this->assertGreaterThan($lowTtl, $this->redisClient->ttl(self::PREFIX.'id'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,28 +142,4 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
array(array('prefix' => 'sfs', 'foo' => 'bar'), false),
|
||||
);
|
||||
}
|
||||
|
||||
protected function setFixture($key, $value, $ttl = null)
|
||||
{
|
||||
if (null !== $ttl) {
|
||||
$this->validator->setex($key, $ttl, $value);
|
||||
} else {
|
||||
$this->validator->set($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getFixture($key)
|
||||
{
|
||||
return $this->validator->get($key);
|
||||
}
|
||||
|
||||
protected function hasFixture($key): bool
|
||||
{
|
||||
return $this->validator->exists($key);
|
||||
}
|
||||
|
||||
protected function fixtureTtl($key): int
|
||||
{
|
||||
return $this->validator->ttl($key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
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;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
|
||||
/**
|
||||
* Test class for NullSessionHandler.
|
||||
|
||||
@@ -389,8 +389,8 @@ class MockPdo extends \PDO
|
||||
|
||||
public function prepare($statement, $driverOptions = array())
|
||||
{
|
||||
return is_callable($this->prepareResult)
|
||||
? call_user_func($this->prepareResult, $statement, $driverOptions)
|
||||
return \is_callable($this->prepareResult)
|
||||
? \call_user_func($this->prepareResult, $statement, $driverOptions)
|
||||
: $this->prepareResult;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,6 @@ class PredisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCas
|
||||
{
|
||||
protected function createRedisClient(string $host): Client
|
||||
{
|
||||
return new Client(array(array('host' => $host)));
|
||||
return new Client(array(array('host' => $host)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for MockArraySessionStorage.
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for MockFileSessionStorage.
|
||||
|
||||
@@ -184,7 +184,7 @@ class NativeSessionStorageTest extends TestCase
|
||||
|
||||
public function testSessionOptions()
|
||||
{
|
||||
if (defined('HHVM_VERSION')) {
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('HHVM is not handled in this test case.');
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for PhpSessionStorage.
|
||||
|
||||
@@ -121,4 +121,37 @@ class SessionHandlerProxyTest extends TestCase
|
||||
|
||||
$this->proxy->gc(86400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHPUnit 5.1
|
||||
*/
|
||||
public function testValidateId()
|
||||
{
|
||||
$mock = $this->getMockBuilder(array('SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'))->getMock();
|
||||
$mock->expects($this->once())
|
||||
->method('validateId');
|
||||
|
||||
$proxy = new SessionHandlerProxy($mock);
|
||||
$proxy->validateId('id');
|
||||
|
||||
$this->assertTrue($this->proxy->validateId('id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHPUnit 5.1
|
||||
*/
|
||||
public function testUpdateTimestamp()
|
||||
{
|
||||
$mock = $this->getMockBuilder(array('SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'))->getMock();
|
||||
$mock->expects($this->once())
|
||||
->method('updateTimestamp');
|
||||
|
||||
$proxy = new SessionHandlerProxy($mock);
|
||||
$proxy->updateTimestamp('id', 'data');
|
||||
|
||||
$this->mock->expects($this->once())
|
||||
->method('write');
|
||||
|
||||
$this->proxy->updateTimestamp('id', 'data');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,4 +123,22 @@ class StreamedResponseTest extends TestCase
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
|
||||
}
|
||||
|
||||
public function testSetNotModified()
|
||||
{
|
||||
$response = new StreamedResponse(function () { echo 'foo'; });
|
||||
$modified = $response->setNotModified();
|
||||
$this->assertObjectHasAttribute('headers', $modified);
|
||||
$this->assertObjectHasAttribute('content', $modified);
|
||||
$this->assertObjectHasAttribute('version', $modified);
|
||||
$this->assertObjectHasAttribute('statusCode', $modified);
|
||||
$this->assertObjectHasAttribute('statusText', $modified);
|
||||
$this->assertObjectHasAttribute('charset', $modified);
|
||||
$this->assertEquals(304, $modified->getStatusCode());
|
||||
|
||||
ob_start();
|
||||
$modified->sendContent();
|
||||
$string = ob_get_clean();
|
||||
$this->assertEmpty($string);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user