Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Jun 7, 2019
1 parent cea3a22 commit 827ba89
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG
@@ -1,6 +1,6 @@
* 1.42.2 (2019-XX-XX)

* n/a
* Display partial output (PHP buffer) when an eeor occurs in debug mode

* 1.42.1 (2019-06-04)

Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -30,6 +30,7 @@
"require-dev": {
"symfony/phpunit-bridge": "^3.4.19|^4.1.8|^5.0",
"symfony/debug": "^2.7",
"symfony/process": "^3.4|^4.0|^5.0",
"psr/container": "^1.0"
},
"autoload": {
Expand Down
22 changes: 22 additions & 0 deletions test/Twig/Tests/ErrorTest.php
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
use Twig\Environment;
use Twig\Error\Error;
use Twig\Error\RuntimeError;
Expand Down Expand Up @@ -207,6 +209,26 @@ public function getErroredTemplates()
],
];
}

public function testTwigLeakOutputInDebugMode()
{
$finder = new PhpExecutableFinder();
$phpBinary = $finder->find();
$process = new Process([$phpBinary, __DIR__.'/Fixtures/errors/leak-output.php', 'debug']);
$process->mustRun();

$this->assertSame('Hello OUPS', $process->getOutput());
}

public function testDoesNotTwigLeakOutput()
{
$finder = new PhpExecutableFinder();
$phpBinary = $finder->find();
$process = new Process([$phpBinary, __DIR__.'/Fixtures/errors/leak-output.php']);
$process->mustRun();

$this->assertSame('', $process->getOutput());
}
}

class Twig_Tests_ErrorTest_Foo
Expand Down
29 changes: 29 additions & 0 deletions test/Twig/Tests/Fixtures/errors/leak-output.php
@@ -0,0 +1,29 @@
<?php

require __DIR__.'/../../../../../vendor/autoload.php';

use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

class BrokenExtension extends AbstractExtension
{
public function getFilters()
{
return [
new TwigFilter('broken', [$this, 'broken']),
];
}

public function broken()
{
die('OUPS');
}
}

$loader = new Twig_Loader_Array([
'index.html.twig' => 'Hello {{ "world"|broken }}',
]);
$twig = new Twig_Environment($loader, ['debug' => isset($argv[1])]);
$twig->addExtension(new BrokenExtension());

echo $twig->render('index.html.twig');

0 comments on commit 827ba89

Please sign in to comment.