Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC] Minor IDE cleanup in test class #19816

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,6 @@ public static function getLocationBlockInfo() {
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \Exception
*/
public static function getRowsElementsAndInfo($mainId, $otherId, $checkPermissions = TRUE) {
$qfZeroBug = 'e8cddb72-a257-11dc-b9cc-0016d3330ee9';
Expand Down
63 changes: 36 additions & 27 deletions tests/phpunit/CRM/Dedupe/MergerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
/**
* Tear down.
*
* @throws \Exception
* @throws \CRM_Core_Exception
*/
public function tearDown() {
public function tearDown(): void {
$this->quickCleanup([
'civicrm_contact',
'civicrm_group_contact',
Expand All @@ -38,7 +38,7 @@ public function tearDown() {
/**
* @throws \CRM_Core_Exception
*/
public function createDupeContacts() {
public function createDupeContacts(): void {
// create a group to hold contacts, so that dupe checks don't consider any other contacts in the DB
$params = [
'name' => 'Test Dupe Merger Group',
Expand Down Expand Up @@ -140,7 +140,7 @@ public function createDupeContacts() {
/**
* Delete all created contacts.
*/
public function deleteDupeContacts() {
public function deleteDupeContacts(): void {
foreach ($this->_contactIds as $contactId) {
$this->contactDelete($contactId);
}
Expand All @@ -150,9 +150,11 @@ public function deleteDupeContacts() {
/**
* Test the batch merge.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testBatchMergeSelectedDuplicates() {
public function testBatchMergeSelectedDuplicates(): void {
$this->createDupeContacts();

// verify that all contacts have been created separately
Expand Down Expand Up @@ -198,8 +200,8 @@ public function testBatchMergeSelectedDuplicates() {
CRM_Core_DAO::singleValueQuery("UPDATE civicrm_prevnext_cache SET is_selected = 1 WHERE id IN ({$pnDupePairs[0]['prevnext_id']}, {$pnDupePairs[1]['prevnext_id']})");

$pnDupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, NULL, NULL, 0, 0, $select);
$this->assertEquals($pnDupePairs[0]['is_selected'], 1, 'Check if first record in dupe pairs is marked as selected.');
$this->assertEquals($pnDupePairs[0]['is_selected'], 1, 'Check if second record in dupe pairs is marked as selected.');
$this->assertEquals(1, $pnDupePairs[0]['is_selected'], 'Check if first record in dupe pairs is marked as selected.');
$this->assertEquals(1, $pnDupePairs[0]['is_selected'], 'Check if second record in dupe pairs is marked as selected.');

// batch merge selected dupes
$result = CRM_Dedupe_Merger::batchMerge($dao->id, $this->_groupId, 'safe', 5, 1);
Expand Down Expand Up @@ -313,7 +315,7 @@ public function testGetCidRefs(): void {
*
* @throws \CRM_Core_Exception
*/
public function testGetMatches() {
public function testGetMatches(): void {
$this->setupMatchData();

$pairs = $this->callAPISuccess('Dedupe', 'getduplicates', [
Expand Down Expand Up @@ -351,7 +353,7 @@ public function testGetMatches() {
*
* @throws \CRM_Core_Exception
*/
public function testGetMatchesExcludeDeleted($isReverse) {
public function testGetMatchesExcludeDeleted(bool $isReverse): void {
$this->setupMatchData();
$pairs = $this->callAPISuccess('Dedupe', 'getduplicates', [
'rule_group_id' => 1,
Expand All @@ -372,8 +374,9 @@ public function testGetMatchesExcludeDeleted($isReverse) {
* Test that location type is ignored when deduping by postal address.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testGetMatchesIgnoreLocationType() {
public function testGetMatchesIgnoreLocationType(): void {
$contact1 = $this->individualCreate();
$contact2 = $this->individualCreate();
$this->callAPISuccess('address', 'create', [
Expand All @@ -396,15 +399,16 @@ public function testGetMatchesIgnoreLocationType() {
$dupeCount = $this->callAPISuccess('Dedupe', 'getduplicates', [
'rule_group_id' => $ruleGroup['id'],
])['count'];
$this->assertEquals($dupeCount, 1);
$this->assertEquals(1, $dupeCount);
}

/**
* Test results are returned when criteria are passed in.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testGetMatchesCriteriaMatched() {
public function testGetMatchesCriteriaMatched(): void {
$this->setupMatchData();
$pairs = $this->callAPISuccess('Dedupe', 'getduplicates', [
'rule_group_id' => 1,
Expand All @@ -417,8 +421,9 @@ public function testGetMatchesCriteriaMatched() {
* Test results are returned when criteria are passed in & limit is respected.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testGetMatchesCriteriaMatchedWithLimit() {
public function testGetMatchesCriteriaMatchedWithLimit(): void {
$this->setupMatchData();
$pairs = $this->callAPISuccess('Dedupe', 'getduplicates', [
'rule_group_id' => 1,
Expand All @@ -429,11 +434,13 @@ public function testGetMatchesCriteriaMatchedWithLimit() {
}

/**
* Test results are returned when criteria are passed in & limit is respected.
* Test results are returned when criteria are passed in & limit is
* respected.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testGetMatchesCriteriaMatchedWithSearchLimit() {
public function testGetMatchesCriteriaMatchedWithSearchLimit(): void {
$this->setupMatchData();
$pairs = $this->callAPISuccess('Dedupe', 'getduplicates', [
'rule_group_id' => 1,
Expand All @@ -447,8 +454,9 @@ public function testGetMatchesCriteriaMatchedWithSearchLimit() {
* Test getting matches where there are no criteria.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testGetMatchesNoCriteria() {
public function testGetMatchesNoCriteria(): void {
$this->setupMatchData();
$pairs = $this->callAPISuccess('Dedupe', 'getduplicates', [
'rule_group_id' => 1,
Expand All @@ -460,8 +468,9 @@ public function testGetMatchesNoCriteria() {
* Test getting matches with a limit in play.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testGetMatchesNoCriteriaButLimit() {
public function testGetMatchesNoCriteriaButLimit(): void {
$this->setupMatchData();
$pairs = $this->callAPISuccess('Dedupe', 'getduplicates', [
'rule_group_id' => 1,
Expand Down Expand Up @@ -490,7 +499,7 @@ public function testGetMatchesCriteriaNotMatched() {
*
* @throws \Exception
*/
public function testGetOrganizationMatches() {
public function testGetOrganizationMatches(): void {
$this->setupMatchData();
$ruleGroups = $this->callAPISuccessGetSingle('RuleGroup', [
'contact_type' => 'Organization',
Expand Down Expand Up @@ -778,7 +787,7 @@ public function testMergeMembership() {
}

/**
* CRM-19653 : Test that custom field data should/shouldn't be overriden on
* CRM-19653 : Test that custom field data should/shouldn't be overridden on
* selecting/not selecting option to migrate data respectively
*
* @throws \CRM_Core_Exception
Expand All @@ -787,7 +796,7 @@ public function testCustomDataOverwrite() {
// Create Custom Field
$createGroup = $this->setupCustomGroupForIndividual();
$createField = $this->setupCustomField('Graduation', $createGroup);
$customFieldName = "custom_" . $createField['id'];
$customFieldName = 'custom_' . $createField['id'];

// Contacts setup
$this->setupMatchData();
Expand All @@ -801,7 +810,7 @@ public function testCustomDataOverwrite() {
// update the text custom field for original contact with value 'abc'
$this->callAPISuccess('Contact', 'create', [
'id' => $originalContactID,
"{$customFieldName}" => 'abc',
$customFieldName => 'abc',
]);
$this->assertCustomFieldValue($originalContactID, 'abc', $customFieldName);

Expand Down Expand Up @@ -868,7 +877,7 @@ public function testCreatedDatePostMerge($keepContactKey, $duplicateContactKey)
'id' => $this->contacts[0]['id'],
'return' => ['created_date'],
])['created_date'];
// Assume contats have been flipped in the UL so merging into the higher id
// Assume contacts have been flipped in the UL so merging into the higher id
$this->mergeContacts($this->contacts[$keepContactKey]['id'], $this->contacts[$duplicateContactKey]['id'], []);
$this->assertEquals($lowerContactCreatedDate, $this->callAPISuccess('Contact', 'getsingle', ['id' => $this->contacts[$keepContactKey]['id'], 'return' => ['created_date']])['created_date']);
}
Expand Down Expand Up @@ -928,6 +937,7 @@ public function testMigrationOfUnselectedCustomDataOnEmptyCustomRecord() {
* no records on the custom group table.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testMigrationOfSomeCustomDataOnEmptyCustomRecord() {
// Create Custom Fields
Expand Down Expand Up @@ -1057,9 +1067,8 @@ public function testMigrationOfContactReferenceCustomField() {
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
private function mergeContacts($originalContactID, $duplicateContactID, $params) {
private function mergeContacts($originalContactID, $duplicateContactID, $params): void {
$rowsElementsAndInfo = CRM_Dedupe_Merger::getRowsElementsAndInfo($originalContactID, $duplicateContactID);

$migrationData = [
Expand All @@ -1081,7 +1090,7 @@ private function mergeContacts($originalContactID, $duplicateContactID, $params)
*
* @throws \CRM_Core_Exception
*/
private function assertCustomFieldValue($contactID, $expectedValue, $customFieldName) {
private function assertCustomFieldValue($contactID, $expectedValue, $customFieldName): void {
$this->assertEntityCustomFieldValue('Contact', $contactID, $expectedValue, $customFieldName);
}

Expand Down Expand Up @@ -1156,9 +1165,9 @@ private function setupCustomField($fieldLabel, $createGroup) {
/**
* Set up some contacts for our matching.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function setupMatchData() {
public function setupMatchData(): void {
$fixtures = [
[
'first_name' => 'Mickey',
Expand Down