|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Shapecode\Tests\Twig\Loader; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Shapecode\Twig\Loader\StringLoader; |
| 9 | +use Twig\Error\LoaderError; |
| 10 | +use function time; |
| 11 | + |
| 12 | +class StringLoaderTest extends TestCase |
| 13 | +{ |
| 14 | + public function testGetSourceContextWhenTemplateDoesNotExist() : void |
| 15 | + { |
| 16 | + $this->expectException(LoaderError::class); |
| 17 | + $loader = new StringLoader(); |
| 18 | + $loader->getSourceContext('foo'); |
| 19 | + } |
| 20 | + |
| 21 | + public function testGetCacheKey() : void |
| 22 | + { |
| 23 | + $loader = new StringLoader(); |
| 24 | + self::assertEquals('327b6f07435811239bc47e1544353273', $loader->getCacheKey('foo bar')); |
| 25 | + } |
| 26 | + |
| 27 | + public function testGetCacheKeyWhenTemplateDoesNotExist() : void |
| 28 | + { |
| 29 | + $this->expectException(LoaderError::class); |
| 30 | + $loader = new StringLoader(); |
| 31 | + $loader->getCacheKey('foo'); |
| 32 | + } |
| 33 | + |
| 34 | + public function testIsFresh() : void |
| 35 | + { |
| 36 | + $loader = new StringLoader(); |
| 37 | + self::assertTrue($loader->isFresh('foo bar', time())); |
| 38 | + } |
| 39 | + |
| 40 | + public function testIsFreshWhenTemplateDoesNotExist() : void |
| 41 | + { |
| 42 | + $this->expectException(LoaderError::class); |
| 43 | + |
| 44 | + $loader = new StringLoader(); |
| 45 | + $loader->isFresh('foo', time()); |
| 46 | + } |
| 47 | + |
| 48 | + public function testExists() : void |
| 49 | + { |
| 50 | + $loader = new StringLoader(); |
| 51 | + self::assertTrue($loader->exists('foo bar')); |
| 52 | + } |
| 53 | + |
| 54 | + public function testExistsFails() : void |
| 55 | + { |
| 56 | + $loader = new StringLoader(); |
| 57 | + self::assertFalse($loader->exists('foo')); |
| 58 | + } |
| 59 | +} |
0 commit comments