Merge branch '3.1'

* 3.1:
  [Form] fixed ChoiceTypeTest after #17822
  [DoctrineBridge] fixed DoctrineChoiceLoaderTest by removing deprecated factory
  [ci] Upgrade phpunit wrapper deps
  [FrameworkBundle] Fix fixtures
  [HttpKernel] Inline ValidateRequestListener logic into HttpKernel
  fixed HttpKernel dependencies after #18688
This commit is contained in:
Nicolas Grekas 2016-06-29 15:38:44 +02:00
commit d08cbe6e8b
21 changed files with 88 additions and 222 deletions

View File

@ -11,7 +11,7 @@
*/
// Please update when phpunit needs to be reinstalled with fresh deps:
// Cache-Id-Version: 2016-03-25 09:45 UTC
// Cache-Id-Version: 2016-06-29 13:45 UTC
use Symfony\Component\Process\ProcessUtils;

View File

@ -18,18 +18,12 @@ use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ChoiceListFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $factory;
/**
* @var ObjectManager|\PHPUnit_Framework_MockObject_MockObject
*/
@ -98,36 +92,60 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadChoiceList()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
);
$choices = array($this->obj1, $this->obj2, $this->obj3);
$choiceList = new ArrayChoiceList(array());
$value = function () {};
$choiceList = new ArrayChoiceList($choices, $value);
$this->repository->expects($this->once())
->method('findAll')
->willReturn($choices);
$this->factory->expects($this->once())
->method('createListFromChoices')
->with($choices, $value)
->willReturn($choiceList);
$this->assertSame($choiceList, $loader->loadChoiceList($value));
$this->assertEquals($choiceList, $loader->loadChoiceList($value));
// no further loads on subsequent calls
$this->assertSame($choiceList, $loader->loadChoiceList($value));
$this->assertEquals($choiceList, $loader->loadChoiceList($value));
}
/**
* @group legacy
*/
public function testLegacyLoadChoiceList()
{
$factory = $this->getMock('Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface');
$loader = new DoctrineChoiceLoader(
$factory,
$this->om,
$this->class,
$this->idReader
);
$choices = array($this->obj1, $this->obj2, $this->obj3);
$value = function () {};
$choiceList = new ArrayChoiceList($choices, $value);
$this->repository->expects($this->once())
->method('findAll')
->willReturn($choices);
$factory->expects($this->never())
->method('createListFromChoices');
$this->assertEquals($choiceList, $loaded = $loader->loadChoiceList($value));
// no further loads on subsequent calls
$this->assertSame($loaded, $loader->loadChoiceList($value));
}
public function testLoadChoiceListUsesObjectLoaderIfAvailable()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader,
@ -135,7 +153,7 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
);
$choices = array($this->obj1, $this->obj2, $this->obj3);
$choiceList = new ArrayChoiceList(array());
$choiceList = new ArrayChoiceList($choices);
$this->repository->expects($this->never())
->method('findAll');
@ -144,39 +162,27 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
->method('getEntities')
->willReturn($choices);
$this->factory->expects($this->once())
->method('createListFromChoices')
->with($choices)
->willReturn($choiceList);
$this->assertSame($choiceList, $loader->loadChoiceList());
$this->assertEquals($choiceList, $loaded = $loader->loadChoiceList());
// no further loads on subsequent calls
$this->assertSame($choiceList, $loader->loadChoiceList());
$this->assertSame($loaded, $loader->loadChoiceList());
}
public function testLoadValuesForChoices()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
);
$choices = array($this->obj1, $this->obj2, $this->obj3);
$choiceList = new ArrayChoiceList($choices);
$this->repository->expects($this->once())
->method('findAll')
->willReturn($choices);
$this->factory->expects($this->once())
->method('createListFromChoices')
->with($choices)
->willReturn($choiceList);
$this->assertSame(array('1', '2'), $loader->loadValuesForChoices(array($this->obj2, $this->obj3)));
// no further loads on subsequent calls
@ -187,7 +193,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadValuesForChoicesDoesNotLoadIfEmptyChoices()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
@ -196,16 +201,12 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$this->repository->expects($this->never())
->method('findAll');
$this->factory->expects($this->never())
->method('createListFromChoices');
$this->assertSame(array(), $loader->loadValuesForChoices(array()));
}
public function testLoadValuesForChoicesDoesNotLoadIfSingleIntId()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
@ -218,9 +219,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$this->repository->expects($this->never())
->method('findAll');
$this->factory->expects($this->never())
->method('createListFromChoices');
$this->idReader->expects($this->any())
->method('getIdValue')
->with($this->obj2)
@ -232,7 +230,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadValuesForChoicesLoadsIfSingleIntIdAndValueGiven()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
@ -240,7 +237,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$choices = array($this->obj1, $this->obj2, $this->obj3);
$value = function (\stdClass $object) { return $object->name; };
$choiceList = new ArrayChoiceList($choices, $value);
$this->idReader->expects($this->any())
->method('isSingleId')
@ -250,11 +246,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
->method('findAll')
->willReturn($choices);
$this->factory->expects($this->once())
->method('createListFromChoices')
->with($choices, $value)
->willReturn($choiceList);
$this->assertSame(array('B'), $loader->loadValuesForChoices(
array($this->obj2),
$value
@ -264,7 +255,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadValuesForChoicesDoesNotLoadIfValueIsIdReader()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
@ -279,9 +269,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$this->repository->expects($this->never())
->method('findAll');
$this->factory->expects($this->never())
->method('createListFromChoices');
$this->idReader->expects($this->any())
->method('getIdValue')
->with($this->obj2)
@ -296,24 +283,17 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadChoicesForValues()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
);
$choices = array($this->obj1, $this->obj2, $this->obj3);
$choiceList = new ArrayChoiceList($choices);
$this->repository->expects($this->once())
->method('findAll')
->willReturn($choices);
$this->factory->expects($this->once())
->method('createListFromChoices')
->with($choices)
->willReturn($choiceList);
$this->assertSame(array($this->obj2, $this->obj3), $loader->loadChoicesForValues(array('1', '2')));
// no further loads on subsequent calls
@ -324,7 +304,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadChoicesForValuesDoesNotLoadIfEmptyValues()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
@ -333,16 +312,12 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$this->repository->expects($this->never())
->method('findAll');
$this->factory->expects($this->never())
->method('createListFromChoices');
$this->assertSame(array(), $loader->loadChoicesForValues(array()));
}
public function testLoadChoicesForValuesLoadsOnlyChoicesIfSingleIntId()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader,
@ -362,9 +337,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$this->repository->expects($this->never())
->method('findAll');
$this->factory->expects($this->never())
->method('createListFromChoices');
$this->objectLoader->expects($this->once())
->method('getEntitiesByIds')
->with('idField', array(4 => '3', 7 => '2'))
@ -386,7 +358,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadChoicesForValuesLoadsAllIfSingleIntIdAndValueGiven()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
@ -394,7 +365,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$choices = array($this->obj1, $this->obj2, $this->obj3);
$value = function (\stdClass $object) { return $object->name; };
$choiceList = new ArrayChoiceList($choices, $value);
$this->idReader->expects($this->any())
->method('isSingleId')
@ -404,11 +374,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
->method('findAll')
->willReturn($choices);
$this->factory->expects($this->once())
->method('createListFromChoices')
->with($choices, $value)
->willReturn($choiceList);
$this->assertSame(array($this->obj2), $loader->loadChoicesForValues(
array('B'),
$value
@ -418,7 +383,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadChoicesForValuesLoadsOnlyChoicesIfValueIsIdReader()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader,
@ -439,9 +403,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$this->repository->expects($this->never())
->method('findAll');
$this->factory->expects($this->never())
->method('createListFromChoices');
$this->objectLoader->expects($this->once())
->method('getEntitiesByIds')
->with('idField', array('2'))

View File

@ -61,9 +61,5 @@
<argument type="service" id="request_stack" />
<tag name="kernel.event_subscriber" />
</service>
<service id="validate_request_listener" class="Symfony\Component\HttpKernel\EventListener\ValidateRequestListener">
<tag name="kernel.event_subscriber" />
</service>
</services>
</container>

View File

@ -1,5 +1,5 @@
--------------------- -----------------------------------------------------------------
Parameter Value
 Parameter   Value 
--------------------- -----------------------------------------------------------------
twig.form.resources ["bootstrap_3_horizontal_layout.html.twig","bootstrap_3_layo...
--------------------- -----------------------------------------------------------------

View File

@ -3,7 +3,7 @@
=================================
------------------- --------------------------------------------------------
Service ID Class name
 Service ID   Class name 
------------------- --------------------------------------------------------
alias_1 alias for "service_1"
alias_2 alias for "service_2"

View File

@ -3,7 +3,7 @@
=============================================
------------------- --------------------------------------------------------
Service ID Class name
 Service ID   Class name 
------------------- --------------------------------------------------------
alias_1 alias for "service_1"
alias_2 alias for "service_2"

View File

@ -3,7 +3,7 @@
====================================================================
-------------- ------- ------- ------- -----------------------
Service ID attr1 attr2 attr3 Class name
 Service ID   attr1   attr2   attr3   Class name 
-------------- ------- ------- ------- -----------------------
definition_2 val1 val2 Full\Qualified\Class2
" val3

View File

@ -1,5 +1,5 @@
------------------ -----------------------------
Option Value
 Option   Value 
------------------ -----------------------------
Service ID -
Class Full\Qualified\Class1

View File

@ -1,5 +1,5 @@
------------------ -------------------------------------------------------
Option Value
 Option   Value 
------------------ -------------------------------------------------------
Service ID -
Class Full\Qualified\Class2

View File

@ -3,7 +3,7 @@
=======================================
------- ------------------- ----------
Order Callable Priority
 Order   Callable   Priority 
------- ------------------- ----------
#1 global_function() 255
#2 \Closure() -1

View File

@ -6,7 +6,7 @@
--------------
------- ------------------- ----------
Order Callable Priority
 Order   Callable   Priority 
------- ------------------- ----------
#1 global_function() 255
#2 \Closure() -1
@ -16,7 +16,7 @@
--------------
------- ----------------------------------------------------------------------------------- ----------
Order Callable Priority
 Order   Callable   Priority 
------- ----------------------------------------------------------------------------------- ----------
#1 Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\CallableClass::__invoke() 0
------- ----------------------------------------------------------------------------------- ----------

View File

@ -1,5 +1,5 @@
--------------- ---------
Parameter Value
 Parameter   Value 
--------------- ---------
database_name symfony
--------------- ---------

View File

@ -3,7 +3,7 @@
============================
----------- --------------------------
Parameter Value
 Parameter   Value 
----------- --------------------------
array [12,"Hello world!",true]
boolean true

View File

@ -1,5 +1,5 @@
--------- ---------- ------------ ----------- ---------------
Name Method Scheme Host Path
 Name   Method   Scheme   Host   Path 
--------- ---------- ------------ ----------- ---------------
route_1 GET|HEAD http|https localhost /hello/{name}
route_2 PUT|POST http|https localhost /name/add

View File

@ -39,7 +39,7 @@
},
"require-dev": {
"symfony/browser-kit": "~2.8|~3.0",
"symfony/console": "~2.8|~3.0",
"symfony/console": "~2.8.8|~3.0.8|~3.1.2|~3.2",
"symfony/css-selector": "~2.8|~3.0",
"symfony/dom-crawler": "~2.8|~3.0",
"symfony/polyfill-intl-icu": "~1.0",

View File

@ -590,7 +590,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
'multiple' => false,
'expanded' => false,
'choices' => array('test'),
'choices_as_values' => true,
'empty_data' => 'test',
));
@ -605,7 +604,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
'multiple' => true,
'expanded' => false,
'choices' => array('test'),
'choices_as_values' => true,
'empty_data' => array('test'),
));
@ -620,7 +618,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
'multiple' => false,
'expanded' => true,
'choices' => array('test'),
'choices_as_values' => true,
'empty_data' => 'test',
));
@ -635,7 +632,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
'multiple' => true,
'expanded' => true,
'choices' => array('test'),
'choices_as_values' => true,
'empty_data' => array('test'),
));

View File

@ -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\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* Validates that the headers and other information indicating the
* client IP address of a request are consistent.
*
* @author Magnus Nordlander <magnus@fervo.se>
*/
class ValidateRequestListener implements EventSubscriberInterface
{
/**
* Performs the validation.
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->isMasterRequest()) {
try {
// This will throw an exception if the headers are inconsistent.
$event->getRequest()->getClientIps();
} catch (ConflictingHeadersException $e) {
throw new BadRequestHttpException('The request headers contain conflicting information regarding the origin of this request.', $e);
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array(
KernelEvents::REQUEST => array(
array('onKernelRequest', 256),
),
);
}
}

View File

@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
@ -24,6 +25,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
@ -117,6 +119,13 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
*/
private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
{
if (self::MASTER_REQUEST === $type && $request::getTrustedProxies()) {
try {
$request->getClientIps();
} catch (ConflictingHeadersException $e) {
throw new BadRequestHttpException('The request headers contain conflicting information regarding the origin of this request.', $e);
}
}
$this->requestStack->push($request);
// request

View File

@ -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 Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
class ValidateRequestListenerTest extends \PHPUnit_Framework_TestCase
{
public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$listener = new ValidateRequestListener();
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request->method('getClientIps')
->will($this->throwException(new ConflictingHeadersException()));
$dispatcher->addListener(KernelEvents::REQUEST, array($listener, 'onKernelRequest'));
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$this->setExpectedException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
}
public function testListenerDoesNothingOnValidRequests()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$listener = new ValidateRequestListener();
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request->method('getClientIps')
->willReturn(array('127.0.0.1'));
$dispatcher->addListener(KernelEvents::REQUEST, array($listener, 'onKernelRequest'));
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
}
public function testListenerDoesNothingOnSubrequests()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$listener = new ValidateRequestListener();
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request->method('getClientIps')
->will($this->throwException(new ConflictingHeadersException()));
$dispatcher->addListener(KernelEvents::REQUEST, array($listener, 'onKernelRequest'));
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST);
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
}
}

View File

@ -302,6 +302,33 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
$kernel->handle($request, HttpKernelInterface::MASTER_REQUEST);
}
/**
* @expectedException Symfony\Component\HttpKernel\Exception\BadRequestHttpException
*/
public function testInconsistentClientIpsOnMasterRequests()
{
$kernel = $this->getHttpKernel(new EventDispatcher());
$request = new Request();
$request->setTrustedProxies(array('1.1.1.1'));
$request->server->set('REMOTE_ADDR', '1.1.1.1');
$request->headers->set('FORWARDED', '2.2.2.2');
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
$kernel->handle($request, $kernel::MASTER_REQUEST, false);
}
public function testInconsistentClientIpsOnSubRequests()
{
$kernel = $this->getHttpKernel(new EventDispatcher());
$request = new Request();
$request->setTrustedProxies(array('1.1.1.1'));
$request->server->set('REMOTE_ADDR', '1.1.1.1');
$request->headers->set('FORWARDED', '2.2.2.2');
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $kernel->handle($request, $kernel::SUB_REQUEST, false));
}
private function getHttpKernel(EventDispatcherInterface $eventDispatcher, $controller = null, RequestStack $requestStack = null, array $arguments = array())
{
if (null === $controller) {

View File

@ -18,7 +18,7 @@
"require": {
"php": ">=5.5.9",
"symfony/event-dispatcher": "~2.8|~3.0",
"symfony/http-foundation": "~2.8|~3.0",
"symfony/http-foundation": "~2.8.8|~3.0.8|~3.1.2|~3.2",
"symfony/debug": "~2.8|~3.0",
"psr/log": "~1.0"
},