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

Skip to content

Commit 413b7e1

Browse files
committed
[TwigBundle] added some tests
1 parent 0d537c4 commit 413b7e1

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\TwigBundle\Tests;
13+
14+
use Symfony\Component\HttpKernel\Kernel;
15+
use Symfony\Component\Config\Loader\LoaderInterface;
16+
use Symfony\Component\Filesystem\Filesystem;
17+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
18+
use Symfony\Bundle\TwigBundle\TwigBundle;
19+
20+
class NoTemplatingEntryTest extends \PHPUnit_Framework_TestCase
21+
{
22+
public function test()
23+
{
24+
$kernel = new NoTemplatingEntryKernel('dev', true);
25+
$kernel->boot();
26+
27+
$container = $kernel->getContainer();
28+
29+
$content = $container->get('twig')->render('index.html.twig');
30+
$this->assertContains('Debug: 1', $content);
31+
$this->assertContains('Env: dev', $content);
32+
}
33+
34+
protected function setUp()
35+
{
36+
$this->deleteTempDir();
37+
}
38+
39+
protected function tearDown()
40+
{
41+
$this->deleteTempDir();
42+
}
43+
44+
protected function deleteTempDir()
45+
{
46+
if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel')) {
47+
return;
48+
}
49+
50+
$fs = new Filesystem();
51+
$fs->remove($dir);
52+
}
53+
}
54+
55+
class NoTemplatingEntryKernel extends Kernel
56+
{
57+
public function registerBundles()
58+
{
59+
return array(new FrameworkBundle(), new TwigBundle());
60+
}
61+
62+
public function registerContainerConfiguration(LoaderInterface $loader)
63+
{
64+
$loader->load(function ($container) {
65+
$container->loadFromExtension('framework', array(
66+
'secret' => '$ecret',
67+
));
68+
});
69+
}
70+
71+
public function getCacheDir()
72+
{
73+
return sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel/cache/'.$this->environment;
74+
}
75+
76+
public function getLogDir()
77+
{
78+
return sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel/logs';
79+
}
80+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Debug: {{ is_debug() }}
2+
Env: {{ env() }}

0 commit comments

Comments
 (0)