From f4ce2aa0d15495d9ffdf5978635897e84858f6a1 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 4 May 2020 09:17:14 +0200 Subject: [PATCH] adjust deprecation messages and cleanup phpunit tests --- .travis.yml | 1 - src/ChainRouter.php | 10 +- src/ContentAwareGenerator.php | 23 ++-- src/DynamicRouter.php | 14 +- src/RouteObjectInterface.php | 2 +- tests/Unit/Routing/ChainRouterTest.php | 6 +- .../Routing/ContentAwareGeneratorTest.php | 120 +++++++++--------- 7 files changed, 96 insertions(+), 80 deletions(-) diff --git a/.travis.yml b/.travis.yml index 92619bc3..80a64c3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,6 @@ cache: - $HOME/.composer/cache env: - matrix: SYMFONY_VERSION=4.0.* global: - SYMFONY_PHPUNIT_VERSION=6 - COMPOSER_MEMORY_LIMIT=-1 diff --git a/src/ChainRouter.php b/src/ChainRouter.php index 87b892d7..b522c2d2 100644 --- a/src/ChainRouter.php +++ b/src/ChainRouter.php @@ -213,13 +213,21 @@ private function doMatch($pathinfo, Request $request = null) /** * {@inheritdoc} * + * @param mixed $name + * + * The CMF routing system used to allow to pass route objects as $name to generate the route. + * Since Symfony 5.0, the UrlGeneratorInterface declares $name as string. We widen the contract + * for BC but deprecate passing non-strings. + * Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object + * in the parameters with key RouteObjectInterface::ROUTE_OBJECT. + * * Loops through all registered routers and returns a router if one is found. * It will always return the first route generated. */ public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH) { if (is_object($name)) { - @trigger_error('Passing an object as route name is deprecated since version 2.3 and will not work in Symfony 5.0. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`.', E_USER_DEPRECATED); + @trigger_error('Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`.', E_USER_DEPRECATED); } $debug = []; diff --git a/src/ContentAwareGenerator.php b/src/ContentAwareGenerator.php index d207c356..2adb8582 100644 --- a/src/ContentAwareGenerator.php +++ b/src/ContentAwareGenerator.php @@ -58,18 +58,25 @@ public function setContentRepository(ContentRepositoryInterface $contentReposito /** * {@inheritdoc} * - * @param string $name ignored - * @param array $parameters must either contain the field 'route' with a - * RouteObjectInterface or the field 'content_id' - * with the id of a document implementing - * RouteReferrersReadInterface + * The CMF routing system used to allow to pass route objects as $name to generate the route. + * Since Symfony 5.0, the UrlGeneratorInterface declares $name as string. We widen the contract + * for BC but deprecate passing non-strings. + * Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object + * in the parameters with key RouteObjectInterface::ROUTE_OBJECT or the ID of a + * RouteReferrersReadInterface in 'content_id. + * + * @param mixed $name ignored + * @param array $parameters must either contain the field 'route' with a + * RouteObjectInterface or the field 'content_id' + * with the id of a document implementing + * RouteReferrersReadInterface * * @throws RouteNotFoundException If there is no such route in the database */ public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH) { if ($name instanceof SymfonyRoute) { - @trigger_error('Passing an object as route name is deprecated since version 2.3 and will not work in Symfony 5.0. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`.', E_USER_DEPRECATED); + @trigger_error('Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT` resp the content id with content_id.', E_USER_DEPRECATED); $route = $this->getBestLocaleRoute($name, $parameters); } elseif (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name) { @@ -172,7 +179,7 @@ protected function getBestLocaleRoute(SymfonyRoute $route, $parameters) protected function getRouteByContent($name, &$parameters) { if ($name instanceof RouteReferrersReadInterface) { - @trigger_error('Passing an object as route name is deprecated since version 2.3 and will not work in Symfony 5.0. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`.', E_USER_DEPRECATED); + @trigger_error('Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`.', E_USER_DEPRECATED); $content = $name; } elseif (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name @@ -193,7 +200,7 @@ protected function getRouteByContent($name, &$parameters) } else { $hint = is_object($name) ? get_class($name) : gettype($name); - throw new RouteNotFoundException("The route name argument '$hint' is not RouteReferrersReadInterface instance and there is no 'content_id' parameter"); + throw new RouteNotFoundException("The route name argument '$hint' is not a RouteReferrersReadInterface instance and there is no 'content_id' parameter"); } $routes = $content->getRoutes(); diff --git a/src/DynamicRouter.php b/src/DynamicRouter.php index b96d5dbb..b9203ac0 100644 --- a/src/DynamicRouter.php +++ b/src/DynamicRouter.php @@ -162,20 +162,20 @@ public function getGenerator() * If the generator is not able to generate the url, it must throw the * RouteNotFoundException as documented below. * - * @param string|Route $name The name of the route or the Route instance - * @param mixed $parameters An array of parameters - * @param bool|string $referenceType The type of reference to be generated (one of the constants in UrlGeneratorInterface) + * The CMF routing system used to allow to pass route objects as $name to generate the route. + * Since Symfony 5.0, the UrlGeneratorInterface declares $name as string. We widen the contract + * for BC but deprecate passing non-strings. + * Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object + * in the parameters with key RouteObjectInterface::ROUTE_OBJECT. * - * @return string The generated URL + * @param string|Route $name The name of the route or the Route instance * * @throws RouteNotFoundException if route doesn't exist - * - * @api */ public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { if (is_object($name)) { - @trigger_error('Passing an object as route name is deprecated since version 2.3 and will not work in Symfony 5.0. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT', E_USER_DEPRECATED); + @trigger_error('Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT', E_USER_DEPRECATED); } if ($this->eventDispatcher) { diff --git a/src/RouteObjectInterface.php b/src/RouteObjectInterface.php index 6e66af68..bf0558f0 100644 --- a/src/RouteObjectInterface.php +++ b/src/RouteObjectInterface.php @@ -69,7 +69,7 @@ interface RouteObjectInterface * If there is no specific content for this url (i.e. its an "application" * page), may return null. * - * @return object the document or entity this route entry points to + * @return null|object the document or entity this route entry points to */ public function getContent(); diff --git a/tests/Unit/Routing/ChainRouterTest.php b/tests/Unit/Routing/ChainRouterTest.php index cf60fd97..2ac03235 100644 --- a/tests/Unit/Routing/ChainRouterTest.php +++ b/tests/Unit/Routing/ChainRouterTest.php @@ -617,7 +617,7 @@ public function testGenerateNotFound() * Route is an object but no versatile generator around to do the debug message. * * @group legacy - * @expectedDeprecation Passing an object as route name is deprecated since version 2.3 and will not work in Symfony 5.0. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`. + * @expectedDeprecation Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`. */ public function testGenerateObjectNotFound() { @@ -645,7 +645,7 @@ public function testGenerateObjectNotFound() * A versatile router will generate the debug message. * * @group legacy - * @expectedDeprecation Passing an object as route name is deprecated since version 2.3 and will not work in Symfony 5.0. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`. + * @expectedDeprecation Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`. */ public function testGenerateObjectNotFoundVersatile() { @@ -681,7 +681,7 @@ public function testGenerateObjectNotFoundVersatile() /** * @group legacy - * @expectedDeprecation Passing an object as route name is deprecated since version 2.3 and will not work in Symfony 5.0. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`. + * @expectedDeprecation Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`. */ public function testGenerateObjectName() { diff --git a/tests/Unit/Routing/ContentAwareGeneratorTest.php b/tests/Unit/Routing/ContentAwareGeneratorTest.php index 447a7a97..ea90f855 100644 --- a/tests/Unit/Routing/ContentAwareGeneratorTest.php +++ b/tests/Unit/Routing/ContentAwareGeneratorTest.php @@ -74,9 +74,9 @@ public function setUp() /** * @group legacy - * @expectedDeprecation Passing an object as route name is deprecated since version 2.3 and will not work in Symfony 5.0. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`. + * @expectedDeprecation Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`. */ - public function testGenerateFromContent() + public function testGenerateFromContent(): void { if (!class_exists(ObjectRouteLoader::class)) { $this->markTestSkipped('Symfony 5 would throw a TypeError.'); @@ -87,17 +87,17 @@ public function testGenerateFromContent() ; $this->contentDocument->expects($this->once()) ->method('getRoutes') - ->will($this->returnValue([$this->routeDocument])) + ->willReturn([$this->routeDocument]) ; $this->routeDocument->expects($this->once()) ->method('compile') - ->will($this->returnValue($this->routeCompiled)) + ->willReturn($this->routeCompiled) ; $this->assertEquals('result_url', $this->generator->generate($this->contentDocument)); } - public function testGenerateFromContentInParameters() + public function testGenerateFromContentInParameters(): void { $this->provider->expects($this->never()) ->method('getRouteByName') @@ -110,7 +110,7 @@ public function testGenerateFromContentInParameters() $this->assertEquals('result_url', $this->generator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, [RouteObjectInterface::ROUTE_OBJECT => $this->routeDocument])); } - public function testGenerateFromContentIdEmptyRouteName() + public function testGenerateFromContentIdEmptyRouteName(): void { $this->provider->expects($this->never()) ->method('getRouteByName') @@ -120,18 +120,18 @@ public function testGenerateFromContentIdEmptyRouteName() $contentRepository->expects($this->once()) ->method('findById') ->with('/content/id') - ->will($this->returnValue($this->contentDocument)) + ->willReturn($this->contentDocument) ; $this->generator->setContentRepository($contentRepository); $this->contentDocument->expects($this->once()) ->method('getRoutes') - ->will($this->returnValue([$this->routeDocument])) + ->willReturn([$this->routeDocument]) ; $this->routeDocument->expects($this->once()) ->method('compile') - ->will($this->returnValue($this->routeCompiled)) + ->willReturn($this->routeCompiled) ; $this->assertEquals('result_url', $this->generator->generate('', ['content_id' => '/content/id'])); @@ -147,18 +147,18 @@ public function testGenerateFromContentId() $contentRepository->expects($this->once()) ->method('findById') ->with('/content/id') - ->will($this->returnValue($this->contentDocument)) + ->willReturn($this->contentDocument) ; $this->generator->setContentRepository($contentRepository); $this->contentDocument->expects($this->once()) ->method('getRoutes') - ->will($this->returnValue([$this->routeDocument])) + ->willReturn([$this->routeDocument]) ; $this->routeDocument->expects($this->once()) ->method('compile') - ->will($this->returnValue($this->routeCompiled)) + ->willReturn($this->routeCompiled) ; $generated = $this->generator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, ['content_id' => '/content/id']); @@ -173,12 +173,12 @@ public function testGenerateEmptyRouteString() $this->contentDocument->expects($this->once()) ->method('getRoutes') - ->will($this->returnValue([$this->routeDocument])) + ->willReturn([$this->routeDocument]) ; $this->routeDocument->expects($this->once()) ->method('compile') - ->will($this->returnValue($this->routeCompiled)) + ->willReturn($this->routeCompiled) ; $generated = $this->generator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, [RouteObjectInterface::ROUTE_OBJECT => $this->contentDocument]); @@ -187,7 +187,7 @@ public function testGenerateEmptyRouteString() public function testGenerateRouteMultilang() { - /** @var RouteMock $route_en */ + /** @var RouteMock&MockObject $route_en */ $route_en = $this->getMockBuilder(RouteMock::class) ->disableOriginalConstructor() ->setMethods(['compile', 'getContent']) @@ -198,18 +198,18 @@ public function testGenerateRouteMultilang() $this->contentDocument->expects($this->once()) ->method('getRoutes') - ->will($this->returnValue([$route_en, $route_de])) + ->willReturn([$route_en, $route_de]) ; $route_en->expects($this->once()) ->method('getContent') - ->will($this->returnValue($this->contentDocument)) + ->willReturn($this->contentDocument) ; $route_en->expects($this->never()) ->method('compile') ; $route_de->expects($this->once()) ->method('compile') - ->will($this->returnValue($this->routeCompiled)) + ->willReturn($this->routeCompiled) ; $generated = $this->generator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, ['_locale' => 'de', RouteObjectInterface::ROUTE_OBJECT => $route_en]); @@ -221,29 +221,30 @@ public function testGenerateRouteMultilangDefaultLocale() $route = $this->createMock(RouteMock::class); $route->expects($this->any()) ->method('compile') - ->will($this->returnValue($this->routeCompiled)) + ->willReturn($this->routeCompiled) ; $route->expects($this->any()) ->method('getRequirement') ->with('_locale') - ->will($this->returnValue('de|en')) + ->willReturn('de|en') ; $route->expects($this->any()) ->method('getDefault') ->with('_locale') - ->will($this->returnValue('en')) + ->willReturn('en') ; $this->routeCompiled->expects($this->any()) ->method('getVariables') - ->will($this->returnValue([])) + ->willReturn([]) ; $generated = $this->generator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, ['_locale' => 'en', RouteObjectInterface::ROUTE_OBJECT => $route]); $this->assertEquals('result_url', $generated); } - public function testGenerateRouteMultilangLocaleNomatch() + public function testGenerateRouteMultilangLocaleNomatch(): void { + /** @var RouteMock&MockObject $route_en */ $route_en = $this->getMockBuilder(RouteMock::class) ->disableOriginalConstructor() ->setMethods(['compile', 'getContent']) @@ -254,15 +255,15 @@ public function testGenerateRouteMultilangLocaleNomatch() $this->contentDocument->expects($this->once()) ->method('getRoutes') - ->will($this->returnValue([$route_en, $route_de])) + ->willReturn([$route_en, $route_de]) ; $route_en->expects($this->once()) ->method('getContent') - ->will($this->returnValue($this->contentDocument)) + ->willReturn($this->contentDocument) ; $route_en->expects($this->once()) ->method('compile') - ->will($this->returnValue($this->routeCompiled)) + ->willReturn($this->routeCompiled) ; $route_de->expects($this->never()) ->method('compile') @@ -272,20 +273,20 @@ public function testGenerateRouteMultilangLocaleNomatch() $this->assertEquals('result_url', $generated); } - public function testGenerateNoncmfRouteMultilang() + public function testGenerateNoncmfRouteMultilang(): void { $route_en = $this->createMock(Route::class); $route_en->expects($this->once()) ->method('compile') - ->will($this->returnValue($this->routeCompiled)) + ->willReturn($this->routeCompiled) ; $generated = $this->generator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, ['_locale' => 'de', RouteObjectInterface::ROUTE_OBJECT => $route_en]); $this->assertEquals('result_url', $generated); } - public function testGenerateRoutenameMultilang() + public function testGenerateRoutenameMultilang(): void { $name = 'foo/bar'; $route_en = $this->getMockBuilder(RouteMock::class) @@ -299,43 +300,44 @@ public function testGenerateRoutenameMultilang() $this->provider->expects($this->once()) ->method('getRouteByName') ->with($name) - ->will($this->returnValue($route_en)) + ->willReturn($route_en) ; $this->contentDocument->expects($this->once()) ->method('getRoutes') - ->will($this->returnValue([$route_en, $route_de])) + ->willReturn([$route_en, $route_de]) ; $route_en->expects($this->once()) ->method('getContent') - ->will($this->returnValue($this->contentDocument)) + ->willReturn($this->contentDocument) ; $route_en->expects($this->never()) ->method('compile') ; $route_de->expects($this->once()) ->method('compile') - ->will($this->returnValue($this->routeCompiled)) + ->willReturn($this->routeCompiled) ; $this->assertEquals('result_url', $this->generator->generate($name, ['_locale' => 'de'])); } - public function testGenerateRoutenameMultilangNotFound() + public function testGenerateRoutenameMultilangNotFound(): void { $name = 'foo/bar'; $this->provider->expects($this->once()) ->method('getRouteByName') ->with($name) - ->will($this->returnValue(null)) + ->willReturn(null) ; $this->expectException(RouteNotFoundException::class); $this->generator->generate($name, ['_locale' => 'de']); } - public function testGenerateDocumentMultilang() + public function testGenerateDocumentMultilang(): void { + /** @var RouteMock&MockObject $route_en */ $route_en = $this->getMockBuilder(RouteMock::class) ->disableOriginalConstructor() ->setMethods(['compile', 'getContent']) @@ -346,21 +348,21 @@ public function testGenerateDocumentMultilang() $this->contentDocument->expects($this->once()) ->method('getRoutes') - ->will($this->returnValue([$route_en, $route_de])) + ->willReturn([$route_en, $route_de]) ; $route_en->expects($this->never()) ->method('compile') ; $route_de->expects($this->once()) ->method('compile') - ->will($this->returnValue($this->routeCompiled)) + ->willReturn($this->routeCompiled) ; $generated = $this->generator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, ['_locale' => 'de', RouteObjectInterface::ROUTE_OBJECT => $this->contentDocument]); $this->assertEquals('result_url', $generated); } - public function testGenerateDocumentMultilangLocaleNomatch() + public function testGenerateDocumentMultilangLocaleNomatch(): void { $route_en = $this->createMock(RouteMock::class); $route_en->setLocale('en'); @@ -369,11 +371,11 @@ public function testGenerateDocumentMultilangLocaleNomatch() $this->contentDocument->expects($this->once()) ->method('getRoutes') - ->will($this->returnValue([$route_en, $route_de])) + ->willReturn([$route_en, $route_de]) ; $route_en->expects($this->once()) ->method('compile') - ->will($this->returnValue($this->routeCompiled)) + ->willReturn($this->routeCompiled) ; $route_de->expects($this->never()) ->method('compile') @@ -386,7 +388,7 @@ public function testGenerateDocumentMultilangLocaleNomatch() /** * Generate without any information. */ - public function testGenerateNoContent() + public function testGenerateNoContent(): void { $this->expectException(RouteNotFoundException::class); $this->generator->generate('', []); @@ -395,7 +397,7 @@ public function testGenerateNoContent() /** * Generate with an object that is neither a route nor route aware. */ - public function testGenerateInvalidContent() + public function testGenerateInvalidContent(): void { $this->expectException(RouteNotFoundException::class); $this->generator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, [RouteObjectInterface::ROUTE_OBJECT => $this]); @@ -406,7 +408,7 @@ public function testGenerateInvalidContent() * * @group legacy */ - public function testGenerateInvalidContentLegacy() + public function testGenerateInvalidContentLegacy(): void { if (!class_exists(ObjectRouteLoader::class)) { $this->markTestSkipped('Symfony 5 would throw a TypeError.'); @@ -419,7 +421,7 @@ public function testGenerateInvalidContentLegacy() /** * Generate with a content_id but there is no content repository. */ - public function testGenerateNoContentRepository() + public function testGenerateNoContentRepository(): void { $this->provider->expects($this->never()) ->method('getRouteByName') @@ -432,7 +434,7 @@ public function testGenerateNoContentRepository() /** * Generate with content_id but the content is not found. */ - public function testGenerateNoContentFoundInRepository() + public function testGenerateNoContentFoundInRepository(): void { $this->provider->expects($this->never()) ->method('getRouteByName') @@ -442,7 +444,7 @@ public function testGenerateNoContentFoundInRepository() $contentRepository->expects($this->once()) ->method('findById') ->with('/content/id') - ->will($this->returnValue(null)) + ->willReturn(null) ; $this->generator->setContentRepository($contentRepository); @@ -453,7 +455,7 @@ public function testGenerateNoContentFoundInRepository() /** * Generate with content_id but the object at id is not route aware. */ - public function testGenerateWrongContentClassInRepository() + public function testGenerateWrongContentClassInRepository(): void { $this->provider->expects($this->never()) ->method('getRouteByName') @@ -463,7 +465,7 @@ public function testGenerateWrongContentClassInRepository() $contentRepository->expects($this->once()) ->method('findById') ->with('/content/id') - ->will($this->returnValue($this)) + ->willReturn($this) ; $this->generator->setContentRepository($contentRepository); @@ -474,11 +476,11 @@ public function testGenerateWrongContentClassInRepository() /** * Generate from a content that has no routes associated. */ - public function testGenerateNoRoutes() + public function testGenerateNoRoutes(): void { $this->contentDocument->expects($this->once()) ->method('getRoutes') - ->will($this->returnValue([])); + ->willReturn([]); $this->expectException(RouteNotFoundException::class); $this->generator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, [RouteObjectInterface::ROUTE_OBJECT => $this->contentDocument]); @@ -487,17 +489,17 @@ public function testGenerateNoRoutes() /** * Generate from a content that returns something that is not a route as route. */ - public function testGenerateInvalidRoute() + public function testGenerateInvalidRoute(): void { $this->contentDocument->expects($this->once()) ->method('getRoutes') - ->will($this->returnValue([$this])); + ->willReturn([$this]); $this->expectException(RouteNotFoundException::class); $this->generator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, [RouteObjectInterface::ROUTE_OBJECT => $this->contentDocument]); } - public function testGetLocaleAttribute() + public function testGetLocaleAttribute(): void { $this->generator->setDefaultLocale('en'); @@ -505,7 +507,7 @@ public function testGetLocaleAttribute() $this->assertEquals('fr', $this->generator->getLocale($attributes)); } - public function testGetLocaleDefault() + public function testGetLocaleDefault(): void { $this->generator->setDefaultLocale('en'); @@ -513,7 +515,7 @@ public function testGetLocaleDefault() $this->assertEquals('en', $this->generator->getLocale($attributes)); } - public function testGetLocaleContext() + public function testGetLocaleContext(): void { $this->generator->setDefaultLocale('en'); @@ -526,7 +528,7 @@ public function testGetLocaleContext() /** * @group legacy */ - public function testSupports() + public function testSupports(): void { $this->assertTrue($this->generator->supports('')); $this->assertTrue($this->generator->supports(null)); @@ -534,7 +536,7 @@ public function testSupports() $this->assertFalse($this->generator->supports($this)); } - public function testGetRouteDebugMessage() + public function testGetRouteDebugMessage(): void { $this->assertContains('/some/content', $this->generator->getRouteDebugMessage(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, ['content_id' => '/some/content'])); $this->assertContains('Route aware content Symfony\Cmf\Component\Routing\Tests\Routing\RouteAware', $this->generator->getRouteDebugMessage(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, [RouteObjectInterface::ROUTE_OBJECT => new RouteAware()])); @@ -544,7 +546,7 @@ public function testGetRouteDebugMessage() /** * @legacy */ - public function testGetRouteDebugMessageLegacy() + public function testGetRouteDebugMessageLegacy(): void { $this->assertContains('/some/content', $this->generator->getRouteDebugMessage(null, ['content_id' => '/some/content'])); $this->assertContains('Route aware content Symfony\Cmf\Component\Routing\Tests\Routing\RouteAware', $this->generator->getRouteDebugMessage(new RouteAware()));