Merge branch '4.3' into 4.4

* 4.3:
  Fix more bad tests
  Fix test fixtures with deprecated method signatures.
  Fix 4.3 tests forward compat
  [Messenger] fix empty amqp body returned as false
  Fix routing cache broken when using generator_class
This commit is contained in:
Nicolas Grekas 2019-09-06 12:03:11 +02:00
commit 28d331bb58
26 changed files with 388 additions and 278 deletions

View File

@ -0,0 +1,27 @@
<?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\Bridge\Monolog\Tests;
use Symfony\Bridge\Monolog\Logger;
class ClassThatInheritLogger extends Logger
{
public function getLogs(): array
{
return parent::getLogs();
}
public function countErrors(): int
{
return parent::countErrors();
}
}

View File

@ -128,33 +128,12 @@ class LoggerTest extends TestCase
/**
* @group legacy
* @expectedDeprecation The "Symfony\Bridge\Monolog\Logger::getLogs()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
* @expectedDeprecation The "Symfony\Bridge\Monolog\Logger::countErrors()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
*/
public function testInheritedClassCallGetLogsWithoutArgument()
public function testInheritedClassWithoutArgument()
{
$loggerChild = new ClassThatInheritLogger('test');
$loggerChild->getLogs();
}
/**
* @group legacy
* @expectedDeprecation The "Symfony\Bridge\Monolog\Logger::countErrors()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
*/
public function testInheritedClassCallCountErrorsWithoutArgument()
{
$loggerChild = new ClassThatInheritLogger('test');
$loggerChild->countErrors();
}
}
class ClassThatInheritLogger extends Logger
{
public function getLogs(): array
{
return parent::getLogs();
}
public function countErrors(): int
{
return parent::countErrors();
}
}

View File

@ -0,0 +1,27 @@
<?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\Bridge\Monolog\Tests\Processor;
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
class ClassThatInheritDebugProcessor extends DebugProcessor
{
public function getLogs(): array
{
return parent::getLogs();
}
public function countErrors(): int
{
return parent::countErrors();
}
}

View File

@ -66,20 +66,12 @@ class DebugProcessorTest extends TestCase
/**
* @group legacy
* @expectedDeprecation The "Symfony\Bridge\Monolog\Processor\DebugProcessor::getLogs()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
* @expectedDeprecation The "Symfony\Bridge\Monolog\Processor\DebugProcessor::countErrors()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
*/
public function testInheritedClassCallGetLogsWithoutArgument()
public function testInheritedClassWithoutArgument()
{
$debugProcessorChild = new ClassThatInheritDebugProcessor();
$debugProcessorChild->getLogs();
}
/**
* @group legacy
* @expectedDeprecation The "Symfony\Bridge\Monolog\Processor\DebugProcessor::countErrors()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
*/
public function testInheritedClassCallCountErrorsWithoutArgument()
{
$debugProcessorChild = new ClassThatInheritDebugProcessor();
$debugProcessorChild->countErrors();
}
@ -96,16 +88,3 @@ class DebugProcessorTest extends TestCase
];
}
}
class ClassThatInheritDebugProcessor extends DebugProcessor
{
public function getLogs(): array
{
return parent::getLogs();
}
public function countErrors(): int
{
return parent::countErrors();
}
}

View File

@ -81,8 +81,6 @@ class AbstractControllerTest extends ControllerTraitTest
class TestAbstractController extends AbstractController
{
use TestControllerTrait;
private $throwOnUnexpectedService;
public function __construct($throwOnUnexpectedService = true)
@ -90,6 +88,11 @@ class TestAbstractController extends AbstractController
$this->throwOnUnexpectedService = $throwOnUnexpectedService;
}
public function __call(string $method, array $arguments)
{
return $this->$method(...$arguments);
}
public function setContainer(ContainerInterface $container)
{
if (!$this->throwOnUnexpectedService) {
@ -114,11 +117,6 @@ class TestAbstractController extends AbstractController
return parent::setContainer($container);
}
public function getParameter(string $name)
{
return parent::getParameter($name);
}
public function fooAction()
{
}

View File

@ -11,7 +11,6 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Form\Form;
@ -545,29 +544,3 @@ abstract class ControllerTraitTest extends TestCase
$this->assertContains($link2, $links);
}
}
trait TestControllerTrait
{
use ControllerTrait {
generateUrl as public;
redirect as public;
forward as public;
getUser as public;
json as public;
file as public;
isGranted as public;
denyAccessUnlessGranted as public;
redirectToRoute as public;
addFlash as public;
isCsrfTokenValid as public;
renderView as public;
render as public;
stream as public;
createNotFoundException as public;
createAccessDeniedException as public;
createForm as public;
createFormBuilder as public;
getDoctrine as public;
addLink as public;
}
}

View File

@ -3,8 +3,30 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait;
class TestController extends Controller
{
use TestControllerTrait;
use ControllerTrait {
generateUrl as public;
redirect as public;
forward as public;
getUser as public;
json as public;
file as public;
isGranted as public;
denyAccessUnlessGranted as public;
redirectToRoute as public;
addFlash as public;
isCsrfTokenValid as public;
renderView as public;
render as public;
stream as public;
createNotFoundException as public;
createAccessDeniedException as public;
createForm as public;
createFormBuilder as public;
getDoctrine as public;
addLink as public;
}
}

View File

@ -24,6 +24,7 @@ class MissingUserProviderTest extends AbstractWebTestCase
$response = $client->getResponse();
$this->assertSame(500, $response->getStatusCode());
$this->stringContains('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException', $response->getContent());
$this->stringContains('"default" firewall requires a user provider but none was defined.', $response->getContent());
}
}

View File

@ -16,5 +16,6 @@ use Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\MissingUserProviderBun
return [
new FrameworkBundle(),
new SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new MissingUserProviderBundle(),
];

View File

@ -1,5 +1,5 @@
imports:
- { resource: ./../config/framework.yml }
- { resource: ./../config/default.yml }
security:
firewalls:

View File

@ -20,61 +20,6 @@ use Symfony\Component\BrowserKit\Response;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\DomCrawler\Form as DomCrawlerForm;
class SpecialResponse extends Response
{
}
class TestClient extends AbstractBrowser
{
protected $nextResponse = null;
protected $nextScript = null;
public function setNextResponse(Response $response)
{
$this->nextResponse = $response;
}
public function setNextScript($script)
{
$this->nextScript = $script;
}
protected function doRequest($request): Response
{
if (null === $this->nextResponse) {
return new Response();
}
$response = $this->nextResponse;
$this->nextResponse = null;
return $response;
}
protected function filterResponse($response): Response
{
if ($response instanceof SpecialResponse) {
return new Response($response->getContent(), $response->getStatusCode(), $response->getHeaders());
}
return $response;
}
protected function getScript($request)
{
$r = new \ReflectionClass('Symfony\Component\BrowserKit\Response');
$path = $r->getFileName();
return <<<EOF
<?php
require_once('$path');
echo serialize($this->nextScript);
EOF;
}
}
class AbstractBrowserTest extends TestCase
{
public function getBrowser(array $server = [], History $history = null, CookieJar $cookieJar = null)
@ -160,17 +105,6 @@ class AbstractBrowserTest extends TestCase
$this->assertNull($client->getResponse());
}
public function testGetInternalResponse()
{
$client = $this->getBrowser();
$client->setNextResponse(new SpecialResponse('foo'));
$client->request('GET', 'http://example.com/');
$this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getInternalResponse());
$this->assertNotInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getInternalResponse());
$this->assertInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getResponse());
}
/**
* @group legacy
* @expectedDeprecation Calling the "Symfony\Component\BrowserKit\Tests\%s::getInternalResponse()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.

View File

@ -0,0 +1,44 @@
<?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\BrowserKit\Tests;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\DomCrawler\Form as DomCrawlerForm;
class ClassThatInheritClient extends AbstractBrowser
{
protected $nextResponse = null;
public function setNextResponse(Response $response)
{
$this->nextResponse = $response;
}
protected function doRequest($request): Response
{
if (null === $this->nextResponse) {
return new Response();
}
$response = $this->nextResponse;
$this->nextResponse = null;
return $response;
}
public function submit(DomCrawlerForm $form, array $values = []): Crawler
{
return parent::submit($form, $values);
}
}

View File

@ -14,89 +14,9 @@ namespace Symfony\Component\BrowserKit\Tests;
use Symfony\Component\BrowserKit\CookieJar;
use Symfony\Component\BrowserKit\History;
use Symfony\Component\BrowserKit\HttpBrowser;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
class SpecialHttpResponse extends Response
{
}
class TestHttpClient extends HttpBrowser
{
protected $nextResponse = null;
protected $nextScript = null;
public function __construct(array $server = [], History $history = null, CookieJar $cookieJar = null)
{
$client = new MockHttpClient(function (string $method, string $url, array $options) {
if (null === $this->nextResponse) {
return new MockResponse();
}
return new MockResponse($this->nextResponse->getContent(), [
'http_code' => $this->nextResponse->getStatusCode(),
'response_headers' => $this->nextResponse->getHeaders(),
]);
});
parent::__construct($client);
$this->setServerParameters($server);
$this->history = $history ?? new History();
$this->cookieJar = $cookieJar ?? new CookieJar();
}
public function setNextResponse(Response $response)
{
$this->nextResponse = $response;
}
public function setNextScript($script)
{
$this->nextScript = $script;
}
protected function filterResponse($response): Response
{
if ($response instanceof SpecialHttpResponse) {
return new Response($response->getContent(), $response->getStatusCode(), $response->getHeaders());
}
return $response;
}
protected function doRequest($request): Response
{
$response = parent::doRequest($request);
if (null === $this->nextResponse) {
return $response;
}
$class = \get_class($this->nextResponse);
$response = new $class($response->getContent(), $response->getStatusCode(), $response->getHeaders());
$this->nextResponse = null;
return $response;
}
protected function getScript($request)
{
$r = new \ReflectionClass('Symfony\Component\BrowserKit\Response');
$path = $r->getFileName();
return <<<EOF
<?php
require_once('$path');
echo serialize($this->nextScript);
EOF;
}
}
class HttpBrowserTest extends AbstractBrowserTest
{
public function getBrowser(array $server = [], History $history = null, CookieJar $cookieJar = null)
@ -104,17 +24,6 @@ class HttpBrowserTest extends AbstractBrowserTest
return new TestHttpClient($server, $history, $cookieJar);
}
public function testGetInternalResponse()
{
$client = $this->getBrowser();
$client->setNextResponse(new SpecialHttpResponse('foo'));
$client->request('GET', 'http://example.com/');
$this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getInternalResponse());
$this->assertNotInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialHttpResponse', $client->getInternalResponse());
$this->assertInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialHttpResponse', $client->getResponse());
}
/**
* @dataProvider validContentTypes
*/

View File

@ -0,0 +1,57 @@
<?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\BrowserKit\Tests;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Response;
class TestClient extends AbstractBrowser
{
protected $nextResponse = null;
protected $nextScript = null;
public function setNextResponse(Response $response)
{
$this->nextResponse = $response;
}
public function setNextScript($script)
{
$this->nextScript = $script;
}
protected function doRequest($request): Response
{
if (null === $this->nextResponse) {
return new Response();
}
$response = $this->nextResponse;
$this->nextResponse = null;
return $response;
}
protected function getScript($request)
{
$r = new \ReflectionClass('Symfony\Component\BrowserKit\Response');
$path = $r->getFileName();
return <<<EOF
<?php
require_once('$path');
echo serialize($this->nextScript);
EOF;
}
}

View File

@ -0,0 +1,80 @@
<?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\BrowserKit\Tests;
use Symfony\Component\BrowserKit\CookieJar;
use Symfony\Component\BrowserKit\History;
use Symfony\Component\BrowserKit\HttpBrowser;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
class TestHttpClient extends HttpBrowser
{
protected $nextResponse = null;
protected $nextScript = null;
public function __construct(array $server = [], History $history = null, CookieJar $cookieJar = null)
{
$client = new MockHttpClient(function (string $method, string $url, array $options) {
if (null === $this->nextResponse) {
return new MockResponse();
}
return new MockResponse($this->nextResponse->getContent(), [
'http_code' => $this->nextResponse->getStatusCode(),
'response_headers' => $this->nextResponse->getHeaders(),
]);
});
parent::__construct($client);
$this->setServerParameters($server);
$this->history = $history ?? new History();
$this->cookieJar = $cookieJar ?? new CookieJar();
}
public function setNextResponse(Response $response)
{
$this->nextResponse = $response;
}
public function setNextScript($script)
{
$this->nextScript = $script;
}
protected function doRequest($request): Response
{
if (null === $this->nextResponse) {
return parent::doRequest($request);
}
$response = $this->nextResponse;
$this->nextResponse = null;
return $response;
}
protected function getScript($request)
{
$r = new \ReflectionClass('Symfony\Component\BrowserKit\Response');
$path = $r->getFileName();
return <<<EOF
<?php
require_once('$path');
echo serialize($this->nextScript);
EOF;
}
}

View File

@ -1337,14 +1337,3 @@ HTML;
return $domxpath->query('//div');
}
}
class ClassThatInheritCrawler extends Crawler
{
/**
* @return static
*/
public function children()
{
return parent::children();
}
}

View File

@ -0,0 +1,25 @@
<?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\DomCrawler\Tests;
use Symfony\Component\DomCrawler\Crawler;
class ClassThatInheritCrawler extends Crawler
{
/**
* @return static
*/
public function children()
{
return parent::children();
}
}

View File

@ -0,0 +1,25 @@
<?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\Finder\Tests;
use Symfony\Component\Finder\Finder;
class ClassThatInheritFinder extends Finder
{
/**
* @return $this
*/
public function sortByName()
{
parent::sortByName();
}
}

View File

@ -873,6 +873,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
$expected = [
self::$tmpDir.\DIRECTORY_SEPARATOR.'test.php',
__DIR__.\DIRECTORY_SEPARATOR.'ClassThatInheritFinder.php',
__DIR__.\DIRECTORY_SEPARATOR.'GitignoreTest.php',
__DIR__.\DIRECTORY_SEPARATOR.'FinderTest.php',
__DIR__.\DIRECTORY_SEPARATOR.'GlobTest.php',
@ -1435,14 +1436,3 @@ class FinderTest extends Iterator\RealIteratorTestCase
return Finder::create();
}
}
class ClassThatInheritFinder extends Finder
{
/**
* @return $this
*/
public function sortByName()
{
parent::sortByName();
}
}

View File

@ -12,12 +12,13 @@
namespace Symfony\Component\Form\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
class AbstractTypeExtensionTest extends TestCase
{
/**
* @group legacy
*/
public function testImplementingNeitherGetExtendedTypeNorExtendsTypeThrowsException()
{
$this->expectException('Symfony\Component\Form\Exception\LogicException');
@ -28,6 +29,7 @@ class AbstractTypeExtensionTest extends TestCase
/**
* @group legacy
* @expectedDeprecation The Symfony\Component\Form\Tests\MultipleTypesExtension::getExtendedType() method is deprecated since Symfony 4.2 and will be removed in 5.0. Use getExtendedTypes() instead.
*/
public function testGetExtendedTypeReturnsFirstConfiguredExtension()
{
@ -36,16 +38,3 @@ class AbstractTypeExtensionTest extends TestCase
$this->assertSame(DateTimeType::class, $extension->getExtendedType());
}
}
class MultipleTypesExtension extends AbstractTypeExtension
{
public static function getExtendedTypes(): iterable
{
yield DateTimeType::class;
yield DateType::class;
}
}
class TypeExtensionWithoutExtendedTypes extends AbstractTypeExtension
{
}

View File

@ -0,0 +1,25 @@
<?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\Form\Tests;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
class MultipleTypesExtension extends AbstractTypeExtension
{
public static function getExtendedTypes(): iterable
{
yield DateTimeType::class;
yield DateType::class;
}
}

View File

@ -0,0 +1,18 @@
<?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\Form\Tests;
use Symfony\Component\Form\AbstractTypeExtension;
class TypeExtensionWithoutExtendedTypes extends AbstractTypeExtension
{
}

View File

@ -159,7 +159,7 @@ class ExceptionListenerTest extends TestCase
class TestLogger extends Logger implements DebugLoggerInterface
{
public function countErrors(): int
public function countErrors(Request $request = null): int
{
return \count($this->logs['critical']);
}

View File

@ -58,9 +58,11 @@ class AmqpReceiver implements ReceiverInterface, MessageCountAwareInterface
return;
}
$body = $amqpEnvelope->getBody();
try {
$envelope = $this->serializer->decode([
'body' => $amqpEnvelope->getBody(),
'body' => false === $body ? '' : $body, // workaround https://github.com/pdezwart/php-amqp/issues/351
'headers' => $amqpEnvelope->getHeaders(),
]);
} catch (MessageDecodingFailedException $exception) {

View File

@ -23,11 +23,13 @@ use Symfony\Component\Routing\Generator\CompiledUrlGenerator;
use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface;
use Symfony\Component\Routing\Generator\Dumper\CompiledUrlGeneratorDumper;
use Symfony\Component\Routing\Generator\Dumper\GeneratorDumperInterface;
use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Matcher\CompiledUrlMatcher;
use Symfony\Component\Routing\Matcher\Dumper\CompiledUrlMatcherDumper;
use Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
@ -388,6 +390,11 @@ class Router implements RouterInterface, RequestMatcherInterface
*/
protected function getGeneratorDumperInstance()
{
// For BC, fallback to PhpGeneratorDumper if the UrlGenerator and UrlGeneratorDumper are not consistent with each other
if (is_a($this->options['generator_class'], CompiledUrlGenerator::class, true) !== is_a($this->options['generator_dumper_class'], CompiledUrlGeneratorDumper::class, true)) {
return new PhpGeneratorDumper($this->getRouteCollection());
}
return new $this->options['generator_dumper_class']($this->getRouteCollection());
}
@ -396,6 +403,11 @@ class Router implements RouterInterface, RequestMatcherInterface
*/
protected function getMatcherDumperInstance()
{
// For BC, fallback to PhpMatcherDumper if the UrlMatcher and UrlMatcherDumper are not consistent with each other
if (is_a($this->options['matcher_class'], CompiledUrlMatcher::class, true) !== is_a($this->options['matcher_dumper_class'], CompiledUrlMatcherDumper::class, true)) {
return new PhpMatcherDumper($this->getRouteCollection());
}
return new $this->options['matcher_dumper_class']($this->getRouteCollection());
}

View File

@ -172,6 +172,10 @@ class FakeCustomToken implements TokenInterface
{
}
public function getRoleNames(): array
{
}
public function getCredentials()
{
}