1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-12-14 10:27:37 +01:00
PHP-Parser/test/PHPParser/Tests/TemplateLoaderTest.php
nikic 3701e02d32 Use inject-once approach for lexer
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);
2012-05-04 10:16:46 +02:00

48 lines
1.5 KiB
PHP

<?php
class PHPParser_Tests_TemplateLoaderTest extends PHPUnit_Framework_TestCase
{
public function testLoadWithoutSuffix() {
$templateLoader = new PHPParser_TemplateLoader(
new PHPParser_Parser(new PHPParser_Lexer),
dirname(__FILE__)
);
// load this file as a template, as we don't really care about the contents
$template = $templateLoader->load('TemplateLoaderTest.php');
$this->assertInstanceOf('PHPParser_Template', $template);
}
public function testLoadWithSuffix() {
$templateLoader = new PHPParser_TemplateLoader(
new PHPParser_Parser(new PHPParser_Lexer),
dirname(__FILE__), '.php'
);
// load this file as a template, as we don't really care about the contents
$template = $templateLoader->load('TemplateLoaderTest');
$this->assertInstanceOf('PHPParser_Template', $template);
}
/**
* @expectedException InvalidArgumentException
*/
public function testNonexistentBaseDirectoryError() {
new PHPParser_TemplateLoader(
new PHPParser_Parser(new PHPParser_Lexer),
dirname(__FILE__) . '/someDirectoryThatDoesNotExist'
);
}
/**
* @expectedException InvalidArgumentException
*/
public function testNonexistentFileError() {
$templateLoader = new PHPParser_TemplateLoader(
new PHPParser_Parser(new PHPParser_Lexer),
dirname(__FILE__)
);
$templateLoader->load('SomeTemplateThatDoesNotExist');
}
}