From 6b8839d95482ccdc74a2efcbda16713f7a5e2315 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Mon, 31 Jan 2022 20:38:30 +0100 Subject: [PATCH] [Routing] AnnotationDirectoryLoader::load() may return null Closes #45259 --- .../Routing/Loader/AnnotationDirectoryLoader.php | 2 +- .../Tests/Loader/AnnotationDirectoryLoaderTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php index c1ca8faff547..de1a260dea94 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php @@ -25,7 +25,7 @@ class AnnotationDirectoryLoader extends AnnotationFileLoader /** * @throws \InvalidArgumentException When the directory does not exist or its routes cannot be parsed */ - public function load(mixed $path, string $type = null): RouteCollection + public function load(mixed $path, string $type = null): ?RouteCollection { if (!is_dir($dir = $this->locator->locate($path))) { return parent::supports($path, $type) ? parent::load($path, $type) : new RouteCollection(); diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php index 858044d459f7..6ddd5b4dde5e 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php @@ -99,6 +99,14 @@ public function testLoadFileIfLocatedResourceIsFile() $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php'); } + public function testLoadAbstractClass() + { + $this->reader->expects($this->never())->method('getClassAnnotation'); + $this->reader->expects($this->never())->method('getMethodAnnotations'); + + $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/AbstractClass.php'); + } + private function expectAnnotationsToBeReadFrom(array $classes) { $this->reader->expects($this->exactly(\count($classes)))