8000 Refactor tests · symfony/symfony@25d7aa5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 25d7aa5

Browse files
author
Olivier Dolbeau
committed
Refactor tests
1 parent 79942b2 commit 25d7aa5

26 files changed

+328
-219
lines changed

src/Symfony/Component/Routing/Loader/Configurator/RouteConfigurator.php

Lines changed: 1 addition & 1 deletion
< F438 th scope="col">Diff line number
Original file line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(RouteCollection $collection, $route, string $name =
4242
*/
4343
final public function host($host): self
4444
{
45-
$this->addHost($this->collection, $host);
45+
$this->addHost($this->route, $host);
4646

4747
return $this;
4848
}

src/Symfony/Component/Routing/Loader/XmlFileLoader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, st
134134
$routes->addDefaults($defaults);
135135
$routes->addRequirements($requirements);
136136
$routes->addOptions($options);
137-
//$routes->setHost($node->getAttribute('host'));
138137
$routes->setSchemes($schemes);
139138
$routes->setMethods($methods);
140139
$routes->setCondition($condition);
@@ -163,7 +162,7 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, s
163162
$trailingSlashOnRoot = $node->hasAttribute('trailing-slash-on-root') ? XmlUtils::phpize($node->getAttribute('trailing-slash-on-root')) : true;
164163
$namePrefix = $node->getAttribute('name-prefix') ?: null;
165164

166-
list($defaults, $requirements, $options, $condition, $paths, $prefixes, $hosts) = $this->parseConfigs($node, $path);
165+
list($defaults, $requirements, $options, $condition, /** $paths */, $prefixes, $hosts) = $this->parseConfigs($node, $path);
167166

168167
if ('' !== $prefix && $prefixes) {
169168
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must not have both a "prefix" attribute and <prefix> child nodes.', $path));
@@ -315,6 +314,8 @@ private function parseConfigs(\DOMElement $node, string $path): array
315314

316315
if ([] === $hosts) {
317316
$hosts = $node->hasAttribute('host') ? $node->getAttribute('host') : null;
317+
} elseif ('' === array_key_first($hosts)) {
318+
$hosts = reset($hosts);
318319
}
319320

320321
return [$defaults, $requirements, $options, $condition, $paths, $prefixes, $hosts];

src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
</xsd:simpleContent>
3333
</xsd:complexType>
3434

35+
<xsd:complexType name="faculative-localized-path">
36+
<xsd:simpleContent>
37+
<xsd:extension base="xsd:string">
38+
<xsd:attribute name="locale" type="xsd:string" />
39+
</xsd:extension>
40+
</xsd:simpleContent>
41+
</xsd:complexType>
42+
3543
<xsd:group name="configs">
3644
<xsd:choice>
3745
<xsd:element name="default" nillable="true" type="default" />
@@ -45,7 +53,7 @@
4553
<xsd:sequence>
4654
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
4755
<xsd:element name="path" type="localized-path" minOccurs="0" maxOccurs="unbounded" />
48-
<xsd:element name="host" type="localized-path" minOccurs="0" maxOccurs="unbounded" />
56+
<xsd:element name="host" type="faculative-localized-path" minOccurs="0" maxOccurs="unbounded" />
4957
</xsd:sequence>
5058
<xsd:attribute name="id" type="xsd:string" use="required" />
5159
<xsd:attribute name="path" type="xsd:string" />
@@ -64,7 +72,7 @@
6472
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
6573
<xsd:element name="prefix" type="localized-path" minOccurs="0" maxOccurs="unbounded" />
6674
<xsd:element name="exclude" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
67-
<xsd:element name="host" type="localized-path" minOccurs="0" maxOccurs="unbounded" />
75+
<xsd:element name="host" type="faculative-localized-path" minOccurs="0" maxOccurs="unbounded" />
6876
</xsd:sequence>
6977
<xsd:attribute name="resource" type="xsd:string" use="required" />
7078
<xsd:attribute name="type" type="xsd:string" />
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
use Symfony\Component\Config\Resource\FileResource;
4+
use Symfony\Component\Routing\Route;
5+
use Symfony\Component\Routing\RouteCollection;
6+
7+
return function (string $format) {
8+
$expectedRoutes = new RouteCollection();
9+
$expectedRoutes->add('imported.en', $route = new Route('/example'));
10+
$route->setHost('www.example.com');
11+
$route->setRequirement('_locale', 'en');
12+
$route->setDefault('_locale', 'en');
13+
$route->setDefault('_canonical_route', 'imported');
14+
$route->setDefault('_controller', 'ImportedController::someAction');
15+
$expectedRoutes->add('imported.nl', $route = new Route('/voorbeeld'));
16+
$route->setHost('www.example.nl');
17+
$route->setRequirement('_locale', 'nl');
18+
$route->setDefault('_locale', 'nl');
19+
$route->setDefault('_canonical_route', 'imported');
20+
$route->setDefault('_controller', 'ImportedController::someAction');
21+
$expectedRoutes->add('imported_not_localized.en', $route = new Route('/here'));
22+
$route->setHost('www.example.com');
23+
$route->setRequirement('_locale', 'en');
24+
$route->setDefault('_locale', 'en');
25+
$route->setDefault('_canonical_route', 'imported_not_localized');
26+
$route->setDefault('_controller', 'ImportedController::someAction');
27+
$expectedRoutes->add('imported_not_localized.nl', $route = new Route('/here'));
28+
$route->setHost('www.example.nl');
29+
$route->setRequirement('_locale', 'nl');
30+
$route->setDefault('_locale', 'nl');
31+
$route->setDefault('_canonical_route', 'imported_not_localized');
32+
$route->setDefault('_controller', 'ImportedController::someAction');
33+
$expectedRoutes->add('imported_single_host.en', $route = new Route('/here_again'));
34+
$route->setHost('www.example.com');
35+
$route->setRequirement('_locale', 'en');
36+
$route->setDefault('_locale', 'en');
37+
$route->setDefault('_canonical_route', 'imported_single_host');
38+
$route->setDefault('_controller', 'ImportedController::someAction');
39+
$expectedRoutes->add('imported_single_host.nl', $route = new Route('/here_again'));
40+
$route->setHost('www.example.nl');
41+
$route->setRequirement('_locale', 'nl');
42+
$route->setDefault('_locale', 'nl');
43+
$route->setDefault('_canonical_route', 'imported_single_host');
44+
$route->setDefault('_controller', 'ImportedController::someAction');
45+
46+
$expectedRoutes->addResource(new FileResource(__DIR__."/imported.$format"));
47+
$expectedRoutes->addResource(new FileResource(__DIR__."/importer-with-host.$format"));
48+
49+
return $expectedRoutes;
50+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
use Symfony\Component\Config\Resource\FileResource;
4+
use Symfony\Component\Routing\Route;
5+
use Symfony\Component\Routing\RouteCollection;
6+
7+
return function (string $format) {
8+
$expectedRoutes = new RouteCollection();
9+
$expectedRoutes->add('imported.en', $route = new Route('/en/example'));
10+
$route->setHost('www.example.com');
11+
$route->setRequirement('_locale', 'en');
12+
$route->setDefault('_locale', 'en');
13+
$route->setDefault('_canonical_route', 'imported');
14+
$route->setDefault('_controller', 'ImportedController::someAction');
15+
$expectedRoutes->add('imported.nl', $route = new Route('/nl/voorbeeld'));
16+
$route->setHost('www.example.nl');
17+
$route->setRequirement('_locale', 'nl');
18+
$route->setDefault('_locale', 'nl');
19+
$route->setDefault('_canonical_route', 'imported');
20+
$route->setDefault('_controller', 'ImportedController::someAction');
21+
$expectedRoutes->add('imported_not_localized.en', $route = new Route('/en/here'));
22+
$route->setHost('www.example.com');
23+
$route->setRequirement('_locale', 'en');
24+
$route->setDefault('_locale', 'en');
25+
$route->setDefault('_canonical_route', 'imported_not_localized');
26+
$route->setDefault('_controller', 'ImportedController::someAction');
27+
$expectedRoutes->add('imported_not_localized.nl', $route = new Route('/nl/here'));
28+
$route->setHost('www.example.nl');
29+
$route->setRequirement('_locale', 'nl');
30+
$route->setDefault('_locale', 'nl');
31+
$route->setDefault('_canonical_route', 'imported_not_localized');
32+
$route->setDefault('_controller', 'ImportedController::someAction');
33+
$expectedRoutes->add('imported_single_host.en', $route = new Route('/en/here_again'));
34+
$route->setHost('www.example.com');
35+
$route->setRequirement('_locale', 'en');
36+
$route->setDefault('_locale', 'en');
37+
$route->setDefault('_canonical_route', 'imported_single_host');
38+
$route->setDefault('_controller', 'ImportedController::someAction');
39+
$expectedRoutes->add('imported_single_host.nl', $route = new Route('/nl/here_again'));
40+
$route->setHost('www.example.nl');
41+
$route->setRequirement('_locale', 'nl');
42+
$route->setDefault('_locale', 'nl');
43+
$route->setDefault('_canonical_route', 'imported_single_host');
44+
$route->setDefault('_controller', 'ImportedController::someAction');
45+
46+
$expectedRoutes->addResource(new FileResource(__DIR__."/imported.$format"));
47+
$expectedRoutes->addResource(new FileResource(__DIR__."/importer-with-locale-and-host.$format"));
48+
49+
return $expectedRoutes;
50+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Symfony\Component\Config\Resource\FileResource;
4+
use Symfony\Component\Routing\Route;
5+
use Symfony\Component\Routing\RouteCollection;
6+
7+
return function (string $format) {
8+
$expectedRoutes = new RouteCollection();
9+
$expectedRoutes->add('imported.en', $route = new Route('/example'));
10+
$route->setHost('www.example.com');
11+
$route->setRequirement('_locale', 'en');
12+
$route->setDefault('_locale', 'en');
13+
$route->setDefault('_canonical_route', 'imported');
14+
$route->setDefault('_controller', 'ImportedController::someAction');
15+
$expectedRoutes->add('imported.nl', $route = new Route('/voorbeeld'));
16+
$route->setHost('www.example.com');
17+
$route->setRequirement('_locale', 'nl');
18+
$route->setDefault('_locale', 'nl');
19+
$route->setDefault('_canonical_route', 'imported');
20+
$route->setDefault('_controller', 'ImportedController::someAction');
21+
$expectedRoutes->add('imported_not_localized', $route = new Route('/here'));
22+
$route->setHost('www.example.com');
23+
$route->setDefault('_controller', 'ImportedController::someAction');
24+
$expectedRoutes->add('imported_single_host', $route = new Route('/here_again'));
25+
$route->setHost('www.example.com');
26+
$route->setDefault('_controller', 'ImportedController::someAction');
27+
28+
$expectedRoutes->addResource(new FileResource(__DIR__."/imported.$format"));
29+
$expectedRoutes->addResource(new FileResource(__DIR__."/importer-with-single-host.$format"));
30+
31+
return $expectedRoutes;
32+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Symfony\Component\Config\Resource\FileResource;
4+
use Symfony\Component\Routing\Route;
5+
use Symfony\Component\Routing\RouteCollection;
6+
7+
return function (string $format) {
8+
$expectedRoutes = new RouteCollection();
9+
$expectedRoutes->add('imported.en', $route = new Route('/example'));
10+
$route->setHost('www.custom.com');
11+
$route->setRequirement('_locale', 'en');
12+
$route->setDefault('_locale', 'en');
13+
$route->setDefault('_canonical_route', 'imported');
14+
$route->setDefault('_controller', 'ImportedController::someAction');
15+
$expectedRoutes->add('imported.nl', $route = new Route('/voorbeeld'));
16+
$route->setHost('www.custom.nl');
17+
$route->setRequirement('_locale', 'nl');
18+
$route->setDefault('_locale', 'nl');
19+
$route->setDefault('_canonical_route', 'imported');
20+
$route->setDefault('_controller', 'ImportedController::someAction');
21+
$expectedRoutes->add('imported_not_localized', $route = new Route('/here'));
22+
$route->setDefault('_controller', 'ImportedController::someAction');
23+
$expectedRoutes->add('imported_single_host', $route = new Route('/here_again'));
24+
$route->setHost('www.custom.com');
25+
$route->setDefault('_controller', 'ImportedController::someAction');
26+
27+
$expectedRoutes->addResource(new FileResource(__DIR__."/imported.$format"));
28+
$expectedRoutes->addResource(new FileResource(__DIR__."/importer-without-host.$format"));
29+
30+
return $expectedRoutes;
31+
};

src/Symfony/Component/Routing/Tests/Fixtures/localized/imported-with-host.php renamed to src/Symfony/Component/Routing/Tests/Fixtures/locale_and_host/imported.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
->add('imported', ['nl' => '/voorbeeld', 'en' => '/example'])
88
->controller('ImportedController::someAction')
99
->host([
10-
'nl' => 'www.example.nl',
11-
'en' => 'www.example.com',
10+
'nl' => 'www.custom.nl',
11+
'en' => 'www.custom.com',
1212
])
1313
->add('imported_not_localized', '/here')
1414
->controller('ImportedController::someAction')
15+
->add('imported_single_host', '/here_again')
16+
->controller('ImportedController::someAction')
17+
->host('www.custom.com')
1518
;
1619
};

src/Symfony/Component/Routing/Tests/Fixtures/localized/imported-with-host.xml renamed to src/Symfony/Component/Routing/Tests/Fixtures/locale_and_host/imported.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@
1313
<route id="imported_not_localized" path="/here">
1414
<default key="_controller">ImportedController::someAction</default>
1515
</route>
16+
<route id="imported_single_host" path="/here_again">
17+
<default key="_controller">ImportedController::someAction</default>
18+
<host>www.custom.com</host>
19+
</route>
1620
</routes>

src/Symfony/Component/Routing/Tests/Fixtures/localized/imported-with-host.yml renamed to src/Symfony/Component/Routing/Tests/Fixtures/locale_and_host/imported.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ imported:
1111
imported_not_localized:
1212
controller: ImportedController::someAction
1313
path: /here
14+
15+
imported_single_host:
16+
controller: ImportedController::someAction
17+
path: /here_again
18+
host: www.custom.com

src/Symfony/Component/Routing/Tests/Fixtures/localized/importer-with-host.php renamed to src/Symfony/Component/Routing/Tests/Fixtures/locale_and_host/importer-with-host.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Symfony\Component\Routing\Loader\Configurator;
44

55
return function (RoutingConfigurator $routes) {
6-
$routes->import('imported-with-host.php')->host([
6+
$routes->import('imported.php')->host([
77
'nl' => 'www.example.nl',
88
'en' => 'www.example.com',
99
]);

src/Symfony/Component/Routing/Tests/Fixtures/localized/importer-with-host.xml renamed to src/Symfony/Component/Routing/Tests/Fixtures/locale_and_host/importer-with-host.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://symfony.com/schema/routing
55
https://symfony.com/schema/routing/routing-1.0.xsd">
6-
<import resource="./imported-with-host.xml">
6+
<import resource="./imported.xml">
77
<host locale="nl">www.example.nl</host>
88
<host locale="en">www.example.com</host>
99
</import>
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
i_need:
3-
resource: ./imported-with-host.yml
3+
resource: ./imported.yml
44
host:
55
nl: www.example.nl
66
en: www.example.com

src/Symfony/Component/Routing/Tests/Fixtures/localized/importer-with-locale-and-host.php renamed to src/Symfony/Component/Routing/Tests/Fixtures/locale_and_host/importer-with-locale-and-host.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Symfony\Component\Routing\Loader\Configurator;
44

55
return function (RoutingConfigurator $routes) {
6-
$routes->import('imported-with-host.php')->host([
6+
$routes->import('imported.php')->host([
77
'nl' => 'www.example.nl',
88
'en' => 'www.example.com',
99
])->prefix([

src/Symfony/Component/Routing/Tests/Fixtures/localized/importer-with-locale-and-host.xml renamed to src/Symfony/Component/Routing/Tests/Fixtures/locale_and_host/importer-with-locale-and-host.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://symfony.com/schema/routing
55
https://symfony.com/schema/routing/routing-1.0.xsd">
6-
<import resource="./imported-with-host.xml">
6+
<import resource="./imported.xml">
77
<prefix locale="nl">/nl</prefix>
88
<prefix locale="en">/en</prefix>
99
<host locale="nl">www.example.nl</host>

src/Symfony/Component/Routing/Tests/Fixtures/localized/importer-with-locale-and-host.yml renamed to src/Symfony/Component/Routing/Tests/Fixtures/locale_and_host/importer-with-locale-and-host.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
i_need:
3-
resource: ./imported-with-host.yml
3+
resource: ./imported.yml
44
prefix:
55
nl: /nl
66
en: /en
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Loader\Configurator;
4+
5+
return function (RoutingConfigurator $routes) {
6+
$routes->import('imported.php')->host('www.example.com');
7+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<routes xmlns="http://symfony.com/schema/routing"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/routing
5+
https://symfony.com/schema/routing/routing-1.0.xsd">
6+
<import resource="./imported.xml">
7+
<host>www.example.com</host>
8+
</import>
9+
</routes>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
i_need:
3+
resource: ./imported.yml
4+
host: www.example.com
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Loader\Configurator;
4+
5+
return function (RoutingConfigurator $routes) {
6+
$routes->import('imported.php');
7+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<routes xmlns="http://symfony.com/schema/routing"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/routing
5+
https://symfony.com/schema/routing/routing-1.0.xsd">
6+
<import resource="./imported.xml">
7+
</import>
8+
</routes>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
i_need:
3+
resource: ./imported.yml

0 commit comments

Comments
 (0)
0