Passed
Push — master ( c385bc...79eb13 )
by Tim
01:38
created

TemplateTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 25
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSyntax() 0 23 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;
13
use SimpleSAML\XHTML\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), ['.', '..']);
0 ignored issues
show
Bug introduced by
It seems like scandir($basedir) can also be of type false; however, parameter $array1 of array_diff() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        $files = array_diff(/** @scrutinizer ignore-type */ scandir($basedir), ['.', '..']);
Loading history...
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();
0 ignored issues
show
Deprecated Code introduced by
The function SimpleSAML\XHTML\Template::show() has been deprecated: Do not use this method, use Twig + send() instead. Will be removed in 2.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

36
                    /** @scrutinizer ignore-deprecated */ $t->show();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
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