Passed
Push — master ( 3d993e...c385bc )
by Tim
03:23
created

TemplateTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 4
1
<?php
2
/**
3
 * Simple test for syntax-checking Twig-templates.
4
 *
5
 * @author Tim van Dijen <[email protected]>
6
 * @package SimpleSAMLphp
7
 */
8
 
9
namespace SimpleSAML\Test\Web;
10
11
use PHPUnit\Framework\TestCase
12
use SimpleSAML\Configuration as Configuration;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_USE, expecting ',' or ';' on line 12 at column 0
Loading history...
13
use SimpleSAML\XHTML\Template as Template;
14
use SimpleSAML\Module;
15
use Twig\Error\SyntaxError;
16
17
class TemplateTest extends TestCase
18
{
19
    public function testSyntax()
20
    {
21
        $config = Configuration::loadFromArray([
22
            'language.i18n.backend' => 'gettext/gettext',
23
            'module.enable' => array_fill_keys(Module::getModules(), true),
24
        ]);
25
26
        Configuration::setPreLoadedConfig($config);
27
        $basedir = dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'templates';
28
29
        // Base templates
30
        $files = array_diff(scandir($basedir), ['.', '..']);
31
        foreach ($files as $file) {
32
            if (preg_match('/.twig$/', $file)) {
33
                $t = new Template($config, 'monitor:'.basename($file));
34
                ob_start();
35
                try {
36
                    $t->show();
37
                    $this->addToAssertionCount(1);
38
                } catch (SyntaxError $e) {
39
                    $this->fail($e->getMessage().' in '.$e->getFile().':'.$e->getLine());
40
                }
41
                ob_end_clean();
42
            }
43
        }
44
    }
45
}
46