Skip to content

Commit de3b4b1

Browse files
committed
BugFix: non required trailing slash. Fixes #27
1 parent 6b31dbd commit de3b4b1

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/PhpRenderer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class PhpRenderer
3737
*/
3838
public function __construct($templatePath = "", $attributes = [])
3939
{
40+
$chr = substr($templatePath,-1);
41+
if ($chr !== '/') {
42+
$templatePath .= '/';
43+
}
4044
$this->templatePath = $templatePath;
4145
$this->attributes = $attributes;
4246
}

tests/PhpRendererTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ public function testRenderer() {
2626
$this->assertEquals("Hi", $newResponse->getBody()->getContents());
2727
}
2828

29+
public function testRenderConstructor() {
30+
$renderer = new \Slim\Views\PhpRenderer("tests");
31+
32+
$headers = new Headers();
33+
$body = new Body(fopen('php://temp', 'r+'));
34+
$response = new Response(200, $headers, $body);
35+
36+
$newResponse = $renderer->render($response, "testTemplate.php", array("hello" => "Hi"));
37+
38+
$newResponse->getBody()->rewind();
39+
40+
$this->assertEquals("Hi", $newResponse->getBody()->getContents());
41+
}
42+
2943
public function testAttributeMerging() {
3044

3145
$renderer = new \Slim\Views\PhpRenderer("tests/", [

0 commit comments

Comments
 (0)