TemplateTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class PHPParser_Tests_TemplateTest extends PHPUnit_Framework_TestCase
  3. {
  4. /**
  5. * @dataProvider provideTestPlaceholderReplacement
  6. * @covers PHPParser_Template
  7. */
  8. public function testPlaceholderReplacement($templateCode, $placeholders, $expectedPrettyPrint) {
  9. $parser = new PHPParser_Parser(new PHPParser_Lexer);
  10. $prettyPrinter = new PHPParser_PrettyPrinter_Default;
  11. $template = new PHPParser_Template($parser, $templateCode);
  12. $this->assertEquals(
  13. $expectedPrettyPrint,
  14. $prettyPrinter->prettyPrint($template->getStmts($placeholders))
  15. );
  16. }
  17. public function provideTestPlaceholderReplacement() {
  18. return array(
  19. array(
  20. '<?php $__name__ + $__Name__;',
  21. array('name' => 'foo'),
  22. '$foo + $Foo;'
  23. ),
  24. array(
  25. '<?php $__name__ + $__Name__;',
  26. array('Name' => 'Foo'),
  27. '$foo + $Foo;'
  28. ),
  29. array(
  30. '<?php $__name__ + $__Name__;',
  31. array('name' => 'foo', 'Name' => 'Bar'),
  32. '$foo + $Bar;'
  33. ),
  34. array(
  35. '<?php $__name__ + $__Name__;',
  36. array('Name' => 'Bar', 'name' => 'foo'),
  37. '$foo + $Bar;'
  38. ),
  39. array(
  40. '<?php $prefix__Name__Suffix;',
  41. array('name' => 'infix'),
  42. '$prefixInfixSuffix;'
  43. ),
  44. array(
  45. '<?php $___name___;',
  46. array('name' => 'foo'),
  47. '$_foo_;'
  48. ),
  49. array(
  50. '<?php $foobar;',
  51. array(),
  52. '$foobar;'
  53. ),
  54. );
  55. }
  56. }