From 6c109c71a9c181211932a058f2f6c7275144f593 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 7 Jun 2019 18:20:29 +0200 Subject: [PATCH 1/4] [FrameworkBundle] fix FC with HttpKernel v5 --- .../ResolveControllerNameSubscriber.php | 22 ++++++++++++++++--- .../ResolveControllerNameSubscriberTest.php | 16 +++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/EventListener/ResolveControllerNameSubscriber.php b/src/Symfony/Bundle/FrameworkBundle/EventListener/ResolveControllerNameSubscriber.php index 1964be1b4b..169c032779 100644 --- a/src/Symfony/Bundle/FrameworkBundle/EventListener/ResolveControllerNameSubscriber.php +++ b/src/Symfony/Bundle/FrameworkBundle/EventListener/ResolveControllerNameSubscriber.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\EventListener; use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -21,6 +21,8 @@ use Symfony\Component\HttpKernel\KernelEvents; * * @author Ryan Weaver * + * @method onKernelRequest(RequestEvent $event) + * * @deprecated since Symfony 4.1 */ class ResolveControllerNameSubscriber implements EventSubscriberInterface @@ -36,8 +38,22 @@ class ResolveControllerNameSubscriber implements EventSubscriberInterface $this->parser = $parser; } - public function onKernelRequest(GetResponseEvent $event) + /** + * @internal + */ + public function resolveControllerName(...$args) { + $this->onKernelRequest(...$args); + } + + public function __call(string $method, array $args) + { + if ('onKernelRequest' !== $method && 'onKernelRequest' !== strtolower($method)) { + throw new \Error(sprintf('Error: Call to undefined method %s::%s()', \get_class($this), $method)); + } + + $event = $args[0]; + $controller = $event->getRequest()->attributes->get('_controller'); if (\is_string($controller) && false === strpos($controller, '::') && 2 === substr_count($controller, ':')) { // controller in the a:b:c notation then @@ -50,7 +66,7 @@ class ResolveControllerNameSubscriber implements EventSubscriberInterface public static function getSubscribedEvents() { return [ - KernelEvents::REQUEST => ['onKernelRequest', 24], + KernelEvents::REQUEST => ['resolveControllerName', 24], ]; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php index 4d9acb9911..362f00e95c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php @@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; use Symfony\Bundle\FrameworkBundle\EventListener\ResolveControllerNameSubscriber; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -23,9 +24,6 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; */ class ResolveControllerNameSubscriberTest extends TestCase { - /** - * @group legacy - */ public function testReplacesControllerAttribute() { $parser = $this->getMockBuilder(ControllerNameParser::class)->disableOriginalConstructor()->getMock(); @@ -41,6 +39,10 @@ class ResolveControllerNameSubscriberTest extends TestCase $subscriber = new ResolveControllerNameSubscriber($parser); $subscriber->onKernelRequest(new RequestEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST)); $this->assertEquals('App\\Final\\Format::methodName', $request->attributes->get('_controller')); + + $subscriber = new ChildResolveControllerNameSubscriber($parser); + $subscriber->onKernelRequest(new RequestEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $this->assertEquals('App\\Final\\Format::methodName', $request->attributes->get('_controller')); } /** @@ -67,3 +69,11 @@ class ResolveControllerNameSubscriberTest extends TestCase yield [function () {}]; } } + +class ChildResolveControllerNameSubscriber extends ResolveControllerNameSubscriber +{ + public function onKernelRequest(GetResponseEvent $event) + { + parent::onKernelRequest($event); + } +} From 5e1ffb8d7ff3c043fa4e32e94dcf82338b2c78bf Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 7 Jun 2019 19:50:04 +0200 Subject: [PATCH 2/4] [travis] increase concurrency --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 405eb68e90..3a02215951 100644 --- a/.travis.yml +++ b/.travis.yml @@ -260,12 +260,12 @@ install: tfold 'phpunit install' ./phpunit install fi if [[ $deps = high ]]; then - echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && $COMPOSER_UP && $PHPUNIT_X$LEGACY'" + echo "$COMPONENTS" | parallel --gnu "tfold {} 'cd {} && $COMPOSER_UP && $PHPUNIT_X$LEGACY'" elif [[ $deps = low ]]; then [[ -e ~/php-ext/composer-lowest.lock.tar ]] && tar -xf ~/php-ext/composer-lowest.lock.tar tar -cf ~/php-ext/composer-lowest.lock.tar --files-from /dev/null php .github/rm-invalid-lowest-lock-files.php $COMPONENTS - echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && ([ -e composer.lock ] && ${COMPOSER_UP/update/install} || $COMPOSER_UP --prefer-lowest --prefer-stable) && $PHPUNIT_X'" + echo "$COMPONENTS" | parallel --gnu "tfold {} 'cd {} && ([ -e composer.lock ] && ${COMPOSER_UP/update/install} || $COMPOSER_UP --prefer-lowest --prefer-stable) && $PHPUNIT_X'" echo "$COMPONENTS" | xargs -n1 -I{} tar --append -f ~/php-ext/composer-lowest.lock.tar {}/composer.lock elif [[ $PHP = hhvm* ]]; then rm src/Symfony/Bridge/PhpUnit -Rf From 5b2991804372d7f54829128d902dd04241c8df69 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 7 Jun 2019 20:09:56 +0200 Subject: [PATCH 3/4] [TwigBundle] fix tests --- .../TwigBundle/Tests/Loader/FilesystemLoaderTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php index 697e6ceb66..b19a1180fc 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php @@ -11,10 +11,13 @@ namespace Symfony\Bundle\TwigBundle\Tests\Loader; -use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; use Symfony\Bundle\TwigBundle\Loader\FilesystemLoader; use Symfony\Bundle\TwigBundle\Tests\TestCase; +use Symfony\Component\Templating\TemplateReferenceInterface; +/** + * @group legacy + */ class FilesystemLoaderTest extends TestCase { public function testGetSourceContext() @@ -61,7 +64,7 @@ class FilesystemLoaderTest extends TestCase ->expects($this->once()) ->method('parse') ->with('name.format.engine') - ->willReturn(new TemplateReference('', '', 'name', 'format', 'engine')) + ->willReturn($this->getMockBuilder(TemplateReferenceInterface::class)->getMock()) ; $locator = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); @@ -85,7 +88,7 @@ class FilesystemLoaderTest extends TestCase ->expects($this->once()) ->method('parse') ->with('name.format.engine') - ->willReturn(new TemplateReference('', '', 'name', 'format', 'engine')) + ->willReturn($this->getMockBuilder(TemplateReferenceInterface::class)->getMock()) ; $locator = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); From b702598b0bb0d03b994b567156bb584003f23388 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 7 Jun 2019 11:25:07 -0400 Subject: [PATCH 4/4] Fixing bug where PropertyInfoLoader tried to add validation to non-existent properties --- .../Component/Validator/Mapping/Loader/PropertyInfoLoader.php | 4 ++++ .../Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php | 4 ++++ .../Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php | 1 + 3 files changed, 9 insertions(+) diff --git a/src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php index df3878d6e2..7ddd534275 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php @@ -60,6 +60,10 @@ final class PropertyInfoLoader implements LoaderInterface continue; } + if (!property_exists($className, $property)) { + continue; + } + $types = $this->typeExtractor->getTypes($className, $property); if (null === $types) { continue; diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php b/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php index 42f048c5d8..5f2a37179d 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php @@ -48,4 +48,8 @@ class PropertyInfoLoaderEntity public $alreadyPartiallyMappedCollection; public $readOnly; + + public function setNonExistentField() + { + } } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php index 71b2691ee5..f87b19f795 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php @@ -46,6 +46,7 @@ class PropertyInfoLoaderTest extends TestCase 'alreadyMappedNotBlank', 'alreadyPartiallyMappedCollection', 'readOnly', + 'nonExistentField', ]) ; $propertyInfoStub