Merge pull request #20313 from eileenmcnaughton/mem_move2
[civicrm-core.git] / tests / phpunit / CiviTest / bootstrap.php
index 5a05bcabf9e7d7a82d579067ce68555b70292759..4c458f17bb4a7d38ed41245429eb2d163e53e6c1 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 // ADAPTED FROM tools/scripts/phpunit
 
-ini_set('safe_mode', 0);
 ini_set('include_path', dirname(__DIR__) . PATH_SEPARATOR . ini_get('include_path'));
 
 #  Relying on system timezone setting produces a warning,
@@ -24,8 +23,32 @@ if (CIVICRM_UF === 'UnitTests') {
   Civi\Test::headless()->apply();
 }
 
+spl_autoload_register(function($class) {
+  _phpunit_mockoloader('api\\v4\\', "tests/phpunit/api/v4/", $class);
+  _phpunit_mockoloader('Civi\\Api4\\', "tests/phpunit/api/v4/Mock/Api4/", $class);
+});
+
 // ------------------------------------------------------------------------------
 
+/**
+ * @param $prefix
+ * @param $base_dir
+ * @param $class
+ */
+function _phpunit_mockoloader($prefix, $base_dir, $class) {
+  $len = strlen($prefix);
+  if (strncmp($prefix, $class, $len) !== 0) {
+    return;
+  }
+
+  global $civicrm_root;
+  $relative_class = substr($class, $len);
+  $file = $civicrm_root . '/' . $base_dir . str_replace('\\', '/', $relative_class) . '.php';
+  if (file_exists($file)) {
+    require $file;
+  }
+}
+
 /**
  * Call the "cv" command.
  *