summaryrefslogtreecommitdiff
path: root/tests/functional/BaseTest.php
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2020-09-13 21:35:16 +0200
committerLaria Carolin Chabowski <laria@laria.me>2020-09-13 21:35:16 +0200
commit4e2bfed23c17929795f2082d6e77937170caeaa9 (patch)
tree4d9f66596c80af8081e4279580a3bbb4721ef184 /tests/functional/BaseTest.php
parent5ee6bbbf3002daf075fa77007daccf4d2af25241 (diff)
downloadste-4e2bfed23c17929795f2082d6e77937170caeaa9.tar.gz
ste-4e2bfed23c17929795f2082d6e77937170caeaa9.tar.bz2
ste-4e2bfed23c17929795f2082d6e77937170caeaa9.zip
Turn our functional tests into PhpUnit tests
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;
+}