Skip to content

Commit

Permalink
Merge pull request #20380 from seamuslee001/api_v3_civi_phpunit8_warn…
Browse files Browse the repository at this point in the history
…ings

[NFC] Fix PHPUnit8 Deprecation Warnings in api_v3 and Civi Test Suites
  • Loading branch information
eileenmcnaughton authored May 23, 2021
2 parents 421da49 + a12620a commit 8e1366e
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 86 deletions.
2 changes: 1 addition & 1 deletion tests/phpunit/Civi/API/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public function invalidEntityActionPairs() {

/**
* @dataProvider invalidEntityActionPairs
* @expectedException \Civi\API\Exception\NotImplementedException
* @param $inEntity
* @param $inAction
* @param $inVersion
* @throws \Civi\API\Exception\NotImplementedException
*/
public function testCreateRequest_InvalidEntityAction($inEntity, $inAction, $inVersion) {
$this->expectException(\Civi\API\Exception\NotImplementedException::class);
Request::create($inEntity, $inAction, ['version' => $inVersion], NULL);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Civi/Core/CiviFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public function testContactSettings_loggedIn() {

/**
* Anonymous users don't have a SettingsBag.
* @expectedException \CRM_Core_Exception
*/
public function testContactSettings_anonFail() {
$this->expectException(\CRM_Core_Exception::class);
\Civi::contactSettings();
}

Expand Down
6 changes: 2 additions & 4 deletions tests/phpunit/Civi/Core/ResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ public function testCall() {

/**
* Test callback for an invalid object in the container.
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\ExceptionInterface
*/
public function testCallWithInvalidService() {
$this->expectException(\Symfony\Component\DependencyInjection\Exception\ExceptionInterface::class);
$this->resolver->get('call://totallyNonexistentService/ping');
}

Expand Down Expand Up @@ -123,10 +122,9 @@ public function testObj() {

/**
* Test object-lookup in the container (invalid name).
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\ExceptionInterface
*/
public function testObjWithInvalidService() {
$this->expectException(\Symfony\Component\DependencyInjection\Exception\ExceptionInterface::class);
$this->resolver->get('obj://totallyNonexistentService');
}

Expand Down
17 changes: 7 additions & 10 deletions tests/phpunit/Civi/Payment/PropertyBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testSetContactID() {
// (php should throw its own warnings about this because of the signature)
$propertyBag = new PropertyBag();
$propertyBag->setContactID('123');
$this->assertInternalType('int', $propertyBag->getContactID());
$this->assertIsInt($propertyBag->getContactID());
$this->assertEquals(123, $propertyBag->getContactID());

// Test we can have different labels
Expand Down Expand Up @@ -70,7 +70,7 @@ public function testSetAmount($value, $expect, $expectedExceptionMessage = '') {
throw $e;
}
$got = $propertyBag->getAmount();
$this->assertInternalType('string', $got);
$this->assertIsString($got);
$this->assertEquals($expect, $got);
}

Expand All @@ -96,10 +96,9 @@ public function setAmountDataProvider() {

/**
* Test we cannot set an invalid contact ID.
*
* @expectedException \InvalidArgumentException
*/
public function testSetContactIDFailsIfInvalid() {
$this->expectException(\InvalidArgumentException::class);
$propertyBag = new PropertyBag();
$propertyBag->setContactID(0);
}
Expand Down Expand Up @@ -225,11 +224,10 @@ public function testSetCustomProp() {

/**
* Test we can't set a custom prop that we know about.
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Attempted to set 'contactID' via setCustomProperty - must use using its setter.
*/
public function testSetCustomPropFails() {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Attempted to set \'contactID\' via setCustomProperty - must use using its setter.');
$propertyBag = new PropertyBag();
$propertyBag->setCustomProperty('contactID', 123);
}
Expand All @@ -238,11 +236,10 @@ public function testSetCustomPropFails() {
* Test we get NULL for custom prop that was not set.
*
* This is only for backward compatibility/ease of transition. One day it would be nice to throw an exception instead.
*
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Property 'aCustomProp' has not been set.
*/
public function testGetCustomPropFails() {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Property \'aCustomProp\' has not been set.');
$propertyBag = new PropertyBag();
// Tricky test. We need to ignore deprecation errors, we're testing deprecated behaviour,
// but we need to listen out for a different exception.
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3099,7 +3099,7 @@ public function testContactCreationPermissions(int $version): void {
$config = CRM_Core_Config::singleton();
$config->userPermissionClass->permissions = ['access CiviCRM'];
$result = $this->callAPIFailure('contact', 'create', $params);
$this->assertContains('failed', $result['error_message'], 'lacking permissions should not be enough to create a contact');
$this->assertStringContainsString('failed', $result['error_message'], 'lacking permissions should not be enough to create a contact');

$config->userPermissionClass->permissions = ['access CiviCRM', 'add contacts', 'import contacts'];
$this->callAPISuccess('contact', 'create', $params);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/api/v3/DomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testGet(): void {
$params = ['sequential' => 1];
$result = $this->callAPIAndDocument('domain', 'get', $params, __FUNCTION__, __FILE__);

$this->assertType('array', $result);
$this->assertIsArray($result);

$domain = $result['values'][0];
$this->assertEquals("info@EXAMPLE.ORG", $domain['from_email']);
Expand All @@ -107,7 +107,7 @@ public function testGetCurrentDomain(): void {
$params = ['current_domain' => 1];
$result = $this->callAPISuccess('domain', 'get', $params);

$this->assertType('array', $result);
$this->assertIsArray($result);

foreach ($result['values'] as $key => $domain) {
if ($key == 'version') {
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/api/v3/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public function testCreateEmailPrimaryHandlingChangeExisting($version) {
public function testCreateEmailWithoutEmail($version) {
$this->_apiversion = $version;
$result = $this->callAPIFailure('Email', 'Create', ['contact_id' => 4]);
$this->assertContains('missing', $result['error_message']);
$this->assertContains('email', $result['error_message']);
$this->assertStringContainsString('missing', $result['error_message']);
$this->assertStringContainsString('email', $result['error_message']);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/api/v3/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -983,10 +983,10 @@ public function testBatchMergeEmailOnHold($onHold1, $onHold2, bool $merge, ?stri
public function getOnHoldSets(): array {
// Each row specifies: contact 1 on_hold, contact 2 on_hold, merge? (0 or 1),
return [
[0, 0, 1, NULL],
[0, 1, 0, "Email 2 (Work): 'batman@gotham.met' vs. 'batman@gotham.met\n(On Hold)'"],
[1, 0, 0, "Email 2 (Work): 'batman@gotham.met\n(On Hold)' vs. 'batman@gotham.met'"],
[1, 1, 1, NULL],
[0, 0, TRUE, NULL],
[0, 1, FALSE, "Email 2 (Work): 'batman@gotham.met' vs. 'batman@gotham.met\n(On Hold)'"],
[1, 0, FALSE, "Email 2 (Work): 'batman@gotham.met\n(On Hold)' vs. 'batman@gotham.met'"],
[1, 1, TRUE, NULL],
];
}

Expand Down
18 changes: 9 additions & 9 deletions tests/phpunit/api/v3/LoggingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function testUpdateLogTableHookINNODB() {
$this->hookClass->setHook('civicrm_alterLogTables', [$this, 'innodbLogTableSpecNewIndex']);
$this->callAPISuccess('System', 'updatelogtables', []);
$this->checkINNODBLogTableCreated();
$this->assertContains('KEY `index_log_user_id` (`log_user_id`)', $this->checkLogTableCreated());
$this->assertStringContainsString('KEY `index_log_user_id` (`log_user_id`)', $this->checkLogTableCreated());
}

/**
Expand All @@ -165,7 +165,7 @@ public function testRebuildTriggerAfterSchemaChange() {
$this->assertTrue($this->checkColumnExistsInTable('log_' . $table, 'temp_col'), 'log_' . $table . ' has temp_col');
$dao = CRM_Core_DAO::executeQuery("SHOW TRIGGERS LIKE '{$table}'");
while ($dao->fetch()) {
$this->assertContains('temp_col', $dao->Statement);
$this->assertStringContainsString('temp_col', $dao->Statement);
}
}
CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_acl DROP column temp_col");
Expand Down Expand Up @@ -216,8 +216,8 @@ protected function checkLogTableCreated() {
$dao->fetch();
$this->assertEquals('log_civicrm_contact', $dao->Table);
$tableField = 'Create_Table';
$this->assertContains('`log_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,', $dao->$tableField);
$this->assertContains('`log_conn_id` varchar(17)', $dao->$tableField);
$this->assertStringContainsString('`log_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,', $dao->$tableField);
$this->assertStringContainsString('`log_conn_id` varchar(17)', $dao->$tableField);
return $dao->$tableField;
}

Expand All @@ -226,9 +226,9 @@ protected function checkLogTableCreated() {
*/
protected function checkINNODBLogTableCreated() {
$createTableString = $this->checkLogTableCreated();
$this->assertContains('ENGINE=InnoDB', $createTableString);
$this->assertContains('ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4', $createTableString);
$this->assertContains('KEY `index_id` (`id`),', $createTableString);
$this->assertStringContainsString('ENGINE=InnoDB', $createTableString);
$this->assertStringContainsString('ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4', $createTableString);
$this->assertStringContainsString('KEY `index_id` (`id`),', $createTableString);
}

/**
Expand All @@ -242,10 +242,10 @@ protected function checkTriggersCreated($unique) {
while ($dao->fetch()) {
if ($dao->Timing == 'After') {
if ($unique) {
$this->assertContains('@uniqueID', $dao->Statement);
$this->assertStringContainsString('@uniqueID', $dao->Statement);
}
else {
$this->assertContains('CONNECTION_ID()', $dao->Statement);
$this->assertStringContainsString('CONNECTION_ID()', $dao->Statement);
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions tests/phpunit/api/v3/MailingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ public function testMailerPreview() {
$baseurl = CRM_Utils_System::baseCMSURL();
$previewResult = $result['values'][$result['id']]['api.Mailing.preview'];
$this->assertEquals("Hello $displayName", $previewResult['values']['subject']);
$this->assertContains("This is $displayName", $previewResult['values']['body_text']);
$this->assertContains("<p>This is $displayName.</p>", $previewResult['values']['body_html']);
$this->assertContains('<a href="' . $baseurl . 'index.php?q=civicrm/mailing/forward&amp;amp;reset=1&amp;jid=&amp;qid=&amp;h=">Forward this email with no protocol</a>', $previewResult['values']['body_html']);
$this->assertNotContains("http://http://", $previewResult['values']['body_html']);
$this->assertStringContainsString("This is $displayName", $previewResult['values']['body_text']);
$this->assertStringContainsString("<p>This is $displayName.</p>", $previewResult['values']['body_html']);
$this->assertStringContainsString('<a href="' . $baseurl . 'index.php?q=civicrm/mailing/forward&amp;amp;reset=1&amp;jid=&amp;qid=&amp;h=">Forward this email with no protocol</a>', $previewResult['values']['body_html']);
$this->assertStringNotContainsString("http://http://", $previewResult['values']['body_html']);
}

public function testMailerPreviewUnknownContact() {
Expand All @@ -308,8 +308,8 @@ public function testMailerPreviewUnknownContact() {
// for the current behavior (i.e. returning blanks).
$previewResult = $result['values'][$result['id']]['api.Mailing.preview'];
$this->assertEquals("Hello ", $previewResult['values']['subject']);
$this->assertContains("This is .", $previewResult['values']['body_text']);
$this->assertContains("<p>This is .</p>", $previewResult['values']['body_html']);
$this->assertStringContainsString("This is .", $previewResult['values']['body_text']);
$this->assertStringContainsString("<p>This is .</p>", $previewResult['values']['body_html']);
}

public function testMailerPreviewRecipients() {
Expand Down Expand Up @@ -846,7 +846,7 @@ public function testClone() {
$cloneId = $clone['id'];

$this->assertNotEquals($createId, $cloneId, 'Create and clone should return different records');
$this->assertInternalType('numeric', $cloneId);
$this->assertIsNumeric($cloneId);

$this->assertNotEmpty($clone['values'][$cloneId]['subject']);
$this->assertEquals($params['subject'], $clone['values'][$cloneId]['subject'], "Cloned subject should match");
Expand Down Expand Up @@ -961,7 +961,7 @@ public function testMailerForwardWrongParams() {
public function createDraftMailing($params = []) {
$createParams = array_merge($this->_params, $params);
$createResult = $this->callAPISuccess('mailing', 'create', $createParams, __FUNCTION__, __FILE__);
$this->assertInternalType('numeric', $createResult['id']);
$this->assertIsNumeric($createResult['id']);
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', [
1 => [$createResult['id'], 'Integer'],
]);
Expand Down Expand Up @@ -992,13 +992,13 @@ public function testUrlWithMissingTrackingHash() {
$this->assertTrue($dao->fetch());

$url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($dao->queue_id, $dao->url_id);
$this->assertContains('https://civicrm.org', $url);
$this->assertStringContainsString('https://civicrm.org', $url);

// Now delete the event queue hashes and see if the tracking still works.
CRM_Core_DAO::executeQuery('DELETE FROM civicrm_mailing_event_queue');

$url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($dao->queue_id, $dao->url_id);
$this->assertContains('https://civicrm.org', $url);
$this->assertStringContainsString('https://civicrm.org', $url);

// Ensure that Google CSS link is not tracked.
$sql = "SELECT id FROM civicrm_mailing_trackable_url where url = 'https://fonts.googleapis.com/css?family=Roboto+Condensed:400,700|Zilla+Slab:500,700'";
Expand Down Expand Up @@ -1028,13 +1028,13 @@ public function testTrackableURLWithUnicodeSign() {
$this->assertTrue($dao->fetch());

$url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($dao->queue_id, $dao->url_id);
$this->assertContains($unicodeURL, $url);
$this->assertStringContainsString($unicodeURL, $url);

// Now delete the event queue hashes and see if the tracking still works.
CRM_Core_DAO::executeQuery('DELETE FROM civicrm_mailing_event_queue');

$url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($dao->queue_id, $dao->url_id);
$this->assertContains($unicodeURL, $url);
$this->assertStringContainsString($unicodeURL, $url);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/api/v3/PaymentProcessorTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testPaymentProcessorTypeCreateWithoutName($version) {
'is_active' => 1,
];
$result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams);
$this->assertContains('name, title, class_name, billing_mode', $result['error_message']);
$this->assertStringContainsString('name, title, class_name, billing_mode', $result['error_message']);
}

/**
Expand Down Expand Up @@ -155,7 +155,7 @@ public function testPaymentProcessorTypeUpdateEmpty($version) {
$this->_apiversion = $version;
$params = [];
$result = $this->callAPIFailure('PaymentProcessorType', 'create', $params);
$this->assertContains('name, title, class_name, billing_mode', $result['error_message']);
$this->assertStringContainsString('name, title, class_name, billing_mode', $result['error_message']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/PledgePaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public function testDeletePledgePayment() {

public function testGetFields() {
$result = $this->callAPISuccess('PledgePayment', 'GetFields', []);
$this->assertType('array', $result);
$this->assertIsArray($result);
}

}
4 changes: 2 additions & 2 deletions tests/phpunit/api/v3/RelationshipTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ public function testRelationshipTypeUpdateEmpty($version) {
$this->_apiversion = $version;
$params = [];
$result = $this->callAPIFailure('relationship_type', 'create', $params);
$this->assertContains('name_a_b', $result['error_message']);
$this->assertContains('name_b_a', $result['error_message']);
$this->assertStringContainsString('name_a_b', $result['error_message']);
$this->assertStringContainsString('name_b_a', $result['error_message']);
}

/**
Expand Down
Loading

0 comments on commit 8e1366e

Please sign in to comment.