8000 fixed yaml tests and prevented using multiple types · symfony/symfony@1345b28 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1345b28

Browse files
committed
fixed yaml tests and prevented using multiple types
1 parent 5d068a4 commit 1345b28

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ 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".', $path, implode('", "', array_keys($types)), $name));
35+
}
36+
3337
foreach (self::$availableKeys as $routeType => $availableKeys) {
3438
if (!isset($config[$routeType])) {
3539
continue;
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

Lines 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