summaryrefslogtreecommitdiff
path: root/tests/functional/BaseTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional/BaseTest.php')
-rw-r--r--tests/functional/BaseTest.php55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/functional/BaseTest.php b/tests/functional/BaseTest.php
new file mode 100644
index 0000000..ce045fb
--- /dev/null
+++ b/tests/functional/BaseTest.php
@@ -0,0 +1,55 @@
+<?php
+
+
+namespace tests\functional;
+
+use PHPUnit\Framework\TestCase;
+use kch42\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;
+}