From 0e0f7410f2cc72ce74f14c3410533cc86e13c2bc Mon Sep 17 00:00:00 2001 From: CiviCRM Date: Sat, 14 Sep 2019 23:48:43 -0400 Subject: [PATCH] api4 - Port PHPUnit autoloading hacks --- tests/phpunit/CiviTest/bootstrap.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/phpunit/CiviTest/bootstrap.php b/tests/phpunit/CiviTest/bootstrap.php index 5a05bcabf9..4c1fff3cd2 100644 --- a/tests/phpunit/CiviTest/bootstrap.php +++ b/tests/phpunit/CiviTest/bootstrap.php @@ -24,8 +24,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. * -- 2.25.1