TestCase.php 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. abstract class Twig_Tests_Node_TestCase extends PHPUnit_Framework_TestCase
  11. {
  12. abstract public function getTests();
  13. /**
  14. * @dataProvider getTests
  15. */
  16. public function testCompile($node, $source, $environment = null)
  17. {
  18. $this->assertNodeCompilation($source, $node, $environment);
  19. }
  20. public function assertNodeCompilation($source, Twig_Node $node, Twig_Environment $environment = null)
  21. {
  22. $compiler = $this->getCompiler($environment);
  23. $compiler->compile($node);
  24. $this->assertEquals($source, trim($compiler->getSource()));
  25. }
  26. protected function getCompiler(Twig_Environment $environment = null)
  27. {
  28. return new Twig_Compiler(null === $environment ? $this->getEnvironment() : $environment);
  29. }
  30. protected function getEnvironment()
  31. {
  32. return new Twig_Environment();
  33. }
  34. }