Skip to content

Commit

Permalink
Fix issue in TwigLoader::load
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Dec 9, 2023
1 parent b5587a1 commit beddc7f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 3 additions & 7 deletions src/Template/TwigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function exists()

/**
* @param string|string[] $path
* @return \Rougin\Slytherin\Template\RendererInterface
* @return \Twig\Environment
*/
public function load($path)
{
Expand All @@ -45,11 +45,7 @@ public function load($path)

$environment = new \ReflectionClass($environment);

/**
* @var \Twig\Environment
*/
$environment = $environment->newInstance($loader);

return new TwigRenderer($environment);
/** @var \Twig\Environment */
return $environment->newInstance($loader);
}
}
8 changes: 4 additions & 4 deletions tests/Template/Twig/RendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function doSetUp()
$this->markTestSkipped('Twig is not installed.');
}

$path = __DIR__ . '/../../Fixture/Templates';
$path = realpath(__DIR__ . '/../../Fixture/Templates');

$this->twig = $twig->load((string) $path);

Expand All @@ -48,7 +48,7 @@ public function testRenderMethod()
{
$expected = 'This is a text from a template.';

$rendered = $this->renderer->render('test.php');
$rendered = $this->renderer->render('test', array(), 'php');

$this->assertEquals($expected, $rendered);
}
Expand All @@ -64,7 +64,7 @@ public function testRenderMethodWithData()

$data = array('name' => 'template');

$rendered = $this->renderer->render('test-with-twig-data.php', $data);
$rendered = $this->renderer->render('test-with-twig-data', $data, 'php');

$this->assertEquals($expected, $rendered);
}
Expand All @@ -84,7 +84,7 @@ public function testRenderMethodWithGlobals()

$renderer->addGlobal('test', 'wew');

$rendered = $renderer->render('test-with-twig-data.php');
$rendered = $renderer->render('test-with-twig-data', array(), 'php');

$this->assertEquals($expected, $rendered);
}
Expand Down

0 comments on commit beddc7f

Please sign in to comment.