Skip to content

Commit 3676156

Browse files
committed
bug #2181 fix triggering deprecations if routing loader is enabled (xabbuh)
This PR was merged into the 2.x branch. Discussion ---------- fix triggering deprecations if routing loader is enabled Commits ------- eeb47ae fix triggering deprecations if routing loader is enabled
2 parents 36d8192 + eeb47ae commit 3676156

File tree

2 files changed

+79
-3
lines changed

2 files changed

+79
-3
lines changed

DependencyInjection/Configuration.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ public function getConfigTreeBuilder(): TreeBuilder
100100
->end()
101101
->arrayNode('routing_loader')
102102
->addDefaultsIfNotSet()
103-
->canBeDisabled()
104103
->beforeNormalization()
105-
->ifTrue(function ($v) { return false !== $v; })
104+
->ifTrue(function ($v) { return isset($v['enabled']) && false !== $v['enabled']; })
106105
->then(function ($v) {
107106
@trigger_error('Enabling the route generation feature is deprecated since FOSRestBundle 2.8.', E_USER_DEPRECATED);
108107

@@ -118,6 +117,13 @@ public function getConfigTreeBuilder(): TreeBuilder
118117
})
119118
->end()
120119
->children()
120+
->booleanNode('enabled')
121+
->defaultValue(function () {
122+
@trigger_error('Enabling the route generation feature is deprecated since FOSRestBundle 2.8.', E_USER_DEPRECATED);
123+
124+
return true;
125+
})
126+
->end()
121127
->scalarNode('default_format')->defaultNull()->end()
122128
->scalarNode('prefix_methods')->defaultTrue()->end()
123129
->scalarNode('include_format')->defaultTrue()->end()

Tests/DependencyInjection/FOSRestExtensionTest.php

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,26 @@ public function testValidatorAliasWhenDisabled()
646646

647647
/**
648648
* @group legacy
649+
* @expectedDeprecation Enabling the route generation feature is deprecated since FOSRestBundle 2.8.
649650
*/
650651
public function testConfigLoadWithRoutingLoaderEnabled()
651652
{
652-
$this->extension->load([], $this->container);
653+
$config = [
654+
'fos_rest' => [
655+
'exception' => [
656+
'exception_listener' => false,
657+
'serialize_exceptions' => false,
658+
],
659+
'service' => [
660+
'templating' => null,
661+
],
662+
'view' => [
663+
'default_engine' => null,
664+
'force_redirects' => [],
665+
],
666+
],
667+
];
668+
$this->extension->load($config, $this->container);
653669

654670
$this->assertTrue($this->container->hasDefinition('fos_rest.routing.loader.controller'));
655671

@@ -681,6 +697,56 @@ public function testConfigLoadWithRoutingLoaderEnabled()
681697
);
682698
}
683699

700+
public function testRoutingLoaderDisabled()
701+
{
702+
$config = [
703+
'fos_rest' => [
704+
'exception' => [
705+
'exception_listener' => false,
706+
'serialize_exceptions' => false,
707+
],
708+
'routing_loader' => false,
709+
'service' => [
710+
'templating' => null,
711+
],
712+
'view' => [
713+
'default_engine' => null,
714+
'force_redirects' => [],
715+
],
716+
],
717+
];
718+
$this->extension->load($config, $this->container);
719+
720+
$this->assertFalse($this->container->hasDefinition('fos_rest.routing.loader.yaml_collection'));
721+
$this->assertFalse($this->container->hasDefinition('fos_rest.routing.loader.xml_collection'));
722+
}
723+
724+
public function testRoutingLoaderDisabledUsingEnabledKey()
725+
{
726+
$config = [
727+
'fos_rest' => [
728+
'exception' => [
729+
'exception_listener' => false,
730+
'serialize_exceptions' => false,
731+
],
732+
'routing_loader' => [
733+
'enabled' => false,
734+
],
735+
'service' => [
736+
'templating' => null,
737+
],
738+
'view' => [
739+
'default_engine' => null,
740+
'force_redirects' => [],
741+
],
742+
],
743+
];
744+
$this->extension->load($config, $this->container);
745+
746+
$this->assertFalse($this->container->hasDefinition('fos_rest.routing.loader.yaml_collection'));
747+
$this->assertFalse($this->container->hasDefinition('fos_rest.routing.loader.xml_collection'));
748+
}
749+
684750
/**
685751
* @group legacy
686752
*/
@@ -995,6 +1061,7 @@ public function testResponseStatusCodeListenerEnabled()
9951061
'serialize_exceptions' => false,
9961062
'map_exception_codes' => true,
9971063
],
1064+
'routing_loader' => false,
9981065
'service' => [
9991066
'templating' => null,
10001067
],
@@ -1017,6 +1084,7 @@ public function testExceptionListenerDisabled()
10171084
'exception_listener' => false,
10181085
'serialize_exceptions' => false,
10191086
],
1087+
'routing_loader' => false,
10201088
'service' => [
10211089
'templating' => null,
10221090
],
@@ -1043,6 +1111,7 @@ public function testExceptionSerializerEnabled()
10431111
'exception_listener' => false,
10441112
'serialize_exceptions' => true,
10451113
],
1114+
'routing_loader' => false,
10461115
'service' => [
10471116
'templating' => null,
10481117
],
@@ -1066,6 +1135,7 @@ public function testExceptionSerializerDisabled()
10661135
'exception_listener' => false,
10671136
'serialize_exceptions' => false,
10681137
],
1138+
'routing_loader' => false,
10691139
'service' => [
10701140
'templating' => null,
10711141
],

0 commit comments

Comments
 (0)