Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21e66c0
commit 026004c
Showing
9 changed files
with
164 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,32 @@ | ||
<?php | ||
|
||
namespace AlexMasterov\EquipTwigTests\Exception; | ||
namespace AlexMasterov\EquipTwig\Tests\Exception; | ||
|
||
use AlexMasterov\EquipTwig\Exception\ExceptionInterface; | ||
use AlexMasterov\EquipTwig\Exception\ExtensionException; | ||
use InvalidArgumentException; | ||
use PHPUnit_Framework_TestCase as TestCase; | ||
use Twig_ExtensionInterface; | ||
use stdClass; | ||
|
||
class ExtensionExceptionTest extends TestCase | ||
{ | ||
public function testInvalidExtension() | ||
{ | ||
$extension = new stdClass; | ||
$interface = Twig_ExtensionInterface::class; | ||
// Stab | ||
$extension = new \stdClass; | ||
$message = sprintf( | ||
'Twig extension `%s` must implement `%s`' , | ||
get_class($extension), | ||
Twig_ExtensionInterface::class | ||
); | ||
|
||
// Execute | ||
$exception = ExtensionException::invalidClass($extension); | ||
|
||
$this->assertInstanceOf(ExtensionException::class, $exception); | ||
$this->assertInstanceOf(InvalidArgumentException::class, $exception); | ||
$this->assertInstanceOf(ExceptionInterface::class, $exception); | ||
$this->assertSame( | ||
'Twig extension `'. get_class($extension) .'` must implement `'. $interface .'`', | ||
$exception->getMessage() | ||
); | ||
// Verify | ||
self::assertInstanceOf(ExtensionException::class, $exception); | ||
self::assertInstanceOf(InvalidArgumentException::class, $exception); | ||
self::assertInstanceOf(ExceptionInterface::class, $exception); | ||
self::assertSame($message, $exception->getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,95 @@ | ||
<?php | ||
|
||
namespace AlexMasterov\EquipTwigTests\Loader; | ||
namespace AlexMasterov\EquipTwig\Tests\Loader; | ||
|
||
use AlexMasterov\EquipTwigTests\Asset\Template; | ||
use AlexMasterov\EquipTwig\Exception\LoaderException; | ||
use AlexMasterov\EquipTwig\Loader\FilesystemLoader; | ||
use PHPUnit_Framework_TestCase as TestCase; | ||
use AlexMasterov\EquipTwig\Tests\TestCase; | ||
use Twig_Source; | ||
|
||
class FilesystemLoaderTest extends TestCase | ||
{ | ||
public function testConstructor() | ||
{ | ||
$fileExtensions = ['html.twig']; | ||
|
||
$loader = new FilesystemLoader( | ||
Template::path(), | ||
$fileExtensions | ||
); | ||
|
||
$class = new \ReflectionClass($loader); | ||
|
||
// path | ||
$propPath = $class->getProperty('path'); | ||
$propPath->setAccessible(true); | ||
|
||
$this->assertSame(Template::path(), $propPath->getValue($loader)); | ||
|
||
// fileExtensions | ||
$propFileExtensions = $class->getProperty('fileExtensions'); | ||
$propFileExtensions->setAccessible(true); | ||
|
||
$this->assertEquals($fileExtensions, $propFileExtensions->getValue($loader)); | ||
} | ||
|
||
public function testGetSource() | ||
{ | ||
$loader = new FilesystemLoader(Template::path()); | ||
$source = $loader->getSource(Template::name()); | ||
|
||
$this->assertSame(Template::code(), $source); | ||
} | ||
|
||
public function testGetSourceContext() | ||
{ | ||
$loader = new FilesystemLoader(Template::path()); | ||
$source = $loader->getSourceContext(Template::name()); | ||
// Stab | ||
$template = $this->template('test.html.twig'); | ||
|
||
$this->assertInstanceOf(Twig_Source::class, $source); | ||
$this->assertSame(Template::name(), $source->getName()); | ||
$this->assertSame(Template::code(), $source->getCode()); | ||
// Execute | ||
$loader = new FilesystemLoader($template->path()); | ||
$source = $loader->getSourceContext($template->name()); | ||
|
||
// Verify | ||
self::assertInstanceOf(Twig_Source::class, $source); | ||
self::assertSame($template->name(), $source->getName()); | ||
self::assertSame($template->code(), $source->getCode()); | ||
} | ||
|
||
public function testGetCacheKey() | ||
{ | ||
$loader = new FilesystemLoader(Template::path()); | ||
$loader->getSourceContext(Template::name()); | ||
// Stab | ||
$template = $this->template('test.html.twig'); | ||
|
||
// Execute | ||
$loader = new FilesystemLoader($template->path()); | ||
$loader->getSourceContext($template->name()); | ||
|
||
$cacheKey = $loader->getCacheKey(Template::name()); | ||
$cacheKey = $loader->getCacheKey($template->name()); | ||
|
||
$this->assertSame(Template::templatePath(), $cacheKey); | ||
// Verify | ||
self::assertSame(realpath($template->templatePath()), $cacheKey); | ||
} | ||
|
||
public function testIsFresh() | ||
{ | ||
$loader = new FilesystemLoader(Template::path()); | ||
// Stab | ||
$template = $this->template('test.html.twig'); | ||
|
||
$this->assertTrue( | ||
$loader->isFresh(Template::name(), time()) | ||
// Execute | ||
$loader = new FilesystemLoader($template->path()); | ||
|
||
// Verify | ||
self::assertTrue( | ||
$loader->isFresh($template->name(), time()) | ||
); | ||
} | ||
|
||
public function testExists() | ||
{ | ||
$loader = new FilesystemLoader(Template::path(), ['html.twig']); | ||
// Stab | ||
$template = $this->template('test.html.twig'); | ||
$ext = 'html.twig'; | ||
|
||
$this->assertTrue( | ||
$loader->exists(Template::name()) | ||
); | ||
// Execute | ||
$loader = new FilesystemLoader($template->path(), [$ext]); | ||
|
||
// cached | ||
$loader->getSourceContext(Template::name()); | ||
// Verify | ||
self::assertTrue($loader->exists($template->name())); | ||
|
||
$this->assertTrue( | ||
$loader->exists(Template::name()) | ||
); | ||
// Execute (with cached) | ||
$loader->getSourceContext($template->name()); | ||
|
||
// without .ext | ||
$name = strstr(Template::name(), '.', true); | ||
$loader->getSourceContext($name); | ||
// Verify | ||
self::assertTrue($loader->exists($template->name())); | ||
|
||
$this->assertTrue( | ||
$loader->exists($name) | ||
// Execute (without .ext) | ||
$loader->getSourceContext( | ||
basename($template->name(), ".{$ext}") | ||
); | ||
|
||
// Verify | ||
self::assertTrue($loader->exists($template->name())); | ||
} | ||
|
||
public function testThenTemplateNotFound() | ||
{ | ||
$this->expectException(LoaderException::class); | ||
// Verify | ||
self::expectException(LoaderException::class); | ||
|
||
// Stab | ||
$template = $this->template('test.html.twig'); | ||
|
||
$loader = new FilesystemLoader(Template::path()); | ||
// Execute | ||
$loader = new FilesystemLoader($template->path()); | ||
$loader->getSourceContext('nowhere.html.twig'); | ||
} | ||
} |
Oops, something went wrong.