Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cd325e1

Browse filesBrowse files
committed
fixed yaml tests and prevented using multiple types
1 parent 5d068a4 commit cd325e1
Copy full SHA for cd325e1

File tree

4 files changed

+22
-8
lines changed
Filter options

4 files changed

+22
-8
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Routing/Loader/YamlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Routing/Loader/YamlFileLoader.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ class YamlFileLoader extends BaseYamlFileLoader
3030

3131
protected function validate($config, $name, $path)
3232
{
33+
if (\count($types = array_intersect_key($config, self::$availableKeys)) > 1) {
34+
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify only one route type among "%s" keys for "%s".', str_replace('/', \DIRECTORY_SEPARATOR, $path), implode('", "', array_keys($types)), $name));
35+
}
36+
3337
foreach (self::$availableKeys as $routeType => $availableKeys) {
3438
if (!isset($config[$routeType])) {
3539
continue;
3640
}
3741

3842
if (isset($config['controller'])) {
39-
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "controller" and the "%s" keys for "%s".', $path, $routeType, $name));
43+
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "controller" and the "%s" keys for "%s".', str_replace('/', \DIRECTORY_SEPARATOR, $path), $routeType, $name));
4044
}
4145

4246
// keys would be invalid for parent::validate(), but we use them below
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
invalid_route:
2+
path: '/path'
3+
template: 'template.html.twig'
4+
redirect_to_route: 'target_route'
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
invalid:
2-
temmplate: 'template.html.twig'
1+
invalid_route:
2+
path: '/path'
3+
template: 'template.html.twig'
34
controller: 'SomeControllerClass'

‎src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Loader/YamlFileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Loader/YamlFileLoaderTest.php
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Routing\Loader;
1313

1414
use Symfony\Bundle\FrameworkBundle\Routing\Loader\YamlFileLoader;
15-
use Symfony\Component\Config\FileLocator;
1615
use Symfony\Component\Config\Loader\LoaderInterface;
1716

1817
class YamlFileLoaderTest extends AbstractLoaderTest
@@ -30,15 +29,21 @@ protected function getType(): string
3029
/**
3130
* @dataProvider getPathsToInvalidFiles
3231
*/
33-
public function testLoadThrowsExceptionWithInvalidFile($filePath)
32+
public function testLoadThrowsExceptionWithInvalidFile(string $filePath, string $exception)
3433
{
35-
$this->expectException('InvalidArgumentException');
36-
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
34+
$loader = $this->getLoader();
35+
36+
$message = sprintf($exception, __DIR__.'/../../Fixtures/Resources/config/routing/'.$filePath);
37+
38+
$this->expectException(\InvalidArgumentException::class);
39+
$this->expectExceptionMessage(str_replace('/', \DIRECTORY_SEPARATOR, $message));
40+
3741
$loader->load($filePath);
3842
}
3943

4044
public function getPathsToInvalidFiles()
4145
{
42-
yield 'defining controller' => ['with_controller_attributes.yaml'];
46+
yield 'defining controller' => ['with_controller_attribute.yaml', 'The routing file "%s" must not specify both the "controller" and the "template" keys for "invalid_route".'];
47+
yield 'defining template and redirect' => ['template_and_redirect.yaml', 'The routing file "%s" must not specify only one route type among "template", "redirect_to_route" keys for "invalid_route".'];
4348
}
4449
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.