From caf853e22b25b5708b3c4645b6784fac40c02c72 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 15 Dec 2021 10:13:37 +1300 Subject: [PATCH] [NFC] Test cleanup This biggest part of this is relying on the tearDown to do the cleanup more. This is the right way because if the test fails the cleanup won't happen if it is in the test itsef --- tests/phpunit/api/v3/RelationshipTest.php | 220 ++++++++++------------ 1 file changed, 103 insertions(+), 117 deletions(-) diff --git a/tests/phpunit/api/v3/RelationshipTest.php b/tests/phpunit/api/v3/RelationshipTest.php index 9af49654d937..0063f35bbe51 100644 --- a/tests/phpunit/api/v3/RelationshipTest.php +++ b/tests/phpunit/api/v3/RelationshipTest.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\RelationshipType; + /** * Class contains api test cases for "civicrm_relationship" * @group headless @@ -31,9 +33,9 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { * @var int */ protected $_cId_b2; - protected $_relTypeID; + protected $relationshipTypeID; protected $_ids = []; - protected $_customFieldId = NULL; + protected $_customFieldId; protected $_params; protected $entity; @@ -63,11 +65,11 @@ public function setUp(): void { 'is_active' => 1, ]; - $this->_relTypeID = $this->relationshipTypeCreate($relTypeParams); + $this->relationshipTypeID = $this->relationshipTypeCreate($relTypeParams); $this->_params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, ]; @@ -81,26 +83,26 @@ public function setUp(): void { */ public function tearDown(): void { $this->quickCleanup(['civicrm_relationship', 'civicrm_membership'], TRUE); - $this->relationshipTypeDelete($this->_relTypeID); + RelationshipType::delete(FALSE)->addWhere('id', '>', ($this->relationshipTypeID - 1))->execute(); parent::tearDown(); } /** * Check with empty array. + * * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testRelationshipCreateEmpty($version): void { + public function testRelationshipCreateEmpty(int $version): void { $this->_apiversion = $version; $this->callAPIFailure('relationship', 'create', []); } /** * Test Current Employer is correctly set. - * - * @throws \CRM_Core_Exception */ - public function testCurrentEmployerRelationship() { + public function testCurrentEmployerRelationship(): void { $employerRelationshipID = $this->callAPISuccessGetValue('RelationshipType', [ 'return' => 'id', 'name_b_a' => 'Employer Of', @@ -118,7 +120,7 @@ public function testCurrentEmployerRelationship() { 'id' => $this->_cId_a, ]); $organisation = $this->callAPISuccessGetValue('Contact', [ - 'return' => "sort_name", + 'return' => 'sort_name', 'id' => $this->_cId_b, ]); $this->assertEquals($employer, $organisation); @@ -126,7 +128,7 @@ public function testCurrentEmployerRelationship() { //Update relationship type $this->callAPISuccess('Relationship', 'create', [ 'id' => $employerRelationship['id'], - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, ]); $employeeContact = $this->callAPISuccessGetSingle('Contact', [ 'return' => ['current_employer'], @@ -138,10 +140,12 @@ public function testCurrentEmployerRelationship() { /** * Check if required fields are not passed. + * * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testRelationshipCreateWithoutRequired($version) { + public function testRelationshipCreateWithoutRequired(int $version): void { $this->_apiversion = $version; $params = [ 'start_date' => ['d' => '10', 'M' => '1', 'Y' => '2008'], @@ -154,10 +158,12 @@ public function testRelationshipCreateWithoutRequired($version) { /** * Check with incorrect required fields. + * * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testRelationshipCreateWithIncorrectData($version) { + public function testRelationshipCreateWithIncorrectData(int $version): void { $this->_apiversion = $version; $params = [ @@ -172,7 +178,7 @@ public function testRelationshipCreateWithIncorrectData($version) { $params = [ 'contact_id_a' => 'invalid', 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => ['d' => '10', 'M' => '1', 'Y' => '2008'], 'is_active' => 1, ]; @@ -190,16 +196,18 @@ public function testRelationshipCreateWithIncorrectData($version) { /** * Check relationship creation with invalid Relationship. + * * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testRelationshipCreateInvalidRelationship($version) { + public function testRelationshipCreateInvalidRelationship(int $version): void { $this->_apiversion = $version; // Both have the contact type Individual. $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_a, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-01-10', 'is_active' => 1, ]; @@ -210,7 +218,7 @@ public function testRelationshipCreateInvalidRelationship($version) { $params = [ 'contact_id_a' => $this->_cId_b, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-01-10', 'is_active' => 1, ]; @@ -220,15 +228,17 @@ public function testRelationshipCreateInvalidRelationship($version) { /** * Check relationship already exists. + * * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testRelationshipCreateAlreadyExists($version) { + public function testRelationshipCreateAlreadyExists(int $version): void { $this->_apiversion = $version; $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-12-20', 'end_date' => NULL, 'is_active' => 1, @@ -238,55 +248,54 @@ public function testRelationshipCreateAlreadyExists($version) { $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, ]; - $this->callAPIFailure('relationship', 'create', $params, 'Duplicate Relationship'); - - $params['id'] = $relationship['id']; - $this->callAPISuccess('relationship', 'delete', $params); + $this->callAPIFailure('Relationship', 'create', $params, 'Duplicate Relationship'); } /** * Check relationship already exists. + * * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testRelationshipCreateUpdateAlreadyExists($version) { + public function testRelationshipCreateUpdateAlreadyExists(int $version): void { $this->_apiversion = $version; $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-12-20', 'end_date' => NULL, 'is_active' => 1, ]; - $relationship = $this->callAPISuccess('relationship', 'create', $params); + $relationship = $this->callAPISuccess('Relationship', 'create', $params); $params = [ 'id' => $relationship['id'], 'is_active' => 0, 'debug' => 1, ]; - $this->callAPISuccess('relationship', 'create', $params); - $this->callAPISuccess('relationship', 'get', $params); - $params['id'] = $relationship['id']; - $this->callAPISuccess('relationship', 'delete', $params); + $this->callAPISuccess('Relationship', 'create', $params); + $this->callAPISuccess('Relationship', 'get', $params); } /** * Check update doesn't reset stuff badly - CRM-11789. + * * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testRelationshipCreateUpdateDoesNotMangle($version) { + public function testRelationshipCreateUpdateDoesNotMangle(int $version): void { $this->_apiversion = $version; $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, 'is_permission_a_b' => 1, @@ -296,34 +305,34 @@ public function testRelationshipCreateUpdateDoesNotMangle($version) { $updateParams = [ 'id' => $relationship['id'], - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, ]; $this->callAPISuccess('relationship', 'create', $updateParams); //make sure the orig params didn't get changed $this->getAndCheck($params, $relationship['id'], 'relationship'); - } /** * Check relationship creation. + * * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testRelationshipCreate($version) { + public function testRelationshipCreate(int $version): void { $this->_apiversion = $version; $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2010-10-30', 'end_date' => '2010-12-30', 'is_active' => 1, 'note' => 'note', ]; - $result = $this->callAPIAndDocument('relationship', 'create', $params, __FUNCTION__, __FILE__); - $this->assertNotNull($result['id']); + $result = $this->callAPIAndDocument('Relationship', 'create', $params, __FUNCTION__, __FILE__); $relationParams = [ 'id' => $result['id'], ]; @@ -333,21 +342,21 @@ public function testRelationshipCreate($version) { $result = $this->callAPISuccess('relationship', 'get', ['id' => $result['id']]); $values = $result['values'][$result['id']]; foreach ($params as $key => $value) { - if ($key == 'note') { + if ($key === 'note') { continue; } $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE)); } - $params['id'] = $result['id']; - $this->callAPISuccess('relationship', 'delete', $params); } /** * Ensure disabling works. + * * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testRelationshipUpdate($version) { + public function testRelationshipUpdate(int $version): void { $this->_apiversion = $version; $result = $this->callAPISuccess('relationship', 'create', $this->_params); $relID = $result['id']; @@ -367,15 +376,17 @@ public function testRelationshipUpdate($version) { /** * Check relationship creation. + * * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testRelationshipCreateEmptyEndDate($version) { + public function testRelationshipCreateEmptyEndDate(int $version): void { $this->_apiversion = $version; $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2010-10-30', 'end_date' => '', 'is_active' => 1, @@ -393,10 +404,10 @@ public function testRelationshipCreateEmptyEndDate($version) { $result = $this->callAPISuccess('relationship', 'get', ['id' => $result['id']]); $values = $result['values'][$result['id']]; foreach ($params as $key => $value) { - if ($key == 'note') { + if ($key === 'note') { continue; } - if ($key == 'end_date') { + if ($key === 'end_date') { $this->assertTrue(empty($values[$key])); continue; } @@ -410,7 +421,7 @@ public function testRelationshipCreateEmptyEndDate($version) { * Check relationship creation with custom data. * FIXME: Api4 */ - public function testRelationshipCreateEditWithCustomData() { + public function testRelationshipCreateEditWithCustomData(): void { $this->createCustomGroupWithFieldsOfAllTypes(); //few custom Values for comparing $custom_params = [ @@ -423,7 +434,7 @@ public function testRelationshipCreateEditWithCustomData() { $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, ]; @@ -437,7 +448,7 @@ public function testRelationshipCreateEditWithCustomData() { $getParams = ['id' => $result['id']]; $updateParams = array_merge($getParams, [ $this->getCustomFieldName('text') => 'Edited Text Value', - 'relationship_type_id' => $this->_relTypeID . '_b_a', + 'relationship_type_id' => $this->relationshipTypeID . '_b_a', 'related_contact_id' => $this->_cId_a, ]); $reln = new CRM_Contact_Form_Relationship(); @@ -446,11 +457,7 @@ public function testRelationshipCreateEditWithCustomData() { $reln->submit($updateParams); $check = $this->callAPISuccess('relationship', 'get', $getParams); - $this->assertEquals("Edited Text Value", $check['values'][$check['id']][$this->getCustomFieldName('text')]); - - $params['id'] = $result['id']; - $this->callAPISuccess('relationship', 'delete', $params); - $this->relationshipTypeDelete($this->_relTypeID); + $this->assertEquals('Edited Text Value', $check['values'][$check['id']][$this->getCustomFieldName('text')]); } /** @@ -460,7 +467,7 @@ public function testRelationshipCreateEditWithCustomData() { * and / or moved to the automated test suite * FIXME: Api4 */ - public function testGetWithCustom() { + public function testGetWithCustom(): void { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); $params = $this->_params; @@ -482,7 +489,7 @@ public function testGetWithCustom() { * @param int $version * @dataProvider versionThreeAndFour */ - public function testRelationshipDeleteWithoutRequired($version) { + public function testRelationshipDeleteWithoutRequired($version): void { $this->_apiversion = $version; $params = [ 'start_date' => '2008-12-20', @@ -496,7 +503,7 @@ public function testRelationshipDeleteWithoutRequired($version) { /** * Check with incorrect required fields. */ - public function testRelationshipDeleteWithIncorrectData() { + public function testRelationshipDeleteWithIncorrectData(): void { $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, @@ -505,7 +512,7 @@ public function testRelationshipDeleteWithIncorrectData() { $this->callAPIFailure('relationship', 'delete', $params, 'Mandatory key(s) missing from params array: id'); - $params['id'] = "Invalid"; + $params['id'] = 'Invalid'; $this->callAPIFailure('relationship', 'delete', $params, 'id is not a valid integer'); } @@ -519,7 +526,7 @@ public function testRelationshipDelete($version) { $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, ]; @@ -527,7 +534,6 @@ public function testRelationshipDelete($version) { $result = $this->callAPISuccess('relationship', 'create', $params); $params = ['id' => $result['id']]; $this->callAPIAndDocument('relationship', 'delete', $params, __FUNCTION__, __FILE__); - $this->relationshipTypeDelete($this->_relTypeID); } ///////////////// civicrm_relationship_update methods @@ -557,7 +563,7 @@ public function testRelationshipCreateDuplicate($version) { $relParams = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '20081214', 'end_date' => '20091214', 'is_active' => 1, @@ -570,16 +576,13 @@ public function testRelationshipCreateDuplicate($version) { $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '20081214', 'end_date' => '20091214', 'is_active' => 0, ]; $this->callAPIFailure('relationship', 'create', $params, 'Duplicate Relationship'); - - $this->callAPISuccess('relationship', 'delete', ['id' => $result['id']]); - $this->relationshipTypeDelete($this->_relTypeID); } /** @@ -587,7 +590,7 @@ public function testRelationshipCreateDuplicate($version) { * should be OK if the custom field values differ. * FIXME: Api4 */ - public function testRelationshipCreateDuplicateWithCustomFields() { + public function testRelationshipCreateDuplicateWithCustomFields(): void { $this->createCustomGroupWithFieldsOfAllTypes(); $custom_params_1 = [ @@ -607,7 +610,7 @@ public function testRelationshipCreateDuplicateWithCustomFields() { $params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, ]; @@ -620,8 +623,6 @@ public function testRelationshipCreateDuplicateWithCustomFields() { $this->assertNotNull($result_2['id']); $this->assertEquals(0, $result_2['is_error']); - - $this->relationshipTypeDelete($this->_relTypeID); } /** @@ -631,7 +632,7 @@ public function testRelationshipCreateDuplicateWithCustomFields() { * does. * FIXME: Api4 */ - public function testRelationshipCreateDuplicateWithCustomFields2() { + public function testRelationshipCreateDuplicateWithCustomFields2(): void { $this->createCustomGroupWithFieldsOfAllTypes(); $custom_params_2 = [ @@ -644,7 +645,7 @@ public function testRelationshipCreateDuplicateWithCustomFields2() { $params_1 = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, ]; @@ -656,8 +657,6 @@ public function testRelationshipCreateDuplicateWithCustomFields2() { $this->assertNotNull($result_2['id']); $this->assertEquals(0, $result_2['is_error']); - - $this->relationshipTypeDelete($this->_relTypeID); } /** @@ -680,7 +679,7 @@ public function testRelationshipCreateDuplicateWithCustomFields3() { $params_2 = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, ]; @@ -692,8 +691,6 @@ public function testRelationshipCreateDuplicateWithCustomFields3() { $this->assertNotNull($result_2['id']); $this->assertEquals(0, $result_2['is_error']); - - $this->relationshipTypeDelete($this->_relTypeID); } /** @@ -703,7 +700,7 @@ public function testRelationshipsGet() { $relParams = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2011-01-01', 'end_date' => '2013-01-01', 'is_active' => 1, @@ -743,7 +740,7 @@ public function testRelationshipGetWithChainedCall($version) { // Try to retrieve it using chaining. $params = [ - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'id' => $id, 'api.Contact.get' => [ 'id' => '$value.contact_id_b', @@ -773,7 +770,7 @@ public function testRelationshipGetInChainedCall($version) { $params = [ 'id' => $this->_cId_a, 'api.Relationship.get' => [ - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'contact_id_a' => '$value.id', 'api.Contact.get' => [ 'id' => '$value.contact_id_b', @@ -802,7 +799,7 @@ public function testRelationshipsGetGeneric($version) { $relParams = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2011-01-01', 'end_date' => '2013-01-01', 'is_active' => 1, @@ -827,7 +824,7 @@ public function testGetIsCurrent($version) { $rel2Params = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b2, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2008-12-20', 'is_active' => 0, ]; @@ -972,52 +969,36 @@ public function testGetRelationshipWithContactB() { $relParams = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2011-01-01', 'end_date' => '2013-01-01', 'is_active' => 1, ]; - $relationship = $this->callAPISuccess('relationship', 'create', $relParams); - - $contacts = [ - 'contact_id' => $this->_cId_a, - ]; - - $result = $this->callAPISuccess('relationship', 'get', $contacts); + $this->callAPISuccess('relationship', 'create', $relParams); + $result = $this->callAPISuccess('Relationship', 'get', ['contact_id' => $this->_cId_a]); $this->assertGreaterThan(0, $result['count']); - $params = [ - 'id' => $relationship['id'], - ]; - $this->callAPISuccess('relationship', 'delete', $params); - $this->relationshipTypeDelete($this->_relTypeID); } /** * Check with valid data with relationshipTypes. */ - public function testGetRelationshipWithRelTypes() { + public function testGetRelationshipWithRelTypes(): void { $relParams = [ 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'start_date' => '2011-01-01', 'end_date' => '2013-01-01', 'is_active' => 1, ]; - $relationship = $this->callAPISuccess('relationship', 'create', $relParams); + $this->callAPISuccess('relationship', 'create', $relParams); $contact_a = [ 'contact_id' => $this->_cId_a, ]; $this->callAPISuccess('relationship', 'get', $contact_a); - - $params = [ - 'id' => $relationship['id'], - ]; - $this->callAPISuccess('relationship', 'delete', $params); - $this->relationshipTypeDelete($this->_relTypeID); } /** @@ -1028,11 +1009,11 @@ public function testGetRelationshipWithRelTypes() { * We should get 1 result without or with correct relationship type id & 0 with * an incorrect one */ - public function testGetRelationshipByTypeReciprocal() { + public function testGetRelationshipByTypeReciprocal(): void { $created = $this->callAPISuccess($this->entity, 'create', $this->_params); $result = $this->callAPISuccess($this->entity, 'get', [ 'contact_id' => $this->_cId_a, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, ]); $this->assertEquals(1, $result['count']); $result = $this->callAPISuccess($this->entity, 'get', [ @@ -1052,7 +1033,7 @@ public function testGetRelationshipByTypeReciprocal() { * @param int $version * @dataProvider versionThreeAndFour */ - public function testGetRelationshipByTypeDAO($version) { + public function testGetRelationshipByTypeDAO($version): void { $this->_apiversion = $version; $this->_ids['relationship'] = $this->callAPISuccess($this->entity, 'create', ['format.only_id' => TRUE] + $this->_params); @@ -1061,7 +1042,7 @@ public function testGetRelationshipByTypeDAO($version) { ], 1); $result = $this->callAPISuccess($this->entity, 'get', [ 'contact_id_a' => $this->_cId_a, - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, ]); $this->assertEquals(1, $result['count']); $result = $this->callAPISuccess($this->entity, 'get', [ @@ -1077,10 +1058,12 @@ public function testGetRelationshipByTypeDAO($version) { * * We should get 1 result without or with correct relationship type id & 0 with * an incorrect one + * * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testGetRelationshipByTypeArrayDAO($version) { + public function testGetRelationshipByTypeArrayDAO(int $version): void { $this->_apiversion = $version; $this->callAPISuccess($this->entity, 'create', $this->_params); $org3 = $this->organizationCreate(); @@ -1107,12 +1090,15 @@ public function testGetRelationshipByTypeArrayDAO($version) { $result = $this->callAPISuccess($this->entity, 'get', [ 'contact_id_a' => $this->_cId_a, - 'relationship_type_id' => ['IN' => [$this->_relTypeID, $relType3]], + 'relationship_type_id' => ['IN' => [$this->relationshipTypeID, $relType3]], ]); $this->assertEquals(2, $result['count']); foreach ($result['values'] as $key => $value) { - $this->assertTrue(in_array($value['relationship_type_id'], [$this->_relTypeID, $relType3])); + $this->assertContains($value['relationship_type_id'], [ + $this->relationshipTypeID, + $relType3 + ]); } } @@ -1148,12 +1134,12 @@ public function testGetRelationshipByTypeArrayReciprocal() { $result = $this->callAPISuccess($this->entity, 'get', [ 'contact_id' => $this->_cId_a, - 'relationship_type_id' => ['IN' => [$this->_relTypeID, $relType3]], + 'relationship_type_id' => ['IN' => [$this->relationshipTypeID, $relType3]], ]); $this->assertEquals(2, $result['count']); foreach ($result['values'] as $key => $value) { - $this->assertTrue(in_array($value['relationship_type_id'], [$this->_relTypeID, $relType3])); + $this->assertTrue(in_array($value['relationship_type_id'], [$this->relationshipTypeID, $relType3])); } } @@ -1220,7 +1206,7 @@ public function testGetRelationshipByMembershipTypeDAO($version) { // although our contact has more than one relationship we have passed them in as contact_id_a & can't get reciprocal $this->assertEquals(1, $result['count']); foreach ($result['values'] as $key => $value) { - $this->assertTrue(in_array($value['relationship_type_id'], [$relType1])); + $this->assertContains($value['relationship_type_id'], [$relType1]); } } @@ -1324,7 +1310,7 @@ public function testCreateRelatedMembership(int $version): void { 'duration_unit' => 'year', 'duration_interval' => 1, 'period_type' => 'rolling', - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'relationship_direction' => 'b_a', 'visibility' => 'Public', 'auto_renew' => 0, @@ -1336,7 +1322,7 @@ public function testCreateRelatedMembership(int $version): void { 'contact_id' => $mainContactID, ]); $this->callAPISuccess('Relationship', 'create', [ - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'contact_id_a' => $this->_cId_a, 'contact_id_b' => $mainContactID, ]); @@ -1345,7 +1331,7 @@ public function testCreateRelatedMembership(int $version): void { // Adding a relationship with a future start date should NOT create a membership $this->callAPISuccess('Relationship', 'create', [ - 'relationship_type_id' => $this->_relTypeID, + 'relationship_type_id' => $this->relationshipTypeID, 'contact_id_a' => $this->_cId_a_2, 'contact_id_b' => $mainContactID, 'start_date' => 'now + 1 week',