Laravel 5.6 updates

Travis config update

Removed HHVM script as Laravel no longer support HHVM after releasing 5.3
This commit is contained in:
Manish Verma
2018-08-06 20:08:55 +05:30
parent 126fbb0255
commit 1ac0f42a58
2464 changed files with 65239 additions and 46734 deletions

View File

@@ -66,7 +66,7 @@ class AcceptHeaderItemTest extends TestCase
),
array(
'text/plain', array('charset' => 'utf-8', 'param' => 'this;should,not=matter', 'footnotes' => 'true'),
'text/plain;charset=utf-8;param="this;should,not=matter";footnotes=true',
'text/plain; charset=utf-8; param="this;should,not=matter"; footnotes=true',
),
);
}

View File

@@ -100,4 +100,31 @@ class AcceptHeaderTest extends TestCase
'order matters when q is equal2' => array('*;q=0.3,utf-8;q=0.7,ISO-8859-1;q=0.7', array('utf-8', 'ISO-8859-1', '*')),
);
}
/**
* @dataProvider provideDefaultValueData
*/
public function testDefaultValue($acceptHeader, $value, $expectedQuality)
{
$header = AcceptHeader::fromString($acceptHeader);
$this->assertSame($expectedQuality, $header->get($value)->getQuality());
}
public function provideDefaultValueData()
{
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, *;q=0.3', 'text/xml', 0.3);
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*;q=0.3', 'text/xml', 0.3);
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*;q=0.3', 'text/html', 1.0);
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*;q=0.3', 'text/plain', 0.5);
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*;q=0.3', '*', 0.3);
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*', '*', 1.0);
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*', 'text/xml', 1.0);
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*', 'text/*', 1.0);
yield array('text/plain;q=0.5, text/html, text/*;q=0.8, */*', 'text/*', 0.8);
yield array('text/plain;q=0.5, text/html, text/*;q=0.8, */*', 'text/html', 1.0);
yield array('text/plain;q=0.5, text/html, text/*;q=0.8, */*', 'text/x-dvi', 0.8);
yield array('*;q=0.3, ISO-8859-1;q=0.7, utf-8;q=0.7', '*', 0.3);
yield array('*;q=0.3, ISO-8859-1;q=0.7, utf-8;q=0.7', 'utf-8', 0.7);
yield array('*;q=0.3, ISO-8859-1;q=0.7, utf-8;q=0.7', 'SHIFT_JIS', 0.3);
}
}

View File

@@ -32,7 +32,7 @@ class BinaryFileResponseTest extends ResponseTestCase
$response = BinaryFileResponse::create($file, 404, array(), true, ResponseHeaderBag::DISPOSITION_INLINE);
$this->assertEquals(404, $response->getStatusCode());
$this->assertFalse($response->headers->has('ETag'));
$this->assertEquals('inline; filename="README.md"', $response->headers->get('Content-Disposition'));
$this->assertEquals('inline; filename=README.md', $response->headers->get('Content-Disposition'));
}
public function testConstructWithNonAsciiFilename()
@@ -66,7 +66,7 @@ class BinaryFileResponseTest extends ResponseTestCase
$response = new BinaryFileResponse(__FILE__);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'föö.html');
$this->assertSame('attachment; filename="f__.html"; filename*=utf-8\'\'f%C3%B6%C3%B6.html', $response->headers->get('Content-Disposition'));
$this->assertSame('attachment; filename=f__.html; filename*=utf-8\'\'f%C3%B6%C3%B6.html', $response->headers->get('Content-Disposition'));
}
public function testSetContentDispositionGeneratesSafeFallbackFilenameForWronglyEncodedFilename()
@@ -77,7 +77,7 @@ class BinaryFileResponseTest extends ResponseTestCase
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $iso88591EncodedFilename);
// the parameter filename* is invalid in this case (rawurldecode('f%F6%F6') does not provide a UTF-8 string but an ISO-8859-1 encoded one)
$this->assertSame('attachment; filename="f__.html"; filename*=utf-8\'\'f%F6%F6.html', $response->headers->get('Content-Disposition'));
$this->assertSame('attachment; filename=f__.html; filename*=utf-8\'\'f%F6%F6.html', $response->headers->get('Content-Disposition'));
}
/**

View File

@@ -104,9 +104,6 @@ class CookieTest extends TestCase
$this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
}
/**
* @requires PHP 5.5
*/
public function testConstructorWithDateTimeImmutable()
{
$expire = new \DateTimeImmutable();
@@ -216,6 +213,9 @@ class CookieTest extends TestCase
$cookie = Cookie::fromString('foo=bar', true);
$this->assertEquals(new Cookie('foo', 'bar', 0, '/', null, false, false), $cookie);
$cookie = Cookie::fromString('foo', true);
$this->assertEquals(new Cookie('foo', null, 0, '/', null, false, false), $cookie);
}
public function testFromStringWithHttpOnly()

View File

@@ -12,6 +12,14 @@
namespace Symfony\Component\HttpFoundation\Tests\File;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\File\Exception\CannotWriteFileException;
use Symfony\Component\HttpFoundation\File\Exception\ExtensionFileException;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\File\Exception\FormSizeFileException;
use Symfony\Component\HttpFoundation\File\Exception\IniSizeFileException;
use Symfony\Component\HttpFoundation\File\Exception\NoFileException;
use Symfony\Component\HttpFoundation\File\Exception\NoTmpDirFileException;
use Symfony\Component\HttpFoundation\File\Exception\PartialFileException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class UploadedFileTest extends TestCase
@@ -40,7 +48,6 @@ class UploadedFileTest extends TestCase
__DIR__.'/Fixtures/test.gif',
'original.gif',
null,
filesize(__DIR__.'/Fixtures/test.gif'),
UPLOAD_ERR_OK
);
@@ -57,7 +64,6 @@ class UploadedFileTest extends TestCase
__DIR__.'/Fixtures/.unknownextension',
'original.gif',
null,
filesize(__DIR__.'/Fixtures/.unknownextension'),
UPLOAD_ERR_OK
);
@@ -70,7 +76,6 @@ class UploadedFileTest extends TestCase
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null
);
@@ -83,7 +88,6 @@ class UploadedFileTest extends TestCase
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/jpeg',
filesize(__DIR__.'/Fixtures/test.gif'),
null
);
@@ -96,7 +100,6 @@ class UploadedFileTest extends TestCase
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null
);
@@ -109,7 +112,6 @@ class UploadedFileTest extends TestCase
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null
);
@@ -122,7 +124,6 @@ class UploadedFileTest extends TestCase
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null
);
@@ -138,13 +139,60 @@ class UploadedFileTest extends TestCase
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
UPLOAD_ERR_OK
);
$movedFile = $file->move(__DIR__.'/Fixtures/directory');
}
public function failedUploadedFile()
{
foreach (array(UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE, UPLOAD_ERR_PARTIAL, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_EXTENSION, -1) as $error) {
yield array(new UploadedFile(
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
$error
));
}
}
/**
* @dataProvider failedUploadedFile
*/
public function testMoveFailed(UploadedFile $file)
{
switch ($file->getError()) {
case UPLOAD_ERR_INI_SIZE:
$exceptionClass = IniSizeFileException::class;
break;
case UPLOAD_ERR_FORM_SIZE:
$exceptionClass = FormSizeFileException::class;
break;
case UPLOAD_ERR_PARTIAL:
$exceptionClass = PartialFileException::class;
break;
case UPLOAD_ERR_NO_FILE:
$exceptionClass = NoFileException::class;
break;
case UPLOAD_ERR_CANT_WRITE:
$exceptionClass = CannotWriteFileException::class;
break;
case UPLOAD_ERR_NO_TMP_DIR:
$exceptionClass = NoTmpDirFileException::class;
break;
case UPLOAD_ERR_EXTENSION:
$exceptionClass = ExtensionFileException::class;
break;
default:
$exceptionClass = FileException::class;
}
$this->expectException($exceptionClass);
$file->move(__DIR__.'/Fixtures/directory');
}
public function testMoveLocalFileIsAllowedInTestMode()
{
$path = __DIR__.'/Fixtures/test.copy.gif';
@@ -158,7 +206,6 @@ class UploadedFileTest extends TestCase
$path,
'original.gif',
'image/gif',
filesize($path),
UPLOAD_ERR_OK,
true
);
@@ -177,9 +224,7 @@ class UploadedFileTest extends TestCase
$file = new UploadedFile(
__DIR__.'/Fixtures/test.gif',
'../../original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null
'image/gif'
);
$this->assertEquals('original.gif', $file->getClientOriginalName());
@@ -190,9 +235,7 @@ class UploadedFileTest extends TestCase
$file = new UploadedFile(
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null
'image/gif'
);
$this->assertEquals(filesize(__DIR__.'/Fixtures/test.gif'), $file->getSize());
@@ -206,12 +249,45 @@ class UploadedFileTest extends TestCase
$this->assertEquals(filesize(__DIR__.'/Fixtures/test'), $file->getSize());
}
public function testGetExtension()
/**
* @group legacy
* @expectedDeprecation Passing a size as 4th argument to the constructor of "Symfony\Component\HttpFoundation\File\UploadedFile" is deprecated since Symfony 4.1.
*/
public function testConstructDeprecatedSize()
{
$file = new UploadedFile(
__DIR__.'/Fixtures/test.gif',
'original.gif',
null
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
UPLOAD_ERR_OK,
false
);
$this->assertEquals(filesize(__DIR__.'/Fixtures/test.gif'), $file->getSize());
}
/**
* @group legacy
* @expectedDeprecation Passing a size as 4th argument to the constructor of "Symfony\Component\HttpFoundation\File\UploadedFile" is deprecated since Symfony 4.1.
*/
public function testConstructDeprecatedSizeWhenPassingOnlyThe4Needed()
{
$file = new UploadedFile(
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif')
);
$this->assertEquals(filesize(__DIR__.'/Fixtures/test.gif'), $file->getSize());
}
public function testGetExtension()
{
$file = new UploadedFile(
__DIR__.'/Fixtures/test.gif',
'original.gif'
);
$this->assertEquals('gif', $file->getExtension());
@@ -223,7 +299,6 @@ class UploadedFileTest extends TestCase
__DIR__.'/Fixtures/test.gif',
'original.gif',
null,
filesize(__DIR__.'/Fixtures/test.gif'),
UPLOAD_ERR_OK,
true
);
@@ -240,7 +315,6 @@ class UploadedFileTest extends TestCase
__DIR__.'/Fixtures/test.gif',
'original.gif',
null,
filesize(__DIR__.'/Fixtures/test.gif'),
$error
);
@@ -264,7 +338,6 @@ class UploadedFileTest extends TestCase
__DIR__.'/Fixtures/test.gif',
'original.gif',
null,
filesize(__DIR__.'/Fixtures/test.gif'),
UPLOAD_ERR_OK
);

View File

@@ -34,14 +34,14 @@ class FileBagTest extends TestCase
public function testShouldConvertsUploadedFiles()
{
$tmpFile = $this->createTempFile();
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain');
$bag = new FileBag(array('file' => array(
'name' => basename($tmpFile),
'type' => 'text/plain',
'tmp_name' => $tmpFile,
'error' => 0,
'size' => 100,
'size' => null,
)));
$this->assertEquals($file, $bag->get('file'));
@@ -89,7 +89,7 @@ class FileBagTest extends TestCase
public function testShouldConvertUploadedFilesWithPhpBug()
{
$tmpFile = $this->createTempFile();
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain');
$bag = new FileBag(array(
'child' => array(
@@ -106,7 +106,7 @@ class FileBagTest extends TestCase
'file' => 0,
),
'size' => array(
'file' => 100,
'file' => null,
),
),
));
@@ -118,7 +118,7 @@ class FileBagTest extends TestCase
public function testShouldConvertNestedUploadedFilesWithPhpBug()
{
$tmpFile = $this->createTempFile();
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain');
$bag = new FileBag(array(
'child' => array(
@@ -135,7 +135,7 @@ class FileBagTest extends TestCase
'sub' => array('file' => 0),
),
'size' => array(
'sub' => array('file' => 100),
'sub' => array('file' => null),
),
),
));
@@ -147,7 +147,7 @@ class FileBagTest extends TestCase
public function testShouldNotConvertNestedUploadedFiles()
{
$tmpFile = $this->createTempFile();
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain');
$bag = new FileBag(array('image' => array('file' => $file)));
$files = $bag->all();
@@ -156,7 +156,10 @@ class FileBagTest extends TestCase
protected function createTempFile()
{
return tempnam(sys_get_temp_dir().'/form_test', 'FormTest');
$tempFile = tempnam(sys_get_temp_dir().'/form_test', 'FormTest');
file_put_contents($tempFile, '1');
return $tempFile;
}
protected function setUp()

View File

@@ -0,0 +1,85 @@
<?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;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\HeaderUtils;
class HeaderUtilsTest extends TestCase
{
public function testSplit()
{
$this->assertSame(array('foo=123', 'bar'), HeaderUtils::split('foo=123,bar', ','));
$this->assertSame(array('foo=123', 'bar'), HeaderUtils::split('foo=123, bar', ','));
$this->assertSame(array(array('foo=123', 'bar')), HeaderUtils::split('foo=123; bar', ',;'));
$this->assertSame(array(array('foo=123'), array('bar')), HeaderUtils::split('foo=123, bar', ',;'));
$this->assertSame(array('foo', '123, bar'), HeaderUtils::split('foo=123, bar', '='));
$this->assertSame(array('foo', '123, bar'), HeaderUtils::split(' foo = 123, bar ', '='));
$this->assertSame(array(array('foo', '123'), array('bar')), HeaderUtils::split('foo=123, bar', ',='));
$this->assertSame(array(array(array('foo', '123')), array(array('bar'), array('foo', '456'))), HeaderUtils::split('foo=123, bar; foo=456', ',;='));
$this->assertSame(array(array(array('foo', 'a,b;c=d'))), HeaderUtils::split('foo="a,b;c=d"', ',;='));
$this->assertSame(array('foo', 'bar'), HeaderUtils::split('foo,,,, bar', ','));
$this->assertSame(array('foo', 'bar'), HeaderUtils::split(',foo, bar,', ','));
$this->assertSame(array('foo', 'bar'), HeaderUtils::split(' , foo, bar, ', ','));
$this->assertSame(array('foo bar'), HeaderUtils::split('foo "bar"', ','));
$this->assertSame(array('foo bar'), HeaderUtils::split('"foo" bar', ','));
$this->assertSame(array('foo bar'), HeaderUtils::split('"foo" "bar"', ','));
// These are not a valid header values. We test that they parse anyway,
// and that both the valid and invalid parts are returned.
$this->assertSame(array(), HeaderUtils::split('', ','));
$this->assertSame(array(), HeaderUtils::split(',,,', ','));
$this->assertSame(array('foo', 'bar', 'baz'), HeaderUtils::split('foo, "bar", "baz', ','));
$this->assertSame(array('foo', 'bar, baz'), HeaderUtils::split('foo, "bar, baz', ','));
$this->assertSame(array('foo', 'bar, baz\\'), HeaderUtils::split('foo, "bar, baz\\', ','));
$this->assertSame(array('foo', 'bar, baz\\'), HeaderUtils::split('foo, "bar, baz\\\\', ','));
}
public function testCombine()
{
$this->assertSame(array('foo' => '123'), HeaderUtils::combine(array(array('foo', '123'))));
$this->assertSame(array('foo' => true), HeaderUtils::combine(array(array('foo'))));
$this->assertSame(array('foo' => true), HeaderUtils::combine(array(array('Foo'))));
$this->assertSame(array('foo' => '123', 'bar' => true), HeaderUtils::combine(array(array('foo', '123'), array('bar'))));
}
public function testToString()
{
$this->assertSame('foo', HeaderUtils::toString(array('foo' => true), ','));
$this->assertSame('foo; bar', HeaderUtils::toString(array('foo' => true, 'bar' => true), ';'));
$this->assertSame('foo=123', HeaderUtils::toString(array('foo' => '123'), ','));
$this->assertSame('foo="1 2 3"', HeaderUtils::toString(array('foo' => '1 2 3'), ','));
$this->assertSame('foo="1 2 3", bar', HeaderUtils::toString(array('foo' => '1 2 3', 'bar' => true), ','));
}
public function testQuote()
{
$this->assertSame('foo', HeaderUtils::quote('foo'));
$this->assertSame('az09!#$%&\'*.^_`|~-', HeaderUtils::quote('az09!#$%&\'*.^_`|~-'));
$this->assertSame('"foo bar"', HeaderUtils::quote('foo bar'));
$this->assertSame('"foo [bar]"', HeaderUtils::quote('foo [bar]'));
$this->assertSame('"foo \"bar\""', HeaderUtils::quote('foo "bar"'));
$this->assertSame('"foo \\\\ bar"', HeaderUtils::quote('foo \\ bar'));
}
public function testUnquote()
{
$this->assertEquals('foo', HeaderUtils::unquote('foo'));
$this->assertEquals('az09!#$%&\'*.^_`|~-', HeaderUtils::unquote('az09!#$%&\'*.^_`|~-'));
$this->assertEquals('foo bar', HeaderUtils::unquote('"foo bar"'));
$this->assertEquals('foo [bar]', HeaderUtils::unquote('"foo [bar]"'));
$this->assertEquals('foo "bar"', HeaderUtils::unquote('"foo \"bar\""'));
$this->assertEquals('foo "bar"', HeaderUtils::unquote('"foo \"\b\a\r\""'));
$this->assertEquals('foo \\ bar', HeaderUtils::unquote('"foo \\\\ bar"'));
}
}

View File

@@ -16,15 +16,6 @@ use Symfony\Component\HttpFoundation\JsonResponse;
class JsonResponseTest extends TestCase
{
protected function setUp()
{
parent::setUp();
if (!\defined('HHVM_VERSION')) {
$this->iniSet('serialize_precision', 14);
}
}
public function testConstructorEmptyCreatesJsonObject()
{
$response = new JsonResponse();

View File

@@ -675,7 +675,7 @@ class RequestTest extends TestCase
public function getQueryStringNormalizationData()
{
return array(
array('foo', 'foo', 'works with valueless parameters'),
array('foo', 'foo=', 'works with valueless parameters'),
array('foo=', 'foo=', 'includes a dangling equal sign'),
array('bar=&foo=bar', 'bar=&foo=bar', '->works with empty parameters'),
array('foo=bar&bar=', 'bar=&foo=bar', 'sorts keys alphabetically'),
@@ -684,18 +684,24 @@ class RequestTest extends TestCase
// PHP also converts "+" to spaces when filling the global _GET or when using the function parse_str.
array('him=John%20Doe&her=Jane+Doe', 'her=Jane%20Doe&him=John%20Doe', 'normalizes spaces in both encodings "%20" and "+"'),
array('foo[]=1&foo[]=2', 'foo%5B%5D=1&foo%5B%5D=2', 'allows array notation'),
array('foo=1&foo=2', 'foo=1&foo=2', 'allows repeated parameters'),
array('foo[]=1&foo[]=2', 'foo%5B0%5D=1&foo%5B1%5D=2', 'allows array notation'),
array('foo=1&foo=2', 'foo=2', 'merges repeated parameters'),
array('pa%3Dram=foo%26bar%3Dbaz&test=test', 'pa%3Dram=foo%26bar%3Dbaz&test=test', 'works with encoded delimiters'),
array('0', '0', 'allows "0"'),
array('Jane Doe&John%20Doe', 'Jane%20Doe&John%20Doe', 'normalizes encoding in keys'),
array('0', '0=', 'allows "0"'),
array('Jane Doe&John%20Doe', 'Jane_Doe=&John_Doe=', 'normalizes encoding in keys'),
array('her=Jane Doe&him=John%20Doe', 'her=Jane%20Doe&him=John%20Doe', 'normalizes encoding in values'),
array('foo=bar&&&test&&', 'foo=bar&test', 'removes unneeded delimiters'),
array('foo=bar&&&test&&', 'foo=bar&test=', 'removes unneeded delimiters'),
array('formula=e=m*c^2', 'formula=e%3Dm%2Ac%5E2', 'correctly treats only the first "=" as delimiter and the next as value'),
// Ignore pairs with empty key, even if there was a value, e.g. "=value", as such nameless values cannot be retrieved anyway.
// PHP also does not include them when building _GET.
array('foo=bar&=a=b&=x=y', 'foo=bar', 'removes params with empty key'),
// Don't reorder nested query string keys
array('foo[]=Z&foo[]=A', 'foo%5B0%5D=Z&foo%5B1%5D=A', 'keeps order of values'),
array('foo[Z]=B&foo[A]=B', 'foo%5BZ%5D=B&foo%5BA%5D=B', 'keeps order of keys'),
array('utf8=✓', 'utf8=%E2%9C%93', 'encodes UTF-8'),
);
}
@@ -893,7 +899,7 @@ class RequestTest extends TestCase
array(array('127.0.0.1'), '127.0.0.1', 'for="_gazonk"', array('127.0.0.1')),
array(array('88.88.88.88'), '127.0.0.1', 'for="88.88.88.88:80"', array('127.0.0.1')),
array(array('192.0.2.60'), '::1', 'for=192.0.2.60;proto=http;by=203.0.113.43', array('::1')),
array(array('2620:0:1cfe:face:b00c::3', '192.0.2.43'), '::1', 'for=192.0.2.43, for=2620:0:1cfe:face:b00c::3', array('::1')),
array(array('2620:0:1cfe:face:b00c::3', '192.0.2.43'), '::1', 'for=192.0.2.43, for="[2620:0:1cfe:face:b00c::3]"', array('::1')),
array(array('2001:db8:cafe::17'), '::1', 'for="[2001:db8:cafe::17]:4711', array('::1')),
);
}
@@ -1077,21 +1083,6 @@ class RequestTest extends TestCase
$this->assertEquals('My other content', $req->getContent());
}
/**
* @expectedException \LogicException
* @dataProvider getContentCantBeCalledTwiceWithResourcesProvider
*/
public function testGetContentCantBeCalledTwiceWithResources($first, $second)
{
if (\PHP_VERSION_ID >= 50600) {
$this->markTestSkipped('PHP >= 5.6 allows to open php://input several times.');
}
$req = new Request();
$req->getContent($first);
$req->getContent($second);
}
public function getContentCantBeCalledTwiceWithResourcesProvider()
{
return array(
@@ -1102,7 +1093,6 @@ class RequestTest extends TestCase
/**
* @dataProvider getContentCanBeCalledTwiceWithResourcesProvider
* @requires PHP 5.6
*/
public function testGetContentCanBeCalledTwiceWithResources($first, $second)
{
@@ -1512,6 +1502,15 @@ class RequestTest extends TestCase
$this->assertObjectHasAttribute('attributeName', $session);
}
/**
* @group legacy
* @expectedDeprecation Calling "Symfony\Component\HttpFoundation\Request::getSession()" when no session has been set is deprecated since Symfony 4.1 and will throw an exception in 5.0. Use "hasSession()" instead.
*/
public function testGetSessionNullable()
{
(new Request())->getSession();
}
public function testHasPreviousSession()
{
$request = new Request();
@@ -1769,53 +1768,6 @@ class RequestTest extends TestCase
$this->assertTrue($request->isSecure());
}
/**
* @group legacy
* @expectedDeprecation The "Symfony\Component\HttpFoundation\Request::setTrustedHeaderName()" method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.
*/
public function testLegacyTrustedProxies()
{
$request = Request::create('http://example.com/');
$request->server->set('REMOTE_ADDR', '3.3.3.3');
$request->headers->set('X_FORWARDED_FOR', '1.1.1.1, 2.2.2.2');
$request->headers->set('X_FORWARDED_HOST', 'foo.example.com, real.example.com:8080');
$request->headers->set('X_FORWARDED_PROTO', 'https');
$request->headers->set('X_FORWARDED_PORT', 443);
$request->headers->set('X_MY_FOR', '3.3.3.3, 4.4.4.4');
$request->headers->set('X_MY_HOST', 'my.example.com');
$request->headers->set('X_MY_PROTO', 'http');
$request->headers->set('X_MY_PORT', 81);
Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'), Request::HEADER_X_FORWARDED_ALL);
// custom header names
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'X_MY_FOR');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, 'X_MY_HOST');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X_MY_PORT');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X_MY_PROTO');
$this->assertEquals('4.4.4.4', $request->getClientIp());
$this->assertEquals('my.example.com', $request->getHost());
$this->assertEquals(81, $request->getPort());
$this->assertFalse($request->isSecure());
// disabling via empty header names
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, null);
Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, null);
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, null);
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, null);
$this->assertEquals('3.3.3.3', $request->getClientIp());
$this->assertEquals('example.com', $request->getHost());
$this->assertEquals(80, $request->getPort());
$this->assertFalse($request->isSecure());
//reset
Request::setTrustedHeaderName(Request::HEADER_FORWARDED, 'FORWARDED');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'X_FORWARDED_FOR');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, 'X_FORWARDED_HOST');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X_FORWARDED_PORT');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X_FORWARDED_PROTO');
}
public function testTrustedProxiesForwarded()
{
$request = Request::create('http://example.com/');
@@ -1865,26 +1817,6 @@ class RequestTest extends TestCase
$this->assertTrue($request->isSecure());
}
/**
* @group legacy
* @expectedException \InvalidArgumentException
*/
public function testSetTrustedProxiesInvalidHeaderName()
{
Request::create('http://example.com/');
Request::setTrustedHeaderName('bogus name', 'X_MY_FOR');
}
/**
* @group legacy
* @expectedException \InvalidArgumentException
*/
public function testGetTrustedProxiesInvalidHeaderName()
{
Request::create('http://example.com/');
Request::getTrustedHeaderName('bogus name');
}
/**
* @dataProvider iisRequestUriProvider
*/
@@ -2102,14 +2034,13 @@ class RequestTest extends TestCase
}
/**
* @group legacy
* @expectedDeprecation Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is deprecated since Symfony 3.2 and will throw an exception in 4.0. Disable checking only for cacheable methods by calling the method with `false` as first argument or use the Request::isMethodCacheable() instead.
* @expectedException \BadMethodCallException
*/
public function testMethodSafeChecksCacheable()
{
$request = new Request();
$request->setMethod('OPTIONS');
$this->assertFalse($request->isMethodSafe());
$request->isMethodSafe();
}
/**
@@ -2138,61 +2069,6 @@ class RequestTest extends TestCase
);
}
/**
* @group legacy
*/
public function testGetTrustedHeaderName()
{
Request::setTrustedProxies(array('8.8.8.8'), Request::HEADER_X_FORWARDED_ALL);
$this->assertNull(Request::getTrustedHeaderName(Request::HEADER_FORWARDED));
$this->assertSame('X_FORWARDED_FOR', Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP));
$this->assertSame('X_FORWARDED_HOST', Request::getTrustedHeaderName(Request::HEADER_CLIENT_HOST));
$this->assertSame('X_FORWARDED_PORT', Request::getTrustedHeaderName(Request::HEADER_CLIENT_PORT));
$this->assertSame('X_FORWARDED_PROTO', Request::getTrustedHeaderName(Request::HEADER_CLIENT_PROTO));
Request::setTrustedProxies(array('8.8.8.8'), Request::HEADER_FORWARDED);
$this->assertSame('FORWARDED', Request::getTrustedHeaderName(Request::HEADER_FORWARDED));
$this->assertNull(Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP));
$this->assertNull(Request::getTrustedHeaderName(Request::HEADER_CLIENT_HOST));
$this->assertNull(Request::getTrustedHeaderName(Request::HEADER_CLIENT_PORT));
$this->assertNull(Request::getTrustedHeaderName(Request::HEADER_CLIENT_PROTO));
Request::setTrustedHeaderName(Request::HEADER_FORWARDED, 'A');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'B');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, 'C');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'D');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'E');
Request::setTrustedProxies(array('8.8.8.8'), Request::HEADER_FORWARDED);
$this->assertSame('A', Request::getTrustedHeaderName(Request::HEADER_FORWARDED));
$this->assertNull(Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP));
$this->assertNull(Request::getTrustedHeaderName(Request::HEADER_CLIENT_HOST));
$this->assertNull(Request::getTrustedHeaderName(Request::HEADER_CLIENT_PORT));
$this->assertNull(Request::getTrustedHeaderName(Request::HEADER_CLIENT_PROTO));
Request::setTrustedProxies(array('8.8.8.8'), Request::HEADER_X_FORWARDED_ALL);
$this->assertNull(Request::getTrustedHeaderName(Request::HEADER_FORWARDED));
$this->assertSame('B', Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP));
$this->assertSame('C', Request::getTrustedHeaderName(Request::HEADER_CLIENT_HOST));
$this->assertSame('D', Request::getTrustedHeaderName(Request::HEADER_CLIENT_PORT));
$this->assertSame('E', Request::getTrustedHeaderName(Request::HEADER_CLIENT_PROTO));
Request::setTrustedProxies(array('8.8.8.8'), Request::HEADER_FORWARDED);
$this->assertSame('A', Request::getTrustedHeaderName(Request::HEADER_FORWARDED));
//reset
Request::setTrustedHeaderName(Request::HEADER_FORWARDED, 'FORWARDED');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'X_FORWARDED_FOR');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, 'X_FORWARDED_HOST');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X_FORWARDED_PORT');
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X_FORWARDED_PROTO');
}
/**
* @dataProvider protocolVersionProvider
*/

View File

@@ -287,12 +287,12 @@ class ResponseHeaderBagTest extends TestCase
public function provideMakeDisposition()
{
return array(
array('attachment', 'foo.html', 'foo.html', 'attachment; filename="foo.html"'),
array('attachment', 'foo.html', '', 'attachment; filename="foo.html"'),
array('attachment', 'foo.html', 'foo.html', 'attachment; filename=foo.html'),
array('attachment', 'foo.html', '', 'attachment; filename=foo.html'),
array('attachment', 'foo bar.html', '', 'attachment; filename="foo bar.html"'),
array('attachment', 'foo "bar".html', '', 'attachment; filename="foo \\"bar\\".html"'),
array('attachment', 'foo%20bar.html', 'foo bar.html', 'attachment; filename="foo bar.html"; filename*=utf-8\'\'foo%2520bar.html'),
array('attachment', 'föö.html', 'foo.html', 'attachment; filename="foo.html"; filename*=utf-8\'\'f%C3%B6%C3%B6.html'),
array('attachment', 'föö.html', 'foo.html', 'attachment; filename=foo.html; filename*=utf-8\'\'f%C3%B6%C3%B6.html'),
);
}

View File

@@ -305,7 +305,7 @@ class ResponseTest extends ResponseTestCase
$response = new Response();
$response->headers->set('Cache-Control', 'must-revalidate');
$response->headers->set('Expires', -1);
$this->assertEquals('Sat, 01 Jan 00 00:00:00 +0000', $response->getExpires()->format(DATE_RFC822));
$this->assertLessThanOrEqual(time() - 2 * 86400, $response->getExpires()->format('U'));
$response = new Response();
$this->assertNull($response->getMaxAge(), '->getMaxAge() returns null if no freshness information available');
@@ -658,6 +658,22 @@ class ResponseTest extends ResponseTestCase
$this->assertTrue($response->isImmutable());
}
public function testSetDate()
{
$response = new Response();
$response->setDate(\DateTime::createFromFormat(\DateTime::ATOM, '2013-01-26T09:21:56+0100', new \DateTimeZone('Europe/Berlin')));
$this->assertEquals('2013-01-26T08:21:56+00:00', $response->getDate()->format(\DateTime::ATOM));
}
public function testSetDateWithImmutable()
{
$response = new Response();
$response->setDate(\DateTimeImmutable::createFromFormat(\DateTime::ATOM, '2013-01-26T09:21:56+0100', new \DateTimeZone('Europe/Berlin')));
$this->assertEquals('2013-01-26T08:21:56+00:00', $response->getDate()->format(\DateTime::ATOM));
}
public function testSetExpires()
{
$response = new Response();
@@ -671,6 +687,16 @@ class ResponseTest extends ResponseTestCase
$this->assertEquals($response->getExpires()->getTimestamp(), $now->getTimestamp());
}
public function testSetExpiresWithImmutable()
{
$response = new Response();
$now = $this->createDateTimeImmutableNow();
$response->setExpires($now);
$this->assertEquals($response->getExpires()->getTimestamp(), $now->getTimestamp());
}
public function testSetLastModified()
{
$response = new Response();
@@ -681,6 +707,16 @@ class ResponseTest extends ResponseTestCase
$this->assertNull($response->getLastModified());
}
public function testSetLastModifiedWithImmutable()
{
$response = new Response();
$response->setLastModified($this->createDateTimeImmutableNow());
$this->assertNotNull($response->getLastModified());
$response->setLastModified(null);
$this->assertNull($response->getLastModified());
}
public function testIsInvalid()
{
$response = new Response();
@@ -917,6 +953,13 @@ class ResponseTest extends ResponseTestCase
return $date->setTimestamp(time());
}
protected function createDateTimeImmutableNow()
{
$date = new \DateTimeImmutable();
return $date->setTimestamp(time());
}
protected function provideResponse()
{
return new Response();
@@ -995,14 +1038,3 @@ class StringableObject
class DefaultResponse extends Response
{
}
class ExtendedResponse extends Response
{
public function setLastModified(\DateTime $date = null)
{
}
public function getDate()
{
}
}

View File

@@ -0,0 +1,177 @@
<?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\RedisSessionHandler;
/**
* @requires extension redis
* @group time-sensitive
*/
abstract class AbstractRedisSessionHandlerTestCase extends TestCase
{
protected const PREFIX = 'prefix_';
/**
* @var RedisSessionHandler
*/
protected $storage;
/**
* @var \Redis|\RedisArray|\RedisCluster|\Predis\Client
*/
protected $redisClient;
/**
* @var \Redis
*/
protected $validator;
/**
* @return \Redis|\RedisArray|\RedisCluster|\Predis\Client
*/
abstract protected function createRedisClient(string $host);
protected function setUp()
{
parent::setUp();
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,
array('prefix' => self::PREFIX)
);
}
protected function tearDown()
{
$this->redisClient = 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->setFixture(self::PREFIX.'id1', null);
$this->setFixture(self::PREFIX.'id2', 'abc123');
$this->assertEquals('', $this->storage->read('id1'));
$this->assertEquals('abc123', $this->storage->read('id2'));
}
public function testWriteSession()
{
$this->assertTrue($this->storage->write('id', 'data'));
$this->assertTrue($this->hasFixture(self::PREFIX.'id'));
$this->assertEquals('data', $this->getFixture(self::PREFIX.'id'));
}
public function testUseSessionGcMaxLifetimeAsTimeToLive()
{
$this->storage->write('id', 'data');
$ttl = $this->fixtureTtl(self::PREFIX.'id');
$this->assertLessThanOrEqual(ini_get('session.gc_maxlifetime'), $ttl);
$this->assertGreaterThanOrEqual(0, $ttl);
}
public function testDestroySession()
{
$this->setFixture(self::PREFIX.'id', 'foo');
$this->assertTrue($this->hasFixture(self::PREFIX.'id'));
$this->assertTrue($this->storage->destroy('id'));
$this->assertFalse($this->hasFixture(self::PREFIX.'id'));
}
public function testGcSession()
{
$this->assertTrue($this->storage->gc(123));
}
public function testUpdateTimestamp()
{
$lowTTL = 10;
$this->setFixture(self::PREFIX.'id', 'foo', $lowTTL);
$this->storage->updateTimestamp('id', array());
$this->assertGreaterThan($lowTTL, $this->fixtureTtl(self::PREFIX.'id'));
}
/**
* @dataProvider getOptionFixtures
*/
public function testSupportedParam(array $options, bool $supported)
{
try {
new RedisSessionHandler($this->redisClient, $options);
$this->assertTrue($supported);
} catch (\InvalidArgumentException $e) {
$this->assertFalse($supported);
}
}
public function getOptionFixtures(): array
{
return array(
array(array('prefix' => 'session'), true),
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);
}
}

View File

@@ -13,9 +13,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
use PHPUnit\Framework\TestCase;
/**
* @requires PHP 7.0
*/
class AbstractSessionHandlerTest extends TestCase
{
private static $server;

View File

@@ -1,135 +0,0 @@
<?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));
}
}

View File

@@ -32,10 +32,6 @@ class MemcachedSessionHandlerTest extends TestCase
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', '<')) {

View File

@@ -0,0 +1,186 @@
<?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\MigratingSessionHandler;
class MigratingSessionHandlerTest extends TestCase
{
private $dualHandler;
private $currentHandler;
private $writeOnlyHandler;
protected function setUp()
{
$this->currentHandler = $this->createMock(\SessionHandlerInterface::class);
$this->writeOnlyHandler = $this->createMock(\SessionHandlerInterface::class);
$this->dualHandler = new MigratingSessionHandler($this->currentHandler, $this->writeOnlyHandler);
}
public function testInstanceOf()
{
$this->assertInstanceOf(\SessionHandlerInterface::class, $this->dualHandler);
$this->assertInstanceOf(\SessionUpdateTimestampHandlerInterface::class, $this->dualHandler);
}
public function testClose()
{
$this->currentHandler->expects($this->once())
->method('close')
->will($this->returnValue(true));
$this->writeOnlyHandler->expects($this->once())
->method('close')
->will($this->returnValue(false));
$result = $this->dualHandler->close();
$this->assertTrue($result);
}
public function testDestroy()
{
$sessionId = 'xyz';
$this->currentHandler->expects($this->once())
->method('destroy')
->with($sessionId)
->will($this->returnValue(true));
$this->writeOnlyHandler->expects($this->once())
->method('destroy')
->with($sessionId)
->will($this->returnValue(false));
$result = $this->dualHandler->destroy($sessionId);
$this->assertTrue($result);
}
public function testGc()
{
$maxlifetime = 357;
$this->currentHandler->expects($this->once())
->method('gc')
->with($maxlifetime)
->will($this->returnValue(true));
$this->writeOnlyHandler->expects($this->once())
->method('gc')
->with($maxlifetime)
->will($this->returnValue(false));
$result = $this->dualHandler->gc($maxlifetime);
$this->assertTrue($result);
}
public function testOpen()
{
$savePath = '/path/to/save/location';
$sessionName = 'xyz';
$this->currentHandler->expects($this->once())
->method('open')
->with($savePath, $sessionName)
->will($this->returnValue(true));
$this->writeOnlyHandler->expects($this->once())
->method('open')
->with($savePath, $sessionName)
->will($this->returnValue(false));
$result = $this->dualHandler->open($savePath, $sessionName);
$this->assertTrue($result);
}
public function testRead()
{
$sessionId = 'xyz';
$readValue = 'something';
$this->currentHandler->expects($this->once())
->method('read')
->with($sessionId)
->will($this->returnValue($readValue));
$this->writeOnlyHandler->expects($this->never())
->method('read')
->with($this->any());
$result = $this->dualHandler->read($sessionId);
$this->assertSame($readValue, $result);
}
public function testWrite()
{
$sessionId = 'xyz';
$data = 'my-serialized-data';
$this->currentHandler->expects($this->once())
->method('write')
->with($sessionId, $data)
->will($this->returnValue(true));
$this->writeOnlyHandler->expects($this->once())
->method('write')
->with($sessionId, $data)
->will($this->returnValue(false));
$result = $this->dualHandler->write($sessionId, $data);
$this->assertTrue($result);
}
public function testValidateId()
{
$sessionId = 'xyz';
$readValue = 'something';
$this->currentHandler->expects($this->once())
->method('read')
->with($sessionId)
->will($this->returnValue($readValue));
$this->writeOnlyHandler->expects($this->never())
->method('read')
->with($this->any());
$result = $this->dualHandler->validateId($sessionId);
$this->assertTrue($result);
}
public function testUpdateTimestamp()
{
$sessionId = 'xyz';
$data = 'my-serialized-data';
$this->currentHandler->expects($this->once())
->method('write')
->with($sessionId, $data)
->will($this->returnValue(true));
$this->writeOnlyHandler->expects($this->once())
->method('write')
->with($sessionId, $data)
->will($this->returnValue(false));
$result = $this->dualHandler->updateTimestamp($sessionId, $data);
$this->assertTrue($result);
}
}

View File

@@ -17,7 +17,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandl
/**
* @author Markus Bachmann <markus.bachmann@bachi.biz>
* @group time-sensitive
* @group legacy
* @requires extension mongodb
*/
class MongoDbSessionHandlerTest extends TestCase
{
@@ -32,21 +32,11 @@ class MongoDbSessionHandlerTest extends TestCase
{
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 (!class_exists(\MongoDB\Client::class)) {
$this->markTestSkipped('The mongodb/mongodb package is required.');
}
if (phpversion('mongodb')) {
$mongoClass = 'MongoDB\Client';
} else {
$mongoClass = version_compare(phpversion('mongo'), '1.3.0', '<') ? 'Mongo' : 'MongoClient';
}
$this->mongo = $this->getMockBuilder($mongoClass)
$this->mongo = $this->getMockBuilder(\MongoDB\Client::class)
->disableOriginalConstructor()
->getMock();
@@ -62,14 +52,6 @@ class MongoDbSessionHandlerTest extends TestCase
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testConstructorShouldThrowExceptionForInvalidMongo()
{
new MongoDbSessionHandler(new \stdClass(), $this->options);
}
/**
* @expectedException \InvalidArgumentException
*/
@@ -110,27 +92,14 @@ class MongoDbSessionHandlerTest extends TestCase
$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);
}
$this->assertInstanceOf(\MongoDB\BSON\UTCDateTime::class, $criteria[$this->options['expiry_field']]['$gte']);
$this->assertGreaterThanOrEqual(round((string) $criteria[$this->options['expiry_field']]['$gte'] / 1000), $testTimeout);
$fields = array(
return array(
$this->options['id_field'] => 'foo',
$this->options['expiry_field'] => new \MongoDB\BSON\UTCDateTime(),
$this->options['data_field'] => new \MongoDB\BSON\Binary('bar', \MongoDB\BSON\Binary::TYPE_OLD_BINARY),
);
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'));
@@ -145,89 +114,22 @@ class MongoDbSessionHandlerTest extends TestCase
->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) {
->method('updateOne')
->will($this->returnCallback(function ($criteria, $updateData, $options) {
$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);
}
$this->assertEquals(array('upsert' => true), $options);
$data = $updateData['$set'];
$expectedExpiry = time() + (int) ini_get('session.gc_maxlifetime');
$this->assertInstanceOf(\MongoDB\BSON\Binary::class, $data[$this->options['data_field']]);
$this->assertEquals('bar', $data[$this->options['data_field']]->getData());
$this->assertInstanceOf(\MongoDB\BSON\UTCDateTime::class, $data[$this->options['time_field']]);
$this->assertInstanceOf(\MongoDB\BSON\UTCDateTime::class, $data[$this->options['expiry_field']]);
$this->assertGreaterThanOrEqual($expectedExpiry, round((string) $data[$this->options['expiry_field']] / 1000));
}));
$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()
@@ -241,10 +143,8 @@ class MongoDbSessionHandlerTest extends TestCase
$data = array();
$methodName = phpversion('mongodb') ? 'updateOne' : 'update';
$collection->expects($this->exactly(2))
->method($methodName)
->method('updateOne')
->will($this->returnCallback(function ($criteria, $updateData, $options) use (&$data) {
$data = $updateData;
}));
@@ -252,11 +152,7 @@ class MongoDbSessionHandlerTest extends TestCase
$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);
}
$this->assertEquals('foobar', $data['$set'][$this->options['data_field']]->getData());
}
public function testDestroy()
@@ -268,10 +164,8 @@ class MongoDbSessionHandlerTest extends TestCase
->with($this->options['database'], $this->options['collection'])
->will($this->returnValue($collection));
$methodName = phpversion('mongodb') ? 'deleteOne' : 'remove';
$collection->expects($this->once())
->method($methodName)
->method('deleteOne')
->with(array($this->options['id_field'] => 'foo'));
$this->assertTrue($this->storage->destroy('foo'));
@@ -286,18 +180,11 @@ class MongoDbSessionHandlerTest extends TestCase
->with($this->options['database'], $this->options['collection'])
->will($this->returnValue($collection));
$methodName = phpversion('mongodb') ? 'deleteMany' : 'remove';
$collection->expects($this->once())
->method($methodName)
->method('deleteMany')
->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->assertInstanceOf(\MongoDB\BSON\UTCDateTime::class, $criteria[$this->options['expiry_field']]['$lt']);
$this->assertGreaterThanOrEqual(time() - 1, round((string) $criteria[$this->options['expiry_field']]['$lt'] / 1000));
}));
$this->assertTrue($this->storage->gc(1));
@@ -308,23 +195,12 @@ class MongoDbSessionHandlerTest extends TestCase
$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));
$this->assertInstanceOf(\MongoDB\Client::class, $method->invoke($this->storage));
}
private function createMongoCollectionMock()
{
$collectionClass = 'MongoCollection';
if (phpversion('mongodb')) {
$collectionClass = 'MongoDB\Collection';
}
$collection = $this->getMockBuilder($collectionClass)
$collection = $this->getMockBuilder(\MongoDB\Collection::class)
->disableOriginalConstructor()
->getMock();

View File

@@ -29,7 +29,6 @@ class NativeFileSessionHandlerTest extends TestCase
{
$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'));

View File

@@ -1,38 +0,0 @@
<?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);
}
}

View File

@@ -136,10 +136,6 @@ class PdoSessionHandlerTest extends TestCase
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();
@@ -157,9 +153,6 @@ class PdoSessionHandlerTest extends TestCase
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.');
}

View File

@@ -0,0 +1,22 @@
<?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 Predis\Client;
class PredisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
{
protected function createRedisClient(string $host): Client
{
return new Client(array(array('host' => $host)));
}
}

View File

@@ -0,0 +1,22 @@
<?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 Predis\Client;
class PredisSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
{
protected function createRedisClient(string $host): Client
{
return new Client(array('host' => $host));
}
}

View File

@@ -0,0 +1,20 @@
<?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;
class RedisArraySessionHandlerTest extends AbstractRedisSessionHandlerTestCase
{
protected function createRedisClient(string $host): \RedisArray
{
return new \RedisArray(array($host));
}
}

View File

@@ -0,0 +1,23 @@
<?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;
class RedisSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
{
protected function createRedisClient(string $host): \Redis
{
$client = new \Redis();
$client->connect($host);
return $client;
}
}

View File

@@ -1,97 +0,0 @@
<?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'));
}
}

View File

@@ -64,13 +64,12 @@ class PhpBridgeSessionStorageTest extends TestCase
{
$storage = $this->getStorage();
$this->assertFalse($storage->getSaveHandler()->isActive());
$this->assertNotSame(\PHP_SESSION_ACTIVE, session_status());
$this->assertFalse($storage->isStarted());
session_start();
$this->assertTrue(isset($_SESSION));
// in PHP 5.4 we can reliably detect a session started
$this->assertTrue($storage->getSaveHandler()->isActive());
$this->assertSame(\PHP_SESSION_ACTIVE, session_status());
// PHP session might have started, but the storage driver has not, so false is correct here
$this->assertFalse($storage->isStarted());

View File

@@ -1,38 +0,0 @@
<?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\Proxy;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy;
/**
* Test class for NativeProxy.
*
* @group legacy
*
* @author Drak <drak@zikula.org>
*/
class NativeProxyTest extends TestCase
{
public function testIsWrapper()
{
$proxy = new NativeProxy();
$this->assertFalse($proxy->isWrapper());
}
public function testGetSaveHandlerName()
{
$name = ini_get('session.save_handler');
$proxy = new NativeProxy();
$this->assertEquals($name, $proxy->getSaveHandlerName());
}
}