FilesystemLoaderTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /*
  3. * This file is part of Mustache.php.
  4. *
  5. * (c) 2012 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Mustache\Test\Loader;
  11. use Mustache\Loader\FilesystemLoader;
  12. /**
  13. * @group unit
  14. */
  15. class FilesystemLoaderTest extends \PHPUnit_Framework_TestCase {
  16. public function testConstructor() {
  17. $baseDir = realpath(__DIR__.'/../../../fixtures/templates');
  18. $loader = new FilesystemLoader($baseDir, array('extension' => '.ms'));
  19. $this->assertEquals('alpha contents', $loader->load('alpha'));
  20. $this->assertEquals('beta contents', $loader->load('beta.ms'));
  21. }
  22. public function testLoadTemplates() {
  23. $baseDir = realpath(__DIR__.'/../../../fixtures/templates');
  24. $loader = new FilesystemLoader($baseDir);
  25. $this->assertEquals('one contents', $loader->load('one'));
  26. $this->assertEquals('two contents', $loader->load('two.mustache'));
  27. }
  28. /**
  29. * @expectedException \RuntimeException
  30. */
  31. public function testMissingBaseDirThrowsException() {
  32. $loader = new FilesystemLoader(__DIR__.'/not_a_directory');
  33. }
  34. /**
  35. * @expectedException \InvalidArgumentException
  36. */
  37. public function testMissingTemplateThrowsException() {
  38. $baseDir = realpath(__DIR__.'/../../../fixtures/templates');
  39. $loader = new FilesystemLoader($baseDir);
  40. $loader->load('fake');
  41. }
  42. }