summaryrefslogtreecommitdiff
path: root/tests/functional/BaseTest.php
blob: 34506007b415864fa735ce2445cfab4a82739744 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php


namespace tests\functional;

use PHPUnit\Framework\TestCase;
use r7r\ste\STECore;

abstract class BaseTest extends TestCase
{
    /** @var STECore */
    protected $ste;

    private static function normalize(string $string): string
    {
        $lines = explode("\n", $string);

        $lines = array_map(static function ($line) {
            return preg_replace('/\s{2,}/', " ", $line);
        }, $lines);
        $lines = array_map('trim', $lines);
        $lines = array_filter($lines);

        return implode("\n", $lines);
    }

    public function setUp(): void
    {
        $this->ste = new STECore(new TestStorage($this->getDirectory()));
        $this->ste->mute_runtime_errors = false;

        $this->setUpSte($this->ste);
    }

    protected function setUpSte(STECore $ste): void
    {
    }

    public function testTemplate(): void
    {
        $have = $this->ste->exectemplate("test.tpl");
        $want = file_get_contents($this->getDirectory() . DIRECTORY_SEPARATOR . "want");

        $normalizedHave = self::normalize($have);
        $normalizedWant = self::normalize($want);

        self::assertSame($normalizedWant, $normalizedHave);
    }

    /**
     * Get the directory of the test.
     * @return string
     */
    abstract protected function getDirectory(): string;
}