From 18d4c4163c763bb8e0d19c8a190c3c6ef95e8412 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 10 Jan 2015 13:28:00 +0100 Subject: [PATCH] [TwigBundle] added some tests --- .../Functional/NoTemplatingEntryTest.php | 78 +++++++++++++++++++ .../Resources/views/index.html.twig | 1 + src/Symfony/Bundle/TwigBundle/composer.json | 2 +- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/Functional/Resources/views/index.html.twig diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php new file mode 100644 index 0000000000..068a10526c --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php @@ -0,0 +1,78 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\TwigBundle\Tests; + +use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use Symfony\Bundle\TwigBundle\TwigBundle; + +class NoTemplatingEntryTest extends \PHPUnit_Framework_TestCase +{ + public function test() + { + $kernel = new NoTemplatingEntryKernel('dev', true); + $kernel->boot(); + + $container = $kernel->getContainer(); + $content = $container->get('twig')->render('index.html.twig'); + $this->assertContains('{ a: b }', $content); + } + + protected function setUp() + { + $this->deleteTempDir(); + } + + protected function tearDown() + { + $this->deleteTempDir(); + } + + protected function deleteTempDir() + { + if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel')) { + return; + } + + $fs = new Filesystem(); + $fs->remove($dir); + } +} + +class NoTemplatingEntryKernel extends Kernel +{ + public function registerBundles() + { + return array(new FrameworkBundle(), new TwigBundle()); + } + + public function registerContainerConfiguration(LoaderInterface $loader) + { + $loader->load(function ($container) { + $container->loadFromExtension('framework', array( + 'secret' => '$ecret', + )); + }); + } + + public function getCacheDir() + { + return sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel/cache/'.$this->environment; + } + + public function getLogDir() + { + return sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel/logs'; + } +} diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/Resources/views/index.html.twig b/src/Symfony/Bundle/TwigBundle/Tests/Functional/Resources/views/index.html.twig new file mode 100644 index 0000000000..ddc4eb4404 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/Resources/views/index.html.twig @@ -0,0 +1 @@ +{{ {a: 'b'}|yaml_encode }} diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index 7a141e0644..6d5e4dbd75 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=5.3.9", - "symfony/twig-bridge": "~2.6|~3.0.0", + "symfony/twig-bridge": "~2.7|~3.0.0", "symfony/http-foundation": "~2.5|~3.0.0", "symfony/http-kernel": "~2.3.24|~2.5.9|~2.6,>=2.6.2|~3.0.0" },