Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 429163f

Browse files
committed
Update unit tests to test glob imports
1 parent 0e5d09d commit 429163f

File tree

8 files changed

+98
-1
lines changed

8 files changed

+98
-1
lines changed

src/Symfony/Component/Config/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
3.3.0
5+
-----
6+
7+
* allow config files to be loaded using a glob pattern
8+
49
3.0.0
510
-----
611

src/Symfony/Component/Config/FileLocator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function locate($name, $currentPath = null, $first = true)
6262
$paths = array_unique($paths);
6363
$filepaths = array();
6464

65-
$load = function ($file) use(&$filepaths) {
65+
$load = function ($file) use (&$filepaths) {
6666
if (@file_exists($file)) {
6767
$filepaths[] = $file;
6868
}

src/Symfony/Component/Config/Tests/FileLocatorTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ public function testLocate()
7676
'->locate() returns an array of absolute filenames'
7777
);
7878

79+
$this->assertEquals(
80+
array(
81+
__DIR__.'/Fixtures/Util'.DIRECTORY_SEPARATOR.'document_type.xml',
82+
__DIR__.'/Fixtures/Util'.DIRECTORY_SEPARATOR.'invalid.xml',
83+
__DIR__.'/Fixtures/Util'.DIRECTORY_SEPARATOR.'invalid_schema.xml',
84+
__DIR__.'/Fixtures/Util'.DIRECTORY_SEPARATOR.'valid.xml',
85+
__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml',
86+
__DIR__.'/Fixtures/Again'.DIRECTORY_SEPARATOR.'foo.xml',
87+
),
88+
$loader->locate('*.xml', __DIR__.'/Fixtures/Util', false),
89+
'->locate() load glob pattern'
90+
);
91+
92+
$this->assertEquals(
93+
array(__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', __DIR__.'/Fixtures/Again'.DIRECTORY_SEPARATOR.'foo.xml'),
94+
$loader->locate('*.xml', __DIR__.'/Fixtures', false),
95+
'->locate() load glob pattern'
96+
);
97+
7998
$loader = new FileLocator(__DIR__.'/Fixtures/Again');
8099

81100
$this->assertEquals(

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CHANGELOG
1414
* using the `PhpDumper` with an uncompiled `ContainerBuilder` is deprecated and
1515
will not be supported anymore in 4.0
1616
* deprecated the `DefinitionDecorator` class in favor of `ChildDefinition`
17+
* allow config files to be loaded using a glob pattern
1718

1819
3.2.0
1920
-----
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
<imports>
7+
<import resource="services2*.xml" ignore-errors="true" />
8+
</imports>
9+
</container>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
imports:
2+
- { resource: services2*.yml }

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,42 @@ public function testLoadImports()
173173
$loader->load('services4_bad_import.xml');
174174
}
175175

176+
public function testLoadGlobImports()
177+
{
178+
$container = new ContainerBuilder();
179+
$resolver = new LoaderResolver(array(
180+
new IniFileLoader($container, new FileLocator(self::$fixturesPath.'/ini')),
181+
new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yml')),
182+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')),
183+
));
184+
$loader->setResolver($resolver);
185+
$loader->load('glob_imports.xml');
186+
187+
$actual = $container->getParameterBag()->all();
188+
$expected = array(
189+
'a string',
190+
'foo' => 'bar',
191+
'values' => array(
192+
0,
193+
'integer' => 4,
194+
100 => null,
195+
'true',
196+
true,
197+
false,
198+
'on',
199+
'off',
200+
'float' => 1.3,
201+
1000.3,
202+
'a string',
203+
array('foo', 'bar'),
204+
),
205+
'mixedcase' => array('MixedCaseKey' => 'value'),
206+
'constant' => PHP_EOL,
207+
);
208+
209+
$this->assertEquals(array_keys($expected), array_keys($actual), '->load() imports and merges imported files');
210+
}
211+
176212
public function testLoadAnonymousServices()
177213
{
178214
$container = new ContainerBuilder();

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,31 @@ public function testLoadImports()
133133
$loader->load('services4_bad_import.yml');
134134
}
135135

136+
public function testLoadGlobImports()
137+
{
138+
$container = new ContainerBuilder();
139+
$resolver = new LoaderResolver(array(
140+
new IniFileLoader($container, new FileLocator(self::$fixturesPath.'/ini')),
141+
new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')),
142+
new PhpFileLoader($container, new FileLocator(self::$fixturesPath.'/php')),
143+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')),
144+
));
145+
$loader->setResolver($resolver);
146+
$loader->load('glob_imports.yml');
147+
148+
$actual = $container->getParameterBag()->all();
149+
$expected = array(
150+
'foo' => 'bar',
151+
'values' => array(true, false, PHP_INT_MAX),
152+
'bar' => '%foo%',
153+
'escape' => '@escapeme',
154+
'foo_bar' => new Reference('foo_bar'),
155+
'mixedcase' => array('MixedCaseKey' => 'value'),
156+
'env(foo)' => 'foo',
157+
);
158+
$this->assertEquals(array_keys($expected), array_keys($actual), '->load() imports and merges imported files');
159+
}
160+
136161
public function testLoadServices()
137162
{
138163
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)