Skip to content

Commit

Permalink
Merge pull request #17663 from seamuslee001/prep_phpunit7
Browse files Browse the repository at this point in the history
[NFC] Fix tests in prepartion for phpunit7
  • Loading branch information
eileenmcnaughton authored Jun 20, 2020
2 parents 41c5f67 + 2f3d066 commit 07ef3e7
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CRM/Core/BAO/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function countryLimit() {
if (!isset(Civi::$statics[__CLASS__]['countryLimit'])) {
$countryIsoCodes = CRM_Core_PseudoConstant::countryIsoCode();
$country = [];
$countryLimit = Civi::settings()->get('countryLimit');
$countryLimit = Civi::settings()->get('countryLimit') ?? [];
if (is_array($countryLimit)) {
foreach ($countryLimit as $val) {
// CRM-12007
Expand Down
2 changes: 1 addition & 1 deletion Civi/Test/DbTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function assertDBCompareValue(
$expectedValue, $message
) {
$value = \CRM_Core_DAO::getFieldValue($daoName, $searchValue, $returnColumn, $searchColumn, TRUE);
$this->assertEquals($expectedValue, $value, $message);
$this->assertEquals(trim($expectedValue), trim($value), $message);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Campaign/Form/CampaignTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testSubmit($thousandSeparator) {
'campaign_type_id' => 1,
], $form);
$campaign = $this->callAPISuccess('campaign', 'get', ['id' => $result['id']]);
$this->assertEquals('10000', $campaign['values'][$campaign['id']]['goal_revenue']);
$this->assertEquals('10000.00', $campaign['values'][$campaign['id']]['goal_revenue']);
}

}
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Contribute/Form/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public function testSubmitCreditCardFee() {
'contact_id' => $this->_individualId,
'contribution_status_id' => 'Completed',
]);
$this->assertEquals('50', $contribution['total_amount']);
$this->assertEquals('50.00', $contribution['total_amount']);
$this->assertEquals(.08, $contribution['fee_amount']);
$this->assertEquals(49.92, $contribution['net_amount']);
$this->assertEquals('tx', $contribution['trxn_id']);
Expand Down Expand Up @@ -464,7 +464,7 @@ public function testSubmitCreditCardFullyDeductible() {
'contact_id' => $this->_individualId,
'contribution_status_id' => 'Completed',
]);
$this->assertEquals('50', $contribution['total_amount']);
$this->assertEquals('50.00', $contribution['total_amount']);
$this->assertEquals(0, $contribution['non_deductible_amount']);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Core/PseudoConstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ public function testGetTaxRates() {
];
CRM_Financial_BAO_FinancialTypeAccount::add($financialAccountParams);
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
$this->assertEquals('5.00', $taxRates[$financialType['id']]);
$this->assertEquals('5.00', round($taxRates[$financialType['id']], 2));
}

}
6 changes: 3 additions & 3 deletions tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {

protected $_priceSetID;

protected $_cheapFee = 80;
protected $_cheapFee = '80.00';

protected $_expensiveFee = 100;
protected $_expensiveFee = '100.00';

protected $_veryExpensive = 120;
protected $_veryExpensive = '120.00';

protected $_noFee = 0;

Expand Down
12 changes: 6 additions & 6 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2859,7 +2859,7 @@ public function _checkFinancialRecords($params, $context) {
if ($context != 'online' && $context != 'payLater') {
$compareParams = [
'to_financial_account_id' => 6,
'total_amount' => CRM_Utils_Array::value('total_amount', $params, 100),
'total_amount' => (float) CRM_Utils_Array::value('total_amount', $params, 100.00),
'status_id' => 1,
];
}
Expand All @@ -2869,15 +2869,15 @@ public function _checkFinancialRecords($params, $context) {
elseif ($context == 'online') {
$compareParams = [
'to_financial_account_id' => 12,
'total_amount' => CRM_Utils_Array::value('total_amount', $params, 100),
'total_amount' => (float) CRM_Utils_Array::value('total_amount', $params, 100.00),
'status_id' => 1,
'payment_instrument_id' => CRM_Utils_Array::value('payment_instrument_id', $params, 1),
];
}
elseif ($context == 'payLater') {
$compareParams = [
'to_financial_account_id' => 7,
'total_amount' => CRM_Utils_Array::value('total_amount', $params, 100),
'total_amount' => (float) CRM_Utils_Array::value('total_amount', $params, 100.00),
'status_id' => 2,
];
}
Expand All @@ -2891,13 +2891,13 @@ public function _checkFinancialRecords($params, $context) {
'id' => $entityTrxn['entity_id'],
];
$compareParams = [
'amount' => CRM_Utils_Array::value('total_amount', $params, 100),
'amount' => (float) CRM_Utils_Array::value('total_amount', $params, 100.00),
'status_id' => 1,
'financial_account_id' => CRM_Utils_Array::value('financial_account_id', $params, 1),
];
if ($context == 'payLater') {
$compareParams = [
'amount' => CRM_Utils_Array::value('total_amount', $params, 100),
'amount' => (float) CRM_Utils_Array::value('total_amount', $params, 100.00),
'status_id' => 3,
'financial_account_id' => CRM_Utils_Array::value('financial_account_id', $params, 1),
];
Expand Down Expand Up @@ -2925,7 +2925,7 @@ public function _checkFinancialRecords($params, $context) {
'entity_table' => 'civicrm_financial_trxn',
];
$compareParams = [
'amount' => 50,
'amount' => 50.00,
'status_id' => 1,
'financial_account_id' => 5,
];
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ContributionRecurTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function setUp() {
'contact_id' => $this->ids['contact'][0],
'installments' => '12',
'frequency_interval' => '1',
'amount' => '500',
'amount' => '500.00',
'contribution_status_id' => 1,
'start_date' => '2012-01-01 00:00:00',
'currency' => 'USD',
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ContributionSoftTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function testCreateContributionSoft() {
$softcontribution = $this->callAPIAndDocument('contribution_soft', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($softcontribution['values'][$softcontribution['id']]['contribution_id'], $this->_contributionId);
$this->assertEquals($softcontribution['values'][$softcontribution['id']]['contact_id'], $this->_softIndividual1Id);
$this->assertEquals($softcontribution['values'][$softcontribution['id']]['amount'], '10.00');
$this->assertEquals($softcontribution['values'][$softcontribution['id']]['amount'], '10');
$this->assertEquals($softcontribution['values'][$softcontribution['id']]['currency'], 'USD');
$this->assertEquals($softcontribution['values'][$softcontribution['id']]['soft_credit_type_id'], 5);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2223,7 +2223,7 @@ public function testCompleteTransactionFeeAmount() {
$contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $contribution['id'], 'sequential' => 1]);
$this->assertEquals('Completed', $contribution['contribution_status']);
$this->assertEquals('7778888', $contribution['trxn_id']);
$this->assertEquals('.56', $contribution['fee_amount']);
$this->assertEquals('0.56', $contribution['fee_amount']);
$this->assertEquals('99.44', $contribution['net_amount']);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/GrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function setUp() {
'contact_id' => $this->ids['contact'][0],
'application_received_date' => 'now',
'decision_date' => 'next Monday',
'amount_total' => '500',
'amount_total' => '500.00',
'status_id' => 1,
'rationale' => 'Just Because',
'currency' => 'USD',
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/api/v3/LoggingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ public function testRevertRestrictedTables() {
// To protect against the modified date not changing due to the updates being too close together.
sleep(1);
$loggings = $this->callAPISuccess('Logging', 'get', ['log_conn_id' => 'bitty bot bot', 'tables' => ['civicrm_address']]);
$this->assertEquals('civicrm_address', $loggings['values'][0]['table'], CRM_Core_DAO::executeQuery('SELECT * FROM log_civicrm_address')->toArray());
$this->assertEquals(1, $loggings['count'], CRM_Core_DAO::executeQuery('SELECT * FROM log_civicrm_address')->toArray());
$this->assertEquals('civicrm_address', $loggings['values'][0]['table'], json_encode(CRM_Core_DAO::executeQuery('SELECT * FROM log_civicrm_address')->toArray()));
$this->assertEquals(1, $loggings['count'], json_encode(CRM_Core_DAO::executeQuery('SELECT * FROM log_civicrm_address')->toArray()));
$this->assertEquals('27 Cool way', $loggings['values'][0]['from']);
$this->assertEquals('25 Dorky way', $loggings['values'][0]['to']);
$this->callAPISuccess('Logging', 'revert', ['log_conn_id' => 'bitty bot bot', 'tables' => ['civicrm_address']]);
Expand Down
5 changes: 5 additions & 0 deletions tests/phpunit/api/v3/SyntaxConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,7 @@ public function testCreateSingleValueAlter($entityName) {
return;
}

$floatFields = [];
$baoString = _civicrm_api3_get_BAO($entityName);
$this->assertNotEmpty($baoString, $entityName);
$this->assertNotEmpty($entityName, $entityName);
Expand Down Expand Up @@ -1438,6 +1439,7 @@ public function testCreateSingleValueAlter($entityName) {

case CRM_Utils_Type::T_FLOAT:
case CRM_Utils_Type::T_MONEY:
$floatFields[] = $field;
$entity[$field] = '22.75';
break;

Expand Down Expand Up @@ -1505,6 +1507,9 @@ public function testCreateSingleValueAlter($entityName) {
$entity[$field] = CRM_Core_DAO::serializeField($checkEntity[$field], $specs['serialize']);
}

foreach ($floatFields as $floatField) {
$checkEntity[$floatField] = rtrim($checkEntity[$floatField], "0");
}
$this->assertAPIArrayComparison($entity, $checkEntity, [], "checking if $fieldName was correctly updated\n" . print_r([
'update-params' => $updateParams,
'update-result' => $update,
Expand Down

0 comments on commit 07ef3e7

Please sign in to comment.