Skip to content

Commit 64dcc28

Browse files
Merge branch '6.3' into 6.4
* 6.3: [Cache] Fix Redis6Proxy [Finder] Disable failing test about open_basedir Fix merge Fix merge [Notifier] Telegram Bridge add escaping for \ [Routing] Fix routing collection defaults when adding a new route to a collection [Messenger] Fix cloned TraceableStack not unstacking the stack independently [DependencyInjection] Fix autocasting null env values to empty string with container.env_var_processors_locator [Cache] Fix support for Redis Sentinel using php-redis 6.0.0 [Notifier] Fix Smsmode HttpClient mandatory headers minor #51693 Disable the dead code analysis in Psalm (stof) Update the PR template [SecurityBundle][PasswordHasher] Fix password migration with custom hasher service with security bundle config [Translator] Fix support for `default_path` in XML [FrameworkBundle] Handle tags array attributes in descriptors [HttpClient] Fix TraceableResponse if response has no destruct method [FrameworkBundle] Always use buildDir as `ConfigBuilderGenerator` outputDir
2 parents ffdb586 + 82616e5 commit 64dcc28

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

Loader/Configurator/CollectionConfigurator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,12 @@ final public function host(string|array $host): static
117117

118118
return $this;
119119
}
120+
121+
/**
122+
* This method overrides the one from LocalizedRouteTrait.
123+
*/
124+
private function createRoute(string $path): Route
125+
{
126+
return (clone $this->route)->setPath($path);
127+
}
120128
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Loader\Configurator;
4+
5+
return function (RoutingConfigurator $routes) {
6+
$collection = $routes->collection();
7+
$collection
8+
->methods(['GET'])
9+
->defaults(['attribute' => true])
10+
->stateless();
11+
12+
$collection->add('defaultsA', '/defaultsA')
13+
->locale('en')
14+
->format('html');
15+
16+
$collection->add('defaultsB', '/defaultsB')
17+
->methods(['POST'])
18+
->stateless(false)
19+
->locale('en')
20+
->format('html');
21+
};

Tests/Loader/PhpFileLoaderTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,31 @@ public function testLoadingRouteWithDefaults()
103103
$this->assertSame('html', $defaultsRoute->getDefault('_format'));
104104
}
105105

106+
public function testLoadingRouteWithCollectionDefaults()
107+
{
108+
$loader = new PhpFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
109+
$routes = $loader->load('collection-defaults.php');
110+
111+
$this->assertCount(2, $routes);
112+
113+
$defaultsRoute = $routes->get('defaultsA');
114+
$this->assertSame(['GET'], $defaultsRoute->getMethods());
115+
$this->assertArrayHasKey('attribute', $defaultsRoute->getDefaults());
116+
$this->assertTrue($defaultsRoute->getDefault('_stateless'));
117+
$this->assertSame('/defaultsA', $defaultsRoute->getPath());
118+
$this->assertSame('en', $defaultsRoute->getDefault('_locale'));
119+
$this->assertSame('html', $defaultsRoute->getDefault('_format'));
120+
121+
// The second route has a specific method and is not stateless, overwriting the collection settings
122+
$defaultsRoute = $routes->get('defaultsB');
123+
$this->assertSame(['POST'], $defaultsRoute->getMethods());
124+
$this->assertArrayHasKey('attribute', $defaultsRoute->getDefaults());
125+
$this->assertFalse($defaultsRoute->getDefault('_stateless'));
126+
$this->assertSame('/defaultsB', $defaultsRoute->getPath());
127+
$this->assertSame('en', $defaultsRoute->getDefault('_locale'));
128+
$this->assertSame('html', $defaultsRoute->getDefault('_format'));
129+
}
130+
106131
public function testLoadingImportedRoutesWithDefaults()
107132
{
108133
$loader = new PhpFileLoader(new FileLocator([__DIR__.'/../Fixtures']));

0 commit comments

Comments
 (0)