Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #20611 [DI] FileLoaders: Allow to explicit type to load (ogiz…
…anagi) This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] FileLoaders: Allow to explicit type to load | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20308 | License | MIT | Doc PR | Not yet (fabbot will scream out regarding the PR fixtures) Commits ------- 6b660c2 [DI] FileLoaders: Allow to explicit type to load
- Loading branch information
Showing
16 changed files
with
139 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/Symfony/Component/DependencyInjection/Tests/Fixtures/ini/ini_with_wrong_ext.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[parameters] | ||
with_wrong_ext = 'from ini' |
3 changes: 3 additions & 0 deletions
3
src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/php_with_wrong_ext.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
$container->setParameter('with_wrong_ext', 'from php'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/xml_with_wrong_ext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<parameters> | ||
<parameter key="with_wrong_ext">from xml</parameter> | ||
</parameters> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/yaml_with_wrong_ext.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
parameters: | ||
with_wrong_ext: from yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/Symfony/Component/DependencyInjection/Tests/Loader/LoaderResolverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\DependencyInjection\Tests\Loader; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\Config\Loader\LoaderResolver; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\ClosureLoader; | ||
use Symfony\Component\DependencyInjection\Loader\IniFileLoader; | ||
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; | ||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
|
||
class LoaderResolverTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private static $fixturesPath; | ||
|
||
/** @var LoaderResolver */ | ||
private $resolver; | ||
|
||
protected function setUp() | ||
{ | ||
self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); | ||
|
||
$container = new ContainerBuilder(); | ||
$this->resolver = new LoaderResolver(array( | ||
new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')), | ||
new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')), | ||
new IniFileLoader($container, new FileLocator(self::$fixturesPath.'/ini')), | ||
new PhpFileLoader($container, new FileLocator(self::$fixturesPath.'/php')), | ||
new ClosureLoader($container), | ||
)); | ||
} | ||
|
||
public function provideResourcesToLoad() | ||
{ | ||
return array( | ||
array('ini_with_wrong_ext.xml', 'ini', IniFileLoader::class), | ||
array('xml_with_wrong_ext.php', 'xml', XmlFileLoader::class), | ||
array('php_with_wrong_ext.yml', 'php', PhpFileLoader::class), | ||
array('yaml_with_wrong_ext.ini', 'yaml', YamlFileLoader::class), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider provideResourcesToLoad | ||
*/ | ||
public function testResolvesForcedType($resource, $type, $expectedClass) | ||
{ | ||
$this->assertInstanceOf($expectedClass, $this->resolver->resolve($resource, $type)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters