Skip to content

Commit

Permalink
Merge pull request #25 from phug-php/add-tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
kylekatarnls committed Jul 4, 2018
2 parents 87f976c + 1e0a3e7 commit 54a0238
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Phug/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function ($path) {
*
* @return bool
*/
public function renderAndWriteFile($inputFile, $outputFile, $parameters)
public function renderAndWriteFile($inputFile, $outputFile, array $parameters = [])
{
$outputDirectory = dirname($outputFile);

Expand Down
20 changes: 20 additions & 0 deletions tests/Phug/AbstractRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,24 @@ public static function assertSameLines($expected, $actual, $message = null)

self::assertSame($expected, $actual, $message);
}

protected static function getReadOnlyDirectory()
{
$dir = __DIR__;
while (is_writable($dir)) {
$parent = realpath($dir.'/..');
if ($parent === $dir) {
$dir = 'C:';
if (!file_exists($dir) || is_writable($dir)) {
self::markTestSkipped('No read-only directory found to do the test');

return;
}
break;
}
$dir = $parent;
}

return $dir;
}
}
16 changes: 1 addition & 15 deletions tests/Phug/Adapter/FileAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,22 +538,8 @@ public function testMissingDirectory()
*/
public function testReadOnlyDirectory()
{
$dir = __DIR__;
while (is_writable($dir)) {
$parent = realpath($dir.'/..');
if ($parent === $dir) {
$dir = 'C:';
if (!file_exists($dir) || is_writable($dir)) {
self::markTestSkipped('No read-only directory found to do the test');

return;
}
break;
}
$dir = $parent;
}
$renderer = new Renderer([
'cache_dir' => $dir,
'cache_dir' => static::getReadOnlyDirectory(),
]);
$renderer->render(__DIR__.'/../../cases/attrs.pug');
}
Expand Down
6 changes: 0 additions & 6 deletions tests/Phug/ProfilerModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,6 @@ public function testEventVarDump()
return;
}

if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
self::markTestSkipped('var_dump test disabled for PHP '.PHP_VERSION.'.');

return;
}

$renderer = new Renderer([
'enable_profiler' => true,
]);
Expand Down
29 changes: 29 additions & 0 deletions tests/Phug/RendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,39 @@ public function testRenderDirectory()
self::assertFileExists($directory.'/subdirectory/subsubdirectory/basic.html');
self::assertFileExists($directory.'/subdirectory/subsubdirectory/blanks.html');

self::emptyDirectory($directory);
file_put_contents("$directory/foo.pug", 'p=foo');

list($success, $errors) = $this->renderer->renderDirectory($directory, ['foo' => 'bar']);

self::assertSame(0, $errors);
self::assertSame(1, $success);
self::assertFileExists("$directory/foo.html");
self::assertSame('<p>bar</p>', trim(file_get_contents("$directory/foo.html")));

self::emptyDirectory($directory);
file_put_contents("$directory/foo.pug", 'p=foo');

list($success, $errors) = $this->renderer->renderDirectory($directory, null, ['foo' => 'bar']);

self::assertSame(0, $errors);
self::assertSame(1, $success);
self::assertFileExists("$directory/foo.html");
self::assertSame('<p>bar</p>', trim(file_get_contents("$directory/foo.html")));

self::emptyDirectory($directory);
@rmdir($directory);
}

/**
* @covers ::renderAndWriteFile
*/
public function testRenderAndWriteFile()
{
self::assertFalse($this->renderer->renderAndWriteFile(__DIR__.'/../utils/error.pug', static::getReadOnlyDirectory().'/output.html'));
self::assertFalse($this->renderer->renderAndWriteFile(__DIR__.'/../utils/error.pug', static::getReadOnlyDirectory().'/foobar/output.html'));
}

/**
* @covers ::displayFile
* @covers ::display
Expand Down

0 comments on commit 54a0238

Please sign in to comment.