Passed
Push — master ( 7afe0b...01e59a )
by Tim
01:49
created

TemplateTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSyntax() 0 24 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
13
use \SimpleSAML\Configuration;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Configuration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use \SimpleSAML\XHTML\Template;
15
use \SimpleSAML\Module;
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), array('.', '..'));
31
32
        foreach ($files as $file) {
33
            if (preg_match('/.twig$/', $file)) {
34
                $t = new Template($config, $file);
35
                ob_start();
36
                try {
37
                    $t->show();
38
                    $this->addToAssertionCount(1);
39
                } catch (\Twig_Error_Syntax $e) {
40
                    $this->fail($e->getMessage().' in '.$e->getFile.':'.$e->getLine());
0 ignored issues
show
Bug introduced by
The property getFile does not seem to exist on Twig_Error_Syntax.
Loading history...
41
                }
42
                ob_clean();
43
            }
44
        }
45
    }
46
}
47