Add test coverage for Mustache.php 2.0
Update legacy tests for new codebase.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Mustache\Test;
|
||||
|
||||
use Mustache\Compiler;
|
||||
use Mustache\Tokenizer;
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
*/
|
||||
class CompilerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider getCompileValues
|
||||
*/
|
||||
public function testCompile($source, array $tree, $name, $expected) {
|
||||
$compiler = new Compiler;
|
||||
|
||||
$compiled = $compiler->compile($source, $tree, $name);
|
||||
foreach ($expected as $contains) {
|
||||
$this->assertContains($contains, $compiled);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCompileValues() {
|
||||
return array(
|
||||
array('', array(), 'Banana', array(
|
||||
"\nclass Banana extends \Mustache\Template",
|
||||
'$buffer->flush();',
|
||||
)),
|
||||
|
||||
array('', array('TEXT'), 'Monkey', array(
|
||||
"\nclass Monkey extends \Mustache\Template",
|
||||
'$buffer->writeText(\'TEXT\');',
|
||||
'$buffer->flush();',
|
||||
)),
|
||||
|
||||
array(
|
||||
'',
|
||||
array(
|
||||
'foo',
|
||||
"\n",
|
||||
array(
|
||||
Tokenizer::TAG => '_v',
|
||||
Tokenizer::NAME => 'name',
|
||||
),
|
||||
array(
|
||||
Tokenizer::TAG => '_v',
|
||||
Tokenizer::NAME => '.',
|
||||
),
|
||||
"'bar'",
|
||||
),
|
||||
'Monkey',
|
||||
array(
|
||||
"\nclass Monkey extends \Mustache\Template",
|
||||
'$buffer->writeText(\'foo\');',
|
||||
'$buffer->writeLine();',
|
||||
'$value = $context->find(\'name\');',
|
||||
'$buffer->writeText($value, true);',
|
||||
'$value = $context->last();',
|
||||
'$buffer->writeText(\'\\\'bar\\\'\');',
|
||||
'$buffer->flush();',
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testCompilerThrowsUnknownNodeTypeException() {
|
||||
$compiler = new Compiler;
|
||||
$compiler->compile('', array(array(Tokenizer::TAG => 'invalid')), 'SomeClass');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user