Skip to content

Commit f4ce2aa

Browse files
committed
adjust deprecation messages and cleanup phpunit tests
1 parent 4f21849 commit f4ce2aa

File tree

7 files changed

+96
-80
lines changed

7 files changed

+96
-80
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ cache:
2727
- $HOME/.composer/cache
2828

2929
env:
30-
matrix: SYMFONY_VERSION=4.0.*
3130
global:
3231
- SYMFONY_PHPUNIT_VERSION=6
3332
- COMPOSER_MEMORY_LIMIT=-1

src/ChainRouter.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,21 @@ private function doMatch($pathinfo, Request $request = null)
213213
/**
214214
* {@inheritdoc}
215215
*
216+
* @param mixed $name
217+
*
218+
* The CMF routing system used to allow to pass route objects as $name to generate the route.
219+
* Since Symfony 5.0, the UrlGeneratorInterface declares $name as string. We widen the contract
220+
* for BC but deprecate passing non-strings.
221+
* Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object
222+
* in the parameters with key RouteObjectInterface::ROUTE_OBJECT.
223+
*
216224
* Loops through all registered routers and returns a router if one is found.
217225
* It will always return the first route generated.
218226
*/
219227
public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
220228
{
221229
if (is_object($name)) {
222-
@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);
230+
@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);
223231
}
224232

225233
$debug = [];

src/ContentAwareGenerator.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,25 @@ public function setContentRepository(ContentRepositoryInterface $contentReposito
5858
/**
5959
* {@inheritdoc}
6060
*
61-
* @param string $name ignored
62-
* @param array $parameters must either contain the field 'route' with a
63-
* RouteObjectInterface or the field 'content_id'
64-
* with the id of a document implementing
65-
* RouteReferrersReadInterface
61+
* The CMF routing system used to allow to pass route objects as $name to generate the route.
62+
* Since Symfony 5.0, the UrlGeneratorInterface declares $name as string. We widen the contract
63+
* for BC but deprecate passing non-strings.
64+
* Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object
65+
* in the parameters with key RouteObjectInterface::ROUTE_OBJECT or the ID of a
66+
* RouteReferrersReadInterface in 'content_id.
67+
*
68+
* @param mixed $name ignored
69+
* @param array $parameters must either contain the field 'route' with a
70+
* RouteObjectInterface or the field 'content_id'
71+
* with the id of a document implementing
72+
* RouteReferrersReadInterface
6673
*
6774
* @throws RouteNotFoundException If there is no such route in the database
6875
*/
6976
public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
7077
{
7178
if ($name instanceof SymfonyRoute) {
72-
@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);
79+
@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);
7380

7481
$route = $this->getBestLocaleRoute($name, $parameters);
7582
} elseif (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name) {
@@ -172,7 +179,7 @@ protected function getBestLocaleRoute(SymfonyRoute $route, $parameters)
172179
protected function getRouteByContent($name, &$parameters)
173180
{
174181
if ($name instanceof RouteReferrersReadInterface) {
175-
@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);
182+
@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);
176183

177184
$content = $name;
178185
} elseif (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name
@@ -193,7 +200,7 @@ protected function getRouteByContent($name, &$parameters)
193200
} else {
194201
$hint = is_object($name) ? get_class($name) : gettype($name);
195202

196-
throw new RouteNotFoundException("The route name argument '$hint' is not RouteReferrersReadInterface instance and there is no 'content_id' parameter");
203+
throw new RouteNotFoundException("The route name argument '$hint' is not a RouteReferrersReadInterface instance and there is no 'content_id' parameter");
197204
}
198205

199206
$routes = $content->getRoutes();

src/DynamicRouter.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,20 @@ public function getGenerator()
162162
* If the generator is not able to generate the url, it must throw the
163163
* RouteNotFoundException as documented below.
164164
*
165-
* @param string|Route $name The name of the route or the Route instance
166-
* @param mixed $parameters An array of parameters
167-
* @param bool|string $referenceType The type of reference to be generated (one of the constants in UrlGeneratorInterface)
165+
* The CMF routing system used to allow to pass route objects as $name to generate the route.
166+
* Since Symfony 5.0, the UrlGeneratorInterface declares $name as string. We widen the contract
167+
* for BC but deprecate passing non-strings.
168+
* Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object
169+
* in the parameters with key RouteObjectInterface::ROUTE_OBJECT.
168170
*
169-
* @return string The generated URL
171+
* @param string|Route $name The name of the route or the Route instance
170172
*
171173
* @throws RouteNotFoundException if route doesn't exist
172-
*
173-
* @api
174174
*/
175175
public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
176176
{
177177
if (is_object($name)) {
178-
@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);
178+
@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);
179179
}
180180

181181
if ($this->eventDispatcher) {

src/RouteObjectInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ interface RouteObjectInterface
6969
* If there is no specific content for this url (i.e. its an "application"
7070
* page), may return null.
7171
*
72-
* @return object the document or entity this route entry points to
72+
* @return null|object the document or entity this route entry points to
7373
*/
7474
public function getContent();
7575

tests/Unit/Routing/ChainRouterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ public function testGenerateNotFound()
617617
* Route is an object but no versatile generator around to do the debug message.
618618
*
619619
* @group legacy
620-
* @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`.
620+
* @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`.
621621
*/
622622
public function testGenerateObjectNotFound()
623623
{
@@ -645,7 +645,7 @@ public function testGenerateObjectNotFound()
645645
* A versatile router will generate the debug message.
646646
*
647647
* @group legacy
648-
* @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`.
648+
* @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`.
649649
*/
650650
public function testGenerateObjectNotFoundVersatile()
651651
{
@@ -681,7 +681,7 @@ public function testGenerateObjectNotFoundVersatile()
681681

682682
/**
683683
* @group legacy
684-
* @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`.
684+
* @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`.
685685
*/
686686
public function testGenerateObjectName()
687687
{

0 commit comments

Comments
 (0)