Skip to content

Commit 637a6a2

Browse files
committed
Autoload the Pug alias and add extend cache test
1 parent 07b082e commit 637a6a2

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

Diff for: composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@
141141
},
142142
"bin": ["pug"],
143143
"autoload": {
144+
"psr-4": {
145+
"": "./src"
146+
},
144147
"psr-0": {
145148
"Pug\\": "src/",
146149
"Jade\\": "src/"

Diff for: tests/features/cache.php

+62
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,66 @@ public function testCacheDirectory()
262262
self::assertSame($expectedCount, $success + $errors, 'Each .pug file in the directory to cache should generate a success or an error.');
263263
self::assertSame($success, $filesCount, 'Each file successfully cached should be in the cache directory.');
264264
}
265+
266+
/**
267+
* @group i
268+
*/
269+
public function testCacheOnExtendsChange()
270+
{
271+
$directory = sys_get_temp_dir().'/pug'.mt_rand(0, 99999999);
272+
$templateDirectory = sys_get_temp_dir().'/pug'.mt_rand(0, 99999999);
273+
$this->emptyDirectory($directory);
274+
$this->emptyDirectory($templateDirectory);
275+
if (!file_exists($directory)) {
276+
mkdir($directory);
277+
}
278+
if (!file_exists($templateDirectory)) {
279+
mkdir($templateDirectory);
280+
}
281+
$renderer = new Pug([
282+
'basedir' => $templateDirectory,
283+
'cache_dir' => $directory,
284+
]);
285+
$base = $templateDirectory.DIRECTORY_SEPARATOR.'base.pug';
286+
file_put_contents($base, implode("\n", [
287+
'p in base',
288+
'block content',
289+
]));
290+
$child = $templateDirectory.DIRECTORY_SEPARATOR.'child.pug';
291+
file_put_contents($child, implode("\n", [
292+
'extends base',
293+
'block content',
294+
' p in child',
295+
]));
296+
297+
$render = function ($path) use ($renderer) {
298+
ob_start();
299+
$renderer->displayFile($path);
300+
$contents = ob_get_contents();
301+
ob_end_clean();
302+
303+
return $contents;
304+
};
305+
306+
self::assertSame('<p>in base</p><p>in child</p>', $render($child));
307+
308+
file_put_contents($base, implode("\n", [
309+
'p in base updated!',
310+
'block content',
311+
]));
312+
touch($base, time() - 3600);
313+
touch($child, time() - 3600);
314+
clearstatcache();
315+
316+
$html = $render($child);
317+
self::assertSame('<p>in base</p><p>in child</p>', $html);
318+
319+
touch($base, time() + 3600);
320+
clearstatcache();
321+
322+
self::assertSame('<p>in base updated!</p><p>in child</p>', $render($child));
323+
324+
$this->emptyDirectory($directory);
325+
$this->emptyDirectory($templateDirectory);
326+
}
265327
}

0 commit comments

Comments
 (0)