mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-12-11 08:39:44 +01:00
3701e02d32
Now the lexer is injected only once when creating the parser. Instead of $parser = new PHPParser_Parser; $parser->parse(new PHPParser_Lexer($code)); $parser->parse(new PHPParser_Lexer($code2)); you write: $parser = new PHPParser_Parser(new PHPParser_Lexer); $parser->parse($code); $parser->parse($code2);
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
class PHPParser_Tests_TemplateTest extends PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* @dataProvider provideTestPlaceholderReplacement
|
|
* @covers PHPParser_Template
|
|
*/
|
|
public function testPlaceholderReplacement($templateCode, $placeholders, $expectedPrettyPrint) {
|
|
$parser = new PHPParser_Parser(new PHPParser_Lexer);
|
|
$prettyPrinter = new PHPParser_PrettyPrinter_Zend;
|
|
|
|
$template = new PHPParser_Template($parser, $templateCode);
|
|
$this->assertEquals(
|
|
$expectedPrettyPrint,
|
|
$prettyPrinter->prettyPrint($template->getStmts($placeholders))
|
|
);
|
|
}
|
|
|
|
public function provideTestPlaceholderReplacement() {
|
|
return array(
|
|
array(
|
|
'<?php $__name__ + $__Name__;',
|
|
array('name' => 'foo'),
|
|
'$foo + $Foo;'
|
|
),
|
|
array(
|
|
'<?php $__name__ + $__Name__;',
|
|
array('Name' => 'Foo'),
|
|
'$foo + $Foo;'
|
|
),
|
|
array(
|
|
'<?php $__name__ + $__Name__;',
|
|
array('name' => 'foo', 'Name' => 'Bar'),
|
|
'$foo + $Bar;'
|
|
),
|
|
array(
|
|
'<?php $__name__ + $__Name__;',
|
|
array('Name' => 'Bar', 'name' => 'foo'),
|
|
'$foo + $Bar;'
|
|
),
|
|
array(
|
|
'<?php $prefix__Name__Suffix;',
|
|
array('name' => 'infix'),
|
|
'$prefixInfixSuffix;'
|
|
),
|
|
array(
|
|
'<?php $___name___;',
|
|
array('name' => 'foo'),
|
|
'$_foo_;'
|
|
)
|
|
);
|
|
}
|
|
} |