Laravel version update
Laravel version update
This commit is contained in:
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\AcceptHeaderItem;
|
||||
|
||||
class AcceptHeaderItemTest extends \PHPUnit_Framework_TestCase
|
||||
class AcceptHeaderItemTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideFromStringData
|
||||
|
@@ -11,10 +11,11 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\AcceptHeader;
|
||||
use Symfony\Component\HttpFoundation\AcceptHeaderItem;
|
||||
|
||||
class AcceptHeaderTest extends \PHPUnit_Framework_TestCase
|
||||
class AcceptHeaderTest extends TestCase
|
||||
{
|
||||
public function testFirst()
|
||||
{
|
||||
|
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\ApacheRequest;
|
||||
|
||||
class ApacheRequestTest extends \PHPUnit_Framework_TestCase
|
||||
class ApacheRequestTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideServerVars
|
||||
|
@@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\File\Stream;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\HttpFoundation\Tests\File\FakeFile;
|
||||
@@ -68,6 +69,17 @@ class BinaryFileResponseTest extends ResponseTestCase
|
||||
$this->assertSame('attachment; filename="f__.html"; filename*=utf-8\'\'f%C3%B6%C3%B6.html', $response->headers->get('Content-Disposition'));
|
||||
}
|
||||
|
||||
public function testSetContentDispositionGeneratesSafeFallbackFilenameForWronglyEncodedFilename()
|
||||
{
|
||||
$response = new BinaryFileResponse(__FILE__);
|
||||
|
||||
$iso88591EncodedFilename = utf8_decode('föö.html');
|
||||
$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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideRanges
|
||||
*/
|
||||
@@ -97,6 +109,7 @@ class BinaryFileResponseTest extends ResponseTestCase
|
||||
|
||||
$this->assertEquals(206, $response->getStatusCode());
|
||||
$this->assertEquals($responseRange, $response->headers->get('Content-Range'));
|
||||
$this->assertSame($length, $response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,6 +328,15 @@ class BinaryFileResponseTest extends ResponseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testStream()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$response = new BinaryFileResponse(new Stream(__DIR__.'/../README.md'), 200, array('Content-Type' => 'text/plain'));
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertNull($response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
protected function provideResponse()
|
||||
{
|
||||
return new BinaryFileResponse(__DIR__.'/../README.md', 200, array('Content-Type' => 'application/octet-stream'));
|
||||
|
103
vendor/symfony/http-foundation/Tests/CookieTest.php
vendored
103
vendor/symfony/http-foundation/Tests/CookieTest.php
vendored
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
/**
|
||||
@@ -21,7 +22,7 @@ use Symfony\Component\HttpFoundation\Cookie;
|
||||
*
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class CookieTest extends \PHPUnit_Framework_TestCase
|
||||
class CookieTest extends TestCase
|
||||
{
|
||||
public function invalidNames()
|
||||
{
|
||||
@@ -52,7 +53,14 @@ class CookieTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidExpiration()
|
||||
{
|
||||
$cookie = new Cookie('MyCookie', 'foo', 'bar');
|
||||
new Cookie('MyCookie', 'foo', 'bar');
|
||||
}
|
||||
|
||||
public function testNegativeExpirationIsNotPossible()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', -100);
|
||||
|
||||
$this->assertSame(0, $cookie->getExpiresTime());
|
||||
}
|
||||
|
||||
public function testGetValue()
|
||||
@@ -72,9 +80,20 @@ class CookieTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetExpiresTime()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', 3600);
|
||||
$cookie = new Cookie('foo', 'bar');
|
||||
|
||||
$this->assertEquals(3600, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
|
||||
$this->assertEquals(0, $cookie->getExpiresTime(), '->getExpiresTime() returns the default expire date');
|
||||
|
||||
$cookie = new Cookie('foo', 'bar', $expire = time() + 3600);
|
||||
|
||||
$this->assertEquals($expire, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
|
||||
}
|
||||
|
||||
public function testGetExpiresTimeIsCastToInt()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', 3600.9);
|
||||
|
||||
$this->assertSame(3600, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date as an integer');
|
||||
}
|
||||
|
||||
public function testConstructorWithDateTime()
|
||||
@@ -107,21 +126,21 @@ class CookieTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetDomain()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', 3600, '/', '.myfoodomain.com');
|
||||
$cookie = new Cookie('foo', 'bar', 0, '/', '.myfoodomain.com');
|
||||
|
||||
$this->assertEquals('.myfoodomain.com', $cookie->getDomain(), '->getDomain() returns the domain name on which the cookie is valid');
|
||||
}
|
||||
|
||||
public function testIsSecure()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', 3600, '/', '.myfoodomain.com', true);
|
||||
$cookie = new Cookie('foo', 'bar', 0, '/', '.myfoodomain.com', true);
|
||||
|
||||
$this->assertTrue($cookie->isSecure(), '->isSecure() returns whether the cookie is transmitted over HTTPS');
|
||||
}
|
||||
|
||||
public function testIsHttpOnly()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', 3600, '/', '.myfoodomain.com', false, true);
|
||||
$cookie = new Cookie('foo', 'bar', 0, '/', '.myfoodomain.com', false, true);
|
||||
|
||||
$this->assertTrue($cookie->isHttpOnly(), '->isHttpOnly() returns whether the cookie is only transmitted over HTTP');
|
||||
}
|
||||
@@ -138,17 +157,79 @@ class CookieTest extends \PHPUnit_Framework_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()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
|
||||
$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly', $cookie->__toString(), '->__toString() returns string representation of the cookie');
|
||||
$cookie = new Cookie('foo', 'bar', $expire = strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
|
||||
$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly', (string) $cookie, '->__toString() returns string representation of the cookie');
|
||||
|
||||
$cookie = new Cookie('foo', 'bar with white spaces', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
|
||||
$this->assertEquals('foo=bar%20with%20white%20spaces; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly', (string) $cookie, '->__toString() encodes the value of the cookie according to RFC 3986 (white space = %20)');
|
||||
|
||||
$cookie = new Cookie('foo', null, 1, '/admin/', '.myfoodomain.com');
|
||||
$this->assertEquals('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/admin/; domain=.myfoodomain.com; httponly', $cookie->__toString(), '->__toString() returns string representation of a cleared cookie if value is NULL');
|
||||
$this->assertEquals('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', $expire = time() - 31536001).'; Max-Age=0; path=/admin/; domain=.myfoodomain.com; httponly', (string) $cookie, '->__toString() returns string representation of a cleared cookie if value is NULL');
|
||||
|
||||
$cookie = new Cookie('foo', 'bar', 0, '/', '');
|
||||
$this->assertEquals('foo=bar; path=/; httponly', $cookie->__toString());
|
||||
$this->assertEquals('foo=bar; path=/; httponly', (string) $cookie);
|
||||
}
|
||||
|
||||
public function testRawCookie()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'b a r', 0, '/', null, false, false);
|
||||
$this->assertFalse($cookie->isRaw());
|
||||
$this->assertEquals('foo=b%20a%20r; path=/', (string) $cookie);
|
||||
|
||||
$cookie = new Cookie('foo', 'b+a+r', 0, '/', null, false, false, true);
|
||||
$this->assertTrue($cookie->isRaw());
|
||||
$this->assertEquals('foo=b+a+r; path=/', (string) $cookie);
|
||||
}
|
||||
|
||||
public function testGetMaxAge()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar');
|
||||
$this->assertEquals(0, $cookie->getMaxAge());
|
||||
|
||||
$cookie = new Cookie('foo', 'bar', $expire = time() + 100);
|
||||
$this->assertEquals($expire - time(), $cookie->getMaxAge());
|
||||
|
||||
$cookie = new Cookie('foo', 'bar', $expire = time() - 100);
|
||||
$this->assertEquals(0, $cookie->getMaxAge());
|
||||
}
|
||||
|
||||
public function testFromString()
|
||||
{
|
||||
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly');
|
||||
$this->assertEquals(new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, true), $cookie);
|
||||
|
||||
$cookie = Cookie::fromString('foo=bar', true);
|
||||
$this->assertEquals(new Cookie('foo', 'bar', 0, '/', null, false, false), $cookie);
|
||||
}
|
||||
|
||||
public function testFromStringWithHttpOnly()
|
||||
{
|
||||
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly');
|
||||
$this->assertTrue($cookie->isHttpOnly());
|
||||
|
||||
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure');
|
||||
$this->assertFalse($cookie->isHttpOnly());
|
||||
}
|
||||
|
||||
public function testSameSiteAttributeIsCaseInsensitive()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', 0, '/', null, false, true, false, 'Lax');
|
||||
$this->assertEquals('lax', $cookie->getSameSite());
|
||||
}
|
||||
}
|
||||
|
@@ -11,11 +11,12 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||
use Symfony\Component\HttpFoundation\ExpressionRequestMatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class ExpressionRequestMatcherTest extends \PHPUnit_Framework_TestCase
|
||||
class ExpressionRequestMatcherTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
|
@@ -11,10 +11,11 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\File;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
||||
|
||||
class FileTest extends \PHPUnit_Framework_TestCase
|
||||
class FileTest extends TestCase
|
||||
{
|
||||
protected $file;
|
||||
|
||||
@@ -63,7 +64,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testConstructWhenFileNotExists()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
|
||||
new File(__DIR__.'/Fixtures/not_here');
|
||||
}
|
||||
@@ -166,7 +167,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function createMockGuesser($path, $mimeType)
|
||||
{
|
||||
$guesser = $this->getMock('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface');
|
||||
$guesser = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface')->getMock();
|
||||
$guesser
|
||||
->expects($this->once())
|
||||
->method('guess')
|
||||
|
@@ -11,13 +11,14 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\File\MimeType;
|
||||
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
||||
|
||||
/**
|
||||
* @requires extension fileinfo
|
||||
*/
|
||||
class MimeTypeTest extends \PHPUnit_Framework_TestCase
|
||||
class MimeTypeTest extends TestCase
|
||||
{
|
||||
protected $path;
|
||||
|
||||
@@ -28,7 +29,7 @@ class MimeTypeTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGuessImageWithDirectory()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
|
||||
MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/directory');
|
||||
}
|
||||
@@ -52,13 +53,13 @@ class MimeTypeTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGuessWithIncorrectPath()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/not_here');
|
||||
}
|
||||
|
||||
public function testGuessWithNonReadablePath()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
if ('\\' === \DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('Can not verify chmod operations on Windows');
|
||||
}
|
||||
|
||||
@@ -70,8 +71,8 @@ class MimeTypeTest extends \PHPUnit_Framework_TestCase
|
||||
touch($path);
|
||||
@chmod($path, 0333);
|
||||
|
||||
if (substr(sprintf('%o', fileperms($path)), -4) == '0333') {
|
||||
$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException');
|
||||
if ('0333' == substr(sprintf('%o', fileperms($path)), -4)) {
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException');
|
||||
MimeTypeGuesser::getInstance()->guess($path);
|
||||
} else {
|
||||
$this->markTestSkipped('Can not verify chmod operations, change of file permissions failed');
|
||||
|
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\File;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class UploadedFileTest extends \PHPUnit_Framework_TestCase
|
||||
class UploadedFileTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
@@ -24,7 +25,7 @@ class UploadedFileTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testConstructWhenFileNotExists()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
|
||||
new UploadedFile(
|
||||
__DIR__.'/Fixtures/not_here',
|
||||
@@ -45,7 +46,7 @@ class UploadedFileTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals('application/octet-stream', $file->getClientMimeType());
|
||||
|
||||
if (extension_loaded('fileinfo')) {
|
||||
if (\extension_loaded('fileinfo')) {
|
||||
$this->assertEquals('image/gif', $file->getMimeType());
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpFoundation\FileBag;
|
||||
|
||||
@@ -20,7 +21,7 @@ use Symfony\Component\HttpFoundation\FileBag;
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
|
||||
*/
|
||||
class FileBagTest extends \PHPUnit_Framework_TestCase
|
||||
class FileBagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
@@ -59,6 +60,32 @@ class FileBagTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertNull($bag->get('file'));
|
||||
}
|
||||
|
||||
public function testShouldRemoveEmptyUploadedFilesForMultiUpload()
|
||||
{
|
||||
$bag = new FileBag(array('files' => array(
|
||||
'name' => array(''),
|
||||
'type' => array(''),
|
||||
'tmp_name' => array(''),
|
||||
'error' => array(UPLOAD_ERR_NO_FILE),
|
||||
'size' => array(0),
|
||||
)));
|
||||
|
||||
$this->assertSame(array(), $bag->get('files'));
|
||||
}
|
||||
|
||||
public function testShouldNotRemoveEmptyUploadedFilesForAssociativeArray()
|
||||
{
|
||||
$bag = new FileBag(array('files' => array(
|
||||
'name' => array('file1' => ''),
|
||||
'type' => array('file1' => ''),
|
||||
'tmp_name' => array('file1' => ''),
|
||||
'error' => array('file1' => UPLOAD_ERR_NO_FILE),
|
||||
'size' => array('file1' => 0),
|
||||
)));
|
||||
|
||||
$this->assertSame(array('file1' => null), $bag->get('files'));
|
||||
}
|
||||
|
||||
public function testShouldConvertUploadedFilesWithPhpBug()
|
||||
{
|
||||
$tmpFile = $this->createTempFile();
|
||||
|
43
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/common.inc
vendored
Normal file
43
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/common.inc
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
$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);
|
||||
|
||||
if (ini_get('xdebug.default_enable')) {
|
||||
xdebug_disable();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
$r = new Response();
|
||||
$r->headers->set('Date', 'Sat, 12 Nov 1955 20:04:00 GMT');
|
||||
|
||||
return $r;
|
11
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_max_age.expected
vendored
Normal file
11
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_max_age.expected
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
Warning: Expiry date cannot have a year greater than 9999 in %scookie_max_age.php on line 10
|
||||
|
||||
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: foo=bar; expires=Sat, 01-Jan-10000 02:46:40 GMT; Max-Age=%d; path=/
|
||||
)
|
||||
shutdown
|
10
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_max_age.php
vendored
Normal file
10
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_max_age.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
$r->headers->setCookie(new Cookie('foo', 'bar', 253402310800, '', null, false, false));
|
||||
$r->sendHeaders();
|
||||
|
||||
setcookie('foo2', 'bar', 253402310800, '/');
|
10
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_raw_urlencode.expected
vendored
Normal file
10
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_raw_urlencode.expected
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
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: ?*():@&+$/%#[]=?*():@&+$/%#[]; path=/
|
||||
[4] => Set-Cookie: ?*():@&+$/%#[]=?*():@&+$/%#[]; path=/
|
||||
)
|
||||
shutdown
|
12
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_raw_urlencode.php
vendored
Normal file
12
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_raw_urlencode.php
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
$str = '?*():@&+$/%#[]';
|
||||
|
||||
$r->headers->setCookie(new Cookie($str, $str, 0, '/', null, false, false, true));
|
||||
$r->sendHeaders();
|
||||
|
||||
setrawcookie($str, $str, 0, '/', null, false, false);
|
@@ -0,0 +1,9 @@
|
||||
|
||||
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: CookieSamesiteLaxTest=LaxValue; path=/; httponly; samesite=lax
|
||||
)
|
||||
shutdown
|
8
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_samesite_lax.php
vendored
Normal file
8
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_samesite_lax.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
$r->headers->setCookie(new Cookie('CookieSamesiteLaxTest', 'LaxValue', 0, '/', null, false, true, false, Cookie::SAMESITE_LAX));
|
||||
$r->sendHeaders();
|
@@ -0,0 +1,9 @@
|
||||
|
||||
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: CookieSamesiteStrictTest=StrictValue; path=/; httponly; samesite=strict
|
||||
)
|
||||
shutdown
|
8
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_samesite_strict.php
vendored
Normal file
8
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_samesite_strict.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
$r->headers->setCookie(new Cookie('CookieSamesiteStrictTest', 'StrictValue', 0, '/', null, false, true, false, Cookie::SAMESITE_STRICT));
|
||||
$r->sendHeaders();
|
10
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_urlencode.expected
vendored
Normal file
10
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_urlencode.expected
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
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; path=/
|
||||
[4] => Set-Cookie: ?*():@&+$/%#[]=%3F%2A%28%29%3A%40%26%2B%24%2F%25%23%5B%5D; path=/
|
||||
)
|
||||
shutdown
|
12
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_urlencode.php
vendored
Normal file
12
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_urlencode.php
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
$str = '?*():@&+$/%#[]';
|
||||
|
||||
$r->headers->setCookie(new Cookie($str, $str, 0, '', null, false, false));
|
||||
$r->sendHeaders();
|
||||
|
||||
setcookie($str, $str, 0, '/');
|
@@ -0,0 +1,6 @@
|
||||
The cookie name "Hello + world" contains invalid characters.
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
)
|
||||
shutdown
|
11
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/invalid_cookie_name.php
vendored
Normal file
11
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/invalid_cookie_name.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
try {
|
||||
$r->headers->setCookie(new Cookie('Hello + world', 'hodor'));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\HeaderBag;
|
||||
|
||||
class HeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
class HeaderBagTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
@@ -171,6 +172,15 @@ class HeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(10, $bag->getCacheControlDirective('max-age'));
|
||||
}
|
||||
|
||||
public function testCacheControlClone()
|
||||
{
|
||||
$headers = array('foo' => 'bar');
|
||||
$bag1 = new HeaderBag($headers);
|
||||
$bag2 = new HeaderBag($bag1->all());
|
||||
|
||||
$this->assertEquals($bag1->all(), $bag2->all());
|
||||
}
|
||||
|
||||
public function testGetIterator()
|
||||
{
|
||||
$headers = array('foo' => 'bar', 'hello' => 'world', 'third' => 'charm');
|
||||
@@ -182,7 +192,7 @@ class HeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array($headers[$key]), $val);
|
||||
}
|
||||
|
||||
$this->assertEquals(count($headers), $i);
|
||||
$this->assertEquals(\count($headers), $i);
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
@@ -190,6 +200,6 @@ class HeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$headers = array('foo' => 'bar', 'HELLO' => 'WORLD');
|
||||
$headerBag = new HeaderBag($headers);
|
||||
|
||||
$this->assertEquals(count($headers), count($headerBag));
|
||||
$this->assertCount(\count($headers), $headerBag);
|
||||
}
|
||||
}
|
||||
|
@@ -11,19 +11,20 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\IpUtils;
|
||||
|
||||
class IpUtilsTest extends \PHPUnit_Framework_TestCase
|
||||
class IpUtilsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider testIpv4Provider
|
||||
* @dataProvider getIpv4Data
|
||||
*/
|
||||
public function testIpv4($matches, $remoteAddr, $cidr)
|
||||
{
|
||||
$this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr));
|
||||
}
|
||||
|
||||
public function testIpv4Provider()
|
||||
public function getIpv4Data()
|
||||
{
|
||||
return array(
|
||||
array(true, '192.168.1.1', '192.168.1.1'),
|
||||
@@ -37,22 +38,23 @@ class IpUtilsTest extends \PHPUnit_Framework_TestCase
|
||||
array(true, '1.2.3.4', '0.0.0.0/0'),
|
||||
array(true, '1.2.3.4', '192.168.1.0/0'),
|
||||
array(false, '1.2.3.4', '256.256.256/0'), // invalid CIDR notation
|
||||
array(false, 'an_invalid_ip', '192.168.1.0/24'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testIpv6Provider
|
||||
* @dataProvider getIpv6Data
|
||||
*/
|
||||
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".');
|
||||
}
|
||||
|
||||
$this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr));
|
||||
}
|
||||
|
||||
public function testIpv6Provider()
|
||||
public function getIpv6Data()
|
||||
{
|
||||
return array(
|
||||
array(true, '2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'),
|
||||
@@ -60,6 +62,8 @@ class IpUtilsTest extends \PHPUnit_Framework_TestCase
|
||||
array(false, '2a01:198:603:0:396e:4789:8e99:890f', '::1'),
|
||||
array(true, '0:0:0:0:0:0:0:1', '::1'),
|
||||
array(false, '0:0:603:0:396e:4789:8e99:0001', '::1'),
|
||||
array(true, '0:0:603:0:396e:4789:8e99:0001', '::/0'),
|
||||
array(true, '0:0:603:0:396e:4789:8e99:0001', '2a01:198:603:0::/0'),
|
||||
array(true, '2a01:198:603:0:396e:4789:8e99:890f', array('::1', '2a01:198:603:0::/65')),
|
||||
array(true, '2a01:198:603:0:396e:4789:8e99:890f', array('2a01:198:603:0::/65', '::1')),
|
||||
array(false, '2a01:198:603:0:396e:4789:8e99:890f', array('::1', '1a01:198:603:0::/65')),
|
||||
@@ -74,10 +78,27 @@ class IpUtilsTest extends \PHPUnit_Framework_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".');
|
||||
}
|
||||
|
||||
IpUtils::checkIp('2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidIpAddressData
|
||||
*/
|
||||
public function testInvalidIpAddressesDoNotMatch($requestIp, $proxyIp)
|
||||
{
|
||||
$this->assertFalse(IpUtils::checkIp4($requestIp, $proxyIp));
|
||||
}
|
||||
|
||||
public function invalidIpAddressData()
|
||||
{
|
||||
return array(
|
||||
'invalid proxy wildcard' => array('192.168.20.13', '*'),
|
||||
'invalid proxy missing netmask' => array('192.168.20.13', '0.0.0.0'),
|
||||
'invalid request IP with invalid proxy wildcard' => array('0.0.0.0', '*'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -11,10 +11,20 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
class JsonResponseTest extends \PHPUnit_Framework_TestCase
|
||||
class JsonResponseTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!\defined('HHVM_VERSION')) {
|
||||
$this->iniSet('serialize_precision', 14);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstructorEmptyCreatesJsonObject()
|
||||
{
|
||||
$response = new JsonResponse();
|
||||
@@ -75,6 +85,19 @@ class JsonResponseTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame('application/vnd.acme.blog-v1+json', $response->headers->get('Content-Type'));
|
||||
}
|
||||
|
||||
public function testSetJson()
|
||||
{
|
||||
$response = new JsonResponse('1', 200, array(), true);
|
||||
$this->assertEquals('1', $response->getContent());
|
||||
|
||||
$response = new JsonResponse('[1]', 200, array(), true);
|
||||
$this->assertEquals('[1]', $response->getContent());
|
||||
|
||||
$response = new JsonResponse(null, 200, array());
|
||||
$response->setJson('true');
|
||||
$this->assertEquals('true', $response->getContent());
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$response = JsonResponse::create(array('foo' => 'bar'), 204);
|
||||
@@ -185,6 +208,12 @@ class JsonResponseTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('{"0":{"0":1,"1":2,"2":3}}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testItAcceptsJsonAsString()
|
||||
{
|
||||
$response = JsonResponse::fromJsonString('{"foo":"bar"}');
|
||||
$this->assertSame('{"foo":"bar"}', $response->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
@@ -208,13 +237,25 @@ class JsonResponseTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSetContentJsonSerializeError()
|
||||
{
|
||||
if (!interface_exists('JsonSerializable', false)) {
|
||||
$this->markTestSkipped('JsonSerializable is required.');
|
||||
}
|
||||
|
||||
$serializable = new JsonSerializableObject();
|
||||
|
||||
JsonResponse::create($serializable);
|
||||
}
|
||||
|
||||
public function testSetComplexCallback()
|
||||
{
|
||||
$response = JsonResponse::create(array('foo' => 'bar'));
|
||||
$response->setCallback('ಠ_ಠ["foo"].bar[0]');
|
||||
|
||||
$this->assertEquals('/**/ಠ_ಠ["foo"].bar[0]({"foo":"bar"});', $response->getContent());
|
||||
}
|
||||
}
|
||||
|
||||
if (interface_exists('JsonSerializable')) {
|
||||
if (interface_exists('JsonSerializable', false)) {
|
||||
class JsonSerializableObject implements \JsonSerializable
|
||||
{
|
||||
public function jsonSerialize()
|
||||
|
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
class ParameterBagTest extends \PHPUnit_Framework_TestCase
|
||||
class ParameterBagTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
@@ -170,7 +171,7 @@ class ParameterBagTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($parameters[$key], $val);
|
||||
}
|
||||
|
||||
$this->assertEquals(count($parameters), $i);
|
||||
$this->assertEquals(\count($parameters), $i);
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
@@ -178,7 +179,7 @@ class ParameterBagTest extends \PHPUnit_Framework_TestCase
|
||||
$parameters = array('foo' => 'bar', 'hello' => 'world');
|
||||
$bag = new ParameterBag($parameters);
|
||||
|
||||
$this->assertEquals(count($parameters), count($bag));
|
||||
$this->assertCount(\count($parameters), $bag);
|
||||
}
|
||||
|
||||
public function testGetBoolean()
|
||||
|
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
|
||||
class RedirectResponseTest extends \PHPUnit_Framework_TestCase
|
||||
class RedirectResponseTest extends TestCase
|
||||
{
|
||||
public function testGenerateMetaRedirect()
|
||||
{
|
||||
@@ -80,4 +81,17 @@ class RedirectResponseTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
|
||||
$this->assertEquals(301, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testCacheHeaders()
|
||||
{
|
||||
$response = new RedirectResponse('foo.bar', 301);
|
||||
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$response = new RedirectResponse('foo.bar', 301, array('cache-control' => 'max-age=86400'));
|
||||
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective('max-age'));
|
||||
|
||||
$response = new RedirectResponse('foo.bar', 302);
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective('no-cache'));
|
||||
}
|
||||
}
|
||||
|
@@ -11,13 +11,14 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RequestMatcher;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestMatcher;
|
||||
|
||||
class RequestMatcherTest extends \PHPUnit_Framework_TestCase
|
||||
class RequestMatcherTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider testMethodFixtures
|
||||
* @dataProvider getMethodData
|
||||
*/
|
||||
public function testMethod($requestMethod, $matcherMethod, $isMatch)
|
||||
{
|
||||
@@ -31,7 +32,7 @@ class RequestMatcherTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($isMatch, $matcher->matches($request));
|
||||
}
|
||||
|
||||
public function testMethodFixtures()
|
||||
public function getMethodData()
|
||||
{
|
||||
return array(
|
||||
array('get', 'get', true),
|
||||
@@ -63,7 +64,7 @@ class RequestMatcherTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testHostFixture
|
||||
* @dataProvider getHostData
|
||||
*/
|
||||
public function testHost($pattern, $isMatch)
|
||||
{
|
||||
@@ -77,7 +78,7 @@ class RequestMatcherTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($isMatch, $matcher->matches($request));
|
||||
}
|
||||
|
||||
public function testHostFixture()
|
||||
public function getHostData()
|
||||
{
|
||||
return array(
|
||||
array('.*\.example\.com', true),
|
||||
|
@@ -11,10 +11,11 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
class RequestStackTest extends \PHPUnit_Framework_TestCase
|
||||
class RequestStackTest extends TestCase
|
||||
{
|
||||
public function testGetCurrentRequest()
|
||||
{
|
||||
|
613
vendor/symfony/http-foundation/Tests/RequestTest.php
vendored
613
vendor/symfony/http-foundation/Tests/RequestTest.php
vendored
@@ -11,12 +11,20 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
class RequestTest extends TestCase
|
||||
{
|
||||
protected function tearDown()
|
||||
{
|
||||
Request::setTrustedProxies(array(), -1);
|
||||
Request::setTrustedHosts(array());
|
||||
}
|
||||
|
||||
public function testInitialize()
|
||||
{
|
||||
$request = new Request();
|
||||
@@ -44,18 +52,18 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetUser()
|
||||
{
|
||||
$request = Request::create('http://user_test:password_test@test.com/');
|
||||
$request = Request::create('http://user:password@test.com');
|
||||
$user = $request->getUser();
|
||||
|
||||
$this->assertEquals('user_test', $user);
|
||||
$this->assertEquals('user', $user);
|
||||
}
|
||||
|
||||
public function testGetPassword()
|
||||
{
|
||||
$request = Request::create('http://user_test:password_test@test.com/');
|
||||
$request = Request::create('http://user:password@test.com');
|
||||
$password = $request->getPassword();
|
||||
|
||||
$this->assertEquals('password_test', $password);
|
||||
$this->assertEquals('password', $password);
|
||||
}
|
||||
|
||||
public function testIsNoCache()
|
||||
@@ -294,7 +302,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFormatToMimeTypeMapProvider
|
||||
* @dataProvider getFormatToMimeTypeMapProviderWithAdditionalNullFormat
|
||||
*/
|
||||
public function testGetFormatFromMimeType($format, $mimeTypes)
|
||||
{
|
||||
@@ -305,9 +313,21 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$request->setFormat($format, $mimeTypes);
|
||||
foreach ($mimeTypes as $mime) {
|
||||
$this->assertEquals($format, $request->getFormat($mime));
|
||||
|
||||
if (null !== $format) {
|
||||
$this->assertEquals($mimeTypes[0], $request->getMimeType($format));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getFormatToMimeTypeMapProviderWithAdditionalNullFormat()
|
||||
{
|
||||
return array_merge(
|
||||
array(array(null, array(null, 'unexistent-mime-type'))),
|
||||
$this->getFormatToMimeTypeMapProvider()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetFormatFromMimeTypeWithParameters()
|
||||
{
|
||||
$request = new Request();
|
||||
@@ -319,10 +339,23 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testGetMimeTypeFromFormat($format, $mimeTypes)
|
||||
{
|
||||
if (null !== $format) {
|
||||
$request = new Request();
|
||||
$this->assertEquals($mimeTypes[0], $request->getMimeType($format));
|
||||
}
|
||||
$request = new Request();
|
||||
$this->assertEquals($mimeTypes[0], $request->getMimeType($format));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFormatToMimeTypeMapProvider
|
||||
*/
|
||||
public function testGetMimeTypesFromFormat($format, $mimeTypes)
|
||||
{
|
||||
$this->assertEquals($mimeTypes, Request::getMimeTypes($format));
|
||||
}
|
||||
|
||||
public function testGetMimeTypesFromInexistentFormat()
|
||||
{
|
||||
$request = new Request();
|
||||
$this->assertNull($request->getMimeType('foo'));
|
||||
$this->assertEquals(array(), Request::getMimeTypes('foo'));
|
||||
}
|
||||
|
||||
public function testGetFormatWithCustomMimeType()
|
||||
@@ -335,11 +368,11 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
public function getFormatToMimeTypeMapProvider()
|
||||
{
|
||||
return array(
|
||||
array(null, array(null, 'unexistent-mime-type')),
|
||||
array('txt', array('text/plain')),
|
||||
array('js', array('application/javascript', 'application/x-javascript', 'text/javascript')),
|
||||
array('css', array('text/css')),
|
||||
array('json', array('application/json', 'application/x-json')),
|
||||
array('jsonld', array('application/ld+json')),
|
||||
array('xml', array('text/xml', 'application/xml', 'application/x-xml')),
|
||||
array('rdf', array('application/rdf+xml')),
|
||||
array('atom', array('application/atom+xml')),
|
||||
@@ -708,7 +741,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(80, $port, 'Without trusted proxies FORWARDED_PROTO and FORWARDED_PORT are ignored.');
|
||||
|
||||
Request::setTrustedProxies(array('1.1.1.1'));
|
||||
Request::setTrustedProxies(array('1.1.1.1'), Request::HEADER_X_FORWARDED_ALL);
|
||||
$request = Request::create('http://example.com', 'GET', array(), array(), array(), array(
|
||||
'HTTP_X_FORWARDED_PROTO' => 'https',
|
||||
'HTTP_X_FORWARDED_PORT' => '8443',
|
||||
@@ -750,8 +783,6 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
));
|
||||
$port = $request->getPort();
|
||||
$this->assertEquals(80, $port, 'With only PROTO set and value is not recognized, getPort() defaults to 80.');
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -817,45 +848,44 @@ class RequestTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testGetClientIpsProvider
|
||||
* @dataProvider getClientIpsProvider
|
||||
*/
|
||||
public function testGetClientIp($expected, $remoteAddr, $httpForwardedFor, $trustedProxies)
|
||||
{
|
||||
$request = $this->getRequestInstanceForClientIpTests($remoteAddr, $httpForwardedFor, $trustedProxies);
|
||||
|
||||
$this->assertEquals($expected[0], $request->getClientIp());
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testGetClientIpsProvider
|
||||
* @dataProvider getClientIpsProvider
|
||||
*/
|
||||
public function testGetClientIps($expected, $remoteAddr, $httpForwardedFor, $trustedProxies)
|
||||
{
|
||||
$request = $this->getRequestInstanceForClientIpTests($remoteAddr, $httpForwardedFor, $trustedProxies);
|
||||
|
||||
$this->assertEquals($expected, $request->getClientIps());
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testGetClientIpsForwardedProvider
|
||||
* @dataProvider getClientIpsForwardedProvider
|
||||
*/
|
||||
public function testGetClientIpsForwarded($expected, $remoteAddr, $httpForwarded, $trustedProxies)
|
||||
{
|
||||
$request = $this->getRequestInstanceForClientIpsForwardedTests($remoteAddr, $httpForwarded, $trustedProxies);
|
||||
|
||||
$this->assertEquals($expected, $request->getClientIps());
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
public function testGetClientIpsForwardedProvider()
|
||||
public function getClientIpsForwardedProvider()
|
||||
{
|
||||
// $expected $remoteAddr $httpForwarded $trustedProxies
|
||||
return array(
|
||||
@@ -868,7 +898,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetClientIpsProvider()
|
||||
public function getClientIpsProvider()
|
||||
{
|
||||
// $expected $remoteAddr $httpForwardedFor $trustedProxies
|
||||
return array(
|
||||
@@ -925,7 +955,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException
|
||||
* @dataProvider testGetClientIpsWithConflictingHeadersProvider
|
||||
* @dataProvider getClientIpsWithConflictingHeadersProvider
|
||||
*/
|
||||
public function testGetClientIpsWithConflictingHeaders($httpForwarded, $httpXForwardedFor)
|
||||
{
|
||||
@@ -937,14 +967,34 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
'HTTP_X_FORWARDED_FOR' => $httpXForwardedFor,
|
||||
);
|
||||
|
||||
Request::setTrustedProxies(array('88.88.88.88'));
|
||||
Request::setTrustedProxies(array('88.88.88.88'), Request::HEADER_X_FORWARDED_ALL | Request::HEADER_FORWARDED);
|
||||
|
||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||
|
||||
$request->getClientIps();
|
||||
}
|
||||
|
||||
public function testGetClientIpsWithConflictingHeadersProvider()
|
||||
/**
|
||||
* @dataProvider getClientIpsWithConflictingHeadersProvider
|
||||
*/
|
||||
public function testGetClientIpsOnlyXHttpForwardedForTrusted($httpForwarded, $httpXForwardedFor)
|
||||
{
|
||||
$request = new Request();
|
||||
|
||||
$server = array(
|
||||
'REMOTE_ADDR' => '88.88.88.88',
|
||||
'HTTP_FORWARDED' => $httpForwarded,
|
||||
'HTTP_X_FORWARDED_FOR' => $httpXForwardedFor,
|
||||
);
|
||||
|
||||
Request::setTrustedProxies(array('88.88.88.88'), Request::HEADER_X_FORWARDED_FOR);
|
||||
|
||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||
|
||||
$this->assertSame(array_reverse(explode(',', $httpXForwardedFor)), $request->getClientIps());
|
||||
}
|
||||
|
||||
public function getClientIpsWithConflictingHeadersProvider()
|
||||
{
|
||||
// $httpForwarded $httpXForwardedFor
|
||||
return array(
|
||||
@@ -957,9 +1007,9 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testGetClientIpsWithAgreeingHeadersProvider
|
||||
* @dataProvider getClientIpsWithAgreeingHeadersProvider
|
||||
*/
|
||||
public function testGetClientIpsWithAgreeingHeaders($httpForwarded, $httpXForwardedFor)
|
||||
public function testGetClientIpsWithAgreeingHeaders($httpForwarded, $httpXForwardedFor, $expectedIps)
|
||||
{
|
||||
$request = new Request();
|
||||
|
||||
@@ -969,25 +1019,25 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
'HTTP_X_FORWARDED_FOR' => $httpXForwardedFor,
|
||||
);
|
||||
|
||||
Request::setTrustedProxies(array('88.88.88.88'));
|
||||
Request::setTrustedProxies(array('88.88.88.88'), Request::HEADER_X_FORWARDED_ALL);
|
||||
|
||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||
|
||||
$request->getClientIps();
|
||||
$clientIps = $request->getClientIps();
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
$this->assertSame($expectedIps, $clientIps);
|
||||
}
|
||||
|
||||
public function testGetClientIpsWithAgreeingHeadersProvider()
|
||||
public function getClientIpsWithAgreeingHeadersProvider()
|
||||
{
|
||||
// $httpForwarded $httpXForwardedFor
|
||||
return array(
|
||||
array('for="192.0.2.60"', '192.0.2.60'),
|
||||
array('for=192.0.2.60, for=87.65.43.21', '192.0.2.60,87.65.43.21'),
|
||||
array('for="[::face]", for=192.0.2.60', '::face,192.0.2.60'),
|
||||
array('for="192.0.2.60:80"', '192.0.2.60'),
|
||||
array('for=192.0.2.60;proto=http;by=203.0.113.43', '192.0.2.60'),
|
||||
array('for="[2001:db8:cafe::17]:4711"', '2001:db8:cafe::17'),
|
||||
array('for="192.0.2.60"', '192.0.2.60', array('192.0.2.60')),
|
||||
array('for=192.0.2.60, for=87.65.43.21', '192.0.2.60,87.65.43.21', array('87.65.43.21', '192.0.2.60')),
|
||||
array('for="[::face]", for=192.0.2.60', '::face,192.0.2.60', array('192.0.2.60', '::face')),
|
||||
array('for="192.0.2.60:80"', '192.0.2.60', array('192.0.2.60')),
|
||||
array('for=192.0.2.60;proto=http;by=203.0.113.43', '192.0.2.60', array('192.0.2.60')),
|
||||
array('for="[2001:db8:cafe::17]:4711"', '2001:db8:cafe::17', array('2001:db8:cafe::17')),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1012,7 +1062,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$req = new Request(array(), array(), array(), array(), array(), array(), 'MyContent');
|
||||
$resource = $req->getContent(true);
|
||||
|
||||
$this->assertTrue(is_resource($resource));
|
||||
$this->assertInternalType('resource', $resource);
|
||||
$this->assertEquals('MyContent', stream_get_contents($resource));
|
||||
}
|
||||
|
||||
@@ -1033,7 +1083,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testGetContentCantBeCalledTwiceWithResources($first, $second)
|
||||
{
|
||||
if (PHP_VERSION_ID >= 50600) {
|
||||
if (\PHP_VERSION_ID >= 50600) {
|
||||
$this->markTestSkipped('PHP >= 5.6 allows to open php://input several times.');
|
||||
}
|
||||
|
||||
@@ -1042,8 +1092,16 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$req->getContent($second);
|
||||
}
|
||||
|
||||
public function getContentCantBeCalledTwiceWithResourcesProvider()
|
||||
{
|
||||
return array(
|
||||
'Resource then fetch' => array(true, false),
|
||||
'Resource then resource' => array(true, true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getContentCantBeCalledTwiceWithResourcesProvider
|
||||
* @dataProvider getContentCanBeCalledTwiceWithResourcesProvider
|
||||
* @requires PHP 5.6
|
||||
*/
|
||||
public function testGetContentCanBeCalledTwiceWithResources($first, $second)
|
||||
@@ -1060,12 +1118,14 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$b = stream_get_contents($b);
|
||||
}
|
||||
|
||||
$this->assertEquals($a, $b);
|
||||
$this->assertSame($a, $b);
|
||||
}
|
||||
|
||||
public function getContentCantBeCalledTwiceWithResourcesProvider()
|
||||
public function getContentCanBeCalledTwiceWithResourcesProvider()
|
||||
{
|
||||
return array(
|
||||
'Fetch then fetch' => array(false, false),
|
||||
'Fetch then resource' => array(false, true),
|
||||
'Resource then fetch' => array(true, false),
|
||||
'Resource then resource' => array(true, true),
|
||||
);
|
||||
@@ -1080,7 +1140,6 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
array('put'),
|
||||
array('delete'),
|
||||
array('patch'),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1149,11 +1208,10 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$request->headers->set('X_FORWARDED_PROTO', 'https');
|
||||
|
||||
Request::setTrustedProxies(array('1.1.1.1'));
|
||||
Request::setTrustedProxies(array('1.1.1.1'), Request::HEADER_X_FORWARDED_ALL);
|
||||
$this->assertFalse($request->isSecure());
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$this->assertTrue($request->isSecure());
|
||||
Request::setTrustedProxies(array());
|
||||
|
||||
$request->overrideGlobals();
|
||||
|
||||
@@ -1254,6 +1312,12 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||
|
||||
$this->assertEquals('/path%20test/info', $request->getPathInfo());
|
||||
|
||||
$server = array();
|
||||
$server['REQUEST_URI'] = '?a=b';
|
||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||
|
||||
$this->assertEquals('/', $request->getPathInfo());
|
||||
}
|
||||
|
||||
public function testGetParameterPrecedence()
|
||||
@@ -1410,6 +1474,11 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$request = new Request();
|
||||
$this->assertEquals('html', $request->getRequestFormat());
|
||||
|
||||
// Ensure that setting different default values over time is possible,
|
||||
// aka. setRequestFormat determines the state.
|
||||
$this->assertEquals('json', $request->getRequestFormat('json'));
|
||||
$this->assertEquals('html', $request->getRequestFormat('html'));
|
||||
|
||||
$request = new Request();
|
||||
$this->assertNull($request->getRequestFormat(null));
|
||||
|
||||
@@ -1459,8 +1528,18 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$request = new Request();
|
||||
|
||||
$request->headers->set('Accept-language', 'zh, en-us; q=0.8, en; q=0.6');
|
||||
$request->cookies->set('Foo', 'Bar');
|
||||
|
||||
$this->assertContains('Accept-Language: zh, en-us; q=0.8, en; q=0.6', $request->__toString());
|
||||
$asString = (string) $request;
|
||||
|
||||
$this->assertContains('Accept-Language: zh, en-us; q=0.8, en; q=0.6', $asString);
|
||||
$this->assertContains('Cookie: Foo=Bar', $asString);
|
||||
|
||||
$request->cookies->set('Another', 'Cookie');
|
||||
|
||||
$asString = (string) $request;
|
||||
|
||||
$this->assertContains('Cookie: Foo=Bar; Another=Cookie', $asString);
|
||||
}
|
||||
|
||||
public function testIsMethod()
|
||||
@@ -1611,7 +1690,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
if ($trustedProxies) {
|
||||
Request::setTrustedProxies($trustedProxies);
|
||||
Request::setTrustedProxies($trustedProxies, Request::HEADER_X_FORWARDED_ALL);
|
||||
}
|
||||
|
||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||
@@ -1630,7 +1709,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
if ($trustedProxies) {
|
||||
Request::setTrustedProxies($trustedProxies);
|
||||
Request::setTrustedProxies($trustedProxies, Request::HEADER_FORWARDED);
|
||||
}
|
||||
|
||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||
@@ -1638,7 +1717,63 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
return $request;
|
||||
}
|
||||
|
||||
public function testTrustedProxies()
|
||||
public function testTrustedProxiesXForwardedFor()
|
||||
{
|
||||
$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:1234, real.example.com:8080');
|
||||
$request->headers->set('X_FORWARDED_PROTO', 'https');
|
||||
$request->headers->set('X_FORWARDED_PORT', 443);
|
||||
|
||||
// no trusted proxies
|
||||
$this->assertEquals('3.3.3.3', $request->getClientIp());
|
||||
$this->assertEquals('example.com', $request->getHost());
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// disabling proxy trusting
|
||||
Request::setTrustedProxies(array(), Request::HEADER_X_FORWARDED_ALL);
|
||||
$this->assertEquals('3.3.3.3', $request->getClientIp());
|
||||
$this->assertEquals('example.com', $request->getHost());
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// request is forwarded by a non-trusted proxy
|
||||
Request::setTrustedProxies(array('2.2.2.2'), Request::HEADER_X_FORWARDED_ALL);
|
||||
$this->assertEquals('3.3.3.3', $request->getClientIp());
|
||||
$this->assertEquals('example.com', $request->getHost());
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// trusted proxy via setTrustedProxies()
|
||||
Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'), Request::HEADER_X_FORWARDED_ALL);
|
||||
$this->assertEquals('1.1.1.1', $request->getClientIp());
|
||||
$this->assertEquals('foo.example.com', $request->getHost());
|
||||
$this->assertEquals(443, $request->getPort());
|
||||
$this->assertTrue($request->isSecure());
|
||||
|
||||
// trusted proxy via setTrustedProxies()
|
||||
Request::setTrustedProxies(array('3.3.3.4', '2.2.2.2'), Request::HEADER_X_FORWARDED_ALL);
|
||||
$this->assertEquals('3.3.3.3', $request->getClientIp());
|
||||
$this->assertEquals('example.com', $request->getHost());
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// check various X_FORWARDED_PROTO header values
|
||||
Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'), Request::HEADER_X_FORWARDED_ALL);
|
||||
$request->headers->set('X_FORWARDED_PROTO', 'ssl');
|
||||
$this->assertTrue($request->isSecure());
|
||||
|
||||
$request->headers->set('X_FORWARDED_PROTO', 'https, http');
|
||||
$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');
|
||||
@@ -1651,47 +1786,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$request->headers->set('X_MY_PROTO', 'http');
|
||||
$request->headers->set('X_MY_PORT', 81);
|
||||
|
||||
// no trusted proxies
|
||||
$this->assertEquals('3.3.3.3', $request->getClientIp());
|
||||
$this->assertEquals('example.com', $request->getHost());
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// disabling proxy trusting
|
||||
Request::setTrustedProxies(array());
|
||||
$this->assertEquals('3.3.3.3', $request->getClientIp());
|
||||
$this->assertEquals('example.com', $request->getHost());
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// request is forwarded by a non-trusted proxy
|
||||
Request::setTrustedProxies(array('2.2.2.2'));
|
||||
$this->assertEquals('3.3.3.3', $request->getClientIp());
|
||||
$this->assertEquals('example.com', $request->getHost());
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// trusted proxy via setTrustedProxies()
|
||||
Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'));
|
||||
$this->assertEquals('1.1.1.1', $request->getClientIp());
|
||||
$this->assertEquals('real.example.com', $request->getHost());
|
||||
$this->assertEquals(443, $request->getPort());
|
||||
$this->assertTrue($request->isSecure());
|
||||
|
||||
// trusted proxy via setTrustedProxies()
|
||||
Request::setTrustedProxies(array('3.3.3.4', '2.2.2.2'));
|
||||
$this->assertEquals('3.3.3.3', $request->getClientIp());
|
||||
$this->assertEquals('example.com', $request->getHost());
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// check various X_FORWARDED_PROTO header values
|
||||
Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'));
|
||||
$request->headers->set('X_FORWARDED_PROTO', 'ssl');
|
||||
$this->assertTrue($request->isSecure());
|
||||
|
||||
$request->headers->set('X_FORWARDED_PROTO', 'https, http');
|
||||
$this->assertTrue($request->isSecure());
|
||||
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');
|
||||
@@ -1713,15 +1808,65 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// reset
|
||||
Request::setTrustedProxies(array());
|
||||
//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/');
|
||||
$request->server->set('REMOTE_ADDR', '3.3.3.3');
|
||||
$request->headers->set('FORWARDED', 'for=1.1.1.1, host=foo.example.com:8080, proto=https, for=2.2.2.2, host=real.example.com:8080');
|
||||
|
||||
// no trusted proxies
|
||||
$this->assertEquals('3.3.3.3', $request->getClientIp());
|
||||
$this->assertEquals('example.com', $request->getHost());
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// disabling proxy trusting
|
||||
Request::setTrustedProxies(array(), Request::HEADER_FORWARDED);
|
||||
$this->assertEquals('3.3.3.3', $request->getClientIp());
|
||||
$this->assertEquals('example.com', $request->getHost());
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// request is forwarded by a non-trusted proxy
|
||||
Request::setTrustedProxies(array('2.2.2.2'), Request::HEADER_FORWARDED);
|
||||
$this->assertEquals('3.3.3.3', $request->getClientIp());
|
||||
$this->assertEquals('example.com', $request->getHost());
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// trusted proxy via setTrustedProxies()
|
||||
Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'), Request::HEADER_FORWARDED);
|
||||
$this->assertEquals('1.1.1.1', $request->getClientIp());
|
||||
$this->assertEquals('foo.example.com', $request->getHost());
|
||||
$this->assertEquals(8080, $request->getPort());
|
||||
$this->assertTrue($request->isSecure());
|
||||
|
||||
// trusted proxy via setTrustedProxies()
|
||||
Request::setTrustedProxies(array('3.3.3.4', '2.2.2.2'), Request::HEADER_FORWARDED);
|
||||
$this->assertEquals('3.3.3.3', $request->getClientIp());
|
||||
$this->assertEquals('example.com', $request->getHost());
|
||||
$this->assertEquals(80, $request->getPort());
|
||||
$this->assertFalse($request->isSecure());
|
||||
|
||||
// check various X_FORWARDED_PROTO header values
|
||||
Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'), Request::HEADER_FORWARDED);
|
||||
$request->headers->set('FORWARDED', 'proto=ssl');
|
||||
$this->assertTrue($request->isSecure());
|
||||
|
||||
$request->headers->set('FORWARDED', 'proto=https, proto=http');
|
||||
$this->assertTrue($request->isSecure());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testSetTrustedProxiesInvalidHeaderName()
|
||||
@@ -1731,6 +1876,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testGetTrustedProxiesInvalidHeaderName()
|
||||
@@ -1758,20 +1904,6 @@ class RequestTest extends \PHPUnit_Framework_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(
|
||||
@@ -1780,36 +1912,6 @@ class RequestTest extends \PHPUnit_Framework_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(
|
||||
@@ -1845,8 +1947,8 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
try {
|
||||
$request->getHost();
|
||||
$this->fail('Request::getHost() should throw an exception when host is not trusted.');
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
$this->assertEquals('Untrusted Host "evil.com"', $e->getMessage());
|
||||
} catch (SuspiciousOperationException $e) {
|
||||
$this->assertEquals('Untrusted Host "evil.com".', $e->getMessage());
|
||||
}
|
||||
|
||||
// trusted hosts
|
||||
@@ -1866,9 +1968,15 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$request->headers->set('host', 'subdomain.trusted.com');
|
||||
$this->assertEquals('subdomain.trusted.com', $request->getHost());
|
||||
}
|
||||
|
||||
// reset request for following tests
|
||||
Request::setTrustedHosts(array());
|
||||
public function testSetTrustedHostsDoesNotBreakOnSpecialCharacters()
|
||||
{
|
||||
Request::setTrustedHosts(array('localhost(\.local){0,1}#,example.com', 'localhost'));
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->headers->set('host', 'localhost');
|
||||
$this->assertSame('localhost', $request->getHost());
|
||||
}
|
||||
|
||||
public function testFactory()
|
||||
@@ -1909,7 +2017,13 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($expectedPort, $request->getPort());
|
||||
}
|
||||
} else {
|
||||
$this->setExpectedException('UnexpectedValueException', 'Invalid Host');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(SuspiciousOperationException::class);
|
||||
$this->expectExceptionMessage('Invalid Host');
|
||||
} else {
|
||||
$this->setExpectedException(SuspiciousOperationException::class, 'Invalid Host');
|
||||
}
|
||||
|
||||
$request->getHost();
|
||||
}
|
||||
}
|
||||
@@ -1935,6 +2049,32 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider methodIdempotentProvider
|
||||
*/
|
||||
public function testMethodIdempotent($method, $idempotent)
|
||||
{
|
||||
$request = new Request();
|
||||
$request->setMethod($method);
|
||||
$this->assertEquals($idempotent, $request->isMethodIdempotent());
|
||||
}
|
||||
|
||||
public function methodIdempotentProvider()
|
||||
{
|
||||
return array(
|
||||
array('HEAD', true),
|
||||
array('GET', true),
|
||||
array('POST', false),
|
||||
array('PUT', true),
|
||||
array('PATCH', false),
|
||||
array('DELETE', true),
|
||||
array('PURGE', true),
|
||||
array('OPTIONS', true),
|
||||
array('TRACE', true),
|
||||
array('CONNECT', false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider methodSafeProvider
|
||||
*/
|
||||
@@ -1942,7 +2082,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$request = new Request();
|
||||
$request->setMethod($method);
|
||||
$this->assertEquals($safe, $request->isMethodSafe());
|
||||
$this->assertEquals($safe, $request->isMethodSafe(false));
|
||||
}
|
||||
|
||||
public function methodSafeProvider()
|
||||
@@ -1960,13 +2100,190 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
array('CONNECT', false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
public function testMethodSafeChecksCacheable()
|
||||
{
|
||||
$request = new Request();
|
||||
$request->setMethod('OPTIONS');
|
||||
$this->assertFalse($request->isMethodSafe());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider methodCacheableProvider
|
||||
*/
|
||||
public function testMethodCacheable($method, $cacheable)
|
||||
{
|
||||
$request = new Request();
|
||||
$request->setMethod($method);
|
||||
$this->assertEquals($cacheable, $request->isMethodCacheable());
|
||||
}
|
||||
|
||||
public function methodCacheableProvider()
|
||||
{
|
||||
return array(
|
||||
array('HEAD', true),
|
||||
array('GET', true),
|
||||
array('POST', false),
|
||||
array('PUT', false),
|
||||
array('PATCH', false),
|
||||
array('DELETE', false),
|
||||
array('PURGE', false),
|
||||
array('OPTIONS', false),
|
||||
array('TRACE', false),
|
||||
array('CONNECT', false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testProtocolVersion($serverProtocol, $trustedProxy, $via, $expected)
|
||||
{
|
||||
if ($trustedProxy) {
|
||||
Request::setTrustedProxies(array('1.1.1.1'), -1);
|
||||
}
|
||||
|
||||
$request = new Request();
|
||||
$request->server->set('SERVER_PROTOCOL', $serverProtocol);
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('Via', $via);
|
||||
|
||||
$this->assertSame($expected, $request->getProtocolVersion());
|
||||
}
|
||||
|
||||
public function protocolVersionProvider()
|
||||
{
|
||||
return array(
|
||||
'untrusted without via' => array('HTTP/2.0', false, '', 'HTTP/2.0'),
|
||||
'untrusted with via' => array('HTTP/2.0', false, '1.0 fred, 1.1 nowhere.com (Apache/1.1)', 'HTTP/2.0'),
|
||||
'trusted without via' => array('HTTP/2.0', true, '', 'HTTP/2.0'),
|
||||
'trusted with via' => array('HTTP/2.0', true, '1.0 fred, 1.1 nowhere.com (Apache/1.1)', 'HTTP/1.0'),
|
||||
'trusted with via and protocol name' => array('HTTP/2.0', true, 'HTTP/1.0 fred, HTTP/1.1 nowhere.com (Apache/1.1)', 'HTTP/1.0'),
|
||||
'trusted with broken via' => array('HTTP/2.0', true, 'HTTP/1^0 foo', 'HTTP/2.0'),
|
||||
'trusted with partially-broken via' => array('HTTP/2.0', true, '1.0 fred, foo', 'HTTP/1.0'),
|
||||
);
|
||||
}
|
||||
|
||||
public function nonstandardRequestsData()
|
||||
{
|
||||
return array(
|
||||
array('', '', '/', 'http://host:8080/', ''),
|
||||
array('/', '', '/', 'http://host:8080/', ''),
|
||||
|
||||
array('hello/app.php/x', '', '/x', 'http://host:8080/hello/app.php/x', '/hello', '/hello/app.php'),
|
||||
array('/hello/app.php/x', '', '/x', 'http://host:8080/hello/app.php/x', '/hello', '/hello/app.php'),
|
||||
|
||||
array('', 'a=b', '/', 'http://host:8080/?a=b'),
|
||||
array('?a=b', 'a=b', '/', 'http://host:8080/?a=b'),
|
||||
array('/?a=b', 'a=b', '/', 'http://host:8080/?a=b'),
|
||||
|
||||
array('x', 'a=b', '/x', 'http://host:8080/x?a=b'),
|
||||
array('x?a=b', 'a=b', '/x', 'http://host:8080/x?a=b'),
|
||||
array('/x?a=b', 'a=b', '/x', 'http://host:8080/x?a=b'),
|
||||
|
||||
array('hello/x', '', '/x', 'http://host:8080/hello/x', '/hello'),
|
||||
array('/hello/x', '', '/x', 'http://host:8080/hello/x', '/hello'),
|
||||
|
||||
array('hello/app.php/x', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'),
|
||||
array('hello/app.php/x?a=b', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'),
|
||||
array('/hello/app.php/x?a=b', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider nonstandardRequestsData
|
||||
*/
|
||||
public function testNonstandardRequests($requestUri, $queryString, $expectedPathInfo, $expectedUri, $expectedBasePath = '', $expectedBaseUrl = null)
|
||||
{
|
||||
if (null === $expectedBaseUrl) {
|
||||
$expectedBaseUrl = $expectedBasePath;
|
||||
}
|
||||
|
||||
$server = array(
|
||||
'HTTP_HOST' => 'host:8080',
|
||||
'SERVER_PORT' => '8080',
|
||||
'QUERY_STRING' => $queryString,
|
||||
'PHP_SELF' => '/hello/app.php',
|
||||
'SCRIPT_FILENAME' => '/some/path/app.php',
|
||||
'REQUEST_URI' => $requestUri,
|
||||
);
|
||||
|
||||
$request = new Request(array(), array(), array(), array(), array(), $server);
|
||||
|
||||
$this->assertEquals($expectedPathInfo, $request->getPathInfo());
|
||||
$this->assertEquals($expectedUri, $request->getUri());
|
||||
$this->assertEquals($queryString, $request->getQueryString());
|
||||
$this->assertEquals(8080, $request->getPort());
|
||||
$this->assertEquals('host:8080', $request->getHttpHost());
|
||||
$this->assertEquals($expectedBaseUrl, $request->getBaseUrl());
|
||||
$this->assertEquals($expectedBasePath, $request->getBasePath());
|
||||
}
|
||||
}
|
||||
|
||||
class RequestContentProxy extends Request
|
||||
{
|
||||
public function getContent($asResource = false)
|
||||
{
|
||||
return http_build_query(array('_method' => 'PUT', 'content' => 'mycontent'));
|
||||
return http_build_query(array('_method' => 'PUT', 'content' => 'mycontent'), '', '&');
|
||||
}
|
||||
}
|
||||
|
||||
|
58
vendor/symfony/http-foundation/Tests/ResponseFunctionalTest.php
vendored
Normal file
58
vendor/symfony/http-foundation/Tests/ResponseFunctionalTest.php
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* @requires PHP 7.0
|
||||
*/
|
||||
class ResponseFunctionalTest 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:8054', $spec, $pipes, __DIR__.'/Fixtures/response-functional')) {
|
||||
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 provideCookie
|
||||
*/
|
||||
public function testCookie($fixture)
|
||||
{
|
||||
$result = file_get_contents(sprintf('http://localhost:8054/%s.php', $fixture));
|
||||
$this->assertStringMatchesFormatFile(__DIR__.sprintf('/Fixtures/response-functional/%s.expected', $fixture), $result);
|
||||
}
|
||||
|
||||
public function provideCookie()
|
||||
{
|
||||
foreach (glob(__DIR__.'/Fixtures/response-functional/*.php') as $file) {
|
||||
yield array(pathinfo($file, PATHINFO_FILENAME));
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,62 +11,39 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
class ResponseHeaderBagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideAllPreserveCase
|
||||
*/
|
||||
public function testAllPreserveCase($headers, $expected)
|
||||
public function testAllPreserveCase()
|
||||
{
|
||||
$bag = new ResponseHeaderBag($headers);
|
||||
|
||||
$this->assertEquals($expected, $bag->allPreserveCase(), '->allPreserveCase() gets all input keys in original case');
|
||||
}
|
||||
|
||||
public function provideAllPreserveCase()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('fOo' => 'BAR'),
|
||||
array('fOo' => array('BAR'), 'Cache-Control' => array('no-cache')),
|
||||
),
|
||||
array(
|
||||
array('ETag' => 'xyzzy'),
|
||||
array('ETag' => array('xyzzy'), 'Cache-Control' => array('private, must-revalidate')),
|
||||
),
|
||||
array(
|
||||
array('Content-MD5' => 'Q2hlY2sgSW50ZWdyaXR5IQ=='),
|
||||
array('Content-MD5' => array('Q2hlY2sgSW50ZWdyaXR5IQ=='), 'Cache-Control' => array('no-cache')),
|
||||
),
|
||||
array(
|
||||
array('P3P' => 'CP="CAO PSA OUR"'),
|
||||
array('P3P' => array('CP="CAO PSA OUR"'), 'Cache-Control' => array('no-cache')),
|
||||
),
|
||||
array(
|
||||
array('WWW-Authenticate' => 'Basic realm="WallyWorld"'),
|
||||
array('WWW-Authenticate' => array('Basic realm="WallyWorld"'), 'Cache-Control' => array('no-cache')),
|
||||
),
|
||||
array(
|
||||
array('X-UA-Compatible' => 'IE=edge,chrome=1'),
|
||||
array('X-UA-Compatible' => array('IE=edge,chrome=1'), 'Cache-Control' => array('no-cache')),
|
||||
),
|
||||
array(
|
||||
array('X-XSS-Protection' => '1; mode=block'),
|
||||
array('X-XSS-Protection' => array('1; mode=block'), 'Cache-Control' => array('no-cache')),
|
||||
),
|
||||
$headers = array(
|
||||
'fOo' => 'BAR',
|
||||
'ETag' => 'xyzzy',
|
||||
'Content-MD5' => 'Q2hlY2sgSW50ZWdyaXR5IQ==',
|
||||
'P3P' => 'CP="CAO PSA OUR"',
|
||||
'WWW-Authenticate' => 'Basic realm="WallyWorld"',
|
||||
'X-UA-Compatible' => 'IE=edge,chrome=1',
|
||||
'X-XSS-Protection' => '1; mode=block',
|
||||
);
|
||||
|
||||
$bag = new ResponseHeaderBag($headers);
|
||||
$allPreservedCase = $bag->allPreserveCase();
|
||||
|
||||
foreach (array_keys($headers) as $headerName) {
|
||||
$this->assertArrayHasKey($headerName, $allPreservedCase, '->allPreserveCase() gets all input keys in original case');
|
||||
}
|
||||
}
|
||||
|
||||
public function testCacheControlHeader()
|
||||
{
|
||||
$bag = new ResponseHeaderBag(array());
|
||||
$this->assertEquals('no-cache', $bag->get('Cache-Control'));
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$bag = new ResponseHeaderBag(array('Cache-Control' => 'public'));
|
||||
@@ -109,6 +86,25 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->set('Last-Modified', 'abcde');
|
||||
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->set('Cache-Control', array('public', 'must-revalidate'));
|
||||
$this->assertCount(1, $bag->get('Cache-Control', null, false));
|
||||
$this->assertEquals('must-revalidate, public', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->set('Cache-Control', 'public');
|
||||
$bag->set('Cache-Control', 'must-revalidate', false);
|
||||
$this->assertCount(1, $bag->get('Cache-Control', null, false));
|
||||
$this->assertEquals('must-revalidate, public', $bag->get('Cache-Control'));
|
||||
}
|
||||
|
||||
public function testCacheControlClone()
|
||||
{
|
||||
$headers = array('foo' => 'bar');
|
||||
$bag1 = new ResponseHeaderBag($headers);
|
||||
$bag2 = new ResponseHeaderBag($bag1->allPreserveCase());
|
||||
$this->assertEquals($bag1->allPreserveCase(), $bag2->allPreserveCase());
|
||||
}
|
||||
|
||||
public function testToStringIncludesCookieHeaders()
|
||||
@@ -116,11 +112,11 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$bag = new ResponseHeaderBag(array());
|
||||
$bag->setCookie(new Cookie('foo', 'bar'));
|
||||
|
||||
$this->assertContains('Set-Cookie: foo=bar; path=/; httponly', explode("\r\n", $bag->__toString()));
|
||||
$this->assertSetCookieHeader('foo=bar; path=/; httponly', $bag);
|
||||
|
||||
$bag->clearCookie('foo');
|
||||
|
||||
$this->assertRegExp('#^Set-Cookie: foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/; httponly#m', $bag->__toString());
|
||||
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; httponly', $bag);
|
||||
}
|
||||
|
||||
public function testClearCookieSecureNotHttpOnly()
|
||||
@@ -129,13 +125,13 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$bag->clearCookie('foo', '/', null, true, false);
|
||||
|
||||
$this->assertRegExp('#^Set-Cookie: foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/; secure#m', $bag->__toString());
|
||||
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; secure', $bag);
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$bag = new ResponseHeaderBag(array());
|
||||
$this->assertEquals('no-cache', $bag->get('Cache-Control'));
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$bag->replace(array('Cache-Control' => 'public'));
|
||||
@@ -146,12 +142,12 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
public function testReplaceWithRemove()
|
||||
{
|
||||
$bag = new ResponseHeaderBag(array());
|
||||
$this->assertEquals('no-cache', $bag->get('Cache-Control'));
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$bag->remove('Cache-Control');
|
||||
$bag->replace(array());
|
||||
$this->assertEquals('no-cache', $bag->get('Cache-Control'));
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
}
|
||||
|
||||
@@ -164,38 +160,50 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$bag->setCookie(new Cookie('foo', 'bar'));
|
||||
|
||||
$this->assertCount(4, $bag->getCookies());
|
||||
$this->assertEquals('foo=bar; path=/path/foo; domain=foo.bar; httponly', $bag->get('set-cookie'));
|
||||
$this->assertEquals(array(
|
||||
'foo=bar; path=/path/foo; domain=foo.bar; httponly',
|
||||
'foo=bar; path=/path/bar; domain=foo.bar; httponly',
|
||||
'foo=bar; path=/path/bar; domain=bar.foo; httponly',
|
||||
'foo=bar; path=/; httponly',
|
||||
), $bag->get('set-cookie', null, false));
|
||||
|
||||
$headers = explode("\r\n", $bag->__toString());
|
||||
$this->assertContains('Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly', $headers);
|
||||
$this->assertContains('Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly', $headers);
|
||||
$this->assertContains('Set-Cookie: foo=bar; path=/path/bar; domain=bar.foo; httponly', $headers);
|
||||
$this->assertContains('Set-Cookie: foo=bar; path=/; httponly', $headers);
|
||||
$this->assertSetCookieHeader('foo=bar; path=/path/foo; domain=foo.bar; httponly', $bag);
|
||||
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=foo.bar; httponly', $bag);
|
||||
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=bar.foo; httponly', $bag);
|
||||
$this->assertSetCookieHeader('foo=bar; path=/; httponly', $bag);
|
||||
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertTrue(isset($cookies['foo.bar']['/path/foo']['foo']));
|
||||
$this->assertTrue(isset($cookies['foo.bar']['/path/bar']['foo']));
|
||||
$this->assertTrue(isset($cookies['bar.foo']['/path/bar']['foo']));
|
||||
$this->assertTrue(isset($cookies['']['/']['foo']));
|
||||
|
||||
$this->assertArrayHasKey('foo', $cookies['foo.bar']['/path/foo']);
|
||||
$this->assertArrayHasKey('foo', $cookies['foo.bar']['/path/bar']);
|
||||
$this->assertArrayHasKey('foo', $cookies['bar.foo']['/path/bar']);
|
||||
$this->assertArrayHasKey('foo', $cookies['']['/']);
|
||||
}
|
||||
|
||||
public function testRemoveCookie()
|
||||
{
|
||||
$bag = new ResponseHeaderBag();
|
||||
$this->assertFalse($bag->has('set-cookie'));
|
||||
|
||||
$bag->setCookie(new Cookie('foo', 'bar', 0, '/path/foo', 'foo.bar'));
|
||||
$bag->setCookie(new Cookie('bar', 'foo', 0, '/path/bar', 'foo.bar'));
|
||||
$this->assertTrue($bag->has('set-cookie'));
|
||||
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertTrue(isset($cookies['foo.bar']['/path/foo']));
|
||||
$this->assertArrayHasKey('/path/foo', $cookies['foo.bar']);
|
||||
|
||||
$bag->removeCookie('foo', '/path/foo', 'foo.bar');
|
||||
$this->assertTrue($bag->has('set-cookie'));
|
||||
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertFalse(isset($cookies['foo.bar']['/path/foo']));
|
||||
$this->assertArrayNotHasKey('/path/foo', $cookies['foo.bar']);
|
||||
|
||||
$bag->removeCookie('bar', '/path/bar', 'foo.bar');
|
||||
$this->assertFalse($bag->has('set-cookie'));
|
||||
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertFalse(isset($cookies['foo.bar']));
|
||||
$this->assertArrayNotHasKey('foo.bar', $cookies);
|
||||
}
|
||||
|
||||
public function testRemoveCookieWithNullRemove()
|
||||
@@ -205,17 +213,33 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$bag->setCookie(new Cookie('bar', 'foo', 0));
|
||||
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertTrue(isset($cookies['']['/']));
|
||||
$this->assertArrayHasKey('/', $cookies['']);
|
||||
|
||||
$bag->removeCookie('foo', null);
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertFalse(isset($cookies['']['/']['foo']));
|
||||
$this->assertArrayNotHasKey('foo', $cookies['']['/']);
|
||||
|
||||
$bag->removeCookie('bar', null);
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertFalse(isset($cookies['']['/']['bar']));
|
||||
}
|
||||
|
||||
public function testSetCookieHeader()
|
||||
{
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->set('set-cookie', 'foo=bar');
|
||||
$this->assertEquals(array(new Cookie('foo', 'bar', 0, '/', null, false, false, true)), $bag->getCookies());
|
||||
|
||||
$bag->set('set-cookie', 'foo2=bar2', false);
|
||||
$this->assertEquals(array(
|
||||
new Cookie('foo', 'bar', 0, '/', null, false, false, true),
|
||||
new Cookie('foo2', 'bar2', 0, '/', null, false, false, true),
|
||||
), $bag->getCookies());
|
||||
|
||||
$bag->remove('set-cookie');
|
||||
$this->assertEquals(array(), $bag->getCookies());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
@@ -223,7 +247,7 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$bag = new ResponseHeaderBag();
|
||||
|
||||
$cookies = $bag->getCookies('invalid_argument');
|
||||
$bag->getCookies('invalid_argument');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,4 +318,46 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
array('attachment', 'föö.html'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testDateHeaderAddedOnCreation()
|
||||
{
|
||||
$now = time();
|
||||
|
||||
$bag = new ResponseHeaderBag();
|
||||
$this->assertTrue($bag->has('Date'));
|
||||
|
||||
$this->assertEquals($now, $bag->getDate('Date')->getTimestamp());
|
||||
}
|
||||
|
||||
public function testDateHeaderCanBeSetOnCreation()
|
||||
{
|
||||
$someDate = 'Thu, 23 Mar 2017 09:15:12 GMT';
|
||||
$bag = new ResponseHeaderBag(array('Date' => $someDate));
|
||||
|
||||
$this->assertEquals($someDate, $bag->get('Date'));
|
||||
}
|
||||
|
||||
public function testDateHeaderWillBeRecreatedWhenRemoved()
|
||||
{
|
||||
$someDate = 'Thu, 23 Mar 2017 09:15:12 GMT';
|
||||
$bag = new ResponseHeaderBag(array('Date' => $someDate));
|
||||
$bag->remove('Date');
|
||||
|
||||
// a (new) Date header is still present
|
||||
$this->assertTrue($bag->has('Date'));
|
||||
$this->assertNotEquals($someDate, $bag->get('Date'));
|
||||
}
|
||||
|
||||
public function testDateHeaderWillBeRecreatedWhenHeadersAreReplaced()
|
||||
{
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->replace(array());
|
||||
|
||||
$this->assertTrue($bag->has('Date'));
|
||||
}
|
||||
|
||||
private function assertSetCookieHeader($expected, ResponseHeaderBag $actual)
|
||||
{
|
||||
$this->assertRegExp('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual));
|
||||
}
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ class ResponseTest extends ResponseTestCase
|
||||
$response = new Response();
|
||||
$response = explode("\r\n", $response);
|
||||
$this->assertEquals('HTTP/1.0 200 OK', $response[0]);
|
||||
$this->assertEquals('Cache-Control: no-cache', $response[1]);
|
||||
$this->assertEquals('Cache-Control: no-cache, private', $response[1]);
|
||||
}
|
||||
|
||||
public function testClone()
|
||||
@@ -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()
|
||||
@@ -276,8 +281,10 @@ class ResponseTest extends ResponseTestCase
|
||||
$this->assertEquals($now->getTimestamp(), $date->getTimestamp(), '->getDate() returns the date when the header has been modified');
|
||||
|
||||
$response = new Response('', 200);
|
||||
$now = $this->createDateTimeNow();
|
||||
$response->headers->remove('Date');
|
||||
$this->assertInstanceOf('\DateTime', $response->getDate());
|
||||
$date = $response->getDate();
|
||||
$this->assertEquals($now->getTimestamp(), $date->getTimestamp(), '->getDate() returns the current Date when the header has previously been removed');
|
||||
}
|
||||
|
||||
public function testGetMaxAge()
|
||||
@@ -442,7 +449,7 @@ class ResponseTest extends ResponseTestCase
|
||||
|
||||
public function testDefaultContentType()
|
||||
{
|
||||
$headerMock = $this->getMock('Symfony\Component\HttpFoundation\ResponseHeaderBag', array('set'));
|
||||
$headerMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\ResponseHeaderBag')->setMethods(array('set'))->getMock();
|
||||
$headerMock->expects($this->at(0))
|
||||
->method('set')
|
||||
->with('Content-Type', 'text/html');
|
||||
@@ -608,6 +615,12 @@ class ResponseTest extends ResponseTestCase
|
||||
$response->setCache(array('private' => false));
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
|
||||
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
|
||||
|
||||
$response->setCache(array('immutable' => true));
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective('immutable'));
|
||||
|
||||
$response->setCache(array('immutable' => false));
|
||||
$this->assertFalse($response->headers->hasCacheControlDirective('immutable'));
|
||||
}
|
||||
|
||||
public function testSendContent()
|
||||
@@ -629,6 +642,22 @@ class ResponseTest extends ResponseTestCase
|
||||
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
|
||||
}
|
||||
|
||||
public function testSetImmutable()
|
||||
{
|
||||
$response = new Response();
|
||||
$response->setImmutable();
|
||||
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective('immutable'));
|
||||
}
|
||||
|
||||
public function testIsImmutable()
|
||||
{
|
||||
$response = new Response();
|
||||
$response->setImmutable();
|
||||
|
||||
$this->assertTrue($response->isImmutable());
|
||||
}
|
||||
|
||||
public function testSetExpires()
|
||||
{
|
||||
$response = new Response();
|
||||
@@ -843,6 +872,16 @@ class ResponseTest extends ResponseTestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testNoDeprecationsAreTriggered()
|
||||
{
|
||||
new DefaultResponse();
|
||||
$this->getMockBuilder(Response::class)->getMock();
|
||||
|
||||
// we just need to ensure that subclasses of Response can be created without any deprecations
|
||||
// being triggered if the subclass does not override any final methods
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function validContentProvider()
|
||||
{
|
||||
return array(
|
||||
@@ -882,6 +921,67 @@ class ResponseTest extends ResponseTestCase
|
||||
{
|
||||
return new Response();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
*
|
||||
* @author Fábio Pacheco
|
||||
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
public function ianaCodesReasonPhrasesProvider()
|
||||
{
|
||||
if (!\in_array('https', stream_get_wrappers(), true)) {
|
||||
$this->markTestSkipped('The "https" wrapper is not available');
|
||||
}
|
||||
|
||||
$ianaHttpStatusCodes = new \DOMDocument();
|
||||
|
||||
libxml_set_streams_context(stream_context_create(array(
|
||||
'http' => array(
|
||||
'method' => 'GET',
|
||||
'timeout' => 30,
|
||||
),
|
||||
)));
|
||||
|
||||
$ianaHttpStatusCodes->load('https://www.iana.org/assignments/http-status-codes/http-status-codes.xml');
|
||||
if (!$ianaHttpStatusCodes->relaxNGValidate(__DIR__.'/schema/http-status-codes.rng')) {
|
||||
self::fail('Invalid IANA\'s HTTP status code list.');
|
||||
}
|
||||
|
||||
$ianaCodesReasonPhrases = array();
|
||||
|
||||
$xpath = new \DOMXPath($ianaHttpStatusCodes);
|
||||
$xpath->registerNamespace('ns', 'http://www.iana.org/assignments');
|
||||
|
||||
$records = $xpath->query('//ns:record');
|
||||
foreach ($records as $record) {
|
||||
$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)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^([0-9]+)\s*\-\s*([0-9]+)$/', $value, $matches)) {
|
||||
for ($value = $matches[1]; $value <= $matches[2]; ++$value) {
|
||||
$ianaCodesReasonPhrases[] = array($value, $description);
|
||||
}
|
||||
} else {
|
||||
$ianaCodesReasonPhrases[] = array($value, $description);
|
||||
}
|
||||
}
|
||||
|
||||
return $ianaCodesReasonPhrases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ianaCodesReasonPhrasesProvider
|
||||
*/
|
||||
public function testReasonPhraseDefaultsAgainstIana($code, $reasonPhrase)
|
||||
{
|
||||
$this->assertEquals($reasonPhrase, Response::$statusTexts[$code]);
|
||||
}
|
||||
}
|
||||
|
||||
class StringableObject
|
||||
@@ -891,3 +991,18 @@ class StringableObject
|
||||
return 'Foo';
|
||||
}
|
||||
}
|
||||
|
||||
class DefaultResponse extends Response
|
||||
{
|
||||
}
|
||||
|
||||
class ExtendedResponse extends Response
|
||||
{
|
||||
public function setLastModified(\DateTime $date = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function getDate()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
abstract class ResponseTestCase extends \PHPUnit_Framework_TestCase
|
||||
abstract class ResponseTestCase extends TestCase
|
||||
{
|
||||
public function testNoCacheControlHeaderOnAttachmentUsingHTTPSAndMSIE()
|
||||
{
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\ServerBag;
|
||||
|
||||
/**
|
||||
@@ -18,7 +19,7 @@ use Symfony\Component\HttpFoundation\ServerBag;
|
||||
*
|
||||
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
|
||||
*/
|
||||
class ServerBagTest extends \PHPUnit_Framework_TestCase
|
||||
class ServerBagTest extends TestCase
|
||||
{
|
||||
public function testShouldExtractHeadersFromServerArray()
|
||||
{
|
||||
@@ -73,8 +74,8 @@ class ServerBagTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// Username and passwords should not be set as the header is bogus
|
||||
$headers = $bag->getHeaders();
|
||||
$this->assertFalse(isset($headers['PHP_AUTH_USER']));
|
||||
$this->assertFalse(isset($headers['PHP_AUTH_PW']));
|
||||
$this->assertArrayNotHasKey('PHP_AUTH_USER', $headers);
|
||||
$this->assertArrayNotHasKey('PHP_AUTH_PW', $headers);
|
||||
}
|
||||
|
||||
public function testHttpBasicAuthWithPhpCgiRedirect()
|
||||
@@ -117,8 +118,8 @@ class ServerBagTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// Username and passwords should not be set as the header is bogus
|
||||
$headers = $bag->getHeaders();
|
||||
$this->assertFalse(isset($headers['PHP_AUTH_USER']));
|
||||
$this->assertFalse(isset($headers['PHP_AUTH_PW']));
|
||||
$this->assertArrayNotHasKey('PHP_AUTH_USER', $headers);
|
||||
$this->assertArrayNotHasKey('PHP_AUTH_PW', $headers);
|
||||
}
|
||||
|
||||
public function testHttpDigestAuthWithPhpCgiRedirect()
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Attribute;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
|
||||
/**
|
||||
@@ -18,12 +19,9 @@ use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class AttributeBagTest extends \PHPUnit_Framework_TestCase
|
||||
class AttributeBagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $array;
|
||||
private $array = array();
|
||||
|
||||
/**
|
||||
* @var AttributeBag
|
||||
@@ -178,11 +176,11 @@ class AttributeBagTest extends \PHPUnit_Framework_TestCase
|
||||
++$i;
|
||||
}
|
||||
|
||||
$this->assertEquals(count($this->array), $i);
|
||||
$this->assertEquals(\count($this->array), $i);
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$this->assertEquals(count($this->array), count($this->bag));
|
||||
$this->assertCount(\count($this->array), $this->bag);
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Attribute;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag;
|
||||
|
||||
/**
|
||||
@@ -18,12 +19,9 @@ use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag;
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class NamespacedAttributeBagTest extends \PHPUnit_Framework_TestCase
|
||||
class NamespacedAttributeBagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $array;
|
||||
private $array = array();
|
||||
|
||||
/**
|
||||
* @var NamespacedAttributeBag
|
||||
@@ -84,6 +82,17 @@ class NamespacedAttributeBagTest extends \PHPUnit_Framework_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
|
||||
*/
|
||||
@@ -98,6 +107,17 @@ class NamespacedAttributeBagTest extends \PHPUnit_Framework_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
|
||||
*/
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Flash;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag as FlashBag;
|
||||
|
||||
/**
|
||||
@@ -18,16 +19,13 @@ use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag as FlashBa
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
|
||||
class AutoExpireFlashBagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag
|
||||
*/
|
||||
private $bag;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $array = array();
|
||||
|
||||
protected function setUp()
|
||||
@@ -61,7 +59,7 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetStorageKey()
|
||||
{
|
||||
$this->assertEquals('_sf2_flashes', $this->bag->getStorageKey());
|
||||
$this->assertEquals('_symfony_flashes', $this->bag->getStorageKey());
|
||||
$attributeBag = new FlashBag('test');
|
||||
$this->assertEquals('test', $attributeBag->getStorageKey());
|
||||
}
|
||||
@@ -152,4 +150,12 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->assertEquals(array('notice' => array('A previous flash message')), $this->bag->clear());
|
||||
}
|
||||
|
||||
public function testDoNotRemoveTheNewFlashesWhenDisplayingTheExistingOnes()
|
||||
{
|
||||
$this->bag->add('success', 'Something');
|
||||
$this->bag->all();
|
||||
|
||||
$this->assertEquals(array('new' => array('success' => array('Something')), 'display' => array()), $this->array);
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Flash;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
|
||||
/**
|
||||
@@ -18,16 +19,13 @@ use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class FlashBagTest extends \PHPUnit_Framework_TestCase
|
||||
class FlashBagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface
|
||||
*/
|
||||
private $bag;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $array = array();
|
||||
|
||||
protected function setUp()
|
||||
@@ -56,7 +54,7 @@ class FlashBagTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetStorageKey()
|
||||
{
|
||||
$this->assertEquals('_sf2_flashes', $this->bag->getStorageKey());
|
||||
$this->assertEquals('_symfony_flashes', $this->bag->getStorageKey());
|
||||
$attributeBag = new FlashBag('test');
|
||||
$this->assertEquals('test', $attributeBag->getStorageKey());
|
||||
}
|
||||
@@ -76,6 +74,18 @@ class FlashBagTest extends \PHPUnit_Framework_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'));
|
||||
@@ -114,6 +124,19 @@ class FlashBagTest extends \PHPUnit_Framework_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');
|
||||
|
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -23,7 +24,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
* @author Robert Schönthal <seroscho@googlemail.com>
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class SessionTest extends \PHPUnit_Framework_TestCase
|
||||
class SessionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface
|
||||
@@ -176,6 +177,8 @@ class SessionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->session->start();
|
||||
$this->session->save();
|
||||
|
||||
$this->assertFalse($this->session->isStarted());
|
||||
}
|
||||
|
||||
public function testGetId()
|
||||
@@ -203,7 +206,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
|
||||
++$i;
|
||||
}
|
||||
|
||||
$this->assertEquals(count($attributes), $i);
|
||||
$this->assertEquals(\count($attributes), $i);
|
||||
}
|
||||
|
||||
public function testGetCount()
|
||||
@@ -218,4 +221,22 @@ class SessionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\MetadataBag', $this->session->getMetadataBag());
|
||||
}
|
||||
|
||||
public function testIsEmpty()
|
||||
{
|
||||
$this->assertTrue($this->session->isEmpty());
|
||||
|
||||
$this->session->set('hello', 'world');
|
||||
$this->assertFalse($this->session->isEmpty());
|
||||
|
||||
$this->session->remove('hello');
|
||||
$this->assertTrue($this->session->isEmpty());
|
||||
|
||||
$flash = $this->session->getFlashBag();
|
||||
$flash->set('hello', 'world');
|
||||
$this->assertFalse($this->session->isEmpty());
|
||||
|
||||
$flash->get('hello');
|
||||
$this->assertTrue($this->session->isEmpty());
|
||||
}
|
||||
}
|
||||
|
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']);
|
@@ -11,16 +11,19 @@
|
||||
|
||||
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 \PHPUnit_Framework_TestCase
|
||||
class MemcacheSessionHandlerTest extends TestCase
|
||||
{
|
||||
const PREFIX = 'prefix_';
|
||||
const TTL = 1000;
|
||||
|
||||
/**
|
||||
* @var MemcacheSessionHandler
|
||||
*/
|
||||
@@ -30,12 +33,12 @@ class MemcacheSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (defined('HHVM_VERSION')) {
|
||||
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->getMock('Memcache');
|
||||
$this->memcache = $this->getMockBuilder('Memcache')->getMock();
|
||||
$this->storage = new MemcacheSessionHandler(
|
||||
$this->memcache,
|
||||
array('prefix' => self::PREFIX, 'expiretime' => self::TTL)
|
||||
@@ -56,12 +59,6 @@ class MemcacheSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testCloseSession()
|
||||
{
|
||||
$this->memcache
|
||||
->expects($this->once())
|
||||
->method('close')
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$this->assertTrue($this->storage->close());
|
||||
}
|
||||
|
||||
|
@@ -11,13 +11,14 @@
|
||||
|
||||
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 \PHPUnit_Framework_TestCase
|
||||
class MemcachedSessionHandlerTest extends TestCase
|
||||
{
|
||||
const PREFIX = 'prefix_';
|
||||
const TTL = 1000;
|
||||
@@ -31,17 +32,17 @@ class MemcachedSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (defined('HHVM_VERSION')) {
|
||||
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', '>=')) {
|
||||
$this->markTestSkipped('Tests can only be run with memcached extension 2.1.0 or lower');
|
||||
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->getMock('Memcached');
|
||||
$this->memcached = $this->getMockBuilder('Memcached')->getMock();
|
||||
$this->storage = new MemcachedSessionHandler(
|
||||
$this->memcached,
|
||||
array('prefix' => self::PREFIX, 'expiretime' => self::TTL)
|
||||
|
@@ -6,18 +6,20 @@
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file this was distributed with this source code.
|
||||
* 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 \PHPUnit_Framework_TestCase
|
||||
class MongoDbSessionHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
@@ -30,7 +32,11 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!extension_loaded('mongo') && !extension_loaded('mongodb')) {
|
||||
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.');
|
||||
}
|
||||
|
||||
@@ -106,7 +112,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$this->options['expiry_field']]['$gte']);
|
||||
$this->assertGreaterThanOrEqual(round(intval((string) $criteria[$this->options['expiry_field']]['$gte']) / 1000), $testTimeout);
|
||||
$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);
|
||||
@@ -164,7 +170,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$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(intval((string) $data[$this->options['expiry_field']]) / 1000));
|
||||
$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']]);
|
||||
@@ -280,14 +286,14 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'deleteOne' : 'remove';
|
||||
$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(intval((string) $criteria[$this->options['expiry_field']]['$lt']) / 1000));
|
||||
$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);
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
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;
|
||||
|
||||
@@ -22,7 +23,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class NativeFileSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
class NativeFileSessionHandlerTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
|
||||
|
||||
/**
|
||||
@@ -20,14 +21,18 @@ use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandle
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @group legacy
|
||||
*/
|
||||
class NativeSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
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->assertTrue($handler instanceof \SessionHandler);
|
||||
$this->assertInstanceOf('SessionHandler', $handler);
|
||||
$this->assertTrue($handler instanceof NativeSessionHandler);
|
||||
}
|
||||
}
|
||||
|
@@ -11,9 +11,10 @@
|
||||
|
||||
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.
|
||||
@@ -23,7 +24,7 @@ use Symfony\Component\HttpFoundation\Session\Session;
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class NullSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
class NullSessionHandlerTest extends TestCase
|
||||
{
|
||||
public function testSaveHandlers()
|
||||
{
|
||||
|
@@ -11,13 +11,14 @@
|
||||
|
||||
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 \PHPUnit_Framework_TestCase
|
||||
class PdoSessionHandlerTest extends TestCase
|
||||
{
|
||||
private $dbFile;
|
||||
|
||||
@@ -135,12 +136,12 @@ class PdoSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testReadConvertsStreamToString()
|
||||
{
|
||||
if (defined('HHVM_VERSION')) {
|
||||
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->getMock('PDOStatement');
|
||||
$pdo->prepareResult = $this->getMockBuilder('PDOStatement')->getMock();
|
||||
|
||||
$content = 'foobar';
|
||||
$stream = $this->createStream($content);
|
||||
@@ -156,13 +157,16 @@ class PdoSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testReadLockedConvertsStreamToString()
|
||||
{
|
||||
if (defined('HHVM_VERSION')) {
|
||||
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->getMock('PDOStatement');
|
||||
$insertStmt = $this->getMock('PDOStatement');
|
||||
$selectStmt = $this->getMockBuilder('PDOStatement')->getMock();
|
||||
$insertStmt = $this->getMockBuilder('PDOStatement')->getMock();
|
||||
|
||||
$pdo->prepareResult = function ($statement) use ($selectStmt, $insertStmt) {
|
||||
return 0 === strpos($statement, 'INSERT') ? $insertStmt : $selectStmt;
|
||||
@@ -268,6 +272,9 @@ class PdoSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame('', $data, 'Destroyed session returns empty string');
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testSessionGC()
|
||||
{
|
||||
$previousLifeTime = ini_set('session.gc_maxlifetime', 1000);
|
||||
@@ -317,6 +324,41 @@ class PdoSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$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();
|
||||
@@ -354,8 +396,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;
|
||||
}
|
||||
|
||||
|
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));
|
||||
}
|
||||
}
|
@@ -11,16 +11,19 @@
|
||||
|
||||
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 \PHPUnit_Framework_TestCase
|
||||
class WriteCheckSessionHandlerTest extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$wrappedSessionHandlerMock = $this->getMock('SessionHandlerInterface');
|
||||
$wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
@@ -35,7 +38,7 @@ class WriteCheckSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$wrappedSessionHandlerMock = $this->getMock('SessionHandlerInterface');
|
||||
$wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
@@ -50,7 +53,7 @@ class WriteCheckSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testSkippedWrite()
|
||||
{
|
||||
$wrappedSessionHandlerMock = $this->getMock('SessionHandlerInterface');
|
||||
$wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
@@ -71,7 +74,7 @@ class WriteCheckSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testNonSkippedWrite()
|
||||
{
|
||||
$wrappedSessionHandlerMock = $this->getMock('SessionHandlerInterface');
|
||||
$wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
|
||||
|
||||
/**
|
||||
@@ -18,16 +19,13 @@ use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
|
||||
*
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class MetadataBagTest extends \PHPUnit_Framework_TestCase
|
||||
class MetadataBagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var MetadataBag
|
||||
*/
|
||||
protected $bag;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $array = array();
|
||||
|
||||
protected function setUp()
|
||||
@@ -102,6 +100,9 @@ class MetadataBagTest extends \PHPUnit_Framework_TestCase
|
||||
public function testClear()
|
||||
{
|
||||
$this->bag->clear();
|
||||
|
||||
// the clear method has no side effects, we just want to ensure it doesn't trigger any exceptions
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testSkipLastUsedUpdate()
|
||||
|
@@ -11,16 +11,17 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
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.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class MockArraySessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
class MockArraySessionStorageTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var MockArraySessionStorage
|
||||
@@ -96,6 +97,30 @@ class MockArraySessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertNotEquals('', $this->storage->getId());
|
||||
}
|
||||
|
||||
public function testClearClearsBags()
|
||||
{
|
||||
$this->storage->clear();
|
||||
|
||||
$this->assertSame(array(), $this->storage->getBag('attributes')->all());
|
||||
$this->assertSame(array(), $this->storage->getBag('flashes')->peekAll());
|
||||
}
|
||||
|
||||
public function testClearStartsSession()
|
||||
{
|
||||
$this->storage->clear();
|
||||
|
||||
$this->assertTrue($this->storage->isStarted());
|
||||
}
|
||||
|
||||
public function testClearWithNoBagsStartsSession()
|
||||
{
|
||||
$storage = new MockArraySessionStorage();
|
||||
|
||||
$storage->clear();
|
||||
|
||||
$this->assertTrue($storage->isStarted());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
|
@@ -11,16 +11,17 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
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.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class MockFileSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
class MockFileSessionStorageTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
|
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
|
||||
@@ -28,7 +29,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
class NativeSessionStorageTest extends TestCase
|
||||
{
|
||||
private $savePath;
|
||||
|
||||
@@ -53,8 +54,6 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*
|
||||
* @return NativeSessionStorage
|
||||
*/
|
||||
protected function getStorage(array $options = array())
|
||||
@@ -183,6 +182,23 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($options, $gco);
|
||||
}
|
||||
|
||||
public function testSessionOptions()
|
||||
{
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('HHVM is not handled in this test case.');
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'url_rewriter.tags' => 'a=href',
|
||||
'cache_expire' => '200',
|
||||
);
|
||||
|
||||
$this->getStorage($options);
|
||||
|
||||
$this->assertSame('a=href', ini_get('url_rewriter.tags'));
|
||||
$this->assertSame('200', ini_get('session.cache_expire'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
@@ -200,9 +216,9 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
|
||||
$storage->setSaveHandler(null);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
|
||||
$storage->setSaveHandler(new SessionHandlerProxy(new NativeSessionHandler()));
|
||||
$storage->setSaveHandler(new SessionHandlerProxy(new NativeFileSessionHandler()));
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
|
||||
$storage->setSaveHandler(new NativeSessionHandler());
|
||||
$storage->setSaveHandler(new NativeFileSessionHandler());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
|
||||
$storage->setSaveHandler(new SessionHandlerProxy(new NullSessionHandler()));
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
|
||||
@@ -228,7 +244,7 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($storage->isStarted());
|
||||
|
||||
$key = $storage->getMetadataBag()->getStorageKey();
|
||||
$this->assertFalse(isset($_SESSION[$key]));
|
||||
$this->assertArrayNotHasKey($key, $_SESSION);
|
||||
$storage->start();
|
||||
}
|
||||
|
||||
@@ -243,4 +259,36 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($id, $storage->getId(), 'Same session ID after restarting');
|
||||
$this->assertSame(7, $storage->getBag('attributes')->get('lucky'), 'Data still available');
|
||||
}
|
||||
|
||||
public function testCanCreateNativeSessionStorageWhenSessionAlreadyStarted()
|
||||
{
|
||||
session_start();
|
||||
$this->getStorage();
|
||||
|
||||
// Assert no exception has been thrown by `getStorage()`
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testSetSessionOptionsOnceSessionStartedIsIgnored()
|
||||
{
|
||||
session_start();
|
||||
$this->getStorage(array(
|
||||
'name' => 'something-else',
|
||||
));
|
||||
|
||||
// Assert no exception has been thrown by `getStorage()`
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testGetBagsOnceSessionStartedIsIgnored()
|
||||
{
|
||||
session_start();
|
||||
$bag = new AttributeBag();
|
||||
$bag->setName('flashes');
|
||||
|
||||
$storage = $this->getStorage();
|
||||
$storage->registerBag($bag);
|
||||
|
||||
$this->assertEquals($storage->getBag('flashes'), $bag);
|
||||
}
|
||||
}
|
||||
|
@@ -11,8 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for PhpSessionStorage.
|
||||
@@ -24,7 +25,7 @@ use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class PhpBridgeSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
class PhpBridgeSessionStorageTest extends TestCase
|
||||
{
|
||||
private $savePath;
|
||||
|
||||
@@ -74,9 +75,9 @@ class PhpBridgeSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($storage->isStarted());
|
||||
|
||||
$key = $storage->getMetadataBag()->getStorageKey();
|
||||
$this->assertFalse(isset($_SESSION[$key]));
|
||||
$this->assertArrayNotHasKey($key, $_SESSION);
|
||||
$storage->start();
|
||||
$this->assertTrue(isset($_SESSION[$key]));
|
||||
$this->assertArrayHasKey($key, $_SESSION);
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
|
@@ -11,47 +11,16 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Proxy;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
|
||||
|
||||
// Note until PHPUnit_Mock_Objects 1.2 is released you cannot mock abstracts due to
|
||||
// https://github.com/sebastianbergmann/phpunit-mock-objects/issues/73
|
||||
class ConcreteProxy extends AbstractProxy
|
||||
{
|
||||
}
|
||||
|
||||
class ConcreteSessionHandlerInterfaceProxy extends AbstractProxy implements \SessionHandlerInterface
|
||||
{
|
||||
public function open($savePath, $sessionName)
|
||||
{
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
}
|
||||
|
||||
public function read($id)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($id, $data)
|
||||
{
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
}
|
||||
|
||||
public function gc($maxlifetime)
|
||||
{
|
||||
}
|
||||
}
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
|
||||
|
||||
/**
|
||||
* Test class for AbstractProxy.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class AbstractProxyTest extends \PHPUnit_Framework_TestCase
|
||||
class AbstractProxyTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var AbstractProxy
|
||||
@@ -60,7 +29,7 @@ class AbstractProxyTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->proxy = new ConcreteProxy();
|
||||
$this->proxy = $this->getMockForAbstractClass(AbstractProxy::class);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
@@ -76,7 +45,7 @@ class AbstractProxyTest extends \PHPUnit_Framework_TestCase
|
||||
public function testIsSessionHandlerInterface()
|
||||
{
|
||||
$this->assertFalse($this->proxy->isSessionHandlerInterface());
|
||||
$sh = new ConcreteSessionHandlerInterfaceProxy();
|
||||
$sh = new SessionHandlerProxy(new \SessionHandler());
|
||||
$this->assertTrue($sh->isSessionHandlerInterface());
|
||||
}
|
||||
|
||||
|
@@ -11,14 +11,17 @@
|
||||
|
||||
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 \PHPUnit_Framework_TestCase
|
||||
class NativeProxyTest extends TestCase
|
||||
{
|
||||
public function testIsWrapper()
|
||||
{
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Proxy;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
|
||||
|
||||
/**
|
||||
@@ -21,7 +22,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class SessionHandlerProxyTest extends \PHPUnit_Framework_TestCase
|
||||
class SessionHandlerProxyTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_Matcher
|
||||
@@ -35,7 +36,7 @@ class SessionHandlerProxyTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->mock = $this->getMock('SessionHandlerInterface');
|
||||
$this->mock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$this->proxy = new SessionHandlerProxy($this->mock);
|
||||
}
|
||||
|
||||
@@ -120,4 +121,37 @@ class SessionHandlerProxyTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
}
|
||||
|
@@ -11,10 +11,11 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class StreamedResponseTest extends \PHPUnit_Framework_TestCase
|
||||
class StreamedResponseTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
@@ -50,10 +51,12 @@ class StreamedResponseTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testPrepareWithHeadRequest()
|
||||
{
|
||||
$response = new StreamedResponse(function () { echo 'foo'; });
|
||||
$response = new StreamedResponse(function () { echo 'foo'; }, 200, array('Content-Length' => '123'));
|
||||
$request = Request::create('/', 'HEAD');
|
||||
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertSame('123', $response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
public function testPrepareWithCacheHeaders()
|
||||
@@ -109,4 +112,33 @@ class StreamedResponseTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testReturnThis()
|
||||
{
|
||||
$response = new StreamedResponse(function () {});
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
|
||||
|
||||
$response = new StreamedResponse(function () {});
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
31
vendor/symfony/http-foundation/Tests/schema/http-status-codes.rng
vendored
Normal file
31
vendor/symfony/http-foundation/Tests/schema/http-status-codes.rng
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version='1.0'?>
|
||||
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
|
||||
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
|
||||
ns="http://www.iana.org/assignments">
|
||||
|
||||
<include href="iana-registry.rng"/>
|
||||
|
||||
<start>
|
||||
<element name="registry">
|
||||
<ref name="registryMeta"/>
|
||||
<element name="registry">
|
||||
<ref name="registryMeta"/>
|
||||
<zeroOrMore>
|
||||
<element name="record">
|
||||
<optional>
|
||||
<attribute name="date"><ref name="genericDate"/></attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="updated"><ref name="genericDate"/></attribute>
|
||||
</optional>
|
||||
<element name="value"><ref name="genericRange"/></element>
|
||||
<element name="description"><text/></element>
|
||||
<ref name="references"/>
|
||||
</element>
|
||||
</zeroOrMore>
|
||||
</element>
|
||||
<ref name="people"/>
|
||||
</element>
|
||||
</start>
|
||||
|
||||
</grammar>
|
198
vendor/symfony/http-foundation/Tests/schema/iana-registry.rng
vendored
Normal file
198
vendor/symfony/http-foundation/Tests/schema/iana-registry.rng
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
<?xml version='1.0'?>
|
||||
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
|
||||
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
|
||||
ns="http://www.iana.org/assignments">
|
||||
|
||||
<define name="registryMeta">
|
||||
<interleave>
|
||||
<attribute name="id"><data type="ID"/></attribute>
|
||||
<optional><element name="title"><ref name="text_with_references"/></element></optional>
|
||||
<optional><element name="created"><ref name="genericDate"/></element></optional>
|
||||
<optional><element name="updated"><data type="date"/></element></optional>
|
||||
<optional><element name="registration_rule"><ref
|
||||
name="text_with_references"/></element></optional>
|
||||
<optional><element name="expert"><text/></element></optional>
|
||||
<optional><element name="description"><ref name="text_with_references"/></element></optional>
|
||||
<zeroOrMore><element name="note"><ref name="text_with_references"/></element></zeroOrMore>
|
||||
<ref name="references"/>
|
||||
<optional><element name="hide"><empty/></element></optional>
|
||||
<zeroOrMore><element name="category"><text/></element></zeroOrMore>
|
||||
<zeroOrMore><ref name="range"/></zeroOrMore>
|
||||
<optional><ref name="file"/></optional>
|
||||
</interleave>
|
||||
</define>
|
||||
|
||||
<define name="range">
|
||||
<element name="range">
|
||||
<interleave>
|
||||
<element name="value"><text/></element>
|
||||
<optional><element name="hex"><text/></element></optional>
|
||||
<element name="registration_rule"><ref name="text_with_references"/></element>
|
||||
<optional><element name="note"><ref name="text_with_references"/></element></optional>
|
||||
<optional><ref name="xref"/></optional>
|
||||
</interleave>
|
||||
</element>
|
||||
</define>
|
||||
|
||||
<define name="people">
|
||||
<element name="people">
|
||||
<zeroOrMore>
|
||||
<element name="person">
|
||||
<attribute name="id"><data type="ID"/></attribute>
|
||||
<optional><element name="name"><text/></element></optional>
|
||||
<optional><element name="org"><text/></element></optional>
|
||||
<zeroOrMore><element name="uri"><data type="anyURI"/></element></zeroOrMore>
|
||||
<optional><element name="updated"><ref name="genericDate"/></element></optional>
|
||||
</element>
|
||||
</zeroOrMore>
|
||||
</element>
|
||||
</define>
|
||||
|
||||
<define name="xref">
|
||||
<element name="xref">
|
||||
<optional>
|
||||
<attribute name="lastupdated"><ref name="genericDate"/></attribute>
|
||||
</optional>
|
||||
<choice>
|
||||
<group>
|
||||
<attribute name="type"><value>uri</value></attribute>
|
||||
<attribute name="data"><data type="anyURI"/></attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>rfc</value></attribute>
|
||||
<attribute name="data">
|
||||
<data type="string">
|
||||
<param name="pattern">(rfc|bcp|std)\d+</param>
|
||||
</data>
|
||||
</attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>rfc-errata</value></attribute>
|
||||
<attribute name="data"><data type="positiveInteger"/></attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>draft</value></attribute>
|
||||
<attribute name="data">
|
||||
<data type="string">
|
||||
<param name="pattern">(draft|RFC)(-[a-zA-Z0-9]+)+</param>
|
||||
</data>
|
||||
</attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>registry</value></attribute>
|
||||
<attribute name="data"><data type="NCName"/></attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>person</value></attribute>
|
||||
<attribute name="data"><data type="NCName"/></attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>text</value></attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>note</value></attribute>
|
||||
<attribute name="data"><data type="positiveInteger"/></attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>unicode</value></attribute>
|
||||
<attribute name="data">
|
||||
<data type="string">
|
||||
<param name="pattern">ucd\d+\.\d+\.\d+</param>
|
||||
</data>
|
||||
</attribute>
|
||||
</group>
|
||||
</choice>
|
||||
<text/>
|
||||
</element>
|
||||
</define>
|
||||
|
||||
<define name="references">
|
||||
<zeroOrMore>
|
||||
<ref name="xref"/>
|
||||
</zeroOrMore>
|
||||
</define>
|
||||
|
||||
<define name="text_with_references">
|
||||
<interleave>
|
||||
<zeroOrMore>
|
||||
<text/>
|
||||
<optional><ref name="xref"/></optional>
|
||||
</zeroOrMore>
|
||||
</interleave>
|
||||
</define>
|
||||
|
||||
<define name="richText">
|
||||
<zeroOrMore>
|
||||
<choice>
|
||||
<interleave>
|
||||
<ref name="text_with_references"/>
|
||||
<optional><element name="br"><empty/></element></optional>
|
||||
</interleave>
|
||||
<element name="paragraph">
|
||||
<interleave>
|
||||
<ref name="text_with_references"/>
|
||||
<optional><element name="br"><empty/></element></optional>
|
||||
</interleave>
|
||||
</element>
|
||||
<element name="artwork"><text/></element>
|
||||
</choice>
|
||||
</zeroOrMore>
|
||||
</define>
|
||||
|
||||
<define name="genericRange">
|
||||
<data type="string">
|
||||
<param name="pattern">(\d+|0x[\da-fA-F]+)(\s*-\s*(\d+|0x[\da-fA-F]+))?</param>
|
||||
</data>
|
||||
</define>
|
||||
|
||||
<define name="genericDate">
|
||||
<choice>
|
||||
<data type="date"/>
|
||||
<data type="gYearMonth"/>
|
||||
</choice>
|
||||
</define>
|
||||
|
||||
<define name="hex32">
|
||||
<data type="string">
|
||||
<param name="pattern">0x[0-9]{8}</param>
|
||||
</data>
|
||||
</define>
|
||||
|
||||
<define name="binary">
|
||||
<data type="string">
|
||||
<param name="pattern">[0-1]+</param>
|
||||
</data>
|
||||
</define>
|
||||
|
||||
<define name="footnotes">
|
||||
<zeroOrMore>
|
||||
<element name="footnote">
|
||||
<attribute name="anchor"><data type="positiveInteger"/></attribute>
|
||||
<interleave>
|
||||
<zeroOrMore>
|
||||
<text/>
|
||||
<optional><ref name="xref"/></optional>
|
||||
</zeroOrMore>
|
||||
</interleave>
|
||||
</element>
|
||||
</zeroOrMore>
|
||||
</define>
|
||||
|
||||
<define name="file">
|
||||
<element name="file">
|
||||
<attribute name="type">
|
||||
<choice>
|
||||
<value>legacy</value>
|
||||
<value>mib</value>
|
||||
<value>template</value>
|
||||
<value>json</value>
|
||||
</choice>
|
||||
</attribute>
|
||||
<optional>
|
||||
<attribute name="name"/>
|
||||
</optional>
|
||||
<data type="anyURI"/>
|
||||
</element>
|
||||
</define>
|
||||
|
||||
</grammar>
|
Reference in New Issue
Block a user