Add test coverage for Mustache.php 2.0

Update legacy tests for new codebase.
This commit is contained in:
Justin Hileman
2012-02-29 19:12:22 -08:00
parent 8710e4b8a4
commit 0034bf657b
16 changed files with 1123 additions and 707 deletions
+75
View File
@@ -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');
}
}