Laravel 5.6 updates

Travis config update

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

View File

@@ -12,11 +12,8 @@
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
@@ -31,24 +28,6 @@ class BundleTest extends TestCase
);
}
/**
* @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));
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface
@@ -59,20 +38,6 @@ class BundleTest extends TestCase
$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();

View File

@@ -39,21 +39,6 @@ class ChainCacheClearerTest extends TestCase
$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();

View File

@@ -45,25 +45,4 @@ class Psr6CacheClearerTest extends TestCase
{
(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(array('pool1' => $pool1));
$clearer->addPool($pool2);
$clearer->clear('');
}
}

View File

@@ -38,34 +38,6 @@ class CacheWarmerAggregateTest extends TestCase
$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(array($warmer));
$aggregate->warmUp(self::$cacheDir);
}
public function testWarmupDoesCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsEnabled()
{
$warmer = $this->getCacheWarmerMock();

View File

@@ -100,8 +100,8 @@ class ClientTest extends TestCase
$client = new Client($kernel);
$files = array(
array('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),
array('tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => null, 'error' => UPLOAD_ERR_OK),
new UploadedFile($source, 'original', 'mime/original', UPLOAD_ERR_OK, true),
);
$file = null;
@@ -116,8 +116,7 @@ class ClientTest extends TestCase
$this->assertEquals('original', $file->getClientOriginalName());
$this->assertEquals('mime/original', $file->getClientMimeType());
$this->assertSame(1, $file->getClientSize());
$this->assertTrue($file->isValid());
$this->assertEquals(1, $file->getSize());
}
$file->move(\dirname($target), basename($target));
@@ -150,15 +149,19 @@ class ClientTest extends TestCase
$file = $this
->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
->setConstructorArgs(array($source, 'original', 'mime/original', 123, UPLOAD_ERR_OK, true))
->setMethods(array('getSize'))
->setConstructorArgs(array($source, 'original', 'mime/original', UPLOAD_ERR_OK, true))
->setMethods(array('getSize', 'getClientSize'))
->getMock()
;
$file->expects($this->once())
/* should be modified when the getClientSize will be removed */
$file->expects($this->any())
->method('getSize')
->will($this->returnValue(INF))
;
$file->expects($this->any())
->method('getClientSize')
->will($this->returnValue(INF))
;
$client->request('POST', '/', array(), array($file));
@@ -172,7 +175,7 @@ class ClientTest extends TestCase
$this->assertEquals(UPLOAD_ERR_INI_SIZE, $file->getError());
$this->assertEquals('mime/original', $file->getClientMimeType());
$this->assertEquals('original', $file->getClientOriginalName());
$this->assertEquals(0, $file->getClientSize());
$this->assertEquals(0, $file->getSize());
unlink($source);
}

View File

@@ -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 = array(
$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(
array('prefix' => $this->prefix, 'variables' => $this->initialEnv),
$this->resource->getResource(),
'->getResource() returns the resource'
);
}
public function testToString()
{
$this->assertSame(
serialize(array('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)));
}
}

View File

@@ -12,10 +12,12 @@
namespace Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\ServiceValueResolver;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
class ServiceValueResolverTest extends TestCase
{
@@ -85,6 +87,25 @@ class ServiceValueResolverTest extends TestCase
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Cannot autowire argument $dummy of "Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver\DummyController::index()": it references class "Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver\DummyService" but no such service exists.
*/
public function testErrorIsTruncated()
{
$container = new ContainerBuilder();
$container->addCompilerPass(new RegisterControllerArgumentLocatorsPass());
$container->register('argument_resolver.service', ServiceValueResolver::class)->addArgument(null)->setPublic(true);
$container->register(DummyController::class)->addTag('controller.service_arguments')->setPublic(true);
$container->compile();
$request = $this->requestWithAttributes(array('_controller' => array(DummyController::class, 'index')));
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
$container->get('argument_resolver.service')->resolve($request, $argument)->current();
}
private function requestWithAttributes(array $attributes)
{
$request = Request::create('/');
@@ -110,3 +131,10 @@ class ServiceValueResolverTest extends TestCase
class DummyService
{
}
class DummyController
{
public function index(DummyService $dummy)
{
}
}

View File

@@ -0,0 +1,76 @@
<?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\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\TraceableValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use Symfony\Component\Stopwatch\Stopwatch;
class TraceableValueResolverTest extends TestCase
{
public function testTimingsInSupports()
{
$stopwatch = new Stopwatch();
$resolver = new TraceableValueResolver(new ResolverStub(), $stopwatch);
$argument = new ArgumentMetadata('dummy', 'string', false, false, null);
$request = new Request();
$this->assertTrue($resolver->supports($request, $argument));
$event = $stopwatch->getEvent(ResolverStub::class.'::supports');
$this->assertCount(1, $event->getPeriods());
}
public function testTimingsInResolve()
{
$stopwatch = new Stopwatch();
$resolver = new TraceableValueResolver(new ResolverStub(), $stopwatch);
$argument = new ArgumentMetadata('dummy', 'string', false, false, null);
$request = new Request();
$iterable = $resolver->resolve($request, $argument);
foreach ($iterable as $index => $resolved) {
$event = $stopwatch->getEvent(ResolverStub::class.'::resolve');
$this->assertTrue($event->isStarted());
$this->assertEmpty($event->getPeriods());
switch ($index) {
case 0:
$this->assertEquals('first', $resolved);
break;
case 1:
$this->assertEquals('second', $resolved);
break;
}
}
$event = $stopwatch->getEvent(ResolverStub::class.'::resolve');
$this->assertCount(1, $event->getPeriods());
}
}
class ResolverStub implements ArgumentValueResolverInterface
{
public function supports(Request $request, ArgumentMetadata $argument)
{
return true;
}
public function resolve(Request $request, ArgumentMetadata $argument)
{
yield 'first';
yield 'second';
}
}

View File

@@ -152,9 +152,6 @@ class ArgumentResolverTest extends TestCase
$this->assertEquals(array($request), self::$resolver->getArguments($request, $controller), '->getArguments() injects the request when extended');
}
/**
* @requires PHP 5.6
*/
public function testGetVariadicArguments()
{
$request = Request::create('/');
@@ -166,7 +163,6 @@ class ArgumentResolverTest extends TestCase
}
/**
* @requires PHP 5.6
* @expectedException \InvalidArgumentException
*/
public function testGetVariadicArgumentsWithoutArrayInRequest()
@@ -180,7 +176,6 @@ class ArgumentResolverTest extends TestCase
}
/**
* @requires PHP 5.6
* @expectedException \InvalidArgumentException
*/
public function testGetArgumentWithoutArray()
@@ -210,9 +205,6 @@ class ArgumentResolverTest extends TestCase
self::$resolver->getArguments($request, $controller);
}
/**
* @requires PHP 7.1
*/
public function testGetNullableArguments()
{
$request = Request::create('/');
@@ -224,9 +216,6 @@ class ArgumentResolverTest extends TestCase
$this->assertEquals(array('foo', new \stdClass(), 'value', 'mandatory'), self::$resolver->getArguments($request, $controller));
}
/**
* @requires PHP 7.1
*/
public function testGetNullableArgumentsWithDefaults()
{
$request = Request::create('/');

View File

@@ -13,15 +13,20 @@ 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()
/**
* @group legacy
* @expectedDeprecation Referencing controllers with a single colon is deprecated since Symfony 4.1. Use foo::action instead.
*/
public function testGetControllerServiceWithSingleColon()
{
$service = new ControllerTestService('foo');
$container = $this->createMockContainer();
$container->expects($this->once())
->method('has')
@@ -30,22 +35,47 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$container->expects($this->once())
->method('get')
->with('foo')
->will($this->returnValue($this))
->will($this->returnValue($service))
;
$resolver = $this->createControllerResolver(null, $container);
$request = Request::create('/');
$request->attributes->set('_controller', 'foo:controllerMethod1');
$request->attributes->set('_controller', 'foo:action');
$controller = $resolver->getController($request);
$this->assertInstanceOf(\get_class($this), $controller[0]);
$this->assertSame('controllerMethod1', $controller[1]);
$this->assertSame($service, $controller[0]);
$this->assertSame('action', $controller[1]);
}
public function testGetControllerService()
{
$service = new ControllerTestService('foo');
$container = $this->createMockContainer();
$container->expects($this->once())
->method('has')
->with('foo')
->will($this->returnValue(true));
$container->expects($this->once())
->method('get')
->with('foo')
->will($this->returnValue($service))
;
$resolver = $this->createControllerResolver(null, $container);
$request = Request::create('/');
$request->attributes->set('_controller', 'foo::action');
$controller = $resolver->getController($request);
$this->assertSame($service, $controller[0]);
$this->assertSame('action', $controller[1]);
}
public function testGetControllerInvokableService()
{
$invokableController = new InvokableController('bar');
$service = new InvokableControllerService('bar');
$container = $this->createMockContainer();
$container->expects($this->once())
@@ -56,7 +86,7 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$container->expects($this->once())
->method('get')
->with('foo')
->will($this->returnValue($invokableController))
->will($this->returnValue($service))
;
$resolver = $this->createControllerResolver(null, $container);
@@ -65,128 +95,72 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$controller = $resolver->getController($request);
$this->assertEquals($invokableController, $controller);
$this->assertSame($service, $controller);
}
public function testGetControllerInvokableServiceWithClassNameAsName()
{
$invokableController = new InvokableController('bar');
$className = __NAMESPACE__.'\InvokableController';
$service = new InvokableControllerService('bar');
$container = $this->createMockContainer();
$container->expects($this->once())
->method('has')
->with($className)
->with(InvokableControllerService::class)
->will($this->returnValue(true))
;
$container->expects($this->once())
->method('get')
->with($className)
->will($this->returnValue($invokableController))
->with(InvokableControllerService::class)
->will($this->returnValue($service))
;
$resolver = $this->createControllerResolver(null, $container);
$request = Request::create('/');
$request->attributes->set('_controller', $className);
$request->attributes->set('_controller', InvokableControllerService::class);
$controller = $resolver->getController($request);
$this->assertEquals($invokableController, $controller);
}
public function testNonInstantiableController()
{
$container = $this->createMockContainer();
$container->expects($this->once())
->method('has')
->with(NonInstantiableController::class)
->will($this->returnValue(false))
;
$resolver = $this->createControllerResolver(null, $container);
$request = Request::create('/');
$request->attributes->set('_controller', array(NonInstantiableController::class, 'action'));
$controller = $resolver->getController($request);
$this->assertSame(array(NonInstantiableController::class, 'action'), $controller);
$this->assertSame($service, $controller);
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage 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"?
* Tests where the fallback instantiation fails due to required constructor arguments.
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Controller "Symfony\Component\HttpKernel\Tests\Controller\ControllerTestService" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?
*/
public function testNonConstructController()
public function testExceptionWhenUsingRemovedControllerServiceWithClassNameAsName()
{
$container = $this->getMockBuilder(Container::class)->getMock();
$container->expects($this->at(0))
$container->expects($this->once())
->method('has')
->with(ImpossibleConstructController::class)
->will($this->returnValue(true))
;
$container->expects($this->at(1))
->method('has')
->with(ImpossibleConstructController::class)
->with(ControllerTestService::class)
->will($this->returnValue(false))
;
$container->expects($this->atLeastOnce())
->method('getRemovedIds')
->with()
->will($this->returnValue(array(ImpossibleConstructController::class => true)))
->will($this->returnValue(array(ControllerTestService::class => true)))
;
$resolver = $this->createControllerResolver(null, $container);
$request = Request::create('/');
$request->attributes->set('_controller', array(ImpossibleConstructController::class, 'action'));
$request->attributes->set('_controller', array(ControllerTestService::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)
->will($this->returnValue(true))
;
$container->expects($this->atLeastOnce())
->method('get')
->with(NonInstantiableController::class)
->will($this->returnValue($service))
;
$resolver = $this->createControllerResolver(null, $container);
$request = Request::create('/');
$request->attributes->set('_controller', array(NonInstantiableController::class, 'action'));
$controller = $resolver->getController($request);
$this->assertSame(array($service, 'action'), $controller);
$resolver->getController($request);
}
/**
* @expectedException \LogicException
* Tests where the fallback instantiation fails due to non-existing class.
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage 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"?
*/
public function testExceptionWhenUsingRemovedControllerService()
{
$container = $this->getMockBuilder(Container::class)->getMock();
$container->expects($this->at(0))
$container->expects($this->once())
->method('has')
->with('app.my_controller')
->will($this->returnValue(false))
@@ -205,62 +179,28 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$resolver->getController($request);
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage Controller "app.my_controller" cannot be called without a method name. Did you forget an "__invoke" method?
*/
public function testExceptionWhenUsingControllerWithoutAnInvokeMethod()
{
$container = $this->getMockBuilder(Container::class)->getMock();
$container->expects($this->once())
->method('has')
->with('app.my_controller')
->will($this->returnValue(true))
;
$container->expects($this->once())
->method('get')
->with('app.my_controller')
->will($this->returnValue(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();
if (method_exists($this, 'expectException')) {
$this->expectException($exceptionName);
$this->expectExceptionMessageRegExp($exceptionMessage);
} else {
$this->setExpectedExceptionRegExp($exceptionName, $exceptionMessage);
}
$request = Request::create('/');
$request->attributes->set('_controller', $controller);
$resolver->getController($request);
}
public function getUndefinedControllers()
{
return array(
array('foo', \LogicException::class, '/Controller not found: service "foo" does not exist\./'),
array('oof::bar', \InvalidArgumentException::class, '/Class "oof" does not exist\./'),
array('stdClass', \LogicException::class, '/Controller not found: service "stdClass" does not exist\./'),
array(
'Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest::bar',
\InvalidArgumentException::class,
'/.?[cC]ontroller(.*?) for URI "\/" is not callable\.( Expected method(.*) Available methods)?/',
),
$tests = parent::getUndefinedControllers();
$tests[0] = array('foo', \InvalidArgumentException::class, 'Controller "foo" does neither exist as service nor as class');
$tests[1] = array('oof::bar', \InvalidArgumentException::class, 'Controller "oof" does neither exist as service nor as class');
$tests[2] = array(array('oof', 'bar'), \InvalidArgumentException::class, 'Controller "oof" does neither exist as service nor as class');
$tests[] = array(
array(ControllerTestService::class, 'action'),
\InvalidArgumentException::class,
'Controller "Symfony\Component\HttpKernel\Tests\Controller\ControllerTestService" has required constructor arguments and does not exist in the container. Did you forget to define such a service?',
);
$tests[] = array(
ControllerTestService::class.'::action',
\InvalidArgumentException::class, 'Controller "Symfony\Component\HttpKernel\Tests\Controller\ControllerTestService" has required constructor arguments and does not exist in the container. Did you forget to define such a service?',
);
$tests[] = array(
InvokableControllerService::class,
\InvalidArgumentException::class,
'Controller "Symfony\Component\HttpKernel\Tests\Controller\InvokableControllerService" has required constructor arguments and does not exist in the container. Did you forget to define such a service?',
);
return $tests;
}
protected function createControllerResolver(LoggerInterface $logger = null, ContainerInterface $container = null)
@@ -278,7 +218,7 @@ class ContainerControllerResolverTest extends ControllerResolverTest
}
}
class InvokableController
class InvokableControllerService
{
public function __construct($bar) // mandatory argument to prevent automatic instantiation
{
@@ -289,16 +229,9 @@ class InvokableController
}
}
abstract class NonInstantiableController
class ControllerTestService
{
public static function action()
{
}
}
class ImpossibleConstructController
{
public function __construct($toto, $controller)
public function __construct($foo)
{
}

View File

@@ -15,8 +15,6 @@ 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
{
@@ -43,51 +41,55 @@ class ControllerResolverTest extends TestCase
public function testGetControllerWithObjectAndInvokeMethod()
{
$resolver = $this->createControllerResolver();
$object = new InvokableController();
$request = Request::create('/');
$request->attributes->set('_controller', $this);
$request->attributes->set('_controller', $object);
$controller = $resolver->getController($request);
$this->assertSame($this, $controller);
$this->assertSame($object, $controller);
}
public function testGetControllerWithObjectAndMethod()
{
$resolver = $this->createControllerResolver();
$object = new ControllerTest();
$request = Request::create('/');
$request->attributes->set('_controller', array($this, 'controllerMethod1'));
$request->attributes->set('_controller', array($object, 'publicAction'));
$controller = $resolver->getController($request);
$this->assertSame(array($this, 'controllerMethod1'), $controller);
$this->assertSame(array($object, 'publicAction'), $controller);
}
public function testGetControllerWithClassAndMethod()
public function testGetControllerWithClassAndMethodAsArray()
{
$resolver = $this->createControllerResolver();
$request = Request::create('/');
$request->attributes->set('_controller', array('Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest', 'controllerMethod4'));
$request->attributes->set('_controller', array(ControllerTest::class, 'publicAction'));
$controller = $resolver->getController($request);
$this->assertSame(array('Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest', 'controllerMethod4'), $controller);
$this->assertInstanceOf(ControllerTest::class, $controller[0]);
$this->assertSame('publicAction', $controller[1]);
}
public function testGetControllerWithObjectAndMethodAsString()
public function testGetControllerWithClassAndMethodAsString()
{
$resolver = $this->createControllerResolver();
$request = Request::create('/');
$request->attributes->set('_controller', 'Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest::controllerMethod1');
$request->attributes->set('_controller', ControllerTest::class.'::publicAction');
$controller = $resolver->getController($request);
$this->assertInstanceOf('Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest', $controller[0], '->getController() returns a PHP callable');
$this->assertInstanceOf(ControllerTest::class, $controller[0]);
$this->assertSame('publicAction', $controller[1]);
}
public function testGetControllerWithClassAndInvokeMethod()
public function testGetControllerWithInvokableClass()
{
$resolver = $this->createControllerResolver();
$request = Request::create('/');
$request->attributes->set('_controller', 'Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest');
$request->attributes->set('_controller', InvokableController::class);
$controller = $resolver->getController($request);
$this->assertInstanceOf('Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest', $controller);
$this->assertInstanceOf(InvokableController::class, $controller);
}
/**
@@ -112,10 +114,49 @@ class ControllerResolverTest extends TestCase
$this->assertSame('Symfony\Component\HttpKernel\Tests\Controller\some_controller_function', $controller);
}
public function testGetControllerWithClosure()
{
$resolver = $this->createControllerResolver();
$closure = function () {
return 'test';
};
$request = Request::create('/');
$request->attributes->set('_controller', $closure);
$controller = $resolver->getController($request);
$this->assertInstanceOf(\Closure::class, $controller);
$this->assertSame('test', $controller());
}
/**
* @dataProvider getStaticControllers
*/
public function testGetControllerWithStaticController($staticController, $returnValue)
{
$resolver = $this->createControllerResolver();
$request = Request::create('/');
$request->attributes->set('_controller', $staticController);
$controller = $resolver->getController($request);
$this->assertSame($staticController, $controller);
$this->assertSame($returnValue, $controller());
}
public function getStaticControllers()
{
return array(
array(TestAbstractController::class.'::staticAction', 'foo'),
array(array(TestAbstractController::class, 'staticAction'), 'foo'),
array(PrivateConstructorController::class.'::staticAction', 'bar'),
array(array(PrivateConstructorController::class, 'staticAction'), 'bar'),
);
}
/**
* @dataProvider getUndefinedControllers
*/
public function testGetControllerOnNonUndefinedFunction($controller, $exceptionName = null, $exceptionMessage = null)
public function testGetControllerWithUndefinedController($controller, $exceptionName = null, $exceptionMessage = null)
{
$resolver = $this->createControllerResolver();
if (method_exists($this, 'expectException')) {
@@ -132,179 +173,30 @@ class ControllerResolverTest extends TestCase
public function getUndefinedControllers()
{
$controller = new ControllerTest();
return array(
array(1, 'InvalidArgumentException', 'Unable to find controller "1".'),
array('foo', 'InvalidArgumentException', 'Unable to find controller "foo".'),
array('oof::bar', 'InvalidArgumentException', 'Class "oof" does not exist.'),
array('stdClass', 'InvalidArgumentException', 'Unable to find controller "stdClass".'),
array('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"?'),
array('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'),
array('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'),
array('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"'),
array('foo', \Error::class, 'Class \'foo\' not found'),
array('oof::bar', \Error::class, 'Class \'oof\' not found'),
array(array('oof', 'bar'), \Error::class, 'Class \'oof\' not found'),
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::staticsAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "staticsAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest", did you mean "staticAction"?'),
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::privateAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "privateAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::protectedAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "protectedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::undefinedAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "undefinedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest". Available methods: "publicAction", "staticAction"'),
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Controller class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" cannot be called without a method name. You need to implement "__invoke" or use one of the available methods: "publicAction", "staticAction".'),
array(array($controller, 'staticsAction'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "staticsAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest", did you mean "staticAction"?'),
array(array($controller, 'privateAction'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "privateAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
array(array($controller, 'protectedAction'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "protectedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
array(array($controller, 'undefinedAction'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "undefinedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest". Available methods: "publicAction", "staticAction"'),
array($controller, \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Controller class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" cannot be called without a method name. You need to implement "__invoke" or use one of the available methods: "publicAction", "staticAction".'),
array(array('a' => 'foo', 'b' => 'bar'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Invalid array callable, expected array(controller, method).'),
);
}
/**
* @group legacy
*/
public function testGetArguments()
{
$resolver = $this->createControllerResolver();
$request = Request::create('/');
$controller = array(new self(), 'testGetArguments');
$this->assertEquals(array(), $resolver->getArguments($request, $controller), '->getArguments() returns an empty array if the method takes no arguments');
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$controller = array(new self(), 'controllerMethod1');
$this->assertEquals(array('foo'), $resolver->getArguments($request, $controller), '->getArguments() returns an array of arguments for the controller method');
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$controller = array(new self(), 'controllerMethod2');
$this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller), '->getArguments() uses default values if present');
$request->attributes->set('bar', 'bar');
$this->assertEquals(array('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(array('foo'), $resolver->getArguments($request, $controller));
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$controller = function ($foo, $bar = 'bar') {};
$this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$controller = new self();
$this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller));
$request->attributes->set('bar', 'bar');
$this->assertEquals(array('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(array('foo', 'foobar'), $resolver->getArguments($request, $controller));
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$request->attributes->set('foobar', 'foobar');
$controller = array(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 = array(new self(), 'controllerMethod5');
$this->assertEquals(array($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', array('foo', 'bar'));
$controller = array(new VariadicController(), 'action');
$this->assertEquals(array('foo', 'foo', 'bar'), $resolver->getArguments($request, $controller));
}
public function testCreateControllerCanReturnAnyCallable()
{
$mock = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolver')->setMethods(array('createController'))->getMock();
$mock->expects($this->once())->method('createController')->will($this->returnValue('Symfony\Component\HttpKernel\Tests\Controller\some_controller_function'));
$request = Request::create('/');
$request->attributes->set('_controller', 'foobar');
$mock->getController($request);
}
/**
* @expectedException \RuntimeException
* @group legacy
*/
public function testIfExceptionIsThrownWhenMissingAnArgument()
{
$resolver = new ControllerResolver();
$request = Request::create('/');
$controller = array($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 = array(new NullableController(), 'action');
$this->assertEquals(array('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 = array(new NullableController(), 'action');
$this->assertEquals(array(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)
@@ -313,6 +205,15 @@ function some_controller_function($foo, $foobar)
class ControllerTest
{
public function __construct()
{
}
public function __toString()
{
return '';
}
public function publicAction()
{
}
@@ -329,3 +230,30 @@ class ControllerTest
{
}
}
class InvokableController
{
public function __invoke($foo, $bar = null)
{
}
}
abstract class TestAbstractController
{
public static function staticAction()
{
return 'foo';
}
}
class PrivateConstructorController
{
private function __construct()
{
}
public static function staticAction()
{
return 'bar';
}
}

View File

@@ -84,9 +84,6 @@ class ArgumentMetadataFactoryTest extends TestCase
), $arguments);
}
/**
* @requires PHP 5.6
*/
public function testVariadicSignature()
{
$arguments = $this->factory->createArgumentMetadata(array(new VariadicController(), 'action'));
@@ -97,9 +94,6 @@ class ArgumentMetadataFactoryTest extends TestCase
), $arguments);
}
/**
* @requires PHP 7.0
*/
public function testBasicTypesSignature()
{
$arguments = $this->factory->createArgumentMetadata(array(new BasicTypesController(), 'action'));
@@ -111,9 +105,6 @@ class ArgumentMetadataFactoryTest extends TestCase
), $arguments);
}
/**
* @requires PHP 7.1
*/
public function testNullableTypesSignature()
{
$arguments = $this->factory->createArgumentMetadata(array(new NullableController(), 'action'));

View File

@@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Server\Connection;
/**
* @author Nicolas Grekas <p@tchwork.com>
@@ -56,6 +57,24 @@ class DumpDataCollectorTest extends TestCase
$this->assertSame('a:2:{i:0;b:0;i:1;s:5:"UTF-8";}', $collector->serialize());
}
public function testDumpWithServerConnection()
{
$data = new Data(array(array(123)));
// Server is up, server dumper is used
$serverDumper = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$serverDumper->expects($this->once())->method('write')->willReturn(true);
$collector = new DumpDataCollector(null, null, null, null, $serverDumper);
$collector->dump($data);
// Collect doesn't re-trigger dump
ob_start();
$collector->collect(new Request(), new Response());
$this->assertEmpty(ob_get_clean());
$this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";%c:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
}
public function testCollectDefault()
{
$data = new Data(array(array(123)));

View File

@@ -13,7 +13,11 @@ namespace Symfony\Component\HttpKernel\Tests\DataCollector;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Debug\Exception\SilencedErrorContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
class LoggerDataCollectorTest extends TestCase
{
@@ -41,6 +45,46 @@ class LoggerDataCollectorTest extends TestCase
), $compilerLogs['Unknown Compiler Pass']);
}
public function testWithMasterRequest()
{
$masterRequest = new Request();
$stack = new RequestStack();
$stack->push($masterRequest);
$logger = $this
->getMockBuilder(DebugLoggerInterface::class)
->setMethods(array('countErrors', 'getLogs', 'clear'))
->getMock();
$logger->expects($this->once())->method('countErrors')->with(null);
$logger->expects($this->exactly(2))->method('getLogs')->with(null)->will($this->returnValue(array()));
$c = new LoggerDataCollector($logger, __DIR__.'/', $stack);
$c->collect($masterRequest, new Response());
$c->lateCollect();
}
public function testWithSubRequest()
{
$masterRequest = new Request();
$subRequest = new Request();
$stack = new RequestStack();
$stack->push($masterRequest);
$stack->push($subRequest);
$logger = $this
->getMockBuilder(DebugLoggerInterface::class)
->setMethods(array('countErrors', 'getLogs', 'clear'))
->getMock();
$logger->expects($this->once())->method('countErrors')->with($subRequest);
$logger->expects($this->exactly(2))->method('getLogs')->with($subRequest)->will($this->returnValue(array()));
$c = new LoggerDataCollector($logger, __DIR__.'/', $stack);
$c->collect($subRequest, new Response());
$c->lateCollect();
}
/**
* @dataProvider getCollectTestData
*/

View File

@@ -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));
}
}

View File

@@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
use Symfony\Component\Stopwatch\Stopwatch;
class ControllerArgumentValueResolverPassTest extends TestCase
{
@@ -42,8 +43,69 @@ class ControllerArgumentValueResolverPassTest extends TestCase
$container->register($id)->addTag('controller.argument_value_resolver', $tag);
}
$container->setParameter('kernel.debug', false);
(new ControllerArgumentValueResolverPass())->process($container);
$this->assertEquals($expected, $definition->getArgument(1)->getValues());
$this->assertFalse($container->hasDefinition('n1.traceable'));
$this->assertFalse($container->hasDefinition('n2.traceable'));
$this->assertFalse($container->hasDefinition('n3.traceable'));
}
public function testInDebugWithStopWatchDefinition()
{
$services = array(
'n3' => array(array()),
'n1' => array(array('priority' => 200)),
'n2' => array(array('priority' => 100)),
);
$expected = array(
new Reference('n1'),
new Reference('n2'),
new Reference('n3'),
);
$definition = new Definition(ArgumentResolver::class, array(null, array()));
$container = new ContainerBuilder();
$container->register('debug.stopwatch', Stopwatch::class);
$container->setDefinition('argument_resolver', $definition);
foreach ($services as $id => list($tag)) {
$container->register($id)->addTag('controller.argument_value_resolver', $tag);
}
$container->setParameter('kernel.debug', true);
(new ControllerArgumentValueResolverPass())->process($container);
$this->assertEquals($expected, $definition->getArgument(1)->getValues());
$this->assertTrue($container->hasDefinition('debug.n1'));
$this->assertTrue($container->hasDefinition('debug.n2'));
$this->assertTrue($container->hasDefinition('debug.n3'));
$this->assertTrue($container->hasDefinition('n1'));
$this->assertTrue($container->hasDefinition('n2'));
$this->assertTrue($container->hasDefinition('n3'));
}
public function testInDebugWithouStopWatchDefinition()
{
$expected = array(new Reference('n1'));
$definition = new Definition(ArgumentResolver::class, array(null, array()));
$container = new ContainerBuilder();
$container->register('n1')->addTag('controller.argument_value_resolver');
$container->setDefinition('argument_resolver', $definition);
$container->setParameter('kernel.debug', true);
(new ControllerArgumentValueResolverPass())->process($container);
$this->assertEquals($expected, $definition->getArgument(1)->getValues());
$this->assertFalse($container->hasDefinition('debug.n1'));
$this->assertTrue($container->hasDefinition('n1'));
}
public function testReturningEmptyArrayWhenNoService()
@@ -52,6 +114,8 @@ class ControllerArgumentValueResolverPassTest extends TestCase
$container = new ContainerBuilder();
$container->setDefinition('argument_resolver', $definition);
$container->setParameter('kernel.debug', false);
(new ControllerArgumentValueResolverPass())->process($container);
$this->assertEquals(array(), $definition->getArgument(1)->getValues());
}

View File

@@ -18,31 +18,6 @@ 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')->will($this->returnValue('foo'));
$renderer->expects($this->any())->method('render')->will($this->returnValue(new Response()));
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
$requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->once())->method('get')->will($this->returnValue($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();

View File

@@ -141,15 +141,15 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$this->assertEquals(array('foo:fooAction'), array_keys($locator));
$this->assertInstanceof(ServiceClosureArgument::class, $locator['foo:fooAction']);
$this->assertEquals(array('foo::fooAction'), array_keys($locator));
$this->assertInstanceof(ServiceClosureArgument::class, $locator['foo::fooAction']);
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
$this->assertSame(ServiceLocator::class, $locator->getClass());
$this->assertFalse($locator->isPublic());
$expected = array('bar' => new ServiceClosureArgument(new TypedReference(ControllerDummy::class, ControllerDummy::class, RegisterTestController::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
$expected = array('bar' => new ServiceClosureArgument(new TypedReference(ControllerDummy::class, ControllerDummy::class, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE)));
$this->assertEquals($expected, $locator->getArgument(0));
}
@@ -167,9 +167,9 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$pass->process($container);
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, RegisterTestController::class)));
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE)));
$this->assertEquals($expected, $locator->getArgument(0));
}
@@ -186,9 +186,9 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$pass->process($container);
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, RegisterTestController::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
$this->assertEquals($expected, $locator->getArgument(0));
}
@@ -204,7 +204,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$pass->process($container);
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$this->assertSame(array('foo:fooAction'), array_keys($locator));
$this->assertSame(array('foo::fooAction'), array_keys($locator));
}
/**
@@ -251,7 +251,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$pass->process($container);
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$this->assertSame(array('foo:barAction', 'foo:fooAction'), array_keys($locator));
$this->assertSame(array('foo::barAction', 'foo::fooAction'), array_keys($locator));
}
public function testArgumentWithNoTypeHintIsOk()
@@ -301,7 +301,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
$expected = array('bar' => new ServiceClosureArgument(new Reference('foo')));
$this->assertEquals($expected, $locator->getArgument(0));
@@ -312,7 +312,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
return array(array(ControllerDummy::class), array('$bar'));
}
public function testDoNotBindScalarValueToControllerArgument()
public function testBindScalarValueToControllerArgument()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
@@ -321,11 +321,24 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
->setBindings(array('$someArg' => '%foo%'))
->addTag('controller.service_arguments');
$container->setParameter('foo', 'foo_val');
$pass = new RegisterControllerArgumentLocatorsPass();
$pass->process($container);
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$this->assertEmpty($locator);
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
// assert the locator has a someArg key
$arguments = $locator->getArgument(0);
$this->assertArrayHasKey('someArg', $arguments);
$this->assertInstanceOf(ServiceClosureArgument::class, $arguments['someArg']);
// get the Reference that someArg points to
$reference = $arguments['someArg']->getValues()[0];
// make sure this service *does* exist and returns the correct value
$this->assertTrue($container->has((string) $reference));
$this->assertSame('foo_val', $container->get((string) $reference));
}
public function testBindingsOnChildDefinitions()
@@ -344,9 +357,9 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$pass->process($container);
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$this->assertInstanceOf(ServiceClosureArgument::class, $locator['child:fooAction']);
$this->assertInstanceOf(ServiceClosureArgument::class, $locator['child::fooAction']);
$locator = $container->getDefinition((string) $locator['child:fooAction']->getValues()[0])->getArgument(0);
$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]);
}

View File

@@ -36,49 +36,30 @@ class RemoveEmptyControllerArgumentLocatorsPassTest extends TestCase
$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));
$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(array(), $container->getDefinition((string) $controllers['c2:fooAction']->getValues()[0])->getArgument(0));
$this->assertCount(1, $container->getDefinition((string) $controllers['c2::setTestCase']->getValues()[0])->getArgument(0));
$this->assertSame(array(), $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(array('c1:fooAction'), array_keys($controllers));
$this->assertSame(array('bar'), array_keys($container->getDefinition((string) $controllers['c1:fooAction']->getValues()[0])->getArgument(0)));
$this->assertSame(array('c1::fooAction', 'c1:fooAction'), array_keys($controllers));
$this->assertSame(array('bar'), array_keys($container->getDefinition((string) $controllers['c1::fooAction']->getValues()[0])->getArgument(0)));
$expectedLog = array(
'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 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(array());
$container->register(RegisterTestController::class, RegisterTestController::class)
->addTag('controller.service_arguments')
;
(new RegisterControllerArgumentLocatorsPass())->process($container);
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
$expected = array(
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();
@@ -92,35 +73,15 @@ class RemoveEmptyControllerArgumentLocatorsPassTest extends TestCase
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
$this->assertEquals(
array('invokable:__invoke', 'invokable'),
array('invokable::__invoke', '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(array());
$container->register(InvokableRegisterTestController::class, InvokableRegisterTestController::class)
->addTag('controller.service_arguments')
;
(new RegisterControllerArgumentLocatorsPass())->process($container);
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
$expected = array(
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)
public function fooAction(\stdClass $bar, ClassNotInContainer $baz = null)
{
}
}
@@ -131,7 +92,7 @@ class RemoveTestController2
{
}
public function fooAction(ClassNotInContainer $bar)
public function fooAction(ClassNotInContainer $bar = null)
{
}
}

View File

@@ -54,11 +54,13 @@ class ExceptionListenerTest extends TestCase
$this->iniSet('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
$l = new ExceptionListener('foo');
$l->logKernelException($event);
$l->onKernelException($event);
$this->assertEquals(new Response('foo'), $event->getResponse());
try {
$l->logKernelException($event2);
$l->onKernelException($event2);
$this->fail('RuntimeException expected');
} catch (\RuntimeException $e) {
@@ -75,11 +77,13 @@ class ExceptionListenerTest extends TestCase
$logger = new TestLogger();
$l = new ExceptionListener('foo', $logger);
$l->logKernelException($event);
$l->onKernelException($event);
$this->assertEquals(new Response('foo'), $event->getResponse());
try {
$l->logKernelException($event2);
$l->onKernelException($event2);
$this->fail('RuntimeException expected');
} catch (\RuntimeException $e) {

View File

@@ -70,12 +70,7 @@ class RouterListenerTest extends TestCase
);
}
/**
* @param string $uri
*
* @return GetResponseEvent
*/
private function createGetResponseEventForUri($uri)
private function createGetResponseEventForUri(string $uri): GetResponseEvent
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$request = Request::create($uri);

View File

@@ -19,6 +19,9 @@ use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\EventListener\SaveSessionListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* @group legacy
*/
class SaveSessionListenerTest extends TestCase
{
public function testOnlyTriggeredOnMasterRequest()

View File

@@ -13,6 +13,7 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
@@ -56,25 +57,66 @@ class SessionListenerTest extends TestCase
$this->assertSame($session, $request->getSession());
}
public function testResponseIsPrivate()
public function testResponseIsPrivateIfSessionStarted()
{
$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);
$container->set('initialized_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));
$response = new Response();
$listener->onKernelResponse(new FilterResponseEvent($kernel, new 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->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
}
public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent()
{
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$container = new Container();
$container->set('initialized_session', $session);
$listener = new SessionListener($container);
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock();
$request = new Request();
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
$response = new Response();
$response->setSharedMaxAge(60);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
$listener->onKernelResponse(new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
$this->assertSame('60', $response->headers->getCacheControlDirective('s-maxage'));
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
}
public function testUninitilizedSession()
{
$event = $this->getMockBuilder(FilterResponseEvent::class)->disableOriginalConstructor()->getMock();
$event->expects($this->once())->method('isMasterRequest')->willReturn(true);
$container = new ServiceLocator(array(
'initialized_session' => function () {},
));
$listener = new SessionListener($container);
$listener->onKernelResponse($event);
}
public function testSurrogateMasterRequestIsPublic()
@@ -83,6 +125,7 @@ class SessionListenerTest extends TestCase
$session->expects($this->exactly(4))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1, 1, 1));
$container = new Container();
$container->set('initialized_session', $session);
$container->set('session', $session);
$listener = new SessionListener($container);

View File

@@ -153,6 +153,16 @@ class TestSessionListenerTest extends TestCase
$this->assertFalse(is_subclass_of(TestSessionListener::class, ServiceSubscriberInterface::class, 'Implementing ServiceSubscriberInterface would create a dep on the DI component, which eg Silex cannot afford'));
}
public function testDoesNotThrowIfRequestDoesNotHaveASession()
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response());
$this->listener->onKernelResponse($event);
$this->assertTrue(true);
}
private function filterResponse(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, Response $response = null)
{
$request->setSession($this->session);

View File

@@ -12,6 +12,19 @@ class MethodNotAllowedHttpExceptionTest extends HttpExceptionTest
$this->assertSame(array('Allow' => 'GET, PUT'), $exception->getHeaders());
}
public function testWithHeaderConstruct()
{
$headers = array(
'Cache-Control' => 'public, s-maxage=1200',
);
$exception = new MethodNotAllowedHttpException(array('get'), null, null, null, $headers);
$headers['Allow'] = 'GET';
$this->assertSame($headers, $exception->getHeaders());
}
/**
* @dataProvider headerDataProvider
*/

View File

@@ -12,6 +12,19 @@ class ServiceUnavailableHttpExceptionTest extends HttpExceptionTest
$this->assertSame(array('Retry-After' => 10), $exception->getHeaders());
}
public function testWithHeaderConstruct()
{
$headers = array(
'Cache-Control' => 'public, s-maxage=1337',
);
$exception = new ServiceUnavailableHttpException(1337, null, null, null, $headers);
$headers['Retry-After'] = 1337;
$this->assertSame($headers, $exception->getHeaders());
}
/**
* @dataProvider headerDataProvider
*/

View File

@@ -12,6 +12,19 @@ class TooManyRequestsHttpExceptionTest extends HttpExceptionTest
$this->assertSame(array('Retry-After' => 10), $exception->getHeaders());
}
public function testWithHeaderConstruct()
{
$headers = array(
'Cache-Control' => 'public, s-maxage=69',
);
$exception = new TooManyRequestsHttpException(69, null, null, null, $headers);
$headers['Retry-After'] = 69;
$this->assertSame($headers, $exception->getHeaders());
}
/**
* @dataProvider headerDataProvider
*/

View File

@@ -12,6 +12,19 @@ class UnauthorizedHttpExceptionTest extends HttpExceptionTest
$this->assertSame(array('WWW-Authenticate' => 'Challenge'), $exception->getHeaders());
}
public function testWithHeaderConstruct()
{
$headers = array(
'Cache-Control' => 'public, s-maxage=1200',
);
$exception = new UnauthorizedHttpException('Challenge', null, null, null, $headers);
$headers['WWW-Authenticate'] = 'Challenge';
$this->assertSame($headers, $exception->getHeaders());
}
/**
* @dataProvider headerDataProvider
*/

View File

@@ -11,10 +11,9 @@
namespace Symfony\Component\HttpKernel\Tests\Fixtures;
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
class TestEventDispatcher extends EventDispatcher implements TraceableEventDispatcherInterface
class TestEventDispatcher extends TraceableEventDispatcher
{
public function getCalledListeners()
{
@@ -29,4 +28,9 @@ class TestEventDispatcher extends EventDispatcher implements TraceableEventDispa
public function reset()
{
}
public function getOrphanedEvents()
{
return array();
}
}

View File

@@ -26,19 +26,7 @@ class EsiFragmentRendererTest extends TestCase
$strategy->render('/', Request::create('/'));
}
/**
* @group legacy
* @expectedDeprecation Passing non-scalar values as part of URI attributes to the ESI and SSI rendering strategies is deprecated %s.
*/
public function testRenderFallbackWithObjectAttributesIsDeprecated()
{
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo'));
$request = Request::create('/');
$reference = new ControllerReference('main_controller', array('foo' => new \stdClass()), array());
$strategy->render($reference, $request);
}
public function testRenderFallbackWithScalarIsNotDeprecated()
public function testRenderFallbackWithScalar()
{
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo'));
$request = Request::create('/');

View File

@@ -16,9 +16,7 @@ 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\ControllerReference;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\KernelEvents;
@@ -53,48 +51,6 @@ class InlineFragmentRendererTest extends TestCase
$this->assertSame('foo', $strategy->render(new ControllerReference('main_controller', array('object' => $object), array()), Request::create('/'))->getContent());
}
/**
* @group legacy
*/
public function testRenderWithObjectsAsAttributesPassedAsObjectsInTheControllerLegacy()
{
$resolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver')->setMethods(array('getController'))->getMock();
$resolver
->expects($this->once())
->method('getController')
->will($this->returnValue(function (\stdClass $object, Bar $object1) {
return new Response($object1->getBar());
}))
;
$kernel = new HttpKernel(new EventDispatcher(), $resolver, new RequestStack());
$renderer = new InlineFragmentRenderer($kernel);
$response = $renderer->render(new ControllerReference('main_controller', array('object' => new \stdClass(), 'object1' => new Bar()), array()), Request::create('/'));
$this->assertEquals('bar', $response->getContent());
}
/**
* @group legacy
*/
public function testRenderWithObjectsAsAttributesPassedAsObjectsInTheController()
{
$resolver = $this->getMockBuilder(ControllerResolverInterface::class)->getMock();
$resolver
->expects($this->once())
->method('getController')
->will($this->returnValue(function (\stdClass $object, Bar $object1) {
return new Response($object1->getBar());
}))
;
$kernel = new HttpKernel(new EventDispatcher(), $resolver, new RequestStack(), new ArgumentResolver());
$renderer = new InlineFragmentRenderer($kernel);
$response = $renderer->render(new ControllerReference('main_controller', array('object' => new \stdClass(), 'object1' => new Bar()), array()), Request::create('/'));
$this->assertEquals('bar', $response->getContent());
}
public function testRenderWithTrustedHeaderDisabled()
{
Request::setTrustedProxies(array(), 0);

View File

@@ -111,24 +111,6 @@ class HttpKernelTest extends TestCase
$this->assertEquals('POST', $response->headers->get('Allow'));
}
/**
* @group legacy
* @dataProvider getStatusCodes
*/
public function testLegacyHandleWhenAnExceptionIsHandledWithASpecificStatusCode($responseStatusCode, $expectedStatusCode)
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(KernelEvents::EXCEPTION, function ($event) use ($responseStatusCode, $expectedStatusCode) {
$event->setResponse(new Response('', $responseStatusCode, array('X-Status-Code' => $expectedStatusCode)));
});
$kernel = $this->getHttpKernel($dispatcher, function () { throw new \RuntimeException(); });
$response = $kernel->handle(new Request());
$this->assertEquals($expectedStatusCode, $response->getStatusCode());
$this->assertFalse($response->headers->has('X-Status-Code'));
}
public function getStatusCodes()
{
return array(

View File

@@ -19,7 +19,6 @@ use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass;
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -124,20 +123,6 @@ class KernelTest extends TestCase
$this->assertTrue($kernel->isBooted());
}
/**
* @group legacy
*/
public function testClassCacheIsLoaded()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer', 'doLoadClassCache'));
$kernel->loadClassCache('name', '.extension');
$kernel->expects($this->once())
->method('doLoadClassCache')
->with('name', '.extension');
$kernel->boot();
}
public function testClassCacheIsNotLoadedByDefault()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer', 'doLoadClassCache'));
@@ -147,53 +132,6 @@ class KernelTest extends TestCase
$kernel->boot();
}
/**
* @group legacy
*/
public function testClassCacheIsNotLoadedWhenKernelIsNotBooted()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer', 'doLoadClassCache'));
$kernel->loadClassCache();
$kernel->expects($this->never())
->method('doLoadClassCache');
}
public function testEnvParametersResourceIsAdded()
{
$container = new ContainerBuilder();
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('getContainerBuilder', 'prepareContainer', 'getCacheDir', 'getLogDir'))
->getMock();
$kernel->expects($this->any())
->method('getContainerBuilder')
->will($this->returnValue($container));
$kernel->expects($this->any())
->method('prepareContainer')
->will($this->returnValue(null));
$kernel->expects($this->any())
->method('getCacheDir')
->will($this->returnValue(sys_get_temp_dir()));
$kernel->expects($this->any())
->method('getLogDir')
->will($this->returnValue(sys_get_temp_dir()));
$reflection = new \ReflectionClass(\get_class($kernel));
$method = $reflection->getMethod('buildContainer');
$method->setAccessible(true);
$method->invoke($kernel);
$found = false;
foreach ($container->getResources() as $resource) {
if ($resource instanceof EnvParametersResource) {
$found = true;
break;
}
}
$this->assertTrue($found);
}
public function testBootKernelSeveralTimesOnlyInitializesBundlesOnce()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer'));
@@ -421,7 +359,7 @@ EOF;
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))))
->will($this->returnValue($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle')))
;
$kernel->locateResource('@Bundle1Bundle/config/routing.xml');
@@ -433,80 +371,19 @@ EOF;
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))))
->will($this->returnValue($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle')))
;
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1Bundle/foo.txt'));
}
/**
* @group legacy
*/
public function testLocateResourceReturnsTheFirstThatMatchesWithParent()
{
$parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle');
$child = $this->getBundle(__DIR__.'/Fixtures/Bundle2Bundle');
$kernel = $this->getKernel(array('getBundle'));
$kernel
->expects($this->exactly(2))
->method('getBundle')
->will($this->returnValue(array($child, $parent)))
;
$this->assertEquals(__DIR__.'/Fixtures/Bundle2Bundle/foo.txt', $kernel->locateResource('@ParentAABundle/foo.txt'));
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/bar.txt', $kernel->locateResource('@ParentAABundle/bar.txt'));
}
/**
* @group legacy
*/
public function testLocateResourceReturnsAllMatches()
{
$parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle');
$child = $this->getBundle(__DIR__.'/Fixtures/Bundle2Bundle');
$kernel = $this->getKernel(array('getBundle'));
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array($child, $parent)))
;
$this->assertEquals(array(
__DIR__.'/Fixtures/Bundle2Bundle/foo.txt',
__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', ),
$kernel->locateResource('@Bundle1Bundle/foo.txt', null, false));
}
/**
* @group legacy
*/
public function testLocateResourceReturnsAllMatchesBis()
{
$kernel = $this->getKernel(array('getBundle'));
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array(
$this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'),
$this->getBundle(__DIR__.'/Foobar'),
)))
;
$this->assertEquals(
array(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt'),
$kernel->locateResource('@Bundle1Bundle/foo.txt', null, false)
);
}
public function testLocateResourceIgnoresDirOnNonResource()
{
$kernel = $this->getKernel(array('getBundle'));
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))))
->will($this->returnValue($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle')))
;
$this->assertEquals(
@@ -521,7 +398,7 @@ EOF;
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle'))))
->will($this->returnValue($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle')))
;
$this->assertEquals(
@@ -530,73 +407,13 @@ EOF;
);
}
/**
* @group legacy
*/
public function testLocateResourceReturnsTheDirOneForResourcesAndBundleOnes()
{
$kernel = $this->getKernel(array('getBundle'));
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1Bundle'))))
;
$this->assertEquals(array(
__DIR__.'/Fixtures/Resources/Bundle1Bundle/foo.txt',
__DIR__.'/Fixtures/Bundle1Bundle/Resources/foo.txt', ),
$kernel->locateResource('@Bundle1Bundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources', false)
);
}
/**
* @group legacy
*/
public function testLocateResourceOverrideBundleAndResourcesFolders()
{
$parent = $this->getBundle(__DIR__.'/Fixtures/BaseBundle', null, 'BaseBundle', 'BaseBundle');
$child = $this->getBundle(__DIR__.'/Fixtures/ChildBundle', 'ParentBundle', 'ChildBundle', 'ChildBundle');
$kernel = $this->getKernel(array('getBundle'));
$kernel
->expects($this->exactly(4))
->method('getBundle')
->will($this->returnValue(array($child, $parent)))
;
$this->assertEquals(array(
__DIR__.'/Fixtures/Resources/ChildBundle/foo.txt',
__DIR__.'/Fixtures/ChildBundle/Resources/foo.txt',
__DIR__.'/Fixtures/BaseBundle/Resources/foo.txt',
),
$kernel->locateResource('@BaseBundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources', false)
);
$this->assertEquals(
__DIR__.'/Fixtures/Resources/ChildBundle/foo.txt',
$kernel->locateResource('@BaseBundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources')
);
try {
$kernel->locateResource('@BaseBundle/Resources/hide.txt', __DIR__.'/Fixtures/Resources', false);
$this->fail('Hidden resources should raise an exception when returning an array of matching paths');
} catch (\RuntimeException $e) {
}
try {
$kernel->locateResource('@BaseBundle/Resources/hide.txt', __DIR__.'/Fixtures/Resources', true);
$this->fail('Hidden resources should raise an exception when returning the first matching path');
} catch (\RuntimeException $e) {
}
}
public function testLocateResourceOnDirectories()
{
$kernel = $this->getKernel(array('getBundle'));
$kernel
->expects($this->exactly(2))
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle'))))
->will($this->returnValue($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle')))
;
$this->assertEquals(
@@ -612,7 +429,7 @@ EOF;
$kernel
->expects($this->exactly(2))
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1Bundle'))))
->will($this->returnValue($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1Bundle')))
;
$this->assertEquals(
@@ -626,103 +443,6 @@ EOF;
}
/**
* @group legacy
*/
public function testInitializeBundles()
{
$parent = $this->getBundle(null, null, 'ParentABundle');
$child = $this->getBundle(null, 'ParentABundle', 'ChildABundle');
// use test kernel so we can access getBundleMap()
$kernel = $this->getKernelForTest(array('registerBundles'));
$kernel
->expects($this->once())
->method('registerBundles')
->will($this->returnValue(array($parent, $child)))
;
$kernel->boot();
$map = $kernel->getBundleMap();
$this->assertEquals(array($child, $parent), $map['ParentABundle']);
}
/**
* @group legacy
*/
public function testInitializeBundlesSupportInheritanceCascade()
{
$grandparent = $this->getBundle(null, null, 'GrandParentBBundle');
$parent = $this->getBundle(null, 'GrandParentBBundle', 'ParentBBundle');
$child = $this->getBundle(null, 'ParentBBundle', 'ChildBBundle');
// use test kernel so we can access getBundleMap()
$kernel = $this->getKernelForTest(array('registerBundles'));
$kernel
->expects($this->once())
->method('registerBundles')
->will($this->returnValue(array($grandparent, $parent, $child)))
;
$kernel->boot();
$map = $kernel->getBundleMap();
$this->assertEquals(array($child, $parent, $grandparent), $map['GrandParentBBundle']);
$this->assertEquals(array($child, $parent), $map['ParentBBundle']);
$this->assertEquals(array($child), $map['ChildBBundle']);
}
/**
* @group legacy
* @expectedException \LogicException
* @expectedExceptionMessage Bundle "ChildCBundle" extends bundle "FooBar", which is not registered.
*/
public function testInitializeBundlesThrowsExceptionWhenAParentDoesNotExists()
{
$child = $this->getBundle(null, 'FooBar', 'ChildCBundle');
$kernel = $this->getKernel(array(), array($child));
$kernel->boot();
}
/**
* @group legacy
*/
public function testInitializeBundlesSupportsArbitraryBundleRegistrationOrder()
{
$grandparent = $this->getBundle(null, null, 'GrandParentCBundle');
$parent = $this->getBundle(null, 'GrandParentCBundle', 'ParentCBundle');
$child = $this->getBundle(null, 'ParentCBundle', 'ChildCBundle');
// use test kernel so we can access getBundleMap()
$kernel = $this->getKernelForTest(array('registerBundles'));
$kernel
->expects($this->once())
->method('registerBundles')
->will($this->returnValue(array($parent, $grandparent, $child)))
;
$kernel->boot();
$map = $kernel->getBundleMap();
$this->assertEquals(array($child, $parent, $grandparent), $map['GrandParentCBundle']);
$this->assertEquals(array($child, $parent), $map['ParentCBundle']);
$this->assertEquals(array($child), $map['ChildCBundle']);
}
/**
* @group legacy
* @expectedException \LogicException
* @expectedExceptionMessage Bundle "ParentCBundle" is directly extended by two bundles "ChildC2Bundle" and "ChildC1Bundle".
*/
public function testInitializeBundlesThrowsExceptionWhenABundleIsDirectlyExtendedByTwoBundles()
{
$parent = $this->getBundle(null, null, 'ParentCBundle');
$child1 = $this->getBundle(null, 'ParentCBundle', 'ChildC1Bundle');
$child2 = $this->getBundle(null, 'ParentCBundle', 'ChildC2Bundle');
$kernel = $this->getKernel(array(), array($parent, $child1, $child2));
$kernel->boot();
}
/**
* @group legacy
* @expectedException \LogicException
* @expectedExceptionMessage Trying to register two bundles with the same name "DuplicateName"
*/
@@ -735,19 +455,6 @@ EOF;
$kernel->boot();
}
/**
* @group legacy
* @expectedException \LogicException
* @expectedExceptionMessage Bundle "CircularRefBundle" can not extend itself.
*/
public function testInitializeBundleThrowsExceptionWhenABundleExtendsItself()
{
$circularRef = $this->getBundle(null, 'CircularRefBundle', 'CircularRefBundle');
$kernel = $this->getKernel(array(), array($circularRef));
$kernel->boot();
}
public function testTerminateReturnsSilentlyIfKernelIsNotBooted()
{
$kernel = $this->getKernel(array('getHttpKernel'));
@@ -807,25 +514,6 @@ EOF;
$this->assertEquals('_123', $kernel->getName());
}
/**
* @group legacy
* @expectedDeprecation The "Symfony\Component\HttpKernel\Kernel::getEnvParameters()" method is deprecated as of 3.3 and will be removed in 4.0. Use the %cenv()%c syntax to get the value of any environment variable from configuration files instead.
* @expectedDeprecation The support of special environment variables that start with SYMFONY__ (such as "SYMFONY__FOO__BAR") is deprecated as of 3.3 and will be removed in 4.0. Use the %cenv()%c syntax instead to get the value of environment variables in configuration files.
*/
public function testSymfonyEnvironmentVariables()
{
$_SERVER['SYMFONY__FOO__BAR'] = 'baz';
$kernel = $this->getKernel();
$method = new \ReflectionMethod($kernel, 'getEnvParameters');
$method->setAccessible(true);
$envParameters = $method->invoke($kernel);
$this->assertSame('baz', $envParameters['foo.bar']);
unset($_SERVER['SYMFONY__FOO__BAR']);
}
public function testProjectDirExtension()
{
$kernel = new CustomProjectDirKernel();