Skip to content

Commit

Permalink
Fix forbidden keys exception
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Jan 3, 2017
1 parent 90c60e6 commit 1104da6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ engines:
checks:
UnusedFormalParameter:
enabled: false
Design/TooManyPublicMethods:
enabled: false
ratings:
paths:
- "**.php"
11 changes: 5 additions & 6 deletions src/Jade/JadeSymfonyBundle/Command/AssetsPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ protected function cacheTemplates(Jade $pug)
$directories = [];
foreach ($pug->getOption('assetDirectory') as $assetDirectory) {
$viewDirectory = $assetDirectory . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views';
if (!is_dir($viewDirectory)) {
continue;
if (is_dir($viewDirectory)) {
$directories[] = $viewDirectory;
$data = $pug->cacheDirectory($viewDirectory);
$success += $data[0];
$errors += $data[1];
}
$directories[] = $viewDirectory;
$data = $pug->cacheDirectory($viewDirectory);
$success += $data[0];
$errors += $data[1];
}

return [$directories, $success, $errors];
Expand Down
2 changes: 1 addition & 1 deletion src/Jade/JadeSymfonyEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function render($name, array $parameters = [])
{
foreach (['view', 'this'] as $forbiddenKey) {
if (array_key_exists($forbiddenKey, $parameters)) {
throw new \ArgumentException('The "' . $forbiddenKey . '" key is forbidden.');
throw new \ErrorException('The "' . $forbiddenKey . '" key is forbidden.');
}
}
$parameters['view'] = $this;
Expand Down
21 changes: 19 additions & 2 deletions tests/Pug/PugSymfonyEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,13 @@ public function testBundleView()
{
$pugSymfony = new PugSymfonyEngine(self::$kernel);

self::assertSame('<p>Hello</p>', trim($pugSymfony->render('TestBundle::bundle.pug')));
self::assertSame('<p>Hello</p>', trim($pugSymfony->render('TestBundle::bundle.pug', ['text' => 'Hello'])));
self::assertSame('<section>World</section>', trim($pugSymfony->render('TestBundle:directory:file.pug')));
}

public function testFilter()
{
$pugSymfony = new PugSymfonyEngine(self::$kernel);
$engine = $pugSymfony->getEngine();

self::assertFalse($pugSymfony->hasFilter('upper'));

Expand Down Expand Up @@ -242,4 +241,22 @@ public function testCustomOptions()
self::assertSame(5, $pugSymfony->getEngine()->getOption('indentSize'));
self::assertSame("<div>\n <p></p>\n</div>", trim($pugSymfony->render('p.pug')));
}

/**
* @expectedException \ErrorException
* @expectedExceptionMessage The "this" key is forbidden.
*/
public function testForbidThis()
{
(new PugSymfonyEngine(self::$kernel))->render('p.pug', ['this' => 42]);
}

/**
* @expectedException \ErrorException
* @expectedExceptionMessage The "view" key is forbidden.
*/
public function testForbidView()
{
(new PugSymfonyEngine(self::$kernel))->render('p.pug', ['view' => 42]);
}
}
2 changes: 1 addition & 1 deletion tests/project/src/TestBundle/Resources/views/bundle.pug
Original file line number Diff line number Diff line change
@@ -1 +1 @@
p Hello
p=text

0 comments on commit 1104da6

Please sign in to comment.