NoTemplatingEntryTest.php 1.9 KB

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