]> BookStack Code Mirror - bookstack/blobdiff - tests/TestCase.php
ZIP Imports: Added API examples, finished testing
[bookstack] / tests / TestCase.php
index f8f59977a1e1ac6a282f91e0cca4399e0c47b853..a8636fb158e2b37abd34c8b8e18b15809f76899b 100644 (file)
@@ -42,7 +42,6 @@ abstract class TestCase extends BaseTestCase
         $this->permissions = new PermissionsProvider($this->users);
         $this->files = new FileProvider();
 
-        User::clearDefault();
         parent::setUp();
 
         // We can uncomment the below to run tests with failings upon deprecations.
@@ -119,32 +118,41 @@ abstract class TestCase extends BaseTestCase
      * Database config is juggled so the value can be restored when
      * parallel testing are used, where multiple databases exist.
      */
-    protected function runWithEnv(string $name, $value, callable $callback)
+    protected function runWithEnv(array $valuesByKey, callable $callback, bool $handleDatabase = true): void
     {
         Env::disablePutenv();
-        $originalVal = $_SERVER[$name] ?? null;
-
-        if (is_null($value)) {
-            unset($_SERVER[$name]);
-        } else {
-            $_SERVER[$name] = $value;
+        $originals = [];
+        foreach ($valuesByKey as $key => $value) {
+            $originals[$key] = $_SERVER[$key] ?? null;
+
+            if (is_null($value)) {
+                unset($_SERVER[$key]);
+            } else {
+                $_SERVER[$key] = $value;
+            }
         }
 
         $database = config('database.connections.mysql_testing.database');
         $this->refreshApplication();
 
-        DB::purge();
-        config()->set('database.connections.mysql_testing.database', $database);
-        DB::beginTransaction();
+        if ($handleDatabase) {
+            DB::purge();
+            config()->set('database.connections.mysql_testing.database', $database);
+            DB::beginTransaction();
+        }
 
         $callback();
 
-        DB::rollBack();
+        if ($handleDatabase) {
+            DB::rollBack();
+        }
 
-        if (is_null($originalVal)) {
-            unset($_SERVER[$name]);
-        } else {
-            $_SERVER[$name] = $originalVal;
+        foreach ($originals as $key => $value) {
+            if (is_null($value)) {
+                unset($_SERVER[$key]);
+            } else {
+                $_SERVER[$key] = $value;
+            }
         }
     }
 
@@ -249,8 +257,8 @@ abstract class TestCase extends BaseTestCase
         $detailsToCheck = ['type' => $type];
 
         if ($entity) {
-            $detailsToCheck['entity_type'] = $entity->getMorphClass();
-            $detailsToCheck['entity_id'] = $entity->id;
+            $detailsToCheck['loggable_type'] = $entity->getMorphClass();
+            $detailsToCheck['loggable_id'] = $entity->id;
         }
 
         if ($detail) {