mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
N°2651 - Remove test directories from lib
This commit is contained in:
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Bundle;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle\ExtensionAbsentBundle;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
|
||||
|
||||
class BundleTest extends TestCase
|
||||
{
|
||||
public function testGetContainerExtension()
|
||||
{
|
||||
$bundle = new ExtensionPresentBundle();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\DependencyInjection\ExtensionPresentExtension',
|
||||
$bundle->getContainerExtension()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Auto-registration of the command "Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand" is deprecated since Symfony 3.4 and won't be supported in 4.0. Use PSR-4 based service discovery instead.
|
||||
*/
|
||||
public function testRegisterCommands()
|
||||
{
|
||||
$cmd = new FooCommand();
|
||||
$app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
|
||||
$app->expects($this->once())->method('add')->with($this->equalTo($cmd));
|
||||
|
||||
$bundle = new ExtensionPresentBundle();
|
||||
$bundle->registerCommands($app);
|
||||
|
||||
$bundle2 = new ExtensionAbsentBundle();
|
||||
|
||||
$this->assertNull($bundle2->registerCommands($app));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetContainerExtensionWithInvalidClass()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
$this->expectExceptionMessage('must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface');
|
||||
$bundle = new ExtensionNotValidBundle();
|
||||
$bundle->getContainerExtension();
|
||||
}
|
||||
|
||||
public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('console.command.symfony_component_httpkernel_tests_fixtures_extensionpresentbundle_command_foocommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
|
||||
|
||||
$application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
|
||||
// add() is never called when the found command classes are already registered as services
|
||||
$application->expects($this->never())->method('add');
|
||||
|
||||
$bundle = new ExtensionPresentBundle();
|
||||
$bundle->setContainer($container);
|
||||
$bundle->registerCommands($application);
|
||||
}
|
||||
|
||||
public function testBundleNameIsGuessedFromClass()
|
||||
{
|
||||
$bundle = new GuessedNameBundle();
|
||||
|
||||
$this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
|
||||
$this->assertSame('GuessedNameBundle', $bundle->getName());
|
||||
}
|
||||
|
||||
public function testBundleNameCanBeExplicitlyProvided()
|
||||
{
|
||||
$bundle = new NamedBundle();
|
||||
|
||||
$this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
|
||||
$this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
|
||||
$this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
|
||||
}
|
||||
}
|
||||
|
||||
class NamedBundle extends Bundle
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'ExplicitlyNamedBundle';
|
||||
}
|
||||
}
|
||||
|
||||
class GuessedNameBundle extends Bundle
|
||||
{
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\CacheClearer;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer;
|
||||
|
||||
class ChainCacheClearerTest extends TestCase
|
||||
{
|
||||
protected static $cacheDir;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$cacheDir = tempnam(sys_get_temp_dir(), 'sf2_cache_clearer_dir');
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
@unlink(self::$cacheDir);
|
||||
}
|
||||
|
||||
public function testInjectClearersInConstructor()
|
||||
{
|
||||
$clearer = $this->getMockClearer();
|
||||
$clearer
|
||||
->expects($this->once())
|
||||
->method('clear');
|
||||
|
||||
$chainClearer = new ChainCacheClearer([$clearer]);
|
||||
$chainClearer->clear(self::$cacheDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testInjectClearerUsingAdd()
|
||||
{
|
||||
$clearer = $this->getMockClearer();
|
||||
$clearer
|
||||
->expects($this->once())
|
||||
->method('clear');
|
||||
|
||||
$chainClearer = new ChainCacheClearer();
|
||||
$chainClearer->add($clearer);
|
||||
$chainClearer->clear(self::$cacheDir);
|
||||
}
|
||||
|
||||
protected function getMockClearer()
|
||||
{
|
||||
return $this->getMockBuilder('Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface')->getMock();
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\CacheClearer;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
|
||||
|
||||
class Psr6CacheClearerTest extends TestCase
|
||||
{
|
||||
public function testClearPoolsInjectedInConstructor()
|
||||
{
|
||||
$pool = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
|
||||
$pool
|
||||
->expects($this->once())
|
||||
->method('clear');
|
||||
|
||||
(new Psr6CacheClearer(['pool' => $pool]))->clear('');
|
||||
}
|
||||
|
||||
public function testClearPool()
|
||||
{
|
||||
$pool = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
|
||||
$pool
|
||||
->expects($this->once())
|
||||
->method('clear');
|
||||
|
||||
(new Psr6CacheClearer(['pool' => $pool]))->clearPool('pool');
|
||||
}
|
||||
|
||||
public function testClearPoolThrowsExceptionOnUnreferencedPool()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Cache pool not found: unknown');
|
||||
(new Psr6CacheClearer())->clearPool('unknown');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer::addPool() method is deprecated since Symfony 3.3 and will be removed in 4.0. Pass an array of pools indexed by name to the constructor instead.
|
||||
*/
|
||||
public function testClearPoolsInjectedByAdder()
|
||||
{
|
||||
$pool1 = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
|
||||
$pool1
|
||||
->expects($this->once())
|
||||
->method('clear');
|
||||
|
||||
$pool2 = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
|
||||
$pool2
|
||||
->expects($this->once())
|
||||
->method('clear');
|
||||
|
||||
$clearer = new Psr6CacheClearer(['pool1' => $pool1]);
|
||||
$clearer->addPool($pool2);
|
||||
$clearer->clear('');
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\CacheWarmer;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate;
|
||||
|
||||
class CacheWarmerAggregateTest extends TestCase
|
||||
{
|
||||
protected static $cacheDir;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$cacheDir = tempnam(sys_get_temp_dir(), 'sf2_cache_warmer_dir');
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
@unlink(self::$cacheDir);
|
||||
}
|
||||
|
||||
public function testInjectWarmersUsingConstructor()
|
||||
{
|
||||
$warmer = $this->getCacheWarmerMock();
|
||||
$warmer
|
||||
->expects($this->once())
|
||||
->method('warmUp');
|
||||
$aggregate = new CacheWarmerAggregate([$warmer]);
|
||||
$aggregate->warmUp(self::$cacheDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testInjectWarmersUsingAdd()
|
||||
{
|
||||
$warmer = $this->getCacheWarmerMock();
|
||||
$warmer
|
||||
->expects($this->once())
|
||||
->method('warmUp');
|
||||
$aggregate = new CacheWarmerAggregate();
|
||||
$aggregate->add($warmer);
|
||||
$aggregate->warmUp(self::$cacheDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testInjectWarmersUsingSetWarmers()
|
||||
{
|
||||
$warmer = $this->getCacheWarmerMock();
|
||||
$warmer
|
||||
->expects($this->once())
|
||||
->method('warmUp');
|
||||
$aggregate = new CacheWarmerAggregate();
|
||||
$aggregate->setWarmers([$warmer]);
|
||||
$aggregate->warmUp(self::$cacheDir);
|
||||
}
|
||||
|
||||
public function testWarmupDoesCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsEnabled()
|
||||
{
|
||||
$warmer = $this->getCacheWarmerMock();
|
||||
$warmer
|
||||
->expects($this->never())
|
||||
->method('isOptional');
|
||||
$warmer
|
||||
->expects($this->once())
|
||||
->method('warmUp');
|
||||
|
||||
$aggregate = new CacheWarmerAggregate([$warmer]);
|
||||
$aggregate->enableOptionalWarmers();
|
||||
$aggregate->warmUp(self::$cacheDir);
|
||||
}
|
||||
|
||||
public function testWarmupDoesNotCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsNotEnabled()
|
||||
{
|
||||
$warmer = $this->getCacheWarmerMock();
|
||||
$warmer
|
||||
->expects($this->once())
|
||||
->method('isOptional')
|
||||
->willReturn(true);
|
||||
$warmer
|
||||
->expects($this->never())
|
||||
->method('warmUp');
|
||||
|
||||
$aggregate = new CacheWarmerAggregate([$warmer]);
|
||||
$aggregate->warmUp(self::$cacheDir);
|
||||
}
|
||||
|
||||
protected function getCacheWarmerMock()
|
||||
{
|
||||
$warmer = $this->getMockBuilder('Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
return $warmer;
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\CacheWarmer;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
|
||||
|
||||
class CacheWarmerTest extends TestCase
|
||||
{
|
||||
protected static $cacheFile;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$cacheFile = tempnam(sys_get_temp_dir(), 'sf2_cache_warmer_dir');
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
@unlink(self::$cacheFile);
|
||||
}
|
||||
|
||||
public function testWriteCacheFileCreatesTheFile()
|
||||
{
|
||||
$warmer = new TestCacheWarmer(self::$cacheFile);
|
||||
$warmer->warmUp(\dirname(self::$cacheFile));
|
||||
|
||||
$this->assertFileExists(self::$cacheFile);
|
||||
}
|
||||
|
||||
public function testWriteNonWritableCacheFileThrowsARuntimeException()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$nonWritableFile = '/this/file/is/very/probably/not/writable';
|
||||
$warmer = new TestCacheWarmer($nonWritableFile);
|
||||
$warmer->warmUp(\dirname($nonWritableFile));
|
||||
}
|
||||
}
|
||||
|
||||
class TestCacheWarmer extends CacheWarmer
|
||||
{
|
||||
protected $file;
|
||||
|
||||
public function __construct($file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
public function warmUp($cacheDir)
|
||||
{
|
||||
$this->writeCacheFile($this->file, 'content');
|
||||
}
|
||||
|
||||
public function isOptional()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Symfony\Component\HttpKernel\Client;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\TestClient;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class ClientTest extends TestCase
|
||||
{
|
||||
public function testDoRequest()
|
||||
{
|
||||
$client = new Client(new TestHttpKernel());
|
||||
|
||||
$client->request('GET', '/');
|
||||
$this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
|
||||
$this->assertInstanceOf('Symfony\Component\BrowserKit\Request', $client->getInternalRequest());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $client->getRequest());
|
||||
$this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getInternalResponse());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $client->getResponse());
|
||||
|
||||
$client->request('GET', 'http://www.example.com/');
|
||||
$this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
|
||||
$this->assertEquals('www.example.com', $client->getRequest()->getHost(), '->doRequest() uses the request handler to make the request');
|
||||
|
||||
$client->request('GET', 'http://www.example.com/?parameter=http://example.com');
|
||||
$this->assertEquals('http://www.example.com/?parameter='.urlencode('http://example.com'), $client->getRequest()->getUri(), '->doRequest() uses the request handler to make the request');
|
||||
}
|
||||
|
||||
public function testGetScript()
|
||||
{
|
||||
$client = new TestClient(new TestHttpKernel());
|
||||
$client->insulate();
|
||||
$client->request('GET', '/');
|
||||
|
||||
$this->assertEquals('Request: /', $client->getResponse()->getContent(), '->getScript() returns a script that uses the request handler to make the request');
|
||||
}
|
||||
|
||||
public function testFilterResponseConvertsCookies()
|
||||
{
|
||||
$client = new Client(new TestHttpKernel());
|
||||
|
||||
$r = new \ReflectionObject($client);
|
||||
$m = $r->getMethod('filterResponse');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$response = new Response();
|
||||
$response->headers->setCookie($cookie1 = new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
|
||||
$domResponse = $m->invoke($client, $response);
|
||||
$this->assertSame((string) $cookie1, $domResponse->getHeader('Set-Cookie'));
|
||||
|
||||
$response = new Response();
|
||||
$response->headers->setCookie($cookie1 = new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
|
||||
$response->headers->setCookie($cookie2 = new Cookie('foo1', 'bar1', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
|
||||
$domResponse = $m->invoke($client, $response);
|
||||
$this->assertSame((string) $cookie1, $domResponse->getHeader('Set-Cookie'));
|
||||
$this->assertSame([(string) $cookie1, (string) $cookie2], $domResponse->getHeader('Set-Cookie', false));
|
||||
}
|
||||
|
||||
public function testFilterResponseSupportsStreamedResponses()
|
||||
{
|
||||
$client = new Client(new TestHttpKernel());
|
||||
|
||||
$r = new \ReflectionObject($client);
|
||||
$m = $r->getMethod('filterResponse');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$response = new StreamedResponse(function () {
|
||||
echo 'foo';
|
||||
});
|
||||
|
||||
$domResponse = $m->invoke($client, $response);
|
||||
$this->assertEquals('foo', $domResponse->getContent());
|
||||
}
|
||||
|
||||
public function testUploadedFile()
|
||||
{
|
||||
$source = tempnam(sys_get_temp_dir(), 'source');
|
||||
file_put_contents($source, '1');
|
||||
$target = sys_get_temp_dir().'/sf.moved.file';
|
||||
@unlink($target);
|
||||
|
||||
$kernel = new TestHttpKernel();
|
||||
$client = new Client($kernel);
|
||||
|
||||
$files = [
|
||||
['tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => 1, 'error' => UPLOAD_ERR_OK],
|
||||
new UploadedFile($source, 'original', 'mime/original', 1, UPLOAD_ERR_OK, true),
|
||||
];
|
||||
|
||||
$file = null;
|
||||
foreach ($files as $file) {
|
||||
$client->request('POST', '/', [], ['foo' => $file]);
|
||||
|
||||
$files = $client->getRequest()->files->all();
|
||||
|
||||
$this->assertCount(1, $files);
|
||||
|
||||
$file = $files['foo'];
|
||||
|
||||
$this->assertEquals('original', $file->getClientOriginalName());
|
||||
$this->assertEquals('mime/original', $file->getClientMimeType());
|
||||
$this->assertSame(1, $file->getClientSize());
|
||||
$this->assertTrue($file->isValid());
|
||||
}
|
||||
|
||||
$file->move(\dirname($target), basename($target));
|
||||
|
||||
$this->assertFileExists($target);
|
||||
unlink($target);
|
||||
}
|
||||
|
||||
public function testUploadedFileWhenNoFileSelected()
|
||||
{
|
||||
$kernel = new TestHttpKernel();
|
||||
$client = new Client($kernel);
|
||||
|
||||
$file = ['tmp_name' => '', 'name' => '', 'type' => '', 'size' => 0, 'error' => UPLOAD_ERR_NO_FILE];
|
||||
|
||||
$client->request('POST', '/', [], ['foo' => $file]);
|
||||
|
||||
$files = $client->getRequest()->files->all();
|
||||
|
||||
$this->assertCount(1, $files);
|
||||
$this->assertNull($files['foo']);
|
||||
}
|
||||
|
||||
public function testUploadedFileWhenSizeExceedsUploadMaxFileSize()
|
||||
{
|
||||
$source = tempnam(sys_get_temp_dir(), 'source');
|
||||
|
||||
$kernel = new TestHttpKernel();
|
||||
$client = new Client($kernel);
|
||||
|
||||
$file = $this
|
||||
->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
|
||||
->setConstructorArgs([$source, 'original', 'mime/original', 123, UPLOAD_ERR_OK, true])
|
||||
->setMethods(['getSize'])
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$file->expects($this->once())
|
||||
->method('getSize')
|
||||
->willReturn(INF)
|
||||
;
|
||||
|
||||
$client->request('POST', '/', [], [$file]);
|
||||
|
||||
$files = $client->getRequest()->files->all();
|
||||
|
||||
$this->assertCount(1, $files);
|
||||
|
||||
$file = $files[0];
|
||||
|
||||
$this->assertFalse($file->isValid());
|
||||
$this->assertEquals(UPLOAD_ERR_INI_SIZE, $file->getError());
|
||||
$this->assertEquals('mime/original', $file->getClientMimeType());
|
||||
$this->assertEquals('original', $file->getClientOriginalName());
|
||||
$this->assertEquals(0, $file->getClientSize());
|
||||
|
||||
unlink($source);
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Config;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class EnvParametersResourceTest extends TestCase
|
||||
{
|
||||
protected $prefix = '__DUMMY_';
|
||||
protected $initialEnv;
|
||||
protected $resource;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->initialEnv = [
|
||||
$this->prefix.'1' => 'foo',
|
||||
$this->prefix.'2' => 'bar',
|
||||
];
|
||||
|
||||
foreach ($this->initialEnv as $key => $value) {
|
||||
$_SERVER[$key] = $value;
|
||||
}
|
||||
|
||||
$this->resource = new EnvParametersResource($this->prefix);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
foreach ($_SERVER as $key => $value) {
|
||||
if (0 === strpos($key, $this->prefix)) {
|
||||
unset($_SERVER[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetResource()
|
||||
{
|
||||
$this->assertSame(
|
||||
['prefix' => $this->prefix, 'variables' => $this->initialEnv],
|
||||
$this->resource->getResource(),
|
||||
'->getResource() returns the resource'
|
||||
);
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$this->assertSame(
|
||||
serialize(['prefix' => $this->prefix, 'variables' => $this->initialEnv]),
|
||||
(string) $this->resource
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsFreshNotChanged()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->resource->isFresh(time()),
|
||||
'->isFresh() returns true if the variables have not changed'
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsFreshValueChanged()
|
||||
{
|
||||
reset($this->initialEnv);
|
||||
$_SERVER[key($this->initialEnv)] = 'baz';
|
||||
|
||||
$this->assertFalse(
|
||||
$this->resource->isFresh(time()),
|
||||
'->isFresh() returns false if a variable has been changed'
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsFreshValueRemoved()
|
||||
{
|
||||
reset($this->initialEnv);
|
||||
unset($_SERVER[key($this->initialEnv)]);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->resource->isFresh(time()),
|
||||
'->isFresh() returns false if a variable has been removed'
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsFreshValueAdded()
|
||||
{
|
||||
$_SERVER[$this->prefix.'3'] = 'foo';
|
||||
|
||||
$this->assertFalse(
|
||||
$this->resource->isFresh(time()),
|
||||
'->isFresh() returns false if a variable has been added'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSerializeUnserialize()
|
||||
{
|
||||
$this->assertEquals($this->resource, unserialize(serialize($this->resource)));
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Config;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\Config\FileLocator;
|
||||
|
||||
class FileLocatorTest extends TestCase
|
||||
{
|
||||
public function testLocate()
|
||||
{
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
|
||||
$kernel
|
||||
->expects($this->atLeastOnce())
|
||||
->method('locateResource')
|
||||
->with('@BundleName/some/path', null, true)
|
||||
->willReturn('/bundle-name/some/path');
|
||||
$locator = new FileLocator($kernel);
|
||||
$this->assertEquals('/bundle-name/some/path', $locator->locate('@BundleName/some/path'));
|
||||
|
||||
$kernel
|
||||
->expects($this->never())
|
||||
->method('locateResource');
|
||||
$this->expectException('LogicException');
|
||||
$locator->locate('/some/path');
|
||||
}
|
||||
|
||||
public function testLocateWithGlobalResourcePath()
|
||||
{
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
|
||||
$kernel
|
||||
->expects($this->atLeastOnce())
|
||||
->method('locateResource')
|
||||
->with('@BundleName/some/path', '/global/resource/path', false);
|
||||
|
||||
$locator = new FileLocator($kernel, '/global/resource/path');
|
||||
$locator->locate('@BundleName/some/path', null, false);
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\ServiceValueResolver;
|
||||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
|
||||
|
||||
class ServiceValueResolverTest extends TestCase
|
||||
{
|
||||
public function testDoNotSupportWhenControllerDoNotExists()
|
||||
{
|
||||
$resolver = new ServiceValueResolver(new ServiceLocator([]));
|
||||
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
|
||||
$request = $this->requestWithAttributes(['_controller' => 'my_controller']);
|
||||
|
||||
$this->assertFalse($resolver->supports($request, $argument));
|
||||
}
|
||||
|
||||
public function testExistingController()
|
||||
{
|
||||
$resolver = new ServiceValueResolver(new ServiceLocator([
|
||||
'App\\Controller\\Mine::method' => function () {
|
||||
return new ServiceLocator([
|
||||
'dummy' => function () {
|
||||
return new DummyService();
|
||||
},
|
||||
]);
|
||||
},
|
||||
]));
|
||||
|
||||
$request = $this->requestWithAttributes(['_controller' => 'App\\Controller\\Mine::method']);
|
||||
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
|
||||
|
||||
$this->assertTrue($resolver->supports($request, $argument));
|
||||
$this->assertYieldEquals([new DummyService()], $resolver->resolve($request, $argument));
|
||||
}
|
||||
|
||||
public function testExistingControllerWithATrailingBackSlash()
|
||||
{
|
||||
$resolver = new ServiceValueResolver(new ServiceLocator([
|
||||
'App\\Controller\\Mine::method' => function () {
|
||||
return new ServiceLocator([
|
||||
'dummy' => function () {
|
||||
return new DummyService();
|
||||
},
|
||||
]);
|
||||
},
|
||||
]));
|
||||
|
||||
$request = $this->requestWithAttributes(['_controller' => '\\App\\Controller\\Mine::method']);
|
||||
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
|
||||
|
||||
$this->assertTrue($resolver->supports($request, $argument));
|
||||
$this->assertYieldEquals([new DummyService()], $resolver->resolve($request, $argument));
|
||||
}
|
||||
|
||||
public function testExistingControllerWithMethodNameStartUppercase()
|
||||
{
|
||||
$resolver = new ServiceValueResolver(new ServiceLocator([
|
||||
'App\\Controller\\Mine::method' => function () {
|
||||
return new ServiceLocator([
|
||||
'dummy' => function () {
|
||||
return new DummyService();
|
||||
},
|
||||
]);
|
||||
},
|
||||
]));
|
||||
$request = $this->requestWithAttributes(['_controller' => 'App\\Controller\\Mine::Method']);
|
||||
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
|
||||
|
||||
$this->assertTrue($resolver->supports($request, $argument));
|
||||
$this->assertYieldEquals([new DummyService()], $resolver->resolve($request, $argument));
|
||||
}
|
||||
|
||||
public function testControllerNameIsAnArray()
|
||||
{
|
||||
$resolver = new ServiceValueResolver(new ServiceLocator([
|
||||
'App\\Controller\\Mine::method' => function () {
|
||||
return new ServiceLocator([
|
||||
'dummy' => function () {
|
||||
return new DummyService();
|
||||
},
|
||||
]);
|
||||
},
|
||||
]));
|
||||
|
||||
$request = $this->requestWithAttributes(['_controller' => ['App\\Controller\\Mine', 'method']]);
|
||||
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
|
||||
|
||||
$this->assertTrue($resolver->supports($request, $argument));
|
||||
$this->assertYieldEquals([new DummyService()], $resolver->resolve($request, $argument));
|
||||
}
|
||||
|
||||
private function requestWithAttributes(array $attributes)
|
||||
{
|
||||
$request = Request::create('/');
|
||||
|
||||
foreach ($attributes as $name => $value) {
|
||||
$request->attributes->set($name, $value);
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
private function assertYieldEquals(array $expected, \Generator $generator)
|
||||
{
|
||||
$args = [];
|
||||
foreach ($generator as $arg) {
|
||||
$args[] = $arg;
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, $args);
|
||||
}
|
||||
}
|
||||
|
||||
class DummyService
|
||||
{
|
||||
}
|
||||
@@ -1,341 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Controller;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestAttributeValueResolver;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
|
||||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\ExtendingRequest;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\ExtendingSession;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\NullableController;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\VariadicController;
|
||||
|
||||
class ArgumentResolverTest extends TestCase
|
||||
{
|
||||
/** @var ArgumentResolver */
|
||||
private static $resolver;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$factory = new ArgumentMetadataFactory();
|
||||
|
||||
self::$resolver = new ArgumentResolver($factory);
|
||||
}
|
||||
|
||||
public function testDefaultState()
|
||||
{
|
||||
$this->assertEquals(self::$resolver, new ArgumentResolver());
|
||||
$this->assertNotEquals(self::$resolver, new ArgumentResolver(null, [new RequestAttributeValueResolver()]));
|
||||
}
|
||||
|
||||
public function testGetArguments()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = [new self(), 'controllerWithFoo'];
|
||||
|
||||
$this->assertEquals(['foo'], self::$resolver->getArguments($request, $controller), '->getArguments() returns an array of arguments for the controller method');
|
||||
}
|
||||
|
||||
public function testGetArgumentsReturnsEmptyArrayWhenNoArguments()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$controller = [new self(), 'controllerWithoutArguments'];
|
||||
|
||||
$this->assertEquals([], self::$resolver->getArguments($request, $controller), '->getArguments() returns an empty array if the method takes no arguments');
|
||||
}
|
||||
|
||||
public function testGetArgumentsUsesDefaultValue()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = [new self(), 'controllerWithFooAndDefaultBar'];
|
||||
|
||||
$this->assertEquals(['foo', null], self::$resolver->getArguments($request, $controller), '->getArguments() uses default values if present');
|
||||
}
|
||||
|
||||
public function testGetArgumentsOverrideDefaultValueByRequestAttribute()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('bar', 'bar');
|
||||
$controller = [new self(), 'controllerWithFooAndDefaultBar'];
|
||||
|
||||
$this->assertEquals(['foo', 'bar'], self::$resolver->getArguments($request, $controller), '->getArguments() overrides default values if provided in the request attributes');
|
||||
}
|
||||
|
||||
public function testGetArgumentsFromClosure()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = function ($foo) {};
|
||||
|
||||
$this->assertEquals(['foo'], self::$resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
public function testGetArgumentsUsesDefaultValueFromClosure()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = function ($foo, $bar = 'bar') {};
|
||||
|
||||
$this->assertEquals(['foo', 'bar'], self::$resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
public function testGetArgumentsFromInvokableObject()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = new self();
|
||||
|
||||
$this->assertEquals(['foo', null], self::$resolver->getArguments($request, $controller));
|
||||
|
||||
// Test default bar overridden by request attribute
|
||||
$request->attributes->set('bar', 'bar');
|
||||
|
||||
$this->assertEquals(['foo', 'bar'], self::$resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
public function testGetArgumentsFromFunctionName()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('foobar', 'foobar');
|
||||
$controller = __NAMESPACE__.'\controller_function';
|
||||
|
||||
$this->assertEquals(['foo', 'foobar'], self::$resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
public function testGetArgumentsFailsOnUnresolvedValue()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('foobar', 'foobar');
|
||||
$controller = [new self(), 'controllerWithFooBarFoobar'];
|
||||
|
||||
try {
|
||||
self::$resolver->getArguments($request, $controller);
|
||||
$this->fail('->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetArgumentsInjectsRequest()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$controller = [new self(), 'controllerWithRequest'];
|
||||
|
||||
$this->assertEquals([$request], self::$resolver->getArguments($request, $controller), '->getArguments() injects the request');
|
||||
}
|
||||
|
||||
public function testGetArgumentsInjectsExtendingRequest()
|
||||
{
|
||||
$request = ExtendingRequest::create('/');
|
||||
$controller = [new self(), 'controllerWithExtendingRequest'];
|
||||
|
||||
$this->assertEquals([$request], self::$resolver->getArguments($request, $controller), '->getArguments() injects the request when extended');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
*/
|
||||
public function testGetVariadicArguments()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('bar', ['foo', 'bar']);
|
||||
$controller = [new VariadicController(), 'action'];
|
||||
|
||||
$this->assertEquals(['foo', 'foo', 'bar'], self::$resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
*/
|
||||
public function testGetVariadicArgumentsWithoutArrayInRequest()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('bar', 'foo');
|
||||
$controller = [new VariadicController(), 'action'];
|
||||
|
||||
self::$resolver->getArguments($request, $controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
*/
|
||||
public function testGetArgumentWithoutArray()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$factory = new ArgumentMetadataFactory();
|
||||
$valueResolver = $this->getMockBuilder(ArgumentValueResolverInterface::class)->getMock();
|
||||
$resolver = new ArgumentResolver($factory, [$valueResolver]);
|
||||
|
||||
$valueResolver->expects($this->any())->method('supports')->willReturn(true);
|
||||
$valueResolver->expects($this->any())->method('resolve')->willReturn('foo');
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('bar', 'foo');
|
||||
$controller = [$this, 'controllerWithFooAndDefaultBar'];
|
||||
$resolver->getArguments($request, $controller);
|
||||
}
|
||||
|
||||
public function testIfExceptionIsThrownWhenMissingAnArgument()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$request = Request::create('/');
|
||||
$controller = [$this, 'controllerWithFoo'];
|
||||
|
||||
self::$resolver->getArguments($request, $controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.1
|
||||
*/
|
||||
public function testGetNullableArguments()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('bar', new \stdClass());
|
||||
$request->attributes->set('mandatory', 'mandatory');
|
||||
$controller = [new NullableController(), 'action'];
|
||||
|
||||
$this->assertEquals(['foo', new \stdClass(), 'value', 'mandatory'], self::$resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.1
|
||||
*/
|
||||
public function testGetNullableArgumentsWithDefaults()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('mandatory', 'mandatory');
|
||||
$controller = [new NullableController(), 'action'];
|
||||
|
||||
$this->assertEquals([null, null, 'value', 'mandatory'], self::$resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
public function testGetSessionArguments()
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/');
|
||||
$request->setSession($session);
|
||||
$controller = [$this, 'controllerWithSession'];
|
||||
|
||||
$this->assertEquals([$session], self::$resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
public function testGetSessionArgumentsWithExtendedSession()
|
||||
{
|
||||
$session = new ExtendingSession(new MockArraySessionStorage());
|
||||
$request = Request::create('/');
|
||||
$request->setSession($session);
|
||||
$controller = [$this, 'controllerWithExtendingSession'];
|
||||
|
||||
$this->assertEquals([$session], self::$resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
public function testGetSessionArgumentsWithInterface()
|
||||
{
|
||||
$session = $this->getMockBuilder(SessionInterface::class)->getMock();
|
||||
$request = Request::create('/');
|
||||
$request->setSession($session);
|
||||
$controller = [$this, 'controllerWithSessionInterface'];
|
||||
|
||||
$this->assertEquals([$session], self::$resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
public function testGetSessionMissMatchWithInterface()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$session = $this->getMockBuilder(SessionInterface::class)->getMock();
|
||||
$request = Request::create('/');
|
||||
$request->setSession($session);
|
||||
$controller = [$this, 'controllerWithExtendingSession'];
|
||||
|
||||
self::$resolver->getArguments($request, $controller);
|
||||
}
|
||||
|
||||
public function testGetSessionMissMatchWithImplementation()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = Request::create('/');
|
||||
$request->setSession($session);
|
||||
$controller = [$this, 'controllerWithExtendingSession'];
|
||||
|
||||
self::$resolver->getArguments($request, $controller);
|
||||
}
|
||||
|
||||
public function testGetSessionMissMatchOnNull()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$request = Request::create('/');
|
||||
$controller = [$this, 'controllerWithExtendingSession'];
|
||||
|
||||
self::$resolver->getArguments($request, $controller);
|
||||
}
|
||||
|
||||
public function __invoke($foo, $bar = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function controllerWithFoo($foo)
|
||||
{
|
||||
}
|
||||
|
||||
public function controllerWithoutArguments()
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerWithFooAndDefaultBar($foo, $bar = null)
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerWithFooBarFoobar($foo, $bar, $foobar)
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerWithRequest(Request $request)
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerWithExtendingRequest(ExtendingRequest $request)
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerWithSession(Session $session)
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerWithSessionInterface(SessionInterface $session)
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerWithExtendingSession(ExtendingSession $session)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
function controller_function($foo, $foobar)
|
||||
{
|
||||
}
|
||||
@@ -1,298 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Controller;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Debug\ErrorHandler;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
|
||||
|
||||
class ContainerControllerResolverTest extends ControllerResolverTest
|
||||
{
|
||||
public function testGetControllerService()
|
||||
{
|
||||
$container = $this->createMockContainer();
|
||||
$container->expects($this->once())
|
||||
->method('has')
|
||||
->with('foo')
|
||||
->willReturn(true);
|
||||
$container->expects($this->once())
|
||||
->method('get')
|
||||
->with('foo')
|
||||
->willReturn($this)
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'foo:controllerMethod1');
|
||||
|
||||
$controller = $resolver->getController($request);
|
||||
|
||||
$this->assertInstanceOf(\get_class($this), $controller[0]);
|
||||
$this->assertSame('controllerMethod1', $controller[1]);
|
||||
}
|
||||
|
||||
public function testGetControllerInvokableService()
|
||||
{
|
||||
$invokableController = new InvokableController('bar');
|
||||
|
||||
$container = $this->createMockContainer();
|
||||
$container->expects($this->once())
|
||||
->method('has')
|
||||
->with('foo')
|
||||
->willReturn(true)
|
||||
;
|
||||
$container->expects($this->once())
|
||||
->method('get')
|
||||
->with('foo')
|
||||
->willReturn($invokableController)
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'foo');
|
||||
|
||||
$controller = $resolver->getController($request);
|
||||
|
||||
$this->assertEquals($invokableController, $controller);
|
||||
}
|
||||
|
||||
public function testGetControllerInvokableServiceWithClassNameAsName()
|
||||
{
|
||||
$invokableController = new InvokableController('bar');
|
||||
$className = __NAMESPACE__.'\InvokableController';
|
||||
|
||||
$container = $this->createMockContainer();
|
||||
$container->expects($this->once())
|
||||
->method('has')
|
||||
->with($className)
|
||||
->willReturn(true)
|
||||
;
|
||||
$container->expects($this->once())
|
||||
->method('get')
|
||||
->with($className)
|
||||
->willReturn($invokableController)
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', $className);
|
||||
|
||||
$controller = $resolver->getController($request);
|
||||
|
||||
$this->assertEquals($invokableController, $controller);
|
||||
}
|
||||
|
||||
public function testNonInstantiableController()
|
||||
{
|
||||
$container = $this->createMockContainer();
|
||||
$container->expects($this->once())
|
||||
->method('has')
|
||||
->with(NonInstantiableController::class)
|
||||
->willReturn(false)
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', [NonInstantiableController::class, 'action']);
|
||||
|
||||
$controller = $resolver->getController($request);
|
||||
|
||||
$this->assertSame([NonInstantiableController::class, 'action'], $controller);
|
||||
}
|
||||
|
||||
public function testNonConstructController()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
$this->expectExceptionMessage('Controller "Symfony\Component\HttpKernel\Tests\Controller\ImpossibleConstructController" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?');
|
||||
$container = $this->getMockBuilder(Container::class)->getMock();
|
||||
$container->expects($this->at(0))
|
||||
->method('has')
|
||||
->with(ImpossibleConstructController::class)
|
||||
->willReturn(true)
|
||||
;
|
||||
|
||||
$container->expects($this->at(1))
|
||||
->method('has')
|
||||
->with(ImpossibleConstructController::class)
|
||||
->willReturn(false)
|
||||
;
|
||||
|
||||
$container->expects($this->atLeastOnce())
|
||||
->method('getRemovedIds')
|
||||
->with()
|
||||
->willReturn([ImpossibleConstructController::class => true])
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', [ImpossibleConstructController::class, 'action']);
|
||||
|
||||
if (\PHP_VERSION_ID < 70100) {
|
||||
ErrorHandler::register();
|
||||
try {
|
||||
$resolver->getController($request);
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
restore_exception_handler();
|
||||
}
|
||||
} else {
|
||||
$resolver->getController($request);
|
||||
}
|
||||
}
|
||||
|
||||
public function testNonInstantiableControllerWithCorrespondingService()
|
||||
{
|
||||
$service = new \stdClass();
|
||||
|
||||
$container = $this->createMockContainer();
|
||||
$container->expects($this->atLeastOnce())
|
||||
->method('has')
|
||||
->with(NonInstantiableController::class)
|
||||
->willReturn(true)
|
||||
;
|
||||
$container->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
->with(NonInstantiableController::class)
|
||||
->willReturn($service)
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', [NonInstantiableController::class, 'action']);
|
||||
|
||||
$controller = $resolver->getController($request);
|
||||
|
||||
$this->assertSame([$service, 'action'], $controller);
|
||||
}
|
||||
|
||||
public function testExceptionWhenUsingRemovedControllerService()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
$this->expectExceptionMessage('Controller "app.my_controller" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?');
|
||||
$container = $this->getMockBuilder(Container::class)->getMock();
|
||||
$container->expects($this->at(0))
|
||||
->method('has')
|
||||
->with('app.my_controller')
|
||||
->willReturn(false)
|
||||
;
|
||||
|
||||
$container->expects($this->atLeastOnce())
|
||||
->method('getRemovedIds')
|
||||
->with()
|
||||
->willReturn(['app.my_controller' => true])
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'app.my_controller');
|
||||
$resolver->getController($request);
|
||||
}
|
||||
|
||||
public function testExceptionWhenUsingControllerWithoutAnInvokeMethod()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
$this->expectExceptionMessage('Controller "app.my_controller" cannot be called without a method name. Did you forget an "__invoke" method?');
|
||||
$container = $this->getMockBuilder(Container::class)->getMock();
|
||||
$container->expects($this->once())
|
||||
->method('has')
|
||||
->with('app.my_controller')
|
||||
->willReturn(true)
|
||||
;
|
||||
$container->expects($this->once())
|
||||
->method('get')
|
||||
->with('app.my_controller')
|
||||
->willReturn(new ImpossibleConstructController('toto', 'controller'))
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'app.my_controller');
|
||||
$resolver->getController($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getUndefinedControllers
|
||||
*/
|
||||
public function testGetControllerOnNonUndefinedFunction($controller, $exceptionName = null, $exceptionMessage = null)
|
||||
{
|
||||
// All this logic needs to be duplicated, since calling parent::testGetControllerOnNonUndefinedFunction will override the expected excetion and not use the regex
|
||||
$resolver = $this->createControllerResolver();
|
||||
$this->expectException($exceptionName);
|
||||
$this->expectExceptionMessageRegExp($exceptionMessage);
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', $controller);
|
||||
$resolver->getController($request);
|
||||
}
|
||||
|
||||
public function getUndefinedControllers()
|
||||
{
|
||||
return [
|
||||
['foo', \LogicException::class, '/Controller not found: service "foo" does not exist\./'],
|
||||
['oof::bar', \InvalidArgumentException::class, '/Class "oof" does not exist\./'],
|
||||
['stdClass', \LogicException::class, '/Controller not found: service "stdClass" does not exist\./'],
|
||||
[
|
||||
'Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest::bar',
|
||||
\InvalidArgumentException::class,
|
||||
'/.?[cC]ontroller(.*?) for URI "\/" is not callable\.( Expected method(.*) Available methods)?/',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function createControllerResolver(LoggerInterface $logger = null, ContainerInterface $container = null)
|
||||
{
|
||||
if (!$container) {
|
||||
$container = $this->createMockContainer();
|
||||
}
|
||||
|
||||
return new ContainerControllerResolver($container, $logger);
|
||||
}
|
||||
|
||||
protected function createMockContainer()
|
||||
{
|
||||
return $this->getMockBuilder(ContainerInterface::class)->getMock();
|
||||
}
|
||||
}
|
||||
|
||||
class InvokableController
|
||||
{
|
||||
public function __construct($bar) // mandatory argument to prevent automatic instantiation
|
||||
{
|
||||
}
|
||||
|
||||
public function __invoke()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
abstract class NonInstantiableController
|
||||
{
|
||||
public static function action()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ImpossibleConstructController
|
||||
{
|
||||
public function __construct($toto, $controller)
|
||||
{
|
||||
}
|
||||
|
||||
public function action()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,325 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Controller;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\NullableController;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\VariadicController;
|
||||
|
||||
class ControllerResolverTest extends TestCase
|
||||
{
|
||||
public function testGetControllerWithoutControllerParameter()
|
||||
{
|
||||
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
|
||||
$logger->expects($this->once())->method('warning')->with('Unable to look for the controller as the "_controller" parameter is missing.');
|
||||
$resolver = $this->createControllerResolver($logger);
|
||||
|
||||
$request = Request::create('/');
|
||||
$this->assertFalse($resolver->getController($request), '->getController() returns false when the request has no _controller attribute');
|
||||
}
|
||||
|
||||
public function testGetControllerWithLambda()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', $lambda = function () {});
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertSame($lambda, $controller);
|
||||
}
|
||||
|
||||
public function testGetControllerWithObjectAndInvokeMethod()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', $this);
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertSame($this, $controller);
|
||||
}
|
||||
|
||||
public function testGetControllerWithObjectAndMethod()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', [$this, 'controllerMethod1']);
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertSame([$this, 'controllerMethod1'], $controller);
|
||||
}
|
||||
|
||||
public function testGetControllerWithClassAndMethod()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', ['Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest', 'controllerMethod4']);
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertSame(['Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest', 'controllerMethod4'], $controller);
|
||||
}
|
||||
|
||||
public function testGetControllerWithObjectAndMethodAsString()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest::controllerMethod1');
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest', $controller[0], '->getController() returns a PHP callable');
|
||||
}
|
||||
|
||||
public function testGetControllerWithClassAndInvokeMethod()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest');
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest', $controller);
|
||||
}
|
||||
|
||||
public function testGetControllerOnObjectWithoutInvokeMethod()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', new \stdClass());
|
||||
$resolver->getController($request);
|
||||
}
|
||||
|
||||
public function testGetControllerWithFunction()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'Symfony\Component\HttpKernel\Tests\Controller\some_controller_function');
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertSame('Symfony\Component\HttpKernel\Tests\Controller\some_controller_function', $controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getUndefinedControllers
|
||||
*/
|
||||
public function testGetControllerOnNonUndefinedFunction($controller, $exceptionName = null, $exceptionMessage = null)
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
$this->expectException($exceptionName);
|
||||
$this->expectExceptionMessage($exceptionMessage);
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', $controller);
|
||||
$resolver->getController($request);
|
||||
}
|
||||
|
||||
public function getUndefinedControllers()
|
||||
{
|
||||
return [
|
||||
[1, 'InvalidArgumentException', 'Unable to find controller "1".'],
|
||||
['foo', 'InvalidArgumentException', 'Unable to find controller "foo".'],
|
||||
['oof::bar', 'InvalidArgumentException', 'Class "oof" does not exist.'],
|
||||
['stdClass', 'InvalidArgumentException', 'Unable to find controller "stdClass".'],
|
||||
['Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::staticsAction', 'InvalidArgumentException', 'The controller for URI "/" is not callable. Expected method "staticsAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest", did you mean "staticAction"?'],
|
||||
['Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::privateAction', 'InvalidArgumentException', 'The controller for URI "/" is not callable. Method "privateAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'],
|
||||
['Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::protectedAction', 'InvalidArgumentException', 'The controller for URI "/" is not callable. Method "protectedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'],
|
||||
['Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::undefinedAction', 'InvalidArgumentException', 'The controller for URI "/" is not callable. Expected method "undefinedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest". Available methods: "publicAction", "staticAction"'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetArguments()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$controller = [new self(), 'testGetArguments'];
|
||||
$this->assertEquals([], $resolver->getArguments($request, $controller), '->getArguments() returns an empty array if the method takes no arguments');
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = [new self(), 'controllerMethod1'];
|
||||
$this->assertEquals(['foo'], $resolver->getArguments($request, $controller), '->getArguments() returns an array of arguments for the controller method');
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = [new self(), 'controllerMethod2'];
|
||||
$this->assertEquals(['foo', null], $resolver->getArguments($request, $controller), '->getArguments() uses default values if present');
|
||||
|
||||
$request->attributes->set('bar', 'bar');
|
||||
$this->assertEquals(['foo', 'bar'], $resolver->getArguments($request, $controller), '->getArguments() overrides default values if provided in the request attributes');
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = function ($foo) {};
|
||||
$this->assertEquals(['foo'], $resolver->getArguments($request, $controller));
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = function ($foo, $bar = 'bar') {};
|
||||
$this->assertEquals(['foo', 'bar'], $resolver->getArguments($request, $controller));
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = new self();
|
||||
$this->assertEquals(['foo', null], $resolver->getArguments($request, $controller));
|
||||
$request->attributes->set('bar', 'bar');
|
||||
$this->assertEquals(['foo', 'bar'], $resolver->getArguments($request, $controller));
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('foobar', 'foobar');
|
||||
$controller = 'Symfony\Component\HttpKernel\Tests\Controller\some_controller_function';
|
||||
$this->assertEquals(['foo', 'foobar'], $resolver->getArguments($request, $controller));
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('foobar', 'foobar');
|
||||
$controller = [new self(), 'controllerMethod3'];
|
||||
|
||||
try {
|
||||
$resolver->getArguments($request, $controller);
|
||||
$this->fail('->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
|
||||
}
|
||||
|
||||
$request = Request::create('/');
|
||||
$controller = [new self(), 'controllerMethod5'];
|
||||
$this->assertEquals([$request], $resolver->getArguments($request, $controller), '->getArguments() injects the request');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetVariadicArguments()
|
||||
{
|
||||
$resolver = new ControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('bar', ['foo', 'bar']);
|
||||
$controller = [new VariadicController(), 'action'];
|
||||
$this->assertEquals(['foo', 'foo', 'bar'], $resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
public function testCreateControllerCanReturnAnyCallable()
|
||||
{
|
||||
$mock = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolver')->setMethods(['createController'])->getMock();
|
||||
$mock->expects($this->once())->method('createController')->willReturn('Symfony\Component\HttpKernel\Tests\Controller\some_controller_function');
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'foobar');
|
||||
$mock->getController($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testIfExceptionIsThrownWhenMissingAnArgument()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$resolver = new ControllerResolver();
|
||||
$request = Request::create('/');
|
||||
|
||||
$controller = [$this, 'controllerMethod1'];
|
||||
|
||||
$resolver->getArguments($request, $controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.1
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetNullableArguments()
|
||||
{
|
||||
$resolver = new ControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('bar', new \stdClass());
|
||||
$request->attributes->set('mandatory', 'mandatory');
|
||||
$controller = [new NullableController(), 'action'];
|
||||
$this->assertEquals(['foo', new \stdClass(), 'value', 'mandatory'], $resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.1
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetNullableArgumentsWithDefaults()
|
||||
{
|
||||
$resolver = new ControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('mandatory', 'mandatory');
|
||||
$controller = [new NullableController(), 'action'];
|
||||
$this->assertEquals([null, null, 'value', 'mandatory'], $resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
protected function createControllerResolver(LoggerInterface $logger = null)
|
||||
{
|
||||
return new ControllerResolver($logger);
|
||||
}
|
||||
|
||||
public function __invoke($foo, $bar = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function controllerMethod1($foo)
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerMethod2($foo, $bar = null)
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerMethod3($foo, $bar, $foobar)
|
||||
{
|
||||
}
|
||||
|
||||
protected static function controllerMethod4()
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerMethod5(Request $request)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
function some_controller_function($foo, $foobar)
|
||||
{
|
||||
}
|
||||
|
||||
class ControllerTest
|
||||
{
|
||||
public function publicAction()
|
||||
{
|
||||
}
|
||||
|
||||
private function privateAction()
|
||||
{
|
||||
}
|
||||
|
||||
protected function protectedAction()
|
||||
{
|
||||
}
|
||||
|
||||
public static function staticAction()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\ControllerMetadata;
|
||||
|
||||
use Fake\ImportedAndFake;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
|
||||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\BasicTypesController;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\NullableController;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\VariadicController;
|
||||
|
||||
class ArgumentMetadataFactoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ArgumentMetadataFactory
|
||||
*/
|
||||
private $factory;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->factory = new ArgumentMetadataFactory();
|
||||
}
|
||||
|
||||
public function testSignature1()
|
||||
{
|
||||
$arguments = $this->factory->createArgumentMetadata([$this, 'signature1']);
|
||||
|
||||
$this->assertEquals([
|
||||
new ArgumentMetadata('foo', self::class, false, false, null),
|
||||
new ArgumentMetadata('bar', 'array', false, false, null),
|
||||
new ArgumentMetadata('baz', 'callable', false, false, null),
|
||||
], $arguments);
|
||||
}
|
||||
|
||||
public function testSignature2()
|
||||
{
|
||||
$arguments = $this->factory->createArgumentMetadata([$this, 'signature2']);
|
||||
|
||||
$this->assertEquals([
|
||||
new ArgumentMetadata('foo', self::class, false, true, null, true),
|
||||
new ArgumentMetadata('bar', __NAMESPACE__.'\FakeClassThatDoesNotExist', false, true, null, true),
|
||||
new ArgumentMetadata('baz', 'Fake\ImportedAndFake', false, true, null, true),
|
||||
], $arguments);
|
||||
}
|
||||
|
||||
public function testSignature3()
|
||||
{
|
||||
$arguments = $this->factory->createArgumentMetadata([$this, 'signature3']);
|
||||
|
||||
$this->assertEquals([
|
||||
new ArgumentMetadata('bar', __NAMESPACE__.'\FakeClassThatDoesNotExist', false, false, null),
|
||||
new ArgumentMetadata('baz', 'Fake\ImportedAndFake', false, false, null),
|
||||
], $arguments);
|
||||
}
|
||||
|
||||
public function testSignature4()
|
||||
{
|
||||
$arguments = $this->factory->createArgumentMetadata([$this, 'signature4']);
|
||||
|
||||
$this->assertEquals([
|
||||
new ArgumentMetadata('foo', null, false, true, 'default'),
|
||||
new ArgumentMetadata('bar', null, false, true, 500),
|
||||
new ArgumentMetadata('baz', null, false, true, []),
|
||||
], $arguments);
|
||||
}
|
||||
|
||||
public function testSignature5()
|
||||
{
|
||||
$arguments = $this->factory->createArgumentMetadata([$this, 'signature5']);
|
||||
|
||||
$this->assertEquals([
|
||||
new ArgumentMetadata('foo', 'array', false, true, null, true),
|
||||
new ArgumentMetadata('bar', null, false, false, null),
|
||||
], $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
*/
|
||||
public function testVariadicSignature()
|
||||
{
|
||||
$arguments = $this->factory->createArgumentMetadata([new VariadicController(), 'action']);
|
||||
|
||||
$this->assertEquals([
|
||||
new ArgumentMetadata('foo', null, false, false, null),
|
||||
new ArgumentMetadata('bar', null, true, false, null),
|
||||
], $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.0
|
||||
*/
|
||||
public function testBasicTypesSignature()
|
||||
{
|
||||
$arguments = $this->factory->createArgumentMetadata([new BasicTypesController(), 'action']);
|
||||
|
||||
$this->assertEquals([
|
||||
new ArgumentMetadata('foo', 'string', false, false, null),
|
||||
new ArgumentMetadata('bar', 'int', false, false, null),
|
||||
new ArgumentMetadata('baz', 'float', false, false, null),
|
||||
], $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.1
|
||||
*/
|
||||
public function testNullableTypesSignature()
|
||||
{
|
||||
$arguments = $this->factory->createArgumentMetadata([new NullableController(), 'action']);
|
||||
|
||||
$this->assertEquals([
|
||||
new ArgumentMetadata('foo', 'string', false, false, null, true),
|
||||
new ArgumentMetadata('bar', \stdClass::class, false, false, null, true),
|
||||
new ArgumentMetadata('baz', 'string', false, true, 'value', true),
|
||||
new ArgumentMetadata('mandatory', null, false, false, null, true),
|
||||
], $arguments);
|
||||
}
|
||||
|
||||
private function signature1(self $foo, array $bar, callable $baz)
|
||||
{
|
||||
}
|
||||
|
||||
private function signature2(self $foo = null, FakeClassThatDoesNotExist $bar = null, ImportedAndFake $baz = null)
|
||||
{
|
||||
}
|
||||
|
||||
private function signature3(FakeClassThatDoesNotExist $bar, ImportedAndFake $baz)
|
||||
{
|
||||
}
|
||||
|
||||
private function signature4($foo = 'default', $bar = 500, $baz = [])
|
||||
{
|
||||
}
|
||||
|
||||
private function signature5(array $foo = null, $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\ControllerMetadata;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
|
||||
|
||||
class ArgumentMetadataTest extends TestCase
|
||||
{
|
||||
public function testWithBcLayerWithDefault()
|
||||
{
|
||||
$argument = new ArgumentMetadata('foo', 'string', false, true, 'default value');
|
||||
|
||||
$this->assertFalse($argument->isNullable());
|
||||
}
|
||||
|
||||
public function testDefaultValueAvailable()
|
||||
{
|
||||
$argument = new ArgumentMetadata('foo', 'string', false, true, 'default value', true);
|
||||
|
||||
$this->assertTrue($argument->isNullable());
|
||||
$this->assertTrue($argument->hasDefaultValue());
|
||||
$this->assertSame('default value', $argument->getDefaultValue());
|
||||
}
|
||||
|
||||
public function testDefaultValueUnavailable()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
$argument = new ArgumentMetadata('foo', 'string', false, false, null, false);
|
||||
|
||||
$this->assertFalse($argument->isNullable());
|
||||
$this->assertFalse($argument->hasDefaultValue());
|
||||
$argument->getDefaultValue();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass: Removed service "Psr\Container\ContainerInterface"; reason: private alias.
|
||||
Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass: Removed service "Symfony\Component\DependencyInjection\ContainerInterface"; reason: private alias.
|
||||
Some custom logging message
|
||||
With ending :
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
class ConfigDataCollectorTest extends TestCase
|
||||
{
|
||||
public function testCollect()
|
||||
{
|
||||
$kernel = new KernelForTest('test', true);
|
||||
$c = new ConfigDataCollector();
|
||||
$c->setKernel($kernel);
|
||||
$c->collect(new Request(), new Response());
|
||||
|
||||
$this->assertSame('test', $c->getEnv());
|
||||
$this->assertTrue($c->isDebug());
|
||||
$this->assertSame('config', $c->getName());
|
||||
$this->assertSame('testkernel', $c->getAppName());
|
||||
$this->assertRegExp('~^'.preg_quote($c->getPhpVersion(), '~').'~', PHP_VERSION);
|
||||
$this->assertRegExp('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', PHP_VERSION);
|
||||
$this->assertSame(PHP_INT_SIZE * 8, $c->getPhpArchitecture());
|
||||
$this->assertSame(class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', $c->getPhpIntlLocale());
|
||||
$this->assertSame(date_default_timezone_get(), $c->getPhpTimezone());
|
||||
$this->assertSame(Kernel::VERSION, $c->getSymfonyVersion());
|
||||
$this->assertNull($c->getToken());
|
||||
$this->assertSame(\extension_loaded('xdebug'), $c->hasXDebug());
|
||||
$this->assertSame(\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN), $c->hasZendOpcache());
|
||||
$this->assertSame(\extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN), $c->hasApcu());
|
||||
}
|
||||
}
|
||||
|
||||
class KernelForTest extends Kernel
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'testkernel';
|
||||
}
|
||||
|
||||
public function registerBundles()
|
||||
{
|
||||
}
|
||||
|
||||
public function getBundles()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function registerContainerConfiguration(LoaderInterface $loader)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\DataCollector\CloneVarDataCollector;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
|
||||
class DataCollectorTest extends TestCase
|
||||
{
|
||||
public function testCloneVarStringWithScheme()
|
||||
{
|
||||
$c = new CloneVarDataCollector('scheme://foo');
|
||||
$c->collect(new Request(), new Response());
|
||||
$cloner = new VarCloner();
|
||||
|
||||
$this->assertEquals($cloner->cloneVar('scheme://foo'), $c->getData());
|
||||
}
|
||||
|
||||
public function testCloneVarExistingFilePath()
|
||||
{
|
||||
$c = new CloneVarDataCollector([$filePath = tempnam(sys_get_temp_dir(), 'clone_var_data_collector_')]);
|
||||
$c->collect(new Request(), new Response());
|
||||
|
||||
$this->assertSame($filePath, $c->getData()[0]);
|
||||
}
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
|
||||
use Symfony\Component\VarDumper\Cloner\Data;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class DumpDataCollectorTest extends TestCase
|
||||
{
|
||||
public function testDump()
|
||||
{
|
||||
$data = new Data([[123]]);
|
||||
|
||||
$collector = new DumpDataCollector();
|
||||
|
||||
$this->assertSame('dump', $collector->getName());
|
||||
|
||||
$collector->dump($data);
|
||||
$line = __LINE__ - 1;
|
||||
$this->assertSame(1, $collector->getDumpsCount());
|
||||
|
||||
$dump = $collector->getDumps('html');
|
||||
$this->assertArrayHasKey('data', $dump[0]);
|
||||
$dump[0]['data'] = preg_replace('/^.*?<pre/', '<pre', $dump[0]['data']);
|
||||
$dump[0]['data'] = preg_replace('/sf-dump-\d+/', 'sf-dump', $dump[0]['data']);
|
||||
|
||||
$xDump = [
|
||||
[
|
||||
'data' => "<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
|
||||
'name' => 'DumpDataCollectorTest.php',
|
||||
'file' => __FILE__,
|
||||
'line' => $line,
|
||||
'fileExcerpt' => false,
|
||||
],
|
||||
];
|
||||
$this->assertEquals($xDump, $dump);
|
||||
|
||||
$this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";%c:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
|
||||
$this->assertSame(0, $collector->getDumpsCount());
|
||||
$this->assertSame('a:2:{i:0;b:0;i:1;s:5:"UTF-8";}', $collector->serialize());
|
||||
}
|
||||
|
||||
public function testCollectDefault()
|
||||
{
|
||||
$data = new Data([[123]]);
|
||||
|
||||
$collector = new DumpDataCollector();
|
||||
|
||||
$collector->dump($data);
|
||||
$line = __LINE__ - 1;
|
||||
|
||||
ob_start();
|
||||
$collector->collect(new Request(), new Response());
|
||||
$output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
|
||||
|
||||
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
|
||||
$this->assertSame(1, $collector->getDumpsCount());
|
||||
$collector->serialize();
|
||||
}
|
||||
|
||||
public function testCollectHtml()
|
||||
{
|
||||
$data = new Data([[123]]);
|
||||
|
||||
$collector = new DumpDataCollector(null, 'test://%f:%l');
|
||||
|
||||
$collector->dump($data);
|
||||
$line = __LINE__ - 1;
|
||||
$file = __FILE__;
|
||||
$xOutput = <<<EOTXT
|
||||
<pre class=sf-dump id=sf-dump data-indent-pad=" "><a href="test://{$file}:{$line}" title="{$file}"><span class=sf-dump-meta>DumpDataCollectorTest.php</span></a> on line <span class=sf-dump-meta>{$line}</span>:
|
||||
<span class=sf-dump-num>123</span>
|
||||
</pre>
|
||||
EOTXT;
|
||||
|
||||
ob_start();
|
||||
$response = new Response();
|
||||
$response->headers->set('Content-Type', 'text/html');
|
||||
$collector->collect(new Request(), $response);
|
||||
$output = ob_get_clean();
|
||||
$output = preg_replace('#<(script|style).*?</\1>#s', '', $output);
|
||||
$output = preg_replace('/sf-dump-\d+/', 'sf-dump', $output);
|
||||
|
||||
$this->assertSame($xOutput, trim($output));
|
||||
$this->assertSame(1, $collector->getDumpsCount());
|
||||
$collector->serialize();
|
||||
}
|
||||
|
||||
public function testFlush()
|
||||
{
|
||||
$data = new Data([[456]]);
|
||||
$collector = new DumpDataCollector();
|
||||
$collector->dump($data);
|
||||
$line = __LINE__ - 1;
|
||||
|
||||
ob_start();
|
||||
$collector->__destruct();
|
||||
$output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
|
||||
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
|
||||
}
|
||||
|
||||
public function testFlushNothingWhenDataDumperIsProvided()
|
||||
{
|
||||
$data = new Data([[456]]);
|
||||
$dumper = new CliDumper('php://output');
|
||||
$collector = new DumpDataCollector(null, null, null, null, $dumper);
|
||||
|
||||
ob_start();
|
||||
$collector->dump($data);
|
||||
$line = __LINE__ - 1;
|
||||
$output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
|
||||
|
||||
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
|
||||
|
||||
ob_start();
|
||||
$collector->__destruct();
|
||||
$this->assertEmpty(ob_get_clean());
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Debug\Exception\FlattenException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;
|
||||
|
||||
class ExceptionDataCollectorTest extends TestCase
|
||||
{
|
||||
public function testCollect()
|
||||
{
|
||||
$e = new \Exception('foo', 500);
|
||||
$c = new ExceptionDataCollector();
|
||||
$flattened = FlattenException::create($e);
|
||||
$trace = $flattened->getTrace();
|
||||
|
||||
$this->assertFalse($c->hasException());
|
||||
|
||||
$c->collect(new Request(), new Response(), $e);
|
||||
|
||||
$this->assertTrue($c->hasException());
|
||||
$this->assertEquals($flattened, $c->getException());
|
||||
$this->assertSame('foo', $c->getMessage());
|
||||
$this->assertSame(500, $c->getCode());
|
||||
$this->assertSame('exception', $c->getName());
|
||||
$this->assertSame($trace, $c->getTrace());
|
||||
}
|
||||
|
||||
public function testCollectWithoutException()
|
||||
{
|
||||
$c = new ExceptionDataCollector();
|
||||
$c->collect(new Request(), new Response());
|
||||
|
||||
$this->assertFalse($c->hasException());
|
||||
}
|
||||
|
||||
public function testReset()
|
||||
{
|
||||
$c = new ExceptionDataCollector();
|
||||
|
||||
$c->collect(new Request(), new Response(), new \Exception());
|
||||
$c->reset();
|
||||
$c->collect(new Request(), new Response());
|
||||
|
||||
$this->assertFalse($c->hasException());
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Debug\Exception\SilencedErrorContext;
|
||||
use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
|
||||
|
||||
class LoggerDataCollectorTest extends TestCase
|
||||
{
|
||||
public function testCollectWithUnexpectedFormat()
|
||||
{
|
||||
$logger = $this
|
||||
->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
|
||||
->setMethods(['countErrors', 'getLogs', 'clear'])
|
||||
->getMock();
|
||||
$logger->expects($this->once())->method('countErrors')->willReturn(123);
|
||||
$logger->expects($this->exactly(2))->method('getLogs')->willReturn([]);
|
||||
|
||||
$c = new LoggerDataCollector($logger, __DIR__.'/');
|
||||
$c->lateCollect();
|
||||
$compilerLogs = $c->getCompilerLogs()->getValue('message');
|
||||
|
||||
$this->assertSame([
|
||||
['message' => 'Removed service "Psr\Container\ContainerInterface"; reason: private alias.'],
|
||||
['message' => 'Removed service "Symfony\Component\DependencyInjection\ContainerInterface"; reason: private alias.'],
|
||||
], $compilerLogs['Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass']);
|
||||
|
||||
$this->assertSame([
|
||||
['message' => 'Some custom logging message'],
|
||||
['message' => 'With ending :'],
|
||||
], $compilerLogs['Unknown Compiler Pass']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getCollectTestData
|
||||
*/
|
||||
public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount, $expectedScreamCount, $expectedPriorities = null)
|
||||
{
|
||||
$logger = $this
|
||||
->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
|
||||
->setMethods(['countErrors', 'getLogs', 'clear'])
|
||||
->getMock();
|
||||
$logger->expects($this->once())->method('countErrors')->willReturn($nb);
|
||||
$logger->expects($this->exactly(2))->method('getLogs')->willReturn($logs);
|
||||
|
||||
$c = new LoggerDataCollector($logger);
|
||||
$c->lateCollect();
|
||||
|
||||
$this->assertEquals('logger', $c->getName());
|
||||
$this->assertEquals($nb, $c->countErrors());
|
||||
|
||||
$logs = array_map(function ($v) {
|
||||
if (isset($v['context']['exception'])) {
|
||||
$e = &$v['context']['exception'];
|
||||
$e = isset($e["\0*\0message"]) ? [$e["\0*\0message"], $e["\0*\0severity"]] : [$e["\0Symfony\Component\Debug\Exception\SilencedErrorContext\0severity"]];
|
||||
}
|
||||
|
||||
return $v;
|
||||
}, $c->getLogs()->getValue(true));
|
||||
$this->assertEquals($expectedLogs, $logs);
|
||||
$this->assertEquals($expectedDeprecationCount, $c->countDeprecations());
|
||||
$this->assertEquals($expectedScreamCount, $c->countScreams());
|
||||
|
||||
if (isset($expectedPriorities)) {
|
||||
$this->assertSame($expectedPriorities, $c->getPriorities()->getValue(true));
|
||||
}
|
||||
}
|
||||
|
||||
public function testReset()
|
||||
{
|
||||
$logger = $this
|
||||
->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
|
||||
->setMethods(['countErrors', 'getLogs', 'clear'])
|
||||
->getMock();
|
||||
$logger->expects($this->once())->method('clear');
|
||||
|
||||
$c = new LoggerDataCollector($logger);
|
||||
$c->reset();
|
||||
}
|
||||
|
||||
public function getCollectTestData()
|
||||
{
|
||||
yield 'simple log' => [
|
||||
1,
|
||||
[['message' => 'foo', 'context' => [], 'priority' => 100, 'priorityName' => 'DEBUG']],
|
||||
[['message' => 'foo', 'context' => [], 'priority' => 100, 'priorityName' => 'DEBUG']],
|
||||
0,
|
||||
0,
|
||||
];
|
||||
|
||||
yield 'log with a context' => [
|
||||
1,
|
||||
[['message' => 'foo', 'context' => ['foo' => 'bar'], 'priority' => 100, 'priorityName' => 'DEBUG']],
|
||||
[['message' => 'foo', 'context' => ['foo' => 'bar'], 'priority' => 100, 'priorityName' => 'DEBUG']],
|
||||
0,
|
||||
0,
|
||||
];
|
||||
|
||||
if (!class_exists(SilencedErrorContext::class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
yield 'logs with some deprecations' => [
|
||||
1,
|
||||
[
|
||||
['message' => 'foo3', 'context' => ['exception' => new \ErrorException('warning', 0, E_USER_WARNING)], 'priority' => 100, 'priorityName' => 'DEBUG'],
|
||||
['message' => 'foo', 'context' => ['exception' => new \ErrorException('deprecated', 0, E_DEPRECATED)], 'priority' => 100, 'priorityName' => 'DEBUG'],
|
||||
['message' => 'foo2', 'context' => ['exception' => new \ErrorException('deprecated', 0, E_USER_DEPRECATED)], 'priority' => 100, 'priorityName' => 'DEBUG'],
|
||||
],
|
||||
[
|
||||
['message' => 'foo3', 'context' => ['exception' => ['warning', E_USER_WARNING]], 'priority' => 100, 'priorityName' => 'DEBUG'],
|
||||
['message' => 'foo', 'context' => ['exception' => ['deprecated', E_DEPRECATED]], 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false],
|
||||
['message' => 'foo2', 'context' => ['exception' => ['deprecated', E_USER_DEPRECATED]], 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false],
|
||||
],
|
||||
2,
|
||||
0,
|
||||
[100 => ['count' => 3, 'name' => 'DEBUG']],
|
||||
];
|
||||
|
||||
yield 'logs with some silent errors' => [
|
||||
1,
|
||||
[
|
||||
['message' => 'foo3', 'context' => ['exception' => new \ErrorException('warning', 0, E_USER_WARNING)], 'priority' => 100, 'priorityName' => 'DEBUG'],
|
||||
['message' => 'foo3', 'context' => ['exception' => new SilencedErrorContext(E_USER_WARNING, __FILE__, __LINE__)], 'priority' => 100, 'priorityName' => 'DEBUG'],
|
||||
],
|
||||
[
|
||||
['message' => 'foo3', 'context' => ['exception' => ['warning', E_USER_WARNING]], 'priority' => 100, 'priorityName' => 'DEBUG'],
|
||||
['message' => 'foo3', 'context' => ['exception' => [E_USER_WARNING]], 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => true],
|
||||
],
|
||||
0,
|
||||
1,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\DataCollector\MemoryDataCollector;
|
||||
|
||||
class MemoryDataCollectorTest extends TestCase
|
||||
{
|
||||
public function testCollect()
|
||||
{
|
||||
$collector = new MemoryDataCollector();
|
||||
$collector->collect(new Request(), new Response());
|
||||
|
||||
$this->assertIsInt($collector->getMemory());
|
||||
$this->assertIsInt($collector->getMemoryLimit());
|
||||
$this->assertSame('memory', $collector->getName());
|
||||
}
|
||||
|
||||
/** @dataProvider getBytesConversionTestData */
|
||||
public function testBytesConversion($limit, $bytes)
|
||||
{
|
||||
$collector = new MemoryDataCollector();
|
||||
$method = new \ReflectionMethod($collector, 'convertToBytes');
|
||||
$method->setAccessible(true);
|
||||
$this->assertEquals($bytes, $method->invoke($collector, $limit));
|
||||
}
|
||||
|
||||
public function getBytesConversionTestData()
|
||||
{
|
||||
return [
|
||||
['2k', 2048],
|
||||
['2 k', 2048],
|
||||
['8m', 8 * 1024 * 1024],
|
||||
['+2 k', 2048],
|
||||
['+2???k', 2048],
|
||||
['0x10', 16],
|
||||
['0xf', 15],
|
||||
['010', 8],
|
||||
['+0x10 k', 16 * 1024],
|
||||
['1g', 1024 * 1024 * 1024],
|
||||
['1G', 1024 * 1024 * 1024],
|
||||
['-1', -1],
|
||||
['0', 0],
|
||||
['2mk', 2048], // the unit must be the last char, so in this case 'k', not 'm'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,334 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
|
||||
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
|
||||
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\HttpKernel;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
class RequestDataCollectorTest extends TestCase
|
||||
{
|
||||
public function testCollect()
|
||||
{
|
||||
$c = new RequestDataCollector();
|
||||
|
||||
$c->collect($request = $this->createRequest(), $this->createResponse());
|
||||
$c->lateCollect();
|
||||
|
||||
$attributes = $c->getRequestAttributes();
|
||||
|
||||
$this->assertSame('request', $c->getName());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestHeaders());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestServer());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestCookies());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $attributes);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestRequest());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestQuery());
|
||||
$this->assertInstanceOf(ParameterBag::class, $c->getResponseCookies());
|
||||
$this->assertSame('html', $c->getFormat());
|
||||
$this->assertEquals('foobar', $c->getRoute());
|
||||
$this->assertEquals(['name' => 'foo'], $c->getRouteParams());
|
||||
$this->assertSame([], $c->getSessionAttributes());
|
||||
$this->assertSame('en', $c->getLocale());
|
||||
$this->assertContains(__FILE__, $attributes->get('resource'));
|
||||
$this->assertSame('stdClass', $attributes->get('object')->getType());
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getResponseHeaders());
|
||||
$this->assertSame('OK', $c->getStatusText());
|
||||
$this->assertSame(200, $c->getStatusCode());
|
||||
$this->assertSame('application/json', $c->getContentType());
|
||||
}
|
||||
|
||||
public function testCollectWithoutRouteParams()
|
||||
{
|
||||
$request = $this->createRequest([]);
|
||||
|
||||
$c = new RequestDataCollector();
|
||||
$c->collect($request, $this->createResponse());
|
||||
$c->lateCollect();
|
||||
|
||||
$this->assertEquals([], $c->getRouteParams());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideControllerCallables
|
||||
*/
|
||||
public function testControllerInspection($name, $callable, $expected)
|
||||
{
|
||||
$c = new RequestDataCollector();
|
||||
$request = $this->createRequest();
|
||||
$response = $this->createResponse();
|
||||
$this->injectController($c, $callable, $request);
|
||||
$c->collect($request, $response);
|
||||
$c->lateCollect();
|
||||
|
||||
$this->assertSame($expected, $c->getController()->getValue(true), sprintf('Testing: %s', $name));
|
||||
}
|
||||
|
||||
public function provideControllerCallables()
|
||||
{
|
||||
// make sure we always match the line number
|
||||
$r1 = new \ReflectionMethod($this, 'testControllerInspection');
|
||||
$r2 = new \ReflectionMethod($this, 'staticControllerMethod');
|
||||
$r3 = new \ReflectionClass($this);
|
||||
|
||||
// test name, callable, expected
|
||||
return [
|
||||
[
|
||||
'"Regular" callable',
|
||||
[$this, 'testControllerInspection'],
|
||||
[
|
||||
'class' => __NAMESPACE__.'\RequestDataCollectorTest',
|
||||
'method' => 'testControllerInspection',
|
||||
'file' => __FILE__,
|
||||
'line' => $r1->getStartLine(),
|
||||
],
|
||||
],
|
||||
|
||||
[
|
||||
'Closure',
|
||||
function () { return 'foo'; },
|
||||
[
|
||||
'class' => __NAMESPACE__.'\{closure}',
|
||||
'method' => null,
|
||||
'file' => __FILE__,
|
||||
'line' => __LINE__ - 5,
|
||||
],
|
||||
],
|
||||
|
||||
[
|
||||
'Static callback as string',
|
||||
__NAMESPACE__.'\RequestDataCollectorTest::staticControllerMethod',
|
||||
[
|
||||
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
|
||||
'method' => 'staticControllerMethod',
|
||||
'file' => __FILE__,
|
||||
'line' => $r2->getStartLine(),
|
||||
],
|
||||
],
|
||||
|
||||
[
|
||||
'Static callable with instance',
|
||||
[$this, 'staticControllerMethod'],
|
||||
[
|
||||
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
|
||||
'method' => 'staticControllerMethod',
|
||||
'file' => __FILE__,
|
||||
'line' => $r2->getStartLine(),
|
||||
],
|
||||
],
|
||||
|
||||
[
|
||||
'Static callable with class name',
|
||||
['Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', 'staticControllerMethod'],
|
||||
[
|
||||
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
|
||||
'method' => 'staticControllerMethod',
|
||||
'file' => __FILE__,
|
||||
'line' => $r2->getStartLine(),
|
||||
],
|
||||
],
|
||||
|
||||
[
|
||||
'Callable with instance depending on __call()',
|
||||
[$this, 'magicMethod'],
|
||||
[
|
||||
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
|
||||
'method' => 'magicMethod',
|
||||
'file' => 'n/a',
|
||||
'line' => 'n/a',
|
||||
],
|
||||
],
|
||||
|
||||
[
|
||||
'Callable with class name depending on __callStatic()',
|
||||
['Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', 'magicMethod'],
|
||||
[
|
||||
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
|
||||
'method' => 'magicMethod',
|
||||
'file' => 'n/a',
|
||||
'line' => 'n/a',
|
||||
],
|
||||
],
|
||||
|
||||
[
|
||||
'Invokable controller',
|
||||
$this,
|
||||
[
|
||||
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
|
||||
'method' => null,
|
||||
'file' => __FILE__,
|
||||
'line' => $r3->getStartLine(),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testItIgnoresInvalidCallables()
|
||||
{
|
||||
$request = $this->createRequestWithSession();
|
||||
$response = new RedirectResponse('/');
|
||||
|
||||
$c = new RequestDataCollector();
|
||||
$c->collect($request, $response);
|
||||
|
||||
$this->assertSame('n/a', $c->getController());
|
||||
}
|
||||
|
||||
public function testItAddsRedirectedAttributesWhenRequestContainsSpecificCookie()
|
||||
{
|
||||
$request = $this->createRequest();
|
||||
$request->cookies->add([
|
||||
'sf_redirect' => '{}',
|
||||
]);
|
||||
|
||||
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
|
||||
|
||||
$c = new RequestDataCollector();
|
||||
$c->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $this->createResponse()));
|
||||
|
||||
$this->assertTrue($request->attributes->get('_redirected'));
|
||||
}
|
||||
|
||||
public function testItSetsARedirectCookieIfTheResponseIsARedirection()
|
||||
{
|
||||
$c = new RequestDataCollector();
|
||||
|
||||
$response = $this->createResponse();
|
||||
$response->setStatusCode(302);
|
||||
$response->headers->set('Location', '/somewhere-else');
|
||||
|
||||
$c->collect($request = $this->createRequest(), $response);
|
||||
$c->lateCollect();
|
||||
|
||||
$cookie = $this->getCookieByName($response, 'sf_redirect');
|
||||
|
||||
$this->assertNotEmpty($cookie->getValue());
|
||||
}
|
||||
|
||||
public function testItCollectsTheRedirectionAndClearTheCookie()
|
||||
{
|
||||
$c = new RequestDataCollector();
|
||||
|
||||
$request = $this->createRequest();
|
||||
$request->attributes->set('_redirected', true);
|
||||
$request->cookies->add([
|
||||
'sf_redirect' => '{"method": "POST"}',
|
||||
]);
|
||||
|
||||
$c->collect($request, $response = $this->createResponse());
|
||||
$c->lateCollect();
|
||||
|
||||
$this->assertEquals('POST', $c->getRedirect()['method']);
|
||||
|
||||
$cookie = $this->getCookieByName($response, 'sf_redirect');
|
||||
$this->assertNull($cookie->getValue());
|
||||
}
|
||||
|
||||
protected function createRequest($routeParams = ['name' => 'foo'])
|
||||
{
|
||||
$request = Request::create('http://test.com/foo?bar=baz');
|
||||
$request->attributes->set('foo', 'bar');
|
||||
$request->attributes->set('_route', 'foobar');
|
||||
$request->attributes->set('_route_params', $routeParams);
|
||||
$request->attributes->set('resource', fopen(__FILE__, 'r'));
|
||||
$request->attributes->set('object', new \stdClass());
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
private function createRequestWithSession()
|
||||
{
|
||||
$request = $this->createRequest();
|
||||
$request->attributes->set('_controller', 'Foo::bar');
|
||||
$request->setSession(new Session(new MockArraySessionStorage()));
|
||||
$request->getSession()->start();
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
protected function createResponse()
|
||||
{
|
||||
$response = new Response();
|
||||
$response->setStatusCode(200);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->headers->set('X-Foo-Bar', null);
|
||||
$response->headers->setCookie(new Cookie('foo', 'bar', 1, '/foo', 'localhost', true, true));
|
||||
$response->headers->setCookie(new Cookie('bar', 'foo', new \DateTime('@946684800')));
|
||||
$response->headers->setCookie(new Cookie('bazz', 'foo', '2000-12-12'));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject the given controller callable into the data collector.
|
||||
*/
|
||||
protected function injectController($collector, $controller, $request)
|
||||
{
|
||||
$resolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface')->getMock();
|
||||
$httpKernel = new HttpKernel(new EventDispatcher(), $resolver, null, $this->getMockBuilder(ArgumentResolverInterface::class)->getMock());
|
||||
$event = new FilterControllerEvent($httpKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
$collector->onKernelController($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy method used as controller callable.
|
||||
*/
|
||||
public static function staticControllerMethod()
|
||||
{
|
||||
throw new \LogicException('Unexpected method call');
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to allow non existing methods to be called and delegated.
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
throw new \LogicException('Unexpected method call');
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to allow non existing methods to be called and delegated.
|
||||
*/
|
||||
public static function __callStatic($method, $args)
|
||||
{
|
||||
throw new \LogicException('Unexpected method call');
|
||||
}
|
||||
|
||||
public function __invoke()
|
||||
{
|
||||
throw new \LogicException('Unexpected method call');
|
||||
}
|
||||
|
||||
private function getCookieByName(Response $response, $name)
|
||||
{
|
||||
foreach ($response->headers->getCookies() as $cookie) {
|
||||
if ($cookie->getName() == $name) {
|
||||
return $cookie;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('Cookie named "%s" is not in response', $name));
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class TimeDataCollectorTest extends TestCase
|
||||
{
|
||||
public function testCollect()
|
||||
{
|
||||
$c = new TimeDataCollector();
|
||||
|
||||
$request = new Request();
|
||||
$request->server->set('REQUEST_TIME', 1);
|
||||
|
||||
$c->collect($request, new Response());
|
||||
|
||||
$this->assertEquals(0, $c->getStartTime());
|
||||
|
||||
$request->server->set('REQUEST_TIME_FLOAT', 2);
|
||||
|
||||
$c->collect($request, new Response());
|
||||
|
||||
$this->assertEquals(2000, $c->getStartTime());
|
||||
|
||||
$request = new Request();
|
||||
$c->collect($request, new Response());
|
||||
$this->assertEquals(0, $c->getStartTime());
|
||||
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
|
||||
$kernel->expects($this->once())->method('getStartTime')->willReturn(123456.0);
|
||||
|
||||
$c = new TimeDataCollector($kernel);
|
||||
$request = new Request();
|
||||
$request->server->set('REQUEST_TIME', 1);
|
||||
|
||||
$c->collect($request, new Response());
|
||||
$this->assertEquals(123456000, $c->getStartTime());
|
||||
$this->assertSame(class_exists(Stopwatch::class, false), $c->isStopwatchInstalled());
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DataCollector\Util;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ValueExporterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ValueExporter
|
||||
*/
|
||||
private $valueExporter;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->valueExporter = new ValueExporter();
|
||||
}
|
||||
|
||||
public function testDateTime()
|
||||
{
|
||||
$dateTime = new \DateTime('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
|
||||
$this->assertSame('Object(DateTime) - 2014-06-10T07:35:40+00:00', $this->valueExporter->exportValue($dateTime));
|
||||
}
|
||||
|
||||
public function testDateTimeImmutable()
|
||||
{
|
||||
$dateTime = new \DateTimeImmutable('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
|
||||
$this->assertSame('Object(DateTimeImmutable) - 2014-06-10T07:35:40+00:00', $this->valueExporter->exportValue($dateTime));
|
||||
}
|
||||
|
||||
public function testIncompleteClass()
|
||||
{
|
||||
$foo = new \__PHP_Incomplete_Class();
|
||||
$array = new \ArrayObject($foo);
|
||||
$array['__PHP_Incomplete_Class_Name'] = 'AppBundle/Foo';
|
||||
$this->assertSame('__PHP_Incomplete_Class(AppBundle/Foo)', $this->valueExporter->exportValue($foo));
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Debug;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
|
||||
|
||||
class FileLinkFormatterTest extends TestCase
|
||||
{
|
||||
public function testWhenNoFileLinkFormatAndNoRequest()
|
||||
{
|
||||
$sut = new FileLinkFormatter();
|
||||
|
||||
$this->assertFalse($sut->format('/kernel/root/src/my/very/best/file.php', 3));
|
||||
}
|
||||
|
||||
public function testWhenFileLinkFormatAndNoRequest()
|
||||
{
|
||||
$file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
|
||||
|
||||
$sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', new RequestStack());
|
||||
|
||||
$this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
|
||||
}
|
||||
|
||||
public function testWhenFileLinkFormatAndRequest()
|
||||
{
|
||||
$file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
|
||||
$requestStack = new RequestStack();
|
||||
$request = new Request();
|
||||
$requestStack->push($request);
|
||||
|
||||
$sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
|
||||
|
||||
$this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
|
||||
}
|
||||
|
||||
public function testWhenNoFileLinkFormatAndRequest()
|
||||
{
|
||||
$file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
|
||||
$requestStack = new RequestStack();
|
||||
$request = new Request();
|
||||
$requestStack->push($request);
|
||||
|
||||
$request->server->set('SERVER_NAME', 'www.example.org');
|
||||
$request->server->set('SERVER_PORT', 80);
|
||||
$request->server->set('SCRIPT_NAME', '/index.php');
|
||||
$request->server->set('SCRIPT_FILENAME', '/public/index.php');
|
||||
$request->server->set('REQUEST_URI', '/index.php/example');
|
||||
|
||||
$sut = new FileLinkFormatter(null, $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
|
||||
|
||||
$this->assertSame('http://www.example.org/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Debug;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
|
||||
use Symfony\Component\HttpKernel\HttpKernel;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
class TraceableEventDispatcherTest extends TestCase
|
||||
{
|
||||
public function testStopwatchSections()
|
||||
{
|
||||
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch = new Stopwatch());
|
||||
$kernel = $this->getHttpKernel($dispatcher, function () { return new Response('', 200, ['X-Debug-Token' => '292e1e']); });
|
||||
$request = Request::create('/');
|
||||
$response = $kernel->handle($request);
|
||||
$kernel->terminate($request, $response);
|
||||
|
||||
$events = $stopwatch->getSectionEvents($response->headers->get('X-Debug-Token'));
|
||||
$this->assertEquals([
|
||||
'__section__',
|
||||
'kernel.request',
|
||||
'kernel.controller',
|
||||
'kernel.controller_arguments',
|
||||
'controller',
|
||||
'kernel.response',
|
||||
'kernel.terminate',
|
||||
], array_keys($events));
|
||||
}
|
||||
|
||||
public function testStopwatchCheckControllerOnRequestEvent()
|
||||
{
|
||||
$stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')
|
||||
->setMethods(['isStarted'])
|
||||
->getMock();
|
||||
$stopwatch->expects($this->once())
|
||||
->method('isStarted')
|
||||
->willReturn(false);
|
||||
|
||||
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch);
|
||||
|
||||
$kernel = $this->getHttpKernel($dispatcher, function () { return new Response(); });
|
||||
$request = Request::create('/');
|
||||
$kernel->handle($request);
|
||||
}
|
||||
|
||||
public function testStopwatchStopControllerOnRequestEvent()
|
||||
{
|
||||
$stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')
|
||||
->setMethods(['isStarted', 'stop'])
|
||||
->getMock();
|
||||
$stopwatch->expects($this->once())
|
||||
->method('isStarted')
|
||||
->willReturn(true);
|
||||
$stopwatch->expects($this->once())
|
||||
->method('stop');
|
||||
|
||||
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch);
|
||||
|
||||
$kernel = $this->getHttpKernel($dispatcher, function () { return new Response(); });
|
||||
$request = Request::create('/');
|
||||
$kernel->handle($request);
|
||||
}
|
||||
|
||||
public function testAddListenerNested()
|
||||
{
|
||||
$called1 = false;
|
||||
$called2 = false;
|
||||
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||
$dispatcher->addListener('my-event', function () use ($dispatcher, &$called1, &$called2) {
|
||||
$called1 = true;
|
||||
$dispatcher->addListener('my-event', function () use (&$called2) {
|
||||
$called2 = true;
|
||||
});
|
||||
});
|
||||
$dispatcher->dispatch('my-event');
|
||||
$this->assertTrue($called1);
|
||||
$this->assertFalse($called2);
|
||||
$dispatcher->dispatch('my-event');
|
||||
$this->assertTrue($called2);
|
||||
}
|
||||
|
||||
public function testListenerCanRemoveItselfWhenExecuted()
|
||||
{
|
||||
$eventDispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||
$listener1 = function () use ($eventDispatcher, &$listener1) {
|
||||
$eventDispatcher->removeListener('foo', $listener1);
|
||||
};
|
||||
$eventDispatcher->addListener('foo', $listener1);
|
||||
$eventDispatcher->addListener('foo', function () {});
|
||||
$eventDispatcher->dispatch('foo');
|
||||
|
||||
$this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed');
|
||||
}
|
||||
|
||||
protected function getHttpKernel($dispatcher, $controller)
|
||||
{
|
||||
$controllerResolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')->getMock();
|
||||
$controllerResolver->expects($this->once())->method('getController')->willReturn($controller);
|
||||
$argumentResolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface')->getMock();
|
||||
$argumentResolver->expects($this->once())->method('getArguments')->willReturn([]);
|
||||
|
||||
return new HttpKernel($dispatcher, $controllerResolver, new RequestStack(), $argumentResolver);
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;
|
||||
|
||||
class AddAnnotatedClassesToCachePassTest extends TestCase
|
||||
{
|
||||
public function testExpandClasses()
|
||||
{
|
||||
$r = new \ReflectionClass(AddAnnotatedClassesToCachePass::class);
|
||||
$pass = $r->newInstanceWithoutConstructor();
|
||||
$r = new \ReflectionMethod(AddAnnotatedClassesToCachePass::class, 'expandClasses');
|
||||
$r->setAccessible(true);
|
||||
$expand = $r->getClosure($pass);
|
||||
|
||||
$this->assertSame('Foo', $expand(['Foo'], [])[0]);
|
||||
$this->assertSame('Foo', $expand(['\\Foo'], [])[0]);
|
||||
$this->assertSame('Foo', $expand(['Foo'], ['\\Foo'])[0]);
|
||||
$this->assertSame('Foo', $expand(['Foo'], ['Foo'])[0]);
|
||||
$this->assertSame('Foo', $expand(['\\Foo'], ['\\Foo\\Bar'])[0]);
|
||||
$this->assertSame('Foo', $expand(['Foo'], ['\\Foo\\Bar'])[0]);
|
||||
$this->assertSame('Foo', $expand(['\\Foo'], ['\\Foo\\Bar\\Acme'])[0]);
|
||||
|
||||
$this->assertSame('Foo\\Bar', $expand(['Foo\\'], ['\\Foo\\Bar'])[0]);
|
||||
$this->assertSame('Foo\\Bar\\Acme', $expand(['Foo\\'], ['\\Foo\\Bar\\Acme'])[0]);
|
||||
$this->assertEmpty($expand(['Foo\\'], ['\\Foo']));
|
||||
|
||||
$this->assertSame('Acme\\Foo\\Bar', $expand(['**\\Foo\\'], ['\\Acme\\Foo\\Bar'])[0]);
|
||||
$this->assertEmpty($expand(['**\\Foo\\'], ['\\Foo\\Bar']));
|
||||
$this->assertEmpty($expand(['**\\Foo\\'], ['\\Acme\\Foo']));
|
||||
$this->assertEmpty($expand(['**\\Foo\\'], ['\\Foo']));
|
||||
|
||||
$this->assertSame('Acme\\Foo', $expand(['**\\Foo'], ['\\Acme\\Foo'])[0]);
|
||||
$this->assertEmpty($expand(['**\\Foo'], ['\\Acme\\Foo\\AcmeBundle']));
|
||||
$this->assertEmpty($expand(['**\\Foo'], ['\\Acme\\FooBar\\AcmeBundle']));
|
||||
|
||||
$this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\*\\Bar'], ['\\Foo\\Acme\\Bar'])[0]);
|
||||
$this->assertEmpty($expand(['Foo\\*\\Bar'], ['\\Foo\\Acme\\Bundle\\Bar']));
|
||||
|
||||
$this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\**\\Bar'], ['\\Foo\\Acme\\Bar'])[0]);
|
||||
$this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(['Foo\\**\\Bar'], ['\\Foo\\Acme\\Bundle\\Bar'])[0]);
|
||||
|
||||
$this->assertSame('Acme\\Bar', $expand(['*\\Bar'], ['\\Acme\\Bar'])[0]);
|
||||
$this->assertEmpty($expand(['*\\Bar'], ['\\Bar']));
|
||||
$this->assertEmpty($expand(['*\\Bar'], ['\\Foo\\Acme\\Bar']));
|
||||
|
||||
$this->assertSame('Foo\\Acme\\Bar', $expand(['**\\Bar'], ['\\Foo\\Acme\\Bar'])[0]);
|
||||
$this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(['**\\Bar'], ['\\Foo\\Acme\\Bundle\\Bar'])[0]);
|
||||
$this->assertEmpty($expand(['**\\Bar'], ['\\Bar']));
|
||||
|
||||
$this->assertSame('Foo\\Bar', $expand(['Foo\\*'], ['\\Foo\\Bar'])[0]);
|
||||
$this->assertEmpty($expand(['Foo\\*'], ['\\Foo\\Acme\\Bar']));
|
||||
|
||||
$this->assertSame('Foo\\Bar', $expand(['Foo\\**'], ['\\Foo\\Bar'])[0]);
|
||||
$this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\**'], ['\\Foo\\Acme\\Bar'])[0]);
|
||||
|
||||
$this->assertSame(['Foo\\Bar'], $expand(['Foo\\*'], ['Foo\\Bar', 'Foo\\BarTest']));
|
||||
$this->assertSame(['Foo\\Bar', 'Foo\\BarTest'], $expand(['Foo\\*', 'Foo\\*Test'], ['Foo\\Bar', 'Foo\\BarTest']));
|
||||
|
||||
$this->assertSame(
|
||||
'Acme\\FooBundle\\Controller\\DefaultController',
|
||||
$expand(['**Bundle\\Controller\\'], ['\\Acme\\FooBundle\\Controller\\DefaultController'])[0]
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'FooBundle\\Controller\\DefaultController',
|
||||
$expand(['**Bundle\\Controller\\'], ['\\FooBundle\\Controller\\DefaultController'])[0]
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'Acme\\FooBundle\\Controller\\Bar\\DefaultController',
|
||||
$expand(['**Bundle\\Controller\\'], ['\\Acme\\FooBundle\\Controller\\Bar\\DefaultController'])[0]
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'Bundle\\Controller\\Bar\\DefaultController',
|
||||
$expand(['**Bundle\\Controller\\'], ['\\Bundle\\Controller\\Bar\\DefaultController'])[0]
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'Acme\\Bundle\\Controller\\Bar\\DefaultController',
|
||||
$expand(['**Bundle\\Controller\\'], ['\\Acme\\Bundle\\Controller\\Bar\\DefaultController'])[0]
|
||||
);
|
||||
|
||||
$this->assertSame('Foo\\Bar', $expand(['Foo\\Bar'], [])[0]);
|
||||
$this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\**'], ['\\Foo\\Acme\\Bar'])[0]);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
|
||||
|
||||
class ControllerArgumentValueResolverPassTest extends TestCase
|
||||
{
|
||||
public function testServicesAreOrderedAccordingToPriority()
|
||||
{
|
||||
$services = [
|
||||
'n3' => [[]],
|
||||
'n1' => [['priority' => 200]],
|
||||
'n2' => [['priority' => 100]],
|
||||
];
|
||||
|
||||
$expected = [
|
||||
new Reference('n1'),
|
||||
new Reference('n2'),
|
||||
new Reference('n3'),
|
||||
];
|
||||
|
||||
$definition = new Definition(ArgumentResolver::class, [null, []]);
|
||||
$container = new ContainerBuilder();
|
||||
$container->setDefinition('argument_resolver', $definition);
|
||||
|
||||
foreach ($services as $id => list($tag)) {
|
||||
$container->register($id)->addTag('controller.argument_value_resolver', $tag);
|
||||
}
|
||||
|
||||
(new ControllerArgumentValueResolverPass())->process($container);
|
||||
$this->assertEquals($expected, $definition->getArgument(1)->getValues());
|
||||
}
|
||||
|
||||
public function testReturningEmptyArrayWhenNoService()
|
||||
{
|
||||
$definition = new Definition(ArgumentResolver::class, [null, []]);
|
||||
$container = new ContainerBuilder();
|
||||
$container->setDefinition('argument_resolver', $definition);
|
||||
|
||||
(new ControllerArgumentValueResolverPass())->process($container);
|
||||
$this->assertEquals([], $definition->getArgument(1)->getValues());
|
||||
}
|
||||
|
||||
public function testNoArgumentResolver()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
(new ControllerArgumentValueResolverPass())->process($container);
|
||||
|
||||
$this->assertFalse($container->hasDefinition('argument_resolver'));
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
|
||||
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
|
||||
|
||||
class FragmentRendererPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Tests that content rendering not implementing FragmentRendererInterface
|
||||
* triggers an exception.
|
||||
*/
|
||||
public function testContentRendererWithoutInterface()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$builder = new ContainerBuilder();
|
||||
$fragmentHandlerDefinition = $builder->register('fragment.handler');
|
||||
$builder->register('my_content_renderer', 'Symfony\Component\DependencyInjection\Definition')
|
||||
->addTag('kernel.fragment_renderer', ['alias' => 'foo']);
|
||||
|
||||
$pass = new FragmentRendererPass();
|
||||
$pass->process($builder);
|
||||
|
||||
$this->assertEquals([['addRendererService', ['foo', 'my_content_renderer']]], $fragmentHandlerDefinition->getMethodCalls());
|
||||
}
|
||||
|
||||
public function testValidContentRenderer()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
$fragmentHandlerDefinition = $builder->register('fragment.handler')
|
||||
->addArgument(null);
|
||||
$builder->register('my_content_renderer', 'Symfony\Component\HttpKernel\Tests\DependencyInjection\RendererService')
|
||||
->addTag('kernel.fragment_renderer', ['alias' => 'foo']);
|
||||
|
||||
$pass = new FragmentRendererPass();
|
||||
$pass->process($builder);
|
||||
|
||||
$serviceLocatorDefinition = $builder->getDefinition((string) $fragmentHandlerDefinition->getArgument(0));
|
||||
$this->assertSame(ServiceLocator::class, $serviceLocatorDefinition->getClass());
|
||||
$this->assertEquals(['foo' => new ServiceClosureArgument(new Reference('my_content_renderer'))], $serviceLocatorDefinition->getArgument(0));
|
||||
}
|
||||
}
|
||||
|
||||
class RendererService implements FragmentRendererInterface
|
||||
{
|
||||
public function render($uri, Request $request = null, array $options = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'test';
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler;
|
||||
|
||||
class LazyLoadingFragmentHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler::addRendererService() method is deprecated since Symfony 3.3 and will be removed in 4.0.
|
||||
*/
|
||||
public function testRenderWithLegacyMapping()
|
||||
{
|
||||
$renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
|
||||
$renderer->expects($this->once())->method('getName')->willReturn('foo');
|
||||
$renderer->expects($this->any())->method('render')->willReturn(new Response());
|
||||
|
||||
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
|
||||
$requestStack->expects($this->any())->method('getCurrentRequest')->willReturn(Request::create('/'));
|
||||
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
|
||||
$container->expects($this->once())->method('get')->willReturn($renderer);
|
||||
|
||||
$handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
|
||||
$handler->addRendererService('foo', 'foo');
|
||||
|
||||
$handler->render('/foo', 'foo');
|
||||
|
||||
// second call should not lazy-load anymore (see once() above on the get() method)
|
||||
$handler->render('/foo', 'foo');
|
||||
}
|
||||
|
||||
public function testRender()
|
||||
{
|
||||
$renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
|
||||
$renderer->expects($this->once())->method('getName')->willReturn('foo');
|
||||
$renderer->expects($this->any())->method('render')->willReturn(new Response());
|
||||
|
||||
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
|
||||
$requestStack->expects($this->any())->method('getCurrentRequest')->willReturn(Request::create('/'));
|
||||
|
||||
$container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock();
|
||||
$container->expects($this->once())->method('has')->with('foo')->willReturn(true);
|
||||
$container->expects($this->once())->method('get')->willReturn($renderer);
|
||||
|
||||
$handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
|
||||
|
||||
$handler->render('/foo', 'foo');
|
||||
|
||||
// second call should not lazy-load anymore (see once() above on the get() method)
|
||||
$handler->render('/foo', 'foo');
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\LoggerPass;
|
||||
use Symfony\Component\HttpKernel\Log\Logger;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class LoggerPassTest extends TestCase
|
||||
{
|
||||
public function testAlwaysSetAutowiringAlias()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('logger', 'Foo');
|
||||
|
||||
(new LoggerPass())->process($container);
|
||||
|
||||
$this->assertFalse($container->getAlias(LoggerInterface::class)->isPublic());
|
||||
}
|
||||
|
||||
public function testDoNotOverrideExistingLogger()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('logger', 'Foo');
|
||||
|
||||
(new LoggerPass())->process($container);
|
||||
|
||||
$this->assertSame('Foo', $container->getDefinition('logger')->getClass());
|
||||
}
|
||||
|
||||
public function testRegisterLogger()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('kernel.debug', false);
|
||||
|
||||
(new LoggerPass())->process($container);
|
||||
|
||||
$definition = $container->getDefinition('logger');
|
||||
$this->assertSame(Logger::class, $definition->getClass());
|
||||
$this->assertFalse($definition->isPublic());
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
|
||||
|
||||
class MergeExtensionConfigurationPassTest extends TestCase
|
||||
{
|
||||
public function testAutoloadMainExtension()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerExtension(new LoadedExtension());
|
||||
$container->registerExtension(new NotLoadedExtension());
|
||||
$container->loadFromExtension('loaded', []);
|
||||
|
||||
$configPass = new MergeExtensionConfigurationPass(['loaded', 'not_loaded']);
|
||||
$configPass->process($container);
|
||||
|
||||
$this->assertTrue($container->hasDefinition('loaded.foo'));
|
||||
$this->assertTrue($container->hasDefinition('not_loaded.bar'));
|
||||
}
|
||||
}
|
||||
|
||||
class LoadedExtension extends Extension
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$container->register('loaded.foo');
|
||||
}
|
||||
}
|
||||
|
||||
class NotLoadedExtension extends Extension
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$container->register('not_loaded.bar');
|
||||
}
|
||||
}
|
||||
@@ -1,397 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||
use Symfony\Component\DependencyInjection\TypedReference;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
|
||||
|
||||
class RegisterControllerArgumentLocatorsPassTest extends TestCase
|
||||
{
|
||||
public function testInvalidClass()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Class "Symfony\Component\HttpKernel\Tests\DependencyInjection\NotFound" used for service "foo" cannot be found.');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', NotFound::class)
|
||||
->addTag('controller.service_arguments')
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testNoAction()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Missing "action" attribute on tag "controller.service_arguments" {"argument":"bar"} for service "foo".');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', ['argument' => 'bar'])
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testNoArgument()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Missing "argument" attribute on tag "controller.service_arguments" {"action":"fooAction"} for service "foo".');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', ['action' => 'fooAction'])
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testNoService()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Missing "id" attribute on tag "controller.service_arguments" {"action":"fooAction","argument":"bar"} for service "foo".');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', ['action' => 'fooAction', 'argument' => 'bar'])
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testInvalidMethod()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Invalid "action" attribute on tag "controller.service_arguments" for service "foo": no public "barAction()" method found on class "Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterTestController".');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', ['action' => 'barAction', 'argument' => 'bar', 'id' => 'bar_service'])
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testInvalidArgument()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Invalid "controller.service_arguments" tag for service "foo": method "fooAction()" has no "baz" argument on class "Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterTestController".');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', ['action' => 'fooAction', 'argument' => 'baz', 'id' => 'bar'])
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testAllActions()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments')
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
|
||||
$this->assertEquals(['foo:fooAction'], array_keys($locator));
|
||||
$this->assertInstanceof(ServiceClosureArgument::class, $locator['foo:fooAction']);
|
||||
|
||||
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
|
||||
|
||||
$this->assertSame(ServiceLocator::class, $locator->getClass());
|
||||
$this->assertFalse($locator->isPublic());
|
||||
|
||||
$expected = ['bar' => new ServiceClosureArgument(new TypedReference(ControllerDummy::class, ControllerDummy::class, RegisterTestController::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE))];
|
||||
$this->assertEquals($expected, $locator->getArgument(0));
|
||||
}
|
||||
|
||||
public function testExplicitArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', ['action' => 'fooAction', 'argument' => 'bar', 'id' => 'bar'])
|
||||
->addTag('controller.service_arguments', ['action' => 'fooAction', 'argument' => 'bar', 'id' => 'baz']) // should be ignored, the first wins
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
|
||||
|
||||
$expected = ['bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, RegisterTestController::class))];
|
||||
$this->assertEquals($expected, $locator->getArgument(0));
|
||||
}
|
||||
|
||||
public function testOptionalArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->addTag('controller.service_arguments', ['action' => 'fooAction', 'argument' => 'bar', 'id' => '?bar'])
|
||||
;
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
|
||||
|
||||
$expected = ['bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, RegisterTestController::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE))];
|
||||
$this->assertEquals($expected, $locator->getArgument(0));
|
||||
}
|
||||
|
||||
public function testSkipSetContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', ContainerAwareRegisterTestController::class)
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$this->assertSame(['foo:fooAction'], array_keys($locator));
|
||||
}
|
||||
|
||||
public function testExceptionOnNonExistentTypeHint()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Cannot determine controller argument for "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClassController::fooAction()": the $nonExistent argument is type-hinted with the non-existent class or interface: "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClass". Did you forget to add a use statement?');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', NonExistentClassController::class)
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testExceptionOnNonExistentTypeHintDifferentNamespace()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Cannot determine controller argument for "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClassDifferentNamespaceController::fooAction()": the $nonExistent argument is type-hinted with the non-existent class or interface: "Acme\NonExistentClass".');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', NonExistentClassDifferentNamespaceController::class)
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testNoExceptionOnNonExistentTypeHintOptionalArg()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', NonExistentClassOptionalController::class)
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$this->assertSame(['foo:barAction', 'foo:fooAction'], array_keys($locator));
|
||||
}
|
||||
|
||||
public function testArgumentWithNoTypeHintIsOk()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', ArgumentWithoutTypeController::class)
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$this->assertEmpty(array_keys($locator));
|
||||
}
|
||||
|
||||
public function testControllersAreMadePublic()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', ArgumentWithoutTypeController::class)
|
||||
->setPublic(false)
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('foo')->isPublic());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideBindings
|
||||
*/
|
||||
public function testBindings($bindingName)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', RegisterTestController::class)
|
||||
->setBindings([$bindingName => new Reference('foo')])
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
|
||||
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
|
||||
|
||||
$expected = ['bar' => new ServiceClosureArgument(new Reference('foo'))];
|
||||
$this->assertEquals($expected, $locator->getArgument(0));
|
||||
}
|
||||
|
||||
public function provideBindings()
|
||||
{
|
||||
return [[ControllerDummy::class], ['$bar']];
|
||||
}
|
||||
|
||||
public function testDoNotBindScalarValueToControllerArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('foo', ArgumentWithoutTypeController::class)
|
||||
->setBindings(['$someArg' => '%foo%'])
|
||||
->addTag('controller.service_arguments');
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$this->assertEmpty($locator);
|
||||
}
|
||||
|
||||
public function testBindingsOnChildDefinitions()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('parent', ArgumentWithoutTypeController::class);
|
||||
|
||||
$container->setDefinition('child', (new ChildDefinition('parent'))
|
||||
->setBindings(['$someArg' => new Reference('parent')])
|
||||
->addTag('controller.service_arguments')
|
||||
);
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
$this->assertInstanceOf(ServiceClosureArgument::class, $locator['child:fooAction']);
|
||||
|
||||
$locator = $container->getDefinition((string) $locator['child:fooAction']->getValues()[0])->getArgument(0);
|
||||
$this->assertInstanceOf(ServiceClosureArgument::class, $locator['someArg']);
|
||||
$this->assertEquals(new Reference('parent'), $locator['someArg']->getValues()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
class RegisterTestController
|
||||
{
|
||||
public function __construct(ControllerDummy $bar)
|
||||
{
|
||||
}
|
||||
|
||||
public function fooAction(ControllerDummy $bar)
|
||||
{
|
||||
}
|
||||
|
||||
protected function barAction(ControllerDummy $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ContainerAwareRegisterTestController implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
public function fooAction(ControllerDummy $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ControllerDummy
|
||||
{
|
||||
}
|
||||
|
||||
class NonExistentClassController
|
||||
{
|
||||
public function fooAction(NonExistentClass $nonExistent)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class NonExistentClassDifferentNamespaceController
|
||||
{
|
||||
public function fooAction(\Acme\NonExistentClass $nonExistent)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class NonExistentClassOptionalController
|
||||
{
|
||||
public function fooAction(NonExistentClass $nonExistent = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function barAction(NonExistentClass $nonExistent = null, $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ArgumentWithoutTypeController
|
||||
{
|
||||
public function fooAction($someArg)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveInvalidReferencesPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass;
|
||||
|
||||
class RemoveEmptyControllerArgumentLocatorsPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('stdClass', 'stdClass');
|
||||
$container->register(TestCase::class, 'stdClass');
|
||||
$container->register('c1', RemoveTestController1::class)->addTag('controller.service_arguments');
|
||||
$container->register('c2', RemoveTestController2::class)->addTag('controller.service_arguments')
|
||||
->addMethodCall('setTestCase', [new Reference('c1')]);
|
||||
|
||||
$pass = new RegisterControllerArgumentLocatorsPass();
|
||||
$pass->process($container);
|
||||
|
||||
$controllers = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
|
||||
$this->assertCount(2, $container->getDefinition((string) $controllers['c1:fooAction']->getValues()[0])->getArgument(0));
|
||||
$this->assertCount(1, $container->getDefinition((string) $controllers['c2:setTestCase']->getValues()[0])->getArgument(0));
|
||||
$this->assertCount(1, $container->getDefinition((string) $controllers['c2:fooAction']->getValues()[0])->getArgument(0));
|
||||
|
||||
(new ResolveInvalidReferencesPass())->process($container);
|
||||
|
||||
$this->assertCount(1, $container->getDefinition((string) $controllers['c2:setTestCase']->getValues()[0])->getArgument(0));
|
||||
$this->assertSame([], $container->getDefinition((string) $controllers['c2:fooAction']->getValues()[0])->getArgument(0));
|
||||
|
||||
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
|
||||
|
||||
$controllers = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
|
||||
|
||||
$this->assertSame(['c1:fooAction'], array_keys($controllers));
|
||||
$this->assertSame(['bar'], array_keys($container->getDefinition((string) $controllers['c1:fooAction']->getValues()[0])->getArgument(0)));
|
||||
|
||||
$expectedLog = [
|
||||
'Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass: Removing service-argument resolver for controller "c2:fooAction": no corresponding services exist for the referenced types.',
|
||||
'Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass: Removing method "setTestCase" of service "c2" from controller candidates: the method is called at instantiation, thus cannot be an action.',
|
||||
];
|
||||
|
||||
$this->assertSame($expectedLog, $container->getCompiler()->getLog());
|
||||
}
|
||||
|
||||
public function testSameIdClass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register(RegisterTestController::class, RegisterTestController::class)
|
||||
->addTag('controller.service_arguments')
|
||||
;
|
||||
|
||||
(new RegisterControllerArgumentLocatorsPass())->process($container);
|
||||
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
|
||||
|
||||
$expected = [
|
||||
RegisterTestController::class.':fooAction',
|
||||
RegisterTestController::class.'::fooAction',
|
||||
];
|
||||
$this->assertEquals($expected, array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0)));
|
||||
}
|
||||
|
||||
public function testInvoke()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register('invokable', InvokableRegisterTestController::class)
|
||||
->addTag('controller.service_arguments')
|
||||
;
|
||||
|
||||
(new RegisterControllerArgumentLocatorsPass())->process($container);
|
||||
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
|
||||
|
||||
$this->assertEquals(
|
||||
['invokable:__invoke', 'invokable'],
|
||||
array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0))
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvokeSameIdClass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$resolver = $container->register('argument_resolver.service')->addArgument([]);
|
||||
|
||||
$container->register(InvokableRegisterTestController::class, InvokableRegisterTestController::class)
|
||||
->addTag('controller.service_arguments')
|
||||
;
|
||||
|
||||
(new RegisterControllerArgumentLocatorsPass())->process($container);
|
||||
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
|
||||
|
||||
$expected = [
|
||||
InvokableRegisterTestController::class.':__invoke',
|
||||
InvokableRegisterTestController::class.'::__invoke',
|
||||
InvokableRegisterTestController::class,
|
||||
];
|
||||
$this->assertEquals($expected, array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0)));
|
||||
}
|
||||
}
|
||||
|
||||
class RemoveTestController1
|
||||
{
|
||||
public function fooAction(\stdClass $bar, ClassNotInContainer $baz)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class RemoveTestController2
|
||||
{
|
||||
public function setTestCase(TestCase $test)
|
||||
{
|
||||
}
|
||||
|
||||
public function fooAction(ClassNotInContainer $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class InvokableRegisterTestController
|
||||
{
|
||||
public function __invoke(\stdClass $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ClassNotInContainer
|
||||
{
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ClearableService;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService;
|
||||
|
||||
class ResettableServicePassTest extends TestCase
|
||||
{
|
||||
public function testCompilerPass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('one', ResettableService::class)
|
||||
->setPublic(true)
|
||||
->addTag('kernel.reset', ['method' => 'reset']);
|
||||
$container->register('two', ClearableService::class)
|
||||
->setPublic(true)
|
||||
->addTag('kernel.reset', ['method' => 'clear']);
|
||||
|
||||
$container->register('services_resetter', ServicesResetter::class)
|
||||
->setPublic(true)
|
||||
->setArguments([null, []]);
|
||||
$container->addCompilerPass(new ResettableServicePass());
|
||||
|
||||
$container->compile();
|
||||
|
||||
$definition = $container->getDefinition('services_resetter');
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
new IteratorArgument([
|
||||
'one' => new Reference('one', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE),
|
||||
'two' => new Reference('two', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE),
|
||||
]),
|
||||
[
|
||||
'one' => 'reset',
|
||||
'two' => 'clear',
|
||||
],
|
||||
],
|
||||
$definition->getArguments()
|
||||
);
|
||||
}
|
||||
|
||||
public function testMissingMethod()
|
||||
{
|
||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException');
|
||||
$this->expectExceptionMessage('Tag kernel.reset requires the "method" attribute to be set.');
|
||||
$container = new ContainerBuilder();
|
||||
$container->register(ResettableService::class)
|
||||
->addTag('kernel.reset');
|
||||
$container->register('services_resetter', ServicesResetter::class)
|
||||
->setArguments([null, []]);
|
||||
$container->addCompilerPass(new ResettableServicePass());
|
||||
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
public function testCompilerPassWithoutResetters()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('services_resetter', ServicesResetter::class)
|
||||
->setArguments([null, []]);
|
||||
$container->addCompilerPass(new ResettableServicePass());
|
||||
|
||||
$container->compile();
|
||||
|
||||
$this->assertFalse($container->has('services_resetter'));
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ClearableService;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService;
|
||||
|
||||
class ServicesResetterTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
ResettableService::$counter = 0;
|
||||
ClearableService::$counter = 0;
|
||||
}
|
||||
|
||||
public function testResetServices()
|
||||
{
|
||||
$resetter = new ServicesResetter(new \ArrayIterator([
|
||||
'id1' => new ResettableService(),
|
||||
'id2' => new ClearableService(),
|
||||
]), [
|
||||
'id1' => 'reset',
|
||||
'id2' => 'clear',
|
||||
]);
|
||||
|
||||
$resetter->reset();
|
||||
|
||||
$this->assertEquals(1, ResettableService::$counter);
|
||||
$this->assertEquals(1, ClearableService::$counter);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Event;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;
|
||||
use Symfony\Component\HttpKernel\Tests\TestHttpKernel;
|
||||
|
||||
class FilterControllerArgumentsEventTest extends TestCase
|
||||
{
|
||||
public function testFilterControllerArgumentsEvent()
|
||||
{
|
||||
$filterController = new FilterControllerArgumentsEvent(new TestHttpKernel(), function () {}, ['test'], new Request(), 1);
|
||||
$this->assertEquals($filterController->getArguments(), ['test']);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Event;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||
use Symfony\Component\HttpKernel\Tests\TestHttpKernel;
|
||||
|
||||
class GetResponseForExceptionEventTest extends TestCase
|
||||
{
|
||||
public function testAllowSuccessfulResponseIsFalseByDefault()
|
||||
{
|
||||
$event = new GetResponseForExceptionEvent(new TestHttpKernel(), new Request(), 1, new \Exception());
|
||||
|
||||
$this->assertFalse($event->isAllowingCustomResponseCode());
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
/**
|
||||
* Test AddRequestFormatsListener class.
|
||||
*
|
||||
* @author Gildas Quemener <gildas.quemener@gmail.com>
|
||||
*/
|
||||
class AddRequestFormatsListenerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var AddRequestFormatsListener
|
||||
*/
|
||||
private $listener;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->listener = new AddRequestFormatsListener(['csv' => ['text/csv', 'text/plain']]);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->listener = null;
|
||||
}
|
||||
|
||||
public function testIsAnEventSubscriber()
|
||||
{
|
||||
$this->assertInstanceOf('Symfony\Component\EventDispatcher\EventSubscriberInterface', $this->listener);
|
||||
}
|
||||
|
||||
public function testRegisteredEvent()
|
||||
{
|
||||
$this->assertEquals(
|
||||
[KernelEvents::REQUEST => ['onKernelRequest', 1]],
|
||||
AddRequestFormatsListener::getSubscribedEvents()
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetAdditionalFormats()
|
||||
{
|
||||
$request = $this->getRequestMock();
|
||||
$event = $this->getGetResponseEventMock($request);
|
||||
|
||||
$request->expects($this->once())
|
||||
->method('setFormat')
|
||||
->with('csv', ['text/csv', 'text/plain']);
|
||||
|
||||
$this->listener->onKernelRequest($event);
|
||||
}
|
||||
|
||||
protected function getRequestMock()
|
||||
{
|
||||
return $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
|
||||
}
|
||||
|
||||
protected function getGetResponseEventMock(Request $request)
|
||||
{
|
||||
$event = $this
|
||||
->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$event->expects($this->any())
|
||||
->method('getRequest')
|
||||
->willReturn($request);
|
||||
|
||||
return $event;
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LogLevel;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\ConsoleEvents;
|
||||
use Symfony\Component\Console\Event\ConsoleEvent;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Debug\ErrorHandler;
|
||||
use Symfony\Component\Debug\ExceptionHandler;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\KernelEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\DebugHandlersListener;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class DebugHandlersListenerTest extends TestCase
|
||||
{
|
||||
public function testConfigure()
|
||||
{
|
||||
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
|
||||
$userHandler = function () {};
|
||||
$listener = new DebugHandlersListener($userHandler, $logger);
|
||||
$xHandler = new ExceptionHandler();
|
||||
$eHandler = new ErrorHandler();
|
||||
$eHandler->setExceptionHandler([$xHandler, 'handle']);
|
||||
|
||||
$exception = null;
|
||||
set_error_handler([$eHandler, 'handleError']);
|
||||
set_exception_handler([$eHandler, 'handleException']);
|
||||
try {
|
||||
$listener->configure();
|
||||
} catch (\Exception $exception) {
|
||||
}
|
||||
restore_exception_handler();
|
||||
restore_error_handler();
|
||||
|
||||
if (null !== $exception) {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$this->assertSame($userHandler, $xHandler->setHandler('var_dump'));
|
||||
|
||||
$loggers = $eHandler->setLoggers([]);
|
||||
|
||||
$this->assertArrayHasKey(E_DEPRECATED, $loggers);
|
||||
$this->assertSame([$logger, LogLevel::INFO], $loggers[E_DEPRECATED]);
|
||||
}
|
||||
|
||||
public function testConfigureForHttpKernelWithNoTerminateWithException()
|
||||
{
|
||||
$listener = new DebugHandlersListener(null);
|
||||
$eHandler = new ErrorHandler();
|
||||
$event = new KernelEvent(
|
||||
$this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(),
|
||||
Request::create('/'),
|
||||
HttpKernelInterface::MASTER_REQUEST
|
||||
);
|
||||
|
||||
$exception = null;
|
||||
$h = set_exception_handler([$eHandler, 'handleException']);
|
||||
try {
|
||||
$listener->configure($event);
|
||||
} catch (\Exception $exception) {
|
||||
}
|
||||
restore_exception_handler();
|
||||
|
||||
if (null !== $exception) {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$this->assertNull($h);
|
||||
}
|
||||
|
||||
public function testConsoleEvent()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$listener = new DebugHandlersListener(null);
|
||||
$app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
|
||||
$app->expects($this->once())->method('getHelperSet')->willReturn(new HelperSet());
|
||||
$command = new Command(__FUNCTION__);
|
||||
$command->setApplication($app);
|
||||
$event = new ConsoleEvent($command, new ArgvInput(), new ConsoleOutput());
|
||||
|
||||
$dispatcher->addSubscriber($listener);
|
||||
|
||||
$xListeners = [
|
||||
KernelEvents::REQUEST => [[$listener, 'configure']],
|
||||
ConsoleEvents::COMMAND => [[$listener, 'configure']],
|
||||
];
|
||||
$this->assertSame($xListeners, $dispatcher->getListeners());
|
||||
|
||||
$exception = null;
|
||||
$eHandler = new ErrorHandler();
|
||||
set_error_handler([$eHandler, 'handleError']);
|
||||
set_exception_handler([$eHandler, 'handleException']);
|
||||
try {
|
||||
$dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
|
||||
} catch (\Exception $exception) {
|
||||
}
|
||||
restore_exception_handler();
|
||||
restore_error_handler();
|
||||
|
||||
if (null !== $exception) {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$xHandler = $eHandler->setExceptionHandler('var_dump');
|
||||
$this->assertInstanceOf('Closure', $xHandler);
|
||||
|
||||
$app->expects($this->once())
|
||||
->method('renderException');
|
||||
|
||||
$xHandler(new \Exception());
|
||||
}
|
||||
|
||||
public function testReplaceExistingExceptionHandler()
|
||||
{
|
||||
$userHandler = function () {};
|
||||
$listener = new DebugHandlersListener($userHandler);
|
||||
$eHandler = new ErrorHandler();
|
||||
$eHandler->setExceptionHandler('var_dump');
|
||||
|
||||
$exception = null;
|
||||
set_exception_handler([$eHandler, 'handleException']);
|
||||
try {
|
||||
$listener->configure();
|
||||
} catch (\Exception $exception) {
|
||||
}
|
||||
restore_exception_handler();
|
||||
|
||||
if (null !== $exception) {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$this->assertSame($userHandler, $eHandler->setExceptionHandler('var_dump'));
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\ConsoleEvents;
|
||||
use Symfony\Component\HttpKernel\EventListener\DumpListener;
|
||||
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
|
||||
use Symfony\Component\VarDumper\Cloner\Data;
|
||||
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
|
||||
use Symfony\Component\VarDumper\VarDumper;
|
||||
|
||||
/**
|
||||
* DumpListenerTest.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class DumpListenerTest extends TestCase
|
||||
{
|
||||
public function testSubscribedEvents()
|
||||
{
|
||||
$this->assertSame(
|
||||
[ConsoleEvents::COMMAND => ['configure', 1024]],
|
||||
DumpListener::getSubscribedEvents()
|
||||
);
|
||||
}
|
||||
|
||||
public function testConfigure()
|
||||
{
|
||||
$prevDumper = VarDumper::setHandler('var_dump');
|
||||
VarDumper::setHandler($prevDumper);
|
||||
|
||||
$cloner = new MockCloner();
|
||||
$dumper = new MockDumper();
|
||||
|
||||
ob_start();
|
||||
$exception = null;
|
||||
$listener = new DumpListener($cloner, $dumper);
|
||||
|
||||
try {
|
||||
$listener->configure();
|
||||
|
||||
VarDumper::dump('foo');
|
||||
VarDumper::dump('bar');
|
||||
|
||||
$this->assertSame('+foo-+bar-', ob_get_clean());
|
||||
} catch (\Exception $exception) {
|
||||
}
|
||||
|
||||
VarDumper::setHandler($prevDumper);
|
||||
|
||||
if (null !== $exception) {
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MockCloner implements ClonerInterface
|
||||
{
|
||||
public function cloneVar($var)
|
||||
{
|
||||
return new Data([[$var.'-']]);
|
||||
}
|
||||
}
|
||||
|
||||
class MockDumper implements DataDumperInterface
|
||||
{
|
||||
public function dump(Data $data)
|
||||
{
|
||||
echo '+'.$data->getValue();
|
||||
}
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Tests\Logger;
|
||||
|
||||
/**
|
||||
* ExceptionListenerTest.
|
||||
*
|
||||
* @author Robert Schönthal <seroscho@googlemail.com>
|
||||
*
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class ExceptionListenerTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$logger = new TestLogger();
|
||||
$l = new ExceptionListener('foo', $logger);
|
||||
|
||||
$_logger = new \ReflectionProperty(\get_class($l), 'logger');
|
||||
$_logger->setAccessible(true);
|
||||
$_controller = new \ReflectionProperty(\get_class($l), 'controller');
|
||||
$_controller->setAccessible(true);
|
||||
|
||||
$this->assertSame($logger, $_logger->getValue($l));
|
||||
$this->assertSame('foo', $_controller->getValue($l));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testHandleWithoutLogger($event, $event2)
|
||||
{
|
||||
$this->iniSet('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
|
||||
|
||||
$l = new ExceptionListener('foo');
|
||||
$l->onKernelException($event);
|
||||
|
||||
$this->assertEquals(new Response('foo'), $event->getResponse());
|
||||
|
||||
try {
|
||||
$l->onKernelException($event2);
|
||||
$this->fail('RuntimeException expected');
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->assertSame('bar', $e->getMessage());
|
||||
$this->assertSame('foo', $e->getPrevious()->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testHandleWithLogger($event, $event2)
|
||||
{
|
||||
$logger = new TestLogger();
|
||||
|
||||
$l = new ExceptionListener('foo', $logger);
|
||||
$l->onKernelException($event);
|
||||
|
||||
$this->assertEquals(new Response('foo'), $event->getResponse());
|
||||
|
||||
try {
|
||||
$l->onKernelException($event2);
|
||||
$this->fail('RuntimeException expected');
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->assertSame('bar', $e->getMessage());
|
||||
$this->assertSame('foo', $e->getPrevious()->getMessage());
|
||||
}
|
||||
|
||||
$this->assertEquals(3, $logger->countErrors());
|
||||
$this->assertCount(3, $logger->getLogs('critical'));
|
||||
}
|
||||
|
||||
public function provider()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
|
||||
return [[null, null]];
|
||||
}
|
||||
|
||||
$request = new Request();
|
||||
$exception = new \Exception('foo');
|
||||
$event = new GetResponseForExceptionEvent(new TestKernel(), $request, HttpKernelInterface::MASTER_REQUEST, $exception);
|
||||
$event2 = new GetResponseForExceptionEvent(new TestKernelThatThrowsException(), $request, HttpKernelInterface::MASTER_REQUEST, $exception);
|
||||
|
||||
return [
|
||||
[$event, $event2],
|
||||
];
|
||||
}
|
||||
|
||||
public function testSubRequestFormat()
|
||||
{
|
||||
$listener = new ExceptionListener('foo', $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock());
|
||||
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) {
|
||||
return new Response($request->getRequestFormat());
|
||||
});
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->setRequestFormat('xml');
|
||||
|
||||
$event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
|
||||
$listener->onKernelException($event);
|
||||
|
||||
$response = $event->getResponse();
|
||||
$this->assertEquals('xml', $response->getContent());
|
||||
}
|
||||
|
||||
public function testCSPHeaderIsRemoved()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) {
|
||||
return new Response($request->getRequestFormat());
|
||||
});
|
||||
|
||||
$listener = new ExceptionListener('foo', $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(), true);
|
||||
|
||||
$dispatcher->addSubscriber($listener);
|
||||
|
||||
$request = Request::create('/');
|
||||
$event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
|
||||
$dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
|
||||
|
||||
$response = new Response('', 200, ['content-security-policy' => "style-src 'self'"]);
|
||||
$this->assertTrue($response->headers->has('content-security-policy'));
|
||||
|
||||
$event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
|
||||
|
||||
$this->assertFalse($response->headers->has('content-security-policy'), 'CSP header has been removed');
|
||||
$this->assertFalse($dispatcher->hasListeners(KernelEvents::RESPONSE), 'CSP removal listener has been removed');
|
||||
}
|
||||
}
|
||||
|
||||
class TestLogger extends Logger implements DebugLoggerInterface
|
||||
{
|
||||
public function countErrors()
|
||||
{
|
||||
return \count($this->logs['critical']);
|
||||
}
|
||||
}
|
||||
|
||||
class TestKernel implements HttpKernelInterface
|
||||
{
|
||||
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
|
||||
{
|
||||
return new Response('foo');
|
||||
}
|
||||
}
|
||||
|
||||
class TestKernelThatThrowsException implements HttpKernelInterface
|
||||
{
|
||||
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
|
||||
{
|
||||
throw new \RuntimeException('bar');
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\FragmentListener;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\UriSigner;
|
||||
|
||||
class FragmentListenerTest extends TestCase
|
||||
{
|
||||
public function testOnlyTriggeredOnFragmentRoute()
|
||||
{
|
||||
$request = Request::create('http://example.com/foo?_path=foo%3Dbar%26_controller%3Dfoo');
|
||||
|
||||
$listener = new FragmentListener(new UriSigner('foo'));
|
||||
$event = $this->createGetResponseEvent($request);
|
||||
|
||||
$expected = $request->attributes->all();
|
||||
|
||||
$listener->onKernelRequest($event);
|
||||
|
||||
$this->assertEquals($expected, $request->attributes->all());
|
||||
$this->assertTrue($request->query->has('_path'));
|
||||
}
|
||||
|
||||
public function testOnlyTriggeredIfControllerWasNotDefinedYet()
|
||||
{
|
||||
$request = Request::create('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo');
|
||||
$request->attributes->set('_controller', 'bar');
|
||||
|
||||
$listener = new FragmentListener(new UriSigner('foo'));
|
||||
$event = $this->createGetResponseEvent($request, HttpKernelInterface::SUB_REQUEST);
|
||||
|
||||
$expected = $request->attributes->all();
|
||||
|
||||
$listener->onKernelRequest($event);
|
||||
|
||||
$this->assertEquals($expected, $request->attributes->all());
|
||||
}
|
||||
|
||||
public function testAccessDeniedWithNonSafeMethods()
|
||||
{
|
||||
$this->expectException('Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException');
|
||||
$request = Request::create('http://example.com/_fragment', 'POST');
|
||||
|
||||
$listener = new FragmentListener(new UriSigner('foo'));
|
||||
$event = $this->createGetResponseEvent($request);
|
||||
|
||||
$listener->onKernelRequest($event);
|
||||
}
|
||||
|
||||
public function testAccessDeniedWithWrongSignature()
|
||||
{
|
||||
$this->expectException('Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException');
|
||||
$request = Request::create('http://example.com/_fragment', 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']);
|
||||
|
||||
$listener = new FragmentListener(new UriSigner('foo'));
|
||||
$event = $this->createGetResponseEvent($request);
|
||||
|
||||
$listener->onKernelRequest($event);
|
||||
}
|
||||
|
||||
public function testWithSignature()
|
||||
{
|
||||
$signer = new UriSigner('foo');
|
||||
$request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo'), 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']);
|
||||
|
||||
$listener = new FragmentListener($signer);
|
||||
$event = $this->createGetResponseEvent($request);
|
||||
|
||||
$listener->onKernelRequest($event);
|
||||
|
||||
$this->assertEquals(['foo' => 'bar', '_controller' => 'foo'], $request->attributes->get('_route_params'));
|
||||
$this->assertFalse($request->query->has('_path'));
|
||||
}
|
||||
|
||||
public function testRemovesPathWithControllerDefined()
|
||||
{
|
||||
$request = Request::create('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo');
|
||||
|
||||
$listener = new FragmentListener(new UriSigner('foo'));
|
||||
$event = $this->createGetResponseEvent($request, HttpKernelInterface::SUB_REQUEST);
|
||||
|
||||
$listener->onKernelRequest($event);
|
||||
|
||||
$this->assertFalse($request->query->has('_path'));
|
||||
}
|
||||
|
||||
public function testRemovesPathWithControllerNotDefined()
|
||||
{
|
||||
$signer = new UriSigner('foo');
|
||||
$request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar'), 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']);
|
||||
|
||||
$listener = new FragmentListener($signer);
|
||||
$event = $this->createGetResponseEvent($request);
|
||||
|
||||
$listener->onKernelRequest($event);
|
||||
|
||||
$this->assertFalse($request->query->has('_path'));
|
||||
}
|
||||
|
||||
private function createGetResponseEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST)
|
||||
{
|
||||
return new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, $requestType);
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\LocaleListener;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
class LocaleListenerTest extends TestCase
|
||||
{
|
||||
private $requestStack;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->disableOriginalConstructor()->getMock();
|
||||
}
|
||||
|
||||
public function testDefaultLocaleWithoutSession()
|
||||
{
|
||||
$listener = new LocaleListener($this->requestStack, 'fr');
|
||||
$event = $this->getEvent($request = Request::create('/'));
|
||||
|
||||
$listener->onKernelRequest($event);
|
||||
$this->assertEquals('fr', $request->getLocale());
|
||||
}
|
||||
|
||||
public function testLocaleFromRequestAttribute()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->cookies->set(session_name(), 'value');
|
||||
|
||||
$request->attributes->set('_locale', 'es');
|
||||
$listener = new LocaleListener($this->requestStack, 'fr');
|
||||
$event = $this->getEvent($request);
|
||||
|
||||
$listener->onKernelRequest($event);
|
||||
$this->assertEquals('es', $request->getLocale());
|
||||
}
|
||||
|
||||
public function testLocaleSetForRoutingContext()
|
||||
{
|
||||
// the request context is updated
|
||||
$context = $this->getMockBuilder('Symfony\Component\Routing\RequestContext')->getMock();
|
||||
$context->expects($this->once())->method('setParameter')->with('_locale', 'es');
|
||||
|
||||
$router = $this->getMockBuilder('Symfony\Component\Routing\Router')->setMethods(['getContext'])->disableOriginalConstructor()->getMock();
|
||||
$router->expects($this->once())->method('getContext')->willReturn($context);
|
||||
|
||||
$request = Request::create('/');
|
||||
|
||||
$request->attributes->set('_locale', 'es');
|
||||
$listener = new LocaleListener($this->requestStack, 'fr', $router);
|
||||
$listener->onKernelRequest($this->getEvent($request));
|
||||
}
|
||||
|
||||
public function testRouterResetWithParentRequestOnKernelFinishRequest()
|
||||
{
|
||||
// the request context is updated
|
||||
$context = $this->getMockBuilder('Symfony\Component\Routing\RequestContext')->getMock();
|
||||
$context->expects($this->once())->method('setParameter')->with('_locale', 'es');
|
||||
|
||||
$router = $this->getMockBuilder('Symfony\Component\Routing\Router')->setMethods(['getContext'])->disableOriginalConstructor()->getMock();
|
||||
$router->expects($this->once())->method('getContext')->willReturn($context);
|
||||
|
||||
$parentRequest = Request::create('/');
|
||||
$parentRequest->setLocale('es');
|
||||
|
||||
$this->requestStack->expects($this->once())->method('getParentRequest')->willReturn($parentRequest);
|
||||
|
||||
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FinishRequestEvent')->disableOriginalConstructor()->getMock();
|
||||
|
||||
$listener = new LocaleListener($this->requestStack, 'fr', $router);
|
||||
$listener->onKernelFinishRequest($event);
|
||||
}
|
||||
|
||||
public function testRequestLocaleIsNotOverridden()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->setLocale('de');
|
||||
$listener = new LocaleListener($this->requestStack, 'fr');
|
||||
$event = $this->getEvent($request);
|
||||
|
||||
$listener->onKernelRequest($event);
|
||||
$this->assertEquals('de', $request->getLocale());
|
||||
}
|
||||
|
||||
private function getEvent(Request $request)
|
||||
{
|
||||
return new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\ProfilerListener;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
use Symfony\Component\HttpKernel\Profiler\Profile;
|
||||
|
||||
class ProfilerListenerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test a master and sub request with an exception and `onlyException` profiler option enabled.
|
||||
*/
|
||||
public function testKernelTerminate()
|
||||
{
|
||||
$profile = new Profile('token');
|
||||
|
||||
$profiler = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$profiler->expects($this->once())
|
||||
->method('collect')
|
||||
->willReturn($profile);
|
||||
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
|
||||
$masterRequest = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$subRequest = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$response = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($masterRequest);
|
||||
|
||||
$onlyException = true;
|
||||
$listener = new ProfilerListener($profiler, $requestStack, null, $onlyException);
|
||||
|
||||
// master request
|
||||
$listener->onKernelResponse(new FilterResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST, $response));
|
||||
|
||||
// sub request
|
||||
$listener->onKernelException(new GetResponseForExceptionEvent($kernel, $subRequest, Kernel::SUB_REQUEST, new HttpException(404)));
|
||||
$listener->onKernelResponse(new FilterResponseEvent($kernel, $subRequest, Kernel::SUB_REQUEST, $response));
|
||||
|
||||
$listener->onKernelTerminate(new PostResponseEvent($kernel, $masterRequest, $response));
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\ResponseListener;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
class ResponseListenerTest extends TestCase
|
||||
{
|
||||
private $dispatcher;
|
||||
|
||||
private $kernel;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->dispatcher = new EventDispatcher();
|
||||
$listener = new ResponseListener('UTF-8');
|
||||
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
|
||||
|
||||
$this->kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->dispatcher = null;
|
||||
$this->kernel = null;
|
||||
}
|
||||
|
||||
public function testFilterDoesNothingForSubRequests()
|
||||
{
|
||||
$response = new Response('foo');
|
||||
|
||||
$event = new FilterResponseEvent($this->kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
|
||||
$this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
|
||||
|
||||
$this->assertEquals('', $event->getResponse()->headers->get('content-type'));
|
||||
}
|
||||
|
||||
public function testFilterSetsNonDefaultCharsetIfNotOverridden()
|
||||
{
|
||||
$listener = new ResponseListener('ISO-8859-15');
|
||||
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1);
|
||||
|
||||
$response = new Response('foo');
|
||||
|
||||
$event = new FilterResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
$this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
|
||||
|
||||
$this->assertEquals('ISO-8859-15', $response->getCharset());
|
||||
}
|
||||
|
||||
public function testFilterDoesNothingIfCharsetIsOverridden()
|
||||
{
|
||||
$listener = new ResponseListener('ISO-8859-15');
|
||||
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1);
|
||||
|
||||
$response = new Response('foo');
|
||||
$response->setCharset('ISO-8859-1');
|
||||
|
||||
$event = new FilterResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
$this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
|
||||
|
||||
$this->assertEquals('ISO-8859-1', $response->getCharset());
|
||||
}
|
||||
|
||||
public function testFiltersSetsNonDefaultCharsetIfNotOverriddenOnNonTextContentType()
|
||||
{
|
||||
$listener = new ResponseListener('ISO-8859-15');
|
||||
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1);
|
||||
|
||||
$response = new Response('foo');
|
||||
$request = Request::create('/');
|
||||
$request->setRequestFormat('application/json');
|
||||
|
||||
$event = new FilterResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
$this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
|
||||
|
||||
$this->assertEquals('ISO-8859-15', $response->getCharset());
|
||||
}
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
|
||||
use Symfony\Component\HttpKernel\EventListener\RouterListener;
|
||||
use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener;
|
||||
use Symfony\Component\HttpKernel\HttpKernel;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\Routing\Exception\NoConfigurationException;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
||||
class RouterListenerTest extends TestCase
|
||||
{
|
||||
private $requestStack;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->disableOriginalConstructor()->getMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPortData
|
||||
*/
|
||||
public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHttpPort, $expectedHttpsPort)
|
||||
{
|
||||
$urlMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\UrlMatcherInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$context = new RequestContext();
|
||||
$context->setHttpPort($defaultHttpPort);
|
||||
$context->setHttpsPort($defaultHttpsPort);
|
||||
$urlMatcher->expects($this->any())
|
||||
->method('getContext')
|
||||
->willReturn($context);
|
||||
|
||||
$listener = new RouterListener($urlMatcher, $this->requestStack);
|
||||
$event = $this->createGetResponseEventForUri($uri);
|
||||
$listener->onKernelRequest($event);
|
||||
|
||||
$this->assertEquals($expectedHttpPort, $context->getHttpPort());
|
||||
$this->assertEquals($expectedHttpsPort, $context->getHttpsPort());
|
||||
$this->assertEquals(0 === strpos($uri, 'https') ? 'https' : 'http', $context->getScheme());
|
||||
}
|
||||
|
||||
public function getPortData()
|
||||
{
|
||||
return [
|
||||
[80, 443, 'http://localhost/', 80, 443],
|
||||
[80, 443, 'http://localhost:90/', 90, 443],
|
||||
[80, 443, 'https://localhost/', 80, 443],
|
||||
[80, 443, 'https://localhost:90/', 80, 90],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
*
|
||||
* @return GetResponseEvent
|
||||
*/
|
||||
private function createGetResponseEventForUri($uri)
|
||||
{
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$request = Request::create($uri);
|
||||
$request->attributes->set('_controller', null); // Prevents going in to routing process
|
||||
|
||||
return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
}
|
||||
|
||||
public function testInvalidMatcher()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
new RouterListener(new \stdClass(), $this->requestStack);
|
||||
}
|
||||
|
||||
public function testRequestMatcher()
|
||||
{
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$request = Request::create('http://localhost/');
|
||||
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
|
||||
$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
|
||||
$requestMatcher->expects($this->once())
|
||||
->method('matchRequest')
|
||||
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
|
||||
->willReturn([]);
|
||||
|
||||
$listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext());
|
||||
$listener->onKernelRequest($event);
|
||||
}
|
||||
|
||||
public function testSubRequestWithDifferentMethod()
|
||||
{
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$request = Request::create('http://localhost/', 'post');
|
||||
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
|
||||
$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
|
||||
$requestMatcher->expects($this->any())
|
||||
->method('matchRequest')
|
||||
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
|
||||
->willReturn([]);
|
||||
|
||||
$context = new RequestContext();
|
||||
|
||||
$listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext());
|
||||
$listener->onKernelRequest($event);
|
||||
|
||||
// sub-request with another HTTP method
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$request = Request::create('http://localhost/', 'get');
|
||||
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST);
|
||||
|
||||
$listener->onKernelRequest($event);
|
||||
|
||||
$this->assertEquals('GET', $context->getMethod());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoggingParameterData
|
||||
*/
|
||||
public function testLoggingParameter($parameter, $log, $parameters)
|
||||
{
|
||||
$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
|
||||
$requestMatcher->expects($this->once())
|
||||
->method('matchRequest')
|
||||
->willReturn($parameter);
|
||||
|
||||
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
|
||||
$logger->expects($this->once())
|
||||
->method('info')
|
||||
->with($this->equalTo($log), $this->equalTo($parameters));
|
||||
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$request = Request::create('http://localhost/');
|
||||
|
||||
$listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext(), $logger);
|
||||
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
|
||||
}
|
||||
|
||||
public function getLoggingParameterData()
|
||||
{
|
||||
return [
|
||||
[['_route' => 'foo'], 'Matched route "{route}".', ['route' => 'foo', 'route_parameters' => ['_route' => 'foo'], 'request_uri' => 'http://localhost/', 'method' => 'GET']],
|
||||
[[], 'Matched route "{route}".', ['route' => 'n/a', 'route_parameters' => [], 'request_uri' => 'http://localhost/', 'method' => 'GET']],
|
||||
];
|
||||
}
|
||||
|
||||
public function testWithBadRequest()
|
||||
{
|
||||
$requestStack = new RequestStack();
|
||||
|
||||
$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
|
||||
$requestMatcher->expects($this->never())->method('matchRequest');
|
||||
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->addSubscriber(new ValidateRequestListener());
|
||||
$dispatcher->addSubscriber(new RouterListener($requestMatcher, $requestStack, new RequestContext()));
|
||||
$dispatcher->addSubscriber(new ExceptionListener(function () {
|
||||
return new Response('Exception handled', 400);
|
||||
}));
|
||||
|
||||
$kernel = new HttpKernel($dispatcher, new ControllerResolver(), $requestStack, new ArgumentResolver());
|
||||
|
||||
$request = Request::create('http://localhost/');
|
||||
$request->headers->set('host', '###');
|
||||
$response = $kernel->handle($request);
|
||||
$this->assertSame(400, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testNoRoutingConfigurationResponse()
|
||||
{
|
||||
$requestStack = new RequestStack();
|
||||
|
||||
$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
|
||||
$requestMatcher
|
||||
->expects($this->once())
|
||||
->method('matchRequest')
|
||||
->willThrowException(new NoConfigurationException())
|
||||
;
|
||||
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->addSubscriber(new RouterListener($requestMatcher, $requestStack, new RequestContext()));
|
||||
|
||||
$kernel = new HttpKernel($dispatcher, new ControllerResolver(), $requestStack, new ArgumentResolver());
|
||||
|
||||
$request = Request::create('http://localhost/');
|
||||
$response = $kernel->handle($request);
|
||||
$this->assertSame(404, $response->getStatusCode());
|
||||
$this->assertStringContainsString('Welcome', $response->getContent());
|
||||
}
|
||||
|
||||
public function testRequestWithBadHost()
|
||||
{
|
||||
$this->expectException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$request = Request::create('http://bad host %22/');
|
||||
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
|
||||
$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
|
||||
|
||||
$listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext());
|
||||
$listener->onKernelRequest($event);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\SaveSessionListener;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
class SaveSessionListenerTest extends TestCase
|
||||
{
|
||||
public function testOnlyTriggeredOnMasterRequest()
|
||||
{
|
||||
$listener = new SaveSessionListener();
|
||||
$event = $this->getMockBuilder(FilterResponseEvent::class)->disableOriginalConstructor()->getMock();
|
||||
$event->expects($this->once())->method('isMasterRequest')->willReturn(false);
|
||||
$event->expects($this->never())->method('getRequest');
|
||||
|
||||
// sub request
|
||||
$listener->onKernelResponse($event);
|
||||
}
|
||||
|
||||
public function testSessionSaved()
|
||||
{
|
||||
$listener = new SaveSessionListener();
|
||||
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$session = $this->getMockBuilder(SessionInterface::class)->disableOriginalConstructor()->getMock();
|
||||
$session->expects($this->once())->method('isStarted')->willReturn(true);
|
||||
$session->expects($this->once())->method('save');
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($session);
|
||||
$response = new Response();
|
||||
$listener->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
|
||||
use Symfony\Component\HttpKernel\EventListener\SessionListener;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
class SessionListenerTest extends TestCase
|
||||
{
|
||||
public function testOnlyTriggeredOnMasterRequest()
|
||||
{
|
||||
$listener = $this->getMockForAbstractClass(AbstractSessionListener::class);
|
||||
$event = $this->getMockBuilder(GetResponseEvent::class)->disableOriginalConstructor()->getMock();
|
||||
$event->expects($this->once())->method('isMasterRequest')->willReturn(false);
|
||||
$event->expects($this->never())->method('getRequest');
|
||||
|
||||
// sub request
|
||||
$listener->onKernelRequest($event);
|
||||
}
|
||||
|
||||
public function testSessionIsSet()
|
||||
{
|
||||
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$container = new Container();
|
||||
$container->set('session', $session);
|
||||
|
||||
$request = new Request();
|
||||
$listener = new SessionListener($container);
|
||||
|
||||
$event = $this->getMockBuilder(GetResponseEvent::class)->disableOriginalConstructor()->getMock();
|
||||
$event->expects($this->once())->method('isMasterRequest')->willReturn(true);
|
||||
$event->expects($this->once())->method('getRequest')->willReturn($request);
|
||||
|
||||
$listener->onKernelRequest($event);
|
||||
|
||||
$this->assertTrue($request->hasSession());
|
||||
$this->assertSame($session, $request->getSession());
|
||||
}
|
||||
|
||||
public function testResponseIsPrivate()
|
||||
{
|
||||
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
|
||||
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
|
||||
|
||||
$container = new Container();
|
||||
$container->set('session', $session);
|
||||
|
||||
$listener = new SessionListener($container);
|
||||
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$request = new Request();
|
||||
$response = new Response();
|
||||
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
|
||||
$listener->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
|
||||
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate'));
|
||||
$this->assertSame('0', $response->headers->getCacheControlDirective('max-age'));
|
||||
|
||||
$this->assertTrue($response->headers->has('Expires'));
|
||||
$this->assertLessThanOrEqual((new \DateTime('now', new \DateTimeZone('UTC'))), (new \DateTime($response->headers->get('Expires'))));
|
||||
}
|
||||
|
||||
public function testSurrogateMasterRequestIsPublic()
|
||||
{
|
||||
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
|
||||
$session->expects($this->exactly(4))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1, 1, 1));
|
||||
|
||||
$container = new Container();
|
||||
$container->set('session', $session);
|
||||
|
||||
$listener = new SessionListener($container);
|
||||
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$request = new Request();
|
||||
$response = new Response();
|
||||
$response->setCache(['public' => true, 'max_age' => '30']);
|
||||
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
|
||||
$this->assertTrue($request->hasSession());
|
||||
|
||||
$subRequest = clone $request;
|
||||
$this->assertSame($request->getSession(), $subRequest->getSession());
|
||||
$listener->onKernelRequest(new GetResponseEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST));
|
||||
$listener->onKernelResponse(new FilterResponseEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST, $response));
|
||||
$listener->onFinishRequest(new FinishRequestEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST));
|
||||
|
||||
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
|
||||
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
|
||||
$this->assertSame('30', $response->headers->getCacheControlDirective('max-age'));
|
||||
|
||||
$this->assertFalse($response->headers->has('Expires'));
|
||||
|
||||
$listener->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
|
||||
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate'));
|
||||
$this->assertSame('0', $response->headers->getCacheControlDirective('max-age'));
|
||||
|
||||
$this->assertTrue($response->headers->has('Expires'));
|
||||
$this->assertLessThanOrEqual((new \DateTime('now', new \DateTimeZone('UTC'))), (new \DateTime($response->headers->get('Expires'))));
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\SurrogateListener;
|
||||
use Symfony\Component\HttpKernel\HttpCache\Esi;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
class SurrogateListenerTest extends TestCase
|
||||
{
|
||||
public function testFilterDoesNothingForSubRequests()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$response = new Response('foo <esi:include src="" />');
|
||||
$listener = new SurrogateListener(new Esi());
|
||||
|
||||
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
|
||||
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
|
||||
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
|
||||
|
||||
$this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control'));
|
||||
}
|
||||
|
||||
public function testFilterWhenThereIsSomeEsiIncludes()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$response = new Response('foo <esi:include src="" />');
|
||||
$listener = new SurrogateListener(new Esi());
|
||||
|
||||
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
|
||||
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
|
||||
|
||||
$this->assertEquals('content="ESI/1.0"', $event->getResponse()->headers->get('Surrogate-Control'));
|
||||
}
|
||||
|
||||
public function testFilterWhenThereIsNoEsiIncludes()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$response = new Response('foo');
|
||||
$listener = new SurrogateListener(new Esi());
|
||||
|
||||
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
|
||||
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
|
||||
|
||||
$this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control'));
|
||||
}
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\SessionListener;
|
||||
use Symfony\Component\HttpKernel\EventListener\TestSessionListener;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
/**
|
||||
* SessionListenerTest.
|
||||
*
|
||||
* Tests SessionListener.
|
||||
*
|
||||
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
|
||||
*/
|
||||
class TestSessionListenerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var TestSessionListener
|
||||
*/
|
||||
private $listener;
|
||||
|
||||
/**
|
||||
* @var SessionInterface
|
||||
*/
|
||||
private $session;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->listener = $this->getMockForAbstractClass('Symfony\Component\HttpKernel\EventListener\AbstractTestSessionListener');
|
||||
$this->session = $this->getSession();
|
||||
$this->listener->expects($this->any())
|
||||
->method('getSession')
|
||||
->willReturn($this->session);
|
||||
}
|
||||
|
||||
public function testShouldSaveMasterRequestSession()
|
||||
{
|
||||
$this->sessionHasBeenStarted();
|
||||
$this->sessionMustBeSaved();
|
||||
|
||||
$this->filterResponse(new Request());
|
||||
}
|
||||
|
||||
public function testShouldNotSaveSubRequestSession()
|
||||
{
|
||||
$this->sessionMustNotBeSaved();
|
||||
|
||||
$this->filterResponse(new Request(), HttpKernelInterface::SUB_REQUEST);
|
||||
}
|
||||
|
||||
public function testDoesNotDeleteCookieIfUsingSessionLifetime()
|
||||
{
|
||||
$this->sessionHasBeenStarted();
|
||||
|
||||
@ini_set('session.cookie_lifetime', 0);
|
||||
|
||||
$response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST);
|
||||
$cookies = $response->headers->getCookies();
|
||||
|
||||
$this->assertEquals(0, reset($cookies)->getExpiresTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires function \Symfony\Component\HttpFoundation\Session\Session::isEmpty
|
||||
*/
|
||||
public function testEmptySessionDoesNotSendCookie()
|
||||
{
|
||||
$this->sessionHasBeenStarted();
|
||||
$this->sessionIsEmpty();
|
||||
|
||||
$response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST);
|
||||
|
||||
$this->assertSame([], $response->headers->getCookies());
|
||||
}
|
||||
|
||||
public function testEmptySessionWithNewSessionIdDoesSendCookie()
|
||||
{
|
||||
$this->sessionHasBeenStarted();
|
||||
$this->sessionIsEmpty();
|
||||
$this->fixSessionId('456');
|
||||
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']);
|
||||
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
$this->listener->onKernelRequest($event);
|
||||
|
||||
$response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST);
|
||||
|
||||
$this->assertNotEmpty($response->headers->getCookies());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider anotherCookieProvider
|
||||
*/
|
||||
public function testSessionWithNewSessionIdAndNewCookieDoesNotSendAnotherCookie($existing, array $expected)
|
||||
{
|
||||
$this->sessionHasBeenStarted();
|
||||
$this->sessionIsEmpty();
|
||||
$this->fixSessionId('456');
|
||||
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']);
|
||||
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
$this->listener->onKernelRequest($event);
|
||||
|
||||
$response = new Response('', 200, ['Set-Cookie' => $existing]);
|
||||
|
||||
$response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
|
||||
$this->assertSame($expected, $response->headers->get('Set-Cookie', null, false));
|
||||
}
|
||||
|
||||
public function anotherCookieProvider()
|
||||
{
|
||||
return [
|
||||
'same' => ['MOCKSESSID=789; path=/', ['MOCKSESSID=789; path=/']],
|
||||
'different domain' => ['MOCKSESSID=789; path=/; domain=example.com', ['MOCKSESSID=789; path=/; domain=example.com', 'MOCKSESSID=456; path=/']],
|
||||
'different path' => ['MOCKSESSID=789; path=/foo', ['MOCKSESSID=789; path=/foo', 'MOCKSESSID=456; path=/']],
|
||||
];
|
||||
}
|
||||
|
||||
public function testUnstartedSessionIsNotSave()
|
||||
{
|
||||
$this->sessionHasNotBeenStarted();
|
||||
$this->sessionMustNotBeSaved();
|
||||
|
||||
$this->filterResponse(new Request());
|
||||
}
|
||||
|
||||
public function testDoesNotImplementServiceSubscriberInterface()
|
||||
{
|
||||
$this->assertTrue(interface_exists(ServiceSubscriberInterface::class));
|
||||
$this->assertTrue(class_exists(SessionListener::class));
|
||||
$this->assertTrue(class_exists(TestSessionListener::class));
|
||||
$this->assertFalse(is_subclass_of(SessionListener::class, ServiceSubscriberInterface::class), 'Implementing ServiceSubscriberInterface would create a dep on the DI component, which eg Silex cannot afford');
|
||||
$this->assertFalse(is_subclass_of(TestSessionListener::class, ServiceSubscriberInterface::class, 'Implementing ServiceSubscriberInterface would create a dep on the DI component, which eg Silex cannot afford'));
|
||||
}
|
||||
|
||||
private function filterResponse(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, Response $response = null)
|
||||
{
|
||||
$request->setSession($this->session);
|
||||
$response = $response ?: new Response();
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$event = new FilterResponseEvent($kernel, $request, $type, $response);
|
||||
|
||||
$this->listener->onKernelResponse($event);
|
||||
|
||||
$this->assertSame($response, $event->getResponse());
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function sessionMustNotBeSaved()
|
||||
{
|
||||
$this->session->expects($this->never())
|
||||
->method('save');
|
||||
}
|
||||
|
||||
private function sessionMustBeSaved()
|
||||
{
|
||||
$this->session->expects($this->once())
|
||||
->method('save');
|
||||
}
|
||||
|
||||
private function sessionHasBeenStarted()
|
||||
{
|
||||
$this->session->expects($this->once())
|
||||
->method('isStarted')
|
||||
->willReturn(true);
|
||||
}
|
||||
|
||||
private function sessionHasNotBeenStarted()
|
||||
{
|
||||
$this->session->expects($this->once())
|
||||
->method('isStarted')
|
||||
->willReturn(false);
|
||||
}
|
||||
|
||||
private function sessionIsEmpty()
|
||||
{
|
||||
$this->session->expects($this->once())
|
||||
->method('isEmpty')
|
||||
->willReturn(true);
|
||||
}
|
||||
|
||||
private function fixSessionId($sessionId)
|
||||
{
|
||||
$this->session->expects($this->any())
|
||||
->method('getId')
|
||||
->willReturn($sessionId);
|
||||
}
|
||||
|
||||
private function getSession()
|
||||
{
|
||||
$mock = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
// set return value for getName()
|
||||
$mock->expects($this->any())->method('getName')->willReturn('MOCKSESSID');
|
||||
|
||||
return $mock;
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\TranslatorListener;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
class TranslatorListenerTest extends TestCase
|
||||
{
|
||||
private $listener;
|
||||
private $translator;
|
||||
private $requestStack;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock();
|
||||
$this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
|
||||
$this->listener = new TranslatorListener($this->translator, $this->requestStack);
|
||||
}
|
||||
|
||||
public function testLocaleIsSetInOnKernelRequest()
|
||||
{
|
||||
$this->translator
|
||||
->expects($this->once())
|
||||
->method('setLocale')
|
||||
->with($this->equalTo('fr'));
|
||||
|
||||
$event = new GetResponseEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
|
||||
$this->listener->onKernelRequest($event);
|
||||
}
|
||||
|
||||
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
|
||||
{
|
||||
$this->translator
|
||||
->expects($this->at(0))
|
||||
->method('setLocale')
|
||||
->willThrowException(new \InvalidArgumentException());
|
||||
$this->translator
|
||||
->expects($this->at(1))
|
||||
->method('setLocale')
|
||||
->with($this->equalTo('en'));
|
||||
|
||||
$event = new GetResponseEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
|
||||
$this->listener->onKernelRequest($event);
|
||||
}
|
||||
|
||||
public function testLocaleIsSetInOnKernelFinishRequestWhenParentRequestExists()
|
||||
{
|
||||
$this->translator
|
||||
->expects($this->once())
|
||||
->method('setLocale')
|
||||
->with($this->equalTo('fr'));
|
||||
|
||||
$this->setMasterRequest($this->createRequest('fr'));
|
||||
$event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST);
|
||||
$this->listener->onKernelFinishRequest($event);
|
||||
}
|
||||
|
||||
public function testLocaleIsNotSetInOnKernelFinishRequestWhenParentRequestDoesNotExist()
|
||||
{
|
||||
$this->translator
|
||||
->expects($this->never())
|
||||
->method('setLocale');
|
||||
|
||||
$event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST);
|
||||
$this->listener->onKernelFinishRequest($event);
|
||||
}
|
||||
|
||||
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
|
||||
{
|
||||
$this->translator
|
||||
->expects($this->at(0))
|
||||
->method('setLocale')
|
||||
->willThrowException(new \InvalidArgumentException());
|
||||
$this->translator
|
||||
->expects($this->at(1))
|
||||
->method('setLocale')
|
||||
->with($this->equalTo('en'));
|
||||
|
||||
$this->setMasterRequest($this->createRequest('fr'));
|
||||
$event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST);
|
||||
$this->listener->onKernelFinishRequest($event);
|
||||
}
|
||||
|
||||
private function createHttpKernel()
|
||||
{
|
||||
return $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
}
|
||||
|
||||
private function createRequest($locale)
|
||||
{
|
||||
$request = new Request();
|
||||
$request->setLocale($locale);
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
private function setMasterRequest($request)
|
||||
{
|
||||
$this->requestStack
|
||||
->expects($this->any())
|
||||
->method('getParentRequest')
|
||||
->willReturn($request);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
class ValidateRequestListenerTest extends TestCase
|
||||
{
|
||||
protected function tearDown()
|
||||
{
|
||||
Request::setTrustedProxies([], -1);
|
||||
}
|
||||
|
||||
public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps()
|
||||
{
|
||||
$this->expectException('Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException');
|
||||
$dispatcher = new EventDispatcher();
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
|
||||
$request = new Request();
|
||||
$request->setTrustedProxies(['1.1.1.1'], Request::HEADER_X_FORWARDED_FOR | Request::HEADER_FORWARDED);
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('FORWARDED', 'for=2.2.2.2');
|
||||
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
|
||||
|
||||
$dispatcher->addListener(KernelEvents::REQUEST, [new ValidateRequestListener(), 'onKernelRequest']);
|
||||
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
|
||||
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
|
||||
class AccessDeniedHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
protected function createException()
|
||||
{
|
||||
return new AccessDeniedHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
class BadRequestHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
protected function createException()
|
||||
{
|
||||
return new BadRequestHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
||||
|
||||
class ConflictHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
protected function createException()
|
||||
{
|
||||
return new ConflictHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\GoneHttpException;
|
||||
|
||||
class GoneHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
protected function createException()
|
||||
{
|
||||
return new GoneHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class HttpExceptionTest extends TestCase
|
||||
{
|
||||
public function headerDataProvider()
|
||||
{
|
||||
return [
|
||||
[['X-Test' => 'Test']],
|
||||
[['X-Test' => 1]],
|
||||
[
|
||||
[
|
||||
['X-Test' => 'Test'],
|
||||
['X-Test-2' => 'Test-2'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testHeadersDefault()
|
||||
{
|
||||
$exception = $this->createException();
|
||||
$this->assertSame([], $exception->getHeaders());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider headerDataProvider
|
||||
*/
|
||||
public function testHeadersConstructor($headers)
|
||||
{
|
||||
$exception = new HttpException(200, null, null, $headers);
|
||||
$this->assertSame($headers, $exception->getHeaders());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider headerDataProvider
|
||||
*/
|
||||
public function testHeadersSetter($headers)
|
||||
{
|
||||
$exception = $this->createException();
|
||||
$exception->setHeaders($headers);
|
||||
$this->assertSame($headers, $exception->getHeaders());
|
||||
}
|
||||
|
||||
protected function createException()
|
||||
{
|
||||
return new HttpException(200);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\LengthRequiredHttpException;
|
||||
|
||||
class LengthRequiredHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
protected function createException()
|
||||
{
|
||||
return new LengthRequiredHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||
|
||||
class MethodNotAllowedHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
public function testHeadersDefault()
|
||||
{
|
||||
$exception = new MethodNotAllowedHttpException(['GET', 'PUT']);
|
||||
$this->assertSame(['Allow' => 'GET, PUT'], $exception->getHeaders());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider headerDataProvider
|
||||
*/
|
||||
public function testHeadersSetter($headers)
|
||||
{
|
||||
$exception = new MethodNotAllowedHttpException(['GET']);
|
||||
$exception->setHeaders($headers);
|
||||
$this->assertSame($headers, $exception->getHeaders());
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
|
||||
|
||||
class NotAcceptableHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
protected function createException()
|
||||
{
|
||||
return new NotAcceptableHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class NotFoundHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
protected function createException()
|
||||
{
|
||||
return new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException;
|
||||
|
||||
class PreconditionFailedHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
protected function createException()
|
||||
{
|
||||
return new PreconditionFailedHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\PreconditionRequiredHttpException;
|
||||
|
||||
class PreconditionRequiredHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
protected function createException()
|
||||
{
|
||||
return new PreconditionRequiredHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
|
||||
|
||||
class ServiceUnavailableHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
public function testHeadersDefaultRetryAfter()
|
||||
{
|
||||
$exception = new ServiceUnavailableHttpException(10);
|
||||
$this->assertSame(['Retry-After' => 10], $exception->getHeaders());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider headerDataProvider
|
||||
*/
|
||||
public function testHeadersSetter($headers)
|
||||
{
|
||||
$exception = new ServiceUnavailableHttpException(10);
|
||||
$exception->setHeaders($headers);
|
||||
$this->assertSame($headers, $exception->getHeaders());
|
||||
}
|
||||
|
||||
protected function createException()
|
||||
{
|
||||
return new ServiceUnavailableHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
|
||||
|
||||
class TooManyRequestsHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
public function testHeadersDefaultRertyAfter()
|
||||
{
|
||||
$exception = new TooManyRequestsHttpException(10);
|
||||
$this->assertSame(['Retry-After' => 10], $exception->getHeaders());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider headerDataProvider
|
||||
*/
|
||||
public function testHeadersSetter($headers)
|
||||
{
|
||||
$exception = new TooManyRequestsHttpException(10);
|
||||
$exception->setHeaders($headers);
|
||||
$this->assertSame($headers, $exception->getHeaders());
|
||||
}
|
||||
|
||||
protected function createException()
|
||||
{
|
||||
return new TooManyRequestsHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
class UnauthorizedHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
public function testHeadersDefault()
|
||||
{
|
||||
$exception = new UnauthorizedHttpException('Challenge');
|
||||
$this->assertSame(['WWW-Authenticate' => 'Challenge'], $exception->getHeaders());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider headerDataProvider
|
||||
*/
|
||||
public function testHeadersSetter($headers)
|
||||
{
|
||||
$exception = new UnauthorizedHttpException('Challenge');
|
||||
$exception->setHeaders($headers);
|
||||
$this->assertSame($headers, $exception->getHeaders());
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
|
||||
class UnprocessableEntityHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
protected function createException()
|
||||
{
|
||||
return new UnprocessableEntityHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
|
||||
|
||||
class UnsupportedMediaTypeHttpExceptionTest extends HttpExceptionTest
|
||||
{
|
||||
protected function createException()
|
||||
{
|
||||
return new UnsupportedMediaTypeHttpException();
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\_123;
|
||||
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
class Kernel123 extends Kernel
|
||||
{
|
||||
public function registerBundles()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function registerContainerConfiguration(LoaderInterface $loader)
|
||||
{
|
||||
}
|
||||
|
||||
public function getCacheDir()
|
||||
{
|
||||
return sys_get_temp_dir().'/'.Kernel::VERSION.'/kernel123/cache/'.$this->environment;
|
||||
}
|
||||
|
||||
public function getLogDir()
|
||||
{
|
||||
return sys_get_temp_dir().'/'.Kernel::VERSION.'/kernel123/logs';
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures;
|
||||
|
||||
class ClearableService
|
||||
{
|
||||
public static $counter = 0;
|
||||
|
||||
public function clear()
|
||||
{
|
||||
++self::$counter;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\Controller;
|
||||
|
||||
class BasicTypesController
|
||||
{
|
||||
public function action(string $foo, int $bar, float $baz)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class ExtendingRequest extends Request
|
||||
{
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
|
||||
class ExtendingSession extends Session
|
||||
{
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\Controller;
|
||||
|
||||
class NullableController
|
||||
{
|
||||
public function action(?string $foo, ?\stdClass $bar, ?string $baz = 'value', $mandatory)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\Controller;
|
||||
|
||||
class VariadicController
|
||||
{
|
||||
public function action($foo, ...$bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\DataCollector;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
|
||||
|
||||
class CloneVarDataCollector extends DataCollector
|
||||
{
|
||||
private $varToClone;
|
||||
|
||||
public function __construct($varToClone)
|
||||
{
|
||||
$this->varToClone = $varToClone;
|
||||
}
|
||||
|
||||
public function collect(Request $request, Response $response, \Exception $exception = null)
|
||||
{
|
||||
$this->data = $this->cloneVar($this->varToClone);
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->data = [];
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'clone_var';
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class ExtensionAbsentBundle extends Bundle
|
||||
{
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\DependencyInjection;
|
||||
|
||||
class ExtensionNotValidExtension
|
||||
{
|
||||
public function getAlias()
|
||||
{
|
||||
return 'extension_not_valid';
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class ExtensionNotValidBundle extends Bundle
|
||||
{
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class FooCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('foo');
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
|
||||
class ExtensionPresentExtension extends Extension
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class ExtensionPresentBundle extends Bundle
|
||||
{
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
class KernelForOverrideName extends Kernel
|
||||
{
|
||||
protected $name = 'overridden';
|
||||
|
||||
public function registerBundles()
|
||||
{
|
||||
}
|
||||
|
||||
public function registerContainerConfiguration(LoaderInterface $loader)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
class KernelForTest extends Kernel
|
||||
{
|
||||
public function getBundleMap()
|
||||
{
|
||||
return $this->bundleMap;
|
||||
}
|
||||
|
||||
public function registerBundles()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function registerContainerConfiguration(LoaderInterface $loader)
|
||||
{
|
||||
}
|
||||
|
||||
public function isBooted()
|
||||
{
|
||||
return $this->booted;
|
||||
}
|
||||
|
||||
public function getProjectDir()
|
||||
{
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
class KernelWithoutBundles extends Kernel
|
||||
{
|
||||
public function registerBundles()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function registerContainerConfiguration(LoaderInterface $loader)
|
||||
{
|
||||
}
|
||||
|
||||
protected function build(ContainerBuilder $container)
|
||||
{
|
||||
$container->setParameter('test_executed', true);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures;
|
||||
|
||||
class ResettableService
|
||||
{
|
||||
public static $counter = 0;
|
||||
|
||||
public function reset()
|
||||
{
|
||||
++self::$counter;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\HttpKernel\Client;
|
||||
|
||||
class TestClient extends Client
|
||||
{
|
||||
protected function getScript($request)
|
||||
{
|
||||
$script = parent::getScript($request);
|
||||
|
||||
$autoload = file_exists(__DIR__.'/../../vendor/autoload.php')
|
||||
? __DIR__.'/../../vendor/autoload.php'
|
||||
: __DIR__.'/../../../../../../vendor/autoload.php'
|
||||
;
|
||||
|
||||
$script = preg_replace('/(\->register\(\);)/', "$0\nrequire_once '$autoload';\n", $script);
|
||||
|
||||
return $script;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user