Passed
Pull Request — master (#653)
by Aleksei
07:43
created

BaseTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 4
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Stempler\Compiler;
13
14
use PHPUnit\Framework\TestCase;
15
use Spiral\Stempler\Compiler;
16
use Spiral\Stempler\Lexer\StringStream;
17
use Spiral\Stempler\Node\Template;
18
use Spiral\Stempler\Parser;
19
20
abstract class BaseTest extends TestCase
21
{
22
    protected const GRAMMARS = [
23
        /* GRAMMAR => SYNTAX */
24
    ];
25
26
    protected const RENDERS = [
27
        /* RENDERER */
28
    ];
29
30
    /**
31
     * @param Template $document
32
     * @return string
33
     */
34
    protected function compile(Template $document): string
35
    {
36
        $compiler = new Compiler();
37
        foreach (static::RENDERS as $renderer) {
38
            $compiler->addRenderer(new $renderer());
39
        }
40
41
        return $compiler->compile($document)->getContent();
42
    }
43
44
    /**
45
     * @param string $string
46
     * @return Template
47
     */
48
    protected function parse(string $string): Template
49
    {
50
        $parser = new Parser();
51
52
        foreach (static::GRAMMARS as $grammar => $syntax) {
53
            $parser->addSyntax(new $grammar(), new $syntax());
54
        }
55
56
        return $parser->parse(new StringStream($string));
57
    }
58
}
59