Skip to content

Commit

Permalink
Merge pull request #17661 from seamuslee001/prep_phpunit7
Browse files Browse the repository at this point in the history
[NFC] Fix tests in preparation for phpunit7
  • Loading branch information
seamuslee001 authored Jun 19, 2020
2 parents 88bc0c6 + 11a56cf commit 2999751
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 10 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));
}

}
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/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
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/LoggingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ 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('civicrm_address', $loggings['values'][0]['table'], json_encode(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('27 Cool way', $loggings['values'][0]['from']);
$this->assertEquals('25 Dorky way', $loggings['values'][0]['to']);
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 2999751

Please sign in to comment.