bug #9719 [TwigBundle] fix configuration tree for paths (mdavis1982, cordoval)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #9719).

Discussion
----------

[TwigBundle] fix configuration tree for paths

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8171
| License       | MIT
| Doc PR        | na

This is a joint effort with @mdavis1982 and @cordoval 👶 pairing up and warming for hacking day in Warsaw

Commits
-------

9aa88e4 added regression test
4201d41 fix issue #8171 on configuration tree for twig extension -- pairing up with @cordoval
This commit is contained in:
Christophe Coevoet 2014-07-10 10:55:42 +02:00
commit 819bb2901f
9 changed files with 34 additions and 10 deletions

View File

@ -136,6 +136,7 @@ class Configuration implements ConfigurationInterface
->scalarNode('optimizations')->end() ->scalarNode('optimizations')->end()
->arrayNode('paths') ->arrayNode('paths')
->normalizeKeys(false) ->normalizeKeys(false)
->useAttributeAsKey('paths')
->beforeNormalization() ->beforeNormalization()
->always() ->always()
->then(function ($paths) { ->then(function ($paths) {

View File

@ -0,0 +1,7 @@
<?php
$container->loadFromExtension('twig', array(
'paths' => array(
'namespaced_path3' => 'namespace3',
),
));

View File

@ -22,7 +22,7 @@ $container->loadFromExtension('twig', array(
'paths' => array( 'paths' => array(
'path1', 'path1',
'path2', 'path2',
'namespaced_path1' => 'namespace', 'namespaced_path1' => 'namespace1',
'namespaced_path2' => 'namespace', 'namespaced_path2' => 'namespace2',
), ),
)); ));

View File

@ -0,0 +1,12 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:twig="http://symfony.com/schema/dic/twig"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
<twig:config auto-reload="true" autoescape="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true">
<twig:path namespace="namespace3">namespaced_path3</twig:path>
</twig:config>
</container>

View File

@ -15,7 +15,7 @@
<twig:global key="pi">3.14</twig:global> <twig:global key="pi">3.14</twig:global>
<twig:path>path1</twig:path> <twig:path>path1</twig:path>
<twig:path>path2</twig:path> <twig:path>path2</twig:path>
<twig:path namespace="namespace">namespaced_path1</twig:path> <twig:path namespace="namespace1">namespaced_path1</twig:path>
<twig:path namespace="namespace">namespaced_path2</twig:path> <twig:path namespace="namespace2">namespaced_path2</twig:path>
</twig:config> </twig:config>
</container> </container>

View File

@ -0,0 +1,3 @@
twig:
paths:
namespaced_path3: namespace3

View File

@ -17,5 +17,5 @@ twig:
paths: paths:
path1: '' path1: ''
path2: '' path2: ''
namespaced_path1: namespace namespaced_path1: namespace1
namespaced_path2: namespace namespaced_path2: namespace2

View File

@ -145,6 +145,7 @@ class TwigExtensionTest extends TestCase
$container = $this->createContainer(); $container = $this->createContainer();
$container->registerExtension(new TwigExtension()); $container->registerExtension(new TwigExtension());
$this->loadFromFile($container, 'full', $format); $this->loadFromFile($container, 'full', $format);
$this->loadFromFile($container, 'extra', $format);
$this->compileContainer($container); $this->compileContainer($container);
$def = $container->getDefinition('twig.loader.filesystem'); $def = $container->getDefinition('twig.loader.filesystem');
@ -160,8 +161,9 @@ class TwigExtensionTest extends TestCase
$this->assertEquals(array( $this->assertEquals(array(
array('path1'), array('path1'),
array('path2'), array('path2'),
array('namespaced_path1', 'namespace'), array('namespaced_path1', 'namespace1'),
array('namespaced_path2', 'namespace'), array('namespaced_path2', 'namespace2'),
array('namespaced_path3', 'namespace3'),
array(__DIR__.'/Fixtures/Resources/TwigBundle/views', 'Twig'), array(__DIR__.'/Fixtures/Resources/TwigBundle/views', 'Twig'),
array(realpath(__DIR__.'/../..').'/Resources/views', 'Twig'), array(realpath(__DIR__.'/../..').'/Resources/views', 'Twig'),
array(__DIR__.'/Fixtures/Resources/views'), array(__DIR__.'/Fixtures/Resources/views'),

View File

@ -16,7 +16,6 @@ use Symfony\Component\Finder\Adapter;
class FinderTest extends Iterator\RealIteratorTestCase class FinderTest extends Iterator\RealIteratorTestCase
{ {
public function testCreate() public function testCreate()
{ {
$this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create()); $this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create());
@ -796,7 +795,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
); );
} }
/** /**
* Searching in multiple locations with sub directories involves * Searching in multiple locations with sub directories involves
* AppendIterator which does an unnecessary rewind which leaves * AppendIterator which does an unnecessary rewind which leaves
* FilterIterator with inner FilesystemIterator in an invalid state. * FilterIterator with inner FilesystemIterator in an invalid state.