From b50ee077dff835d35c5c4b69e71cb6af56eff80d Mon Sep 17 00:00:00 2001 From: colemanw Date: Wed, 15 Nov 2023 21:23:01 -0500 Subject: [PATCH] Afform - Namespace mock tests for autoloading --- ext/afform/mock/phpunit.xml.dist | 27 +++------- .../AfformAutocompleteUsageTest.php | 15 +++--- .../{ => Afform}/AfformContactUsageTest.php | 51 ++++++++++--------- .../AfformCustomFieldUsageTest.php | 5 +- .../v4/{ => Afform}/AfformFileUploadTest.php | 5 +- .../{ => Afform}/AfformPrefillUsageTest.php | 7 +-- .../AfformRelationshipUsageTest.php | 9 ++-- .../api/v4/{ => Afform}/AfformRoutingTest.php | 19 +++---- .../api/v4/{ => Afform}/AfformTest.php | 15 +++--- .../api/v4/{ => Afform}/AfformTestCase.php | 7 +-- .../v4/{ => Afform}/AfformUsageTestCase.php | 3 +- ext/afform/mock/tests/phpunit/bootstrap.php | 28 +++++----- 12 files changed, 94 insertions(+), 97 deletions(-) rename ext/afform/mock/tests/phpunit/api/v4/{ => Afform}/AfformAutocompleteUsageTest.php (95%) rename ext/afform/mock/tests/phpunit/api/v4/{ => Afform}/AfformContactUsageTest.php (90%) rename ext/afform/mock/tests/phpunit/api/v4/{ => Afform}/AfformCustomFieldUsageTest.php (95%) rename ext/afform/mock/tests/phpunit/api/v4/{ => Afform}/AfformFileUploadTest.php (97%) rename ext/afform/mock/tests/phpunit/api/v4/{ => Afform}/AfformPrefillUsageTest.php (96%) rename ext/afform/mock/tests/phpunit/api/v4/{ => Afform}/AfformRelationshipUsageTest.php (96%) rename ext/afform/mock/tests/phpunit/api/v4/{ => Afform}/AfformRoutingTest.php (78%) rename ext/afform/mock/tests/phpunit/api/v4/{ => Afform}/AfformTest.php (96%) rename ext/afform/mock/tests/phpunit/api/v4/{ => Afform}/AfformTestCase.php (66%) rename ext/afform/mock/tests/phpunit/api/v4/{ => Afform}/AfformUsageTestCase.php (91%) diff --git a/ext/afform/mock/phpunit.xml.dist b/ext/afform/mock/phpunit.xml.dist index 1f804252c5..ea391745fa 100644 --- a/ext/afform/mock/phpunit.xml.dist +++ b/ext/afform/mock/phpunit.xml.dist @@ -1,30 +1,15 @@ - - - - ./ - - + ./tests/phpunit - - ./ang - + + + ./ + + diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformAutocompleteUsageTest.php b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformAutocompleteUsageTest.php similarity index 95% rename from ext/afform/mock/tests/phpunit/api/v4/AfformAutocompleteUsageTest.php rename to ext/afform/mock/tests/phpunit/api/v4/Afform/AfformAutocompleteUsageTest.php index 54c721ef66..a56ae183f5 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformAutocompleteUsageTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformAutocompleteUsageTest.php @@ -1,4 +1,5 @@ useValues([ 'layout' => $layout, - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); // Saved search for filtering @@ -95,7 +96,7 @@ EOHTML; ->execute(); $this->fail(); } - catch (CRM_Core_Exception $e) { + catch (\CRM_Core_Exception $e) { $this->assertEquals('Validation Error', $e->getMessage()); } @@ -163,7 +164,7 @@ EOHTML; $this->useValues([ 'layout' => $layout, - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $result = Contact::autocomplete() @@ -195,7 +196,7 @@ EOHTML; ->execute(); $this->fail(); } - catch (CRM_Core_Exception $e) { + catch (\CRM_Core_Exception $e) { $this->assertEquals('Validation Error', $e->getMessage()); } @@ -257,7 +258,7 @@ EOHTML; $this->useValues([ 'layout' => $layout, - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $result = Contact::autocomplete() @@ -293,7 +294,7 @@ EOHTML; ->execute(); $this->fail(); } - catch (CRM_Core_Exception $e) { + catch (\CRM_Core_Exception $e) { $this->assertEquals('Validation Error', $e->getMessage()); } diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformContactUsageTest.php b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformContactUsageTest.php similarity index 90% rename from ext/afform/mock/tests/phpunit/api/v4/AfformContactUsageTest.php rename to ext/afform/mock/tests/phpunit/api/v4/Afform/AfformContactUsageTest.php index 0d83ebdfb8..1528c5852c 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformContactUsageTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformContactUsageTest.php @@ -1,13 +1,16 @@ useValues([ 'layout' => self::$layouts['aboutMe'], - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $cid = $this->createLoggedInUser(); - CRM_Core_Config::singleton()->userPermissionTemp = new CRM_Core_Permission_Temp(); + \CRM_Core_Config::singleton()->userPermissionTemp = new \CRM_Core_Permission_Temp(); // Autofill form with current user. See `Civi\Afform\Behavior\ContactAutofill` $prefill = Afform::prefill() @@ -103,7 +106,7 @@ EOHTML; ->setValues(['me' => $submission]) ->execute(); - $contact = Civi\Api4\Contact::get(FALSE)->addWhere('id', '=', $cid)->execute()->first(); + $contact = Contact::get(FALSE)->addWhere('id', '=', $cid)->execute()->first(); $this->assertEquals('Firsty', $contact['first_name']); $this->assertEquals('Lasty', $contact['last_name']); } @@ -111,7 +114,7 @@ EOHTML; public function testChainSelect(): void { $this->useValues([ 'layout' => self::$layouts['aboutMe'], - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); // Get states for USA @@ -120,7 +123,7 @@ EOHTML; ->setModelName('me') ->setFieldName('state_province_id') ->setJoinEntity('Address') - ->setValues(['country_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Country', 'United States', 'id', 'name')]) + ->setValues(['country_id' => \CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Country', 'United States', 'id', 'name')]) ->execute(); $this->assertEquals('Alabama', $result[0]['label']); @@ -130,7 +133,7 @@ EOHTML; ->setModelName('me') ->setFieldName('state_province_id') ->setJoinEntity('Address') - ->setValues(['country_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Country', 'United Kingdom', 'id', 'name')]) + ->setValues(['country_id' => \CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Country', 'United Kingdom', 'id', 'name')]) ->execute(); $this->assertEquals('Aberdeen City', $result[0]['label']); } @@ -138,7 +141,7 @@ EOHTML; public function testCheckEntityReferenceFieldsReplacement(): void { $this->useValues([ 'layout' => self::$layouts['registerSite'], - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, 'create_submission' => TRUE, ]); @@ -170,7 +173,7 @@ EOHTML; ->setValues($values) ->execute(); - $submission = Civi\Api4\AfformSubmission::get(FALSE) + $submission = AfformSubmission::get(FALSE) ->addOrderBy('id', 'DESC') ->execute()->first(); @@ -204,8 +207,8 @@ EOHTML; 'permission' => ['access CiviCRM'], ]); $this->createLoggedInUser(); - CRM_Core_Config::singleton()->userPermissionTemp = NULL; - CRM_Core_Config::singleton()->userPermissionClass->permissions = [ + \CRM_Core_Config::singleton()->userPermissionTemp = NULL; + \CRM_Core_Config::singleton()->userPermissionClass->permissions = [ 'access Contact Dashboard', ]; $check = Afform::checkAccess() @@ -213,7 +216,7 @@ EOHTML; ->setAction('get') ->execute()->first(); $this->assertFalse($check['access']); - CRM_Core_Config::singleton()->userPermissionClass->permissions = [ + \CRM_Core_Config::singleton()->userPermissionClass->permissions = [ 'access CiviCRM', ]; $check = Afform::checkAccess() @@ -226,11 +229,11 @@ EOHTML; public function testAboutMeForbidden(): void { $this->useValues([ 'layout' => self::$layouts['aboutMe'], - 'permission' => CRM_Core_Permission::ALWAYS_DENY_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_DENY_PERMISSION, ]); $this->createLoggedInUser(); - CRM_Core_Config::singleton()->userPermissionTemp = new CRM_Core_Permission_Temp(); + \CRM_Core_Config::singleton()->userPermissionTemp = new \CRM_Core_Permission_Temp(); try { Afform::prefill() @@ -262,7 +265,7 @@ EOHTML; public function testEmployerReference(): void { $this->useValues([ 'layout' => self::$layouts['employer'], - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $firstName = uniqid(__FUNCTION__); @@ -303,7 +306,7 @@ EOHTML; public function testEmptyEmployerReference(): void { $this->useValues([ 'layout' => self::$layouts['employer'], - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $firstName = uniqid(__FUNCTION__); @@ -342,12 +345,12 @@ EOHTML; $this->useValues([ 'layout' => self::$layouts['employer'], 'create_submission' => TRUE, - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $individualEmail = uniqid('individual@') . '.test'; $orgEmail = uniqid('org@') . '.test'; - $locationType = CRM_Core_BAO_LocationType::getDefault()->id; + $locationType = \CRM_Core_BAO_LocationType::getDefault()->id; $values = [ 'Individual1' => [ [ @@ -413,7 +416,7 @@ EOHTML; EOHTML; $this->useValues([ 'layout' => $layout, - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $lastName = uniqid(__FUNCTION__); @@ -423,7 +426,7 @@ EOHTML; ->addValue('email_primary.email', '123@example.com') ->execute()->single(); - $locationType = CRM_Core_BAO_LocationType::getDefault()->id; + $locationType = \CRM_Core_BAO_LocationType::getDefault()->id; $values = [ 'Individual1' => [ [ @@ -455,7 +458,7 @@ EOHTML; public function testFormValidationEntityFields(): void { $this->useValues([ 'layout' => self::$layouts['updateInfo'], - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $values = [ @@ -491,7 +494,7 @@ EOHTML; public function testFormValidationEntityJoinFields(): void { $this->useValues([ 'layout' => self::$layouts['updateInfo'], - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $values = [ @@ -526,13 +529,13 @@ EOHTML; public function testSubmissionLimit() { $this->useValues([ 'layout' => self::$layouts['aboutMe'], - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, 'create_submission' => TRUE, 'submit_limit' => 3, ]); $cid = $this->createLoggedInUser(); - CRM_Core_Config::singleton()->userPermissionTemp = new CRM_Core_Permission_Temp(); + \CRM_Core_Config::singleton()->userPermissionTemp = new \CRM_Core_Permission_Temp(); $submitValues = [ ['fields' => ['first_name' => 'Firsty', 'last_name' => 'Lasty']], diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformCustomFieldUsageTest.php b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformCustomFieldUsageTest.php similarity index 95% rename from ext/afform/mock/tests/phpunit/api/v4/AfformCustomFieldUsageTest.php rename to ext/afform/mock/tests/phpunit/api/v4/Afform/AfformCustomFieldUsageTest.php index f572a35c35..b33fec6849 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformCustomFieldUsageTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformCustomFieldUsageTest.php @@ -1,4 +1,5 @@ useValues([ 'layout' => self::$layouts['customMulti'], - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $firstName = uniqid(__FUNCTION__); $values = [ diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformFileUploadTest.php similarity index 97% rename from ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php rename to ext/afform/mock/tests/phpunit/api/v4/Afform/AfformFileUploadTest.php index cd51151122..0f7e665cfa 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformFileUploadTest.php @@ -1,4 +1,5 @@ useValues([ 'layout' => self::$layouts['customFiles'], - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $lastName = uniqid(__FUNCTION__); diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformPrefillUsageTest.php b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformPrefillUsageTest.php similarity index 96% rename from ext/afform/mock/tests/phpunit/api/v4/AfformPrefillUsageTest.php rename to ext/afform/mock/tests/phpunit/api/v4/Afform/AfformPrefillUsageTest.php index f99602750f..32dd640327 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformPrefillUsageTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformPrefillUsageTest.php @@ -1,4 +1,5 @@ useValues([ 'layout' => $layout, - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $cid = $this->saveTestRecords('Contact', [ @@ -120,7 +121,7 @@ EOHTML; $this->useValues([ 'layout' => $layout, - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $uid = $this->createLoggedInUser(); diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformRelationshipUsageTest.php b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformRelationshipUsageTest.php similarity index 96% rename from ext/afform/mock/tests/phpunit/api/v4/AfformRelationshipUsageTest.php rename to ext/afform/mock/tests/phpunit/api/v4/Afform/AfformRelationshipUsageTest.php index 1d6a07b8fa..36b6d83fb4 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformRelationshipUsageTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformRelationshipUsageTest.php @@ -1,4 +1,5 @@ useValues([ 'layout' => $layout, - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $lastName = uniqid(__FUNCTION__); @@ -91,7 +92,7 @@ EOHTML; $this->useValues([ 'layout' => $layout, - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $types = [ @@ -162,7 +163,7 @@ EOHTML; $this->useValues([ 'layout' => $layout, - 'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, + 'permission' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, ]); $contact = Contact::save(FALSE) diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformRoutingTest.php b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformRoutingTest.php similarity index 78% rename from ext/afform/mock/tests/phpunit/api/v4/AfformRoutingTest.php rename to ext/afform/mock/tests/phpunit/api/v4/Afform/AfformRoutingTest.php index 01118ef23e..28f49ea12b 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformRoutingTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformRoutingTest.php @@ -1,4 +1,5 @@ FALSE]); $url = function ($path, $query = NULL) { - return CRM_Utils_System::url($path, $query, TRUE, NULL, FALSE); + return \CRM_Utils_System::url($path, $query, TRUE, NULL, FALSE); }; $result = $http->get($url('civicrm/mock-page')); @@ -44,7 +45,7 @@ class api_v4_AfformRoutingTest extends \PHPUnit\Framework\TestCase implements \C Afform::update() ->setCheckPermissions(FALSE) ->addWhere('name', '=', $this->formName) - ->addValue('permission', CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) + ->addValue('permission', \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) ->execute(); $result = $http->get($url('civicrm/mock-page')); @@ -54,13 +55,13 @@ class api_v4_AfformRoutingTest extends \PHPUnit\Framework\TestCase implements \C public function testChangingPath(): void { $http = new \GuzzleHttp\Client(['http_errors' => FALSE]); $url = function ($path, $query = NULL) { - return CRM_Utils_System::url($path, $query, TRUE, NULL, FALSE); + return \CRM_Utils_System::url($path, $query, TRUE, NULL, FALSE); }; Afform::update() ->setCheckPermissions(FALSE) ->addWhere('name', '=', $this->formName) - ->addValue('permission', CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) + ->addValue('permission', \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) ->execute(); $this->assertOpensPage($http->get($url('civicrm/mock-page')), 'mock-page'); @@ -77,10 +78,10 @@ class api_v4_AfformRoutingTest extends \PHPUnit\Framework\TestCase implements \C } /** - * @param $result + * @param \Psr\Http\Message\ResponseInterface $result * @param string $directive */ - private function assertNotAuthorized(Psr\Http\Message\ResponseInterface $result, $directive) { + private function assertNotAuthorized(\Psr\Http\Message\ResponseInterface $result, string $directive) { $contents = $result->getBody()->getContents(); $this->assertEquals(403, $result->getStatusCode()); $this->assertMatchesRegularExpression(';You are not authorized to access;', $contents); @@ -88,11 +89,11 @@ class api_v4_AfformRoutingTest extends \PHPUnit\Framework\TestCase implements \C } /** - * @param $result + * @param \Psr\Http\Message\ResponseInterface $result * @param string $directive * The name of the directive which auto-opens. */ - private function assertOpensPage(Psr\Http\Message\ResponseInterface $result, $directive) { + private function assertOpensPage(\Psr\Http\Message\ResponseInterface $result, string $directive) { $contents = $result->getBody()->getContents(); $this->assertEquals(200, $result->getStatusCode()); $this->assertDoesNotMatchRegularExpression(';You are not authorized to access;', $contents); diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformTest.php similarity index 96% rename from ext/afform/mock/tests/phpunit/api/v4/AfformTest.php rename to ext/afform/mock/tests/phpunit/api/v4/Afform/AfformTest.php index 15172613c5..4d6b9bfba5 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformTest.php @@ -1,4 +1,5 @@ addWhere('name', '=', $formName)->execute(); - $angModule = Civi::service('angular')->getModule($formName); + $angModule = \Civi::service('angular')->getModule($formName); sort($angModule['requires']); $storedRequires = Afform::get()->addWhere('name', '=', $formName)->addSelect('requires')->execute(); $this->assertEquals(['afCore', 'mockBareFile', 'mockBespoke', 'mockFoo'], $angModule['requires']); @@ -290,7 +291,7 @@ class api_v4_AfformTest extends api_v4_AfformTestCase { ->setLayoutFormat('html') ->setValues(['layout' => '
The bare file says ""
']) ->execute(); - $angModule = Civi::service('angular')->getModule($formName); + $angModule = \Civi::service('angular')->getModule($formName); sort($angModule['requires']); $storedRequires = Afform::get()->addWhere('name', '=', $formName)->addSelect('requires')->execute(); $this->assertEquals(['afCore', 'mockBareFile', 'mockBespoke'], $angModule['requires']); @@ -305,13 +306,13 @@ class api_v4_AfformTest extends api_v4_AfformTestCase { 'requires' => [], ]) ->execute(); - $angModule = Civi::service('angular')->getModule($formName); + $angModule = \Civi::service('angular')->getModule($formName); $this->assertEquals(['afCore'], $angModule['requires']); $storedRequires = Afform::get()->addWhere('name', '=', $formName)->addSelect('requires')->execute(); $this->assertEquals([], $storedRequires[0]['requires']); Afform::revert()->addWhere('name', '=', $formName)->execute(); - $angModule = Civi::service('angular')->getModule($formName); + $angModule = \Civi::service('angular')->getModule($formName); sort($angModule['requires']); $this->assertEquals(['afCore', 'mockBareFile', 'mockBespoke', 'mockFoo'], $angModule['requires']); } diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformTestCase.php b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformTestCase.php similarity index 66% rename from ext/afform/mock/tests/phpunit/api/v4/AfformTestCase.php rename to ext/afform/mock/tests/phpunit/api/v4/Afform/AfformTestCase.php index 43b174e415..8951f5e05c 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformTestCase.php +++ b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformTestCase.php @@ -1,4 +1,5 @@ userPermissionTemp = new CRM_Core_Permission_Temp(); - CRM_Core_Config::singleton()->userPermissionTemp->grant('administer CiviCRM'); + \CRM_Core_Config::singleton()->userPermissionTemp = new \CRM_Core_Permission_Temp(); + \CRM_Core_Config::singleton()->userPermissionTemp->grant('administer CiviCRM'); } } diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformUsageTestCase.php b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformUsageTestCase.php similarity index 91% rename from ext/afform/mock/tests/phpunit/api/v4/AfformUsageTestCase.php rename to ext/afform/mock/tests/phpunit/api/v4/Afform/AfformUsageTestCase.php index 2e9b7b30bc..7d86d1ea70 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformUsageTestCase.php +++ b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformUsageTestCase.php @@ -1,4 +1,5 @@ add('CRM_', $dir); - $loader->add('Civi\\', $dir); - $loader->add('api_', $dir); - $loader->add('api\\', $dir); - $loader->register(); -} +$loader = new \Composer\Autoload\ClassLoader(); +$loader->add('CRM_', [__DIR__ . '/../..', __DIR__]); +$loader->addPsr4('Civi\\', [__DIR__ . '/../../Civi', __DIR__ . '/Civi']); +$loader->add('api_', [__DIR__ . '/../..', __DIR__]); +$loader->addPsr4('api\\', [__DIR__ . '/../../api', __DIR__ . '/api']); + +$loader->register(); /** * Call the "cv" command. @@ -22,16 +21,17 @@ foreach ([__DIR__] as $dir) { * The rest of the command to send. * @param string $decode * Ex: 'json' or 'phpcode'. - * @return string + * @return mixed * Response output (if the command executed normally). + * For 'raw' or 'phpcode', this will be a string. For 'json', it could be any JSON value. * @throws \RuntimeException * If the command terminates abnormally. */ -function cv($cmd, $decode = 'json') { +function cv(string $cmd, string $decode = 'json') { $cmd = 'cv ' . $cmd; - $descriptorSpec = [0 => ["pipe", "r"], 1 => ["pipe", "w"], 2 => STDERR]; + $descriptorSpec = [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => STDERR]; $oldOutput = getenv('CV_OUTPUT'); - putenv("CV_OUTPUT=json"); + putenv('CV_OUTPUT=json'); // Execute `cv` in the original folder. This is a work-around for // phpunit/codeception, which seem to manipulate PWD. @@ -51,7 +51,7 @@ function cv($cmd, $decode = 'json') { case 'phpcode': // If the last output is /*PHPCODE*/, then we managed to complete execution. - if (substr(trim($result), 0, 12) !== "/*BEGINPHP*/" || substr(trim($result), -10) !== "/*ENDPHP*/") { + if (substr(trim($result), 0, 12) !== '/*BEGINPHP*/' || substr(trim($result), -10) !== '/*ENDPHP*/') { throw new \RuntimeException("Command failed ($cmd):\n$result"); } return $result; -- 2.25.1