From a12620aa74972ff165d57cc2bdf26aeb213fa96d Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 22 May 2021 14:20:56 +1000 Subject: [PATCH] [NFC] Fix PHPUnit8 Deprecation Warnings in api_v3 and Civi Test Suites --- tests/phpunit/Civi/API/RequestTest.php | 2 +- tests/phpunit/Civi/Core/CiviFacadeTest.php | 2 +- tests/phpunit/Civi/Core/ResolverTest.php | 6 ++-- .../phpunit/Civi/Payment/PropertyBagTest.php | 17 ++++------ tests/phpunit/api/v3/ContactTest.php | 2 +- tests/phpunit/api/v3/DomainTest.php | 4 +-- tests/phpunit/api/v3/EmailTest.php | 4 +-- tests/phpunit/api/v3/JobTest.php | 8 ++--- tests/phpunit/api/v3/LoggingTest.php | 18 +++++----- tests/phpunit/api/v3/MailingTest.php | 24 ++++++------- .../api/v3/PaymentProcessorTypeTest.php | 4 +-- tests/phpunit/api/v3/PledgePaymentTest.php | 2 +- tests/phpunit/api/v3/RelationshipTypeTest.php | 4 +-- tests/phpunit/api/v3/ReportTemplateTest.php | 34 +++++++++---------- .../phpunit/api/v3/SyntaxConformanceTest.php | 16 ++++----- tests/phpunit/api/v3/UFJoinTest.php | 20 +++++------ 16 files changed, 81 insertions(+), 86 deletions(-) diff --git a/tests/phpunit/Civi/API/RequestTest.php b/tests/phpunit/Civi/API/RequestTest.php index 3434d2cad7..384d6bee05 100644 --- a/tests/phpunit/Civi/API/RequestTest.php +++ b/tests/phpunit/Civi/API/RequestTest.php @@ -58,13 +58,13 @@ class RequestTest extends \CiviUnitTestCase { /** * @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); } diff --git a/tests/phpunit/Civi/Core/CiviFacadeTest.php b/tests/phpunit/Civi/Core/CiviFacadeTest.php index 04503b7412..ef68482906 100644 --- a/tests/phpunit/Civi/Core/CiviFacadeTest.php +++ b/tests/phpunit/Civi/Core/CiviFacadeTest.php @@ -31,9 +31,9 @@ class CiviFacadeTest extends \CiviUnitTestCase { /** * Anonymous users don't have a SettingsBag. - * @expectedException \CRM_Core_Exception */ public function testContactSettings_anonFail() { + $this->expectException(\CRM_Core_Exception::class); \Civi::contactSettings(); } diff --git a/tests/phpunit/Civi/Core/ResolverTest.php b/tests/phpunit/Civi/Core/ResolverTest.php index 67a7ef5da4..3a4a4373fb 100644 --- a/tests/phpunit/Civi/Core/ResolverTest.php +++ b/tests/phpunit/Civi/Core/ResolverTest.php @@ -85,10 +85,9 @@ namespace Civi\Core { /** * 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'); } @@ -123,10 +122,9 @@ namespace Civi\Core { /** * 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'); } diff --git a/tests/phpunit/Civi/Payment/PropertyBagTest.php b/tests/phpunit/Civi/Payment/PropertyBagTest.php index 892fec2254..38443283df 100644 --- a/tests/phpunit/Civi/Payment/PropertyBagTest.php +++ b/tests/phpunit/Civi/Payment/PropertyBagTest.php @@ -33,7 +33,7 @@ class PropertyBagTest extends \PHPUnit\Framework\TestCase implements HeadlessInt // (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 @@ -70,7 +70,7 @@ class PropertyBagTest extends \PHPUnit\Framework\TestCase implements HeadlessInt throw $e; } $got = $propertyBag->getAmount(); - $this->assertInternalType('string', $got); + $this->assertIsString($got); $this->assertEquals($expect, $got); } @@ -96,10 +96,9 @@ class PropertyBagTest extends \PHPUnit\Framework\TestCase implements HeadlessInt /** * Test we cannot set an invalid contact ID. - * - * @expectedException \InvalidArgumentException */ public function testSetContactIDFailsIfInvalid() { + $this->expectException(\InvalidArgumentException::class); $propertyBag = new PropertyBag(); $propertyBag->setContactID(0); } @@ -225,11 +224,10 @@ class PropertyBagTest extends \PHPUnit\Framework\TestCase implements HeadlessInt /** * 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); } @@ -238,11 +236,10 @@ class PropertyBagTest extends \PHPUnit\Framework\TestCase implements HeadlessInt * 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. diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 62cf5b7b04..f4c4b40c5a 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -3099,7 +3099,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { $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); diff --git a/tests/phpunit/api/v3/DomainTest.php b/tests/phpunit/api/v3/DomainTest.php index becd5c235e..3f1f65aa58 100644 --- a/tests/phpunit/api/v3/DomainTest.php +++ b/tests/phpunit/api/v3/DomainTest.php @@ -81,7 +81,7 @@ class api_v3_DomainTest extends CiviUnitTestCase { $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']); @@ -107,7 +107,7 @@ class api_v3_DomainTest extends CiviUnitTestCase { $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') { diff --git a/tests/phpunit/api/v3/EmailTest.php b/tests/phpunit/api/v3/EmailTest.php index 549e6ba1fc..65bbb3377a 100644 --- a/tests/phpunit/api/v3/EmailTest.php +++ b/tests/phpunit/api/v3/EmailTest.php @@ -135,8 +135,8 @@ class api_v3_EmailTest extends CiviUnitTestCase { 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']); } /** diff --git a/tests/phpunit/api/v3/JobTest.php b/tests/phpunit/api/v3/JobTest.php index 781773a59b..ef77a10a56 100644 --- a/tests/phpunit/api/v3/JobTest.php +++ b/tests/phpunit/api/v3/JobTest.php @@ -983,10 +983,10 @@ class api_v3_JobTest extends CiviUnitTestCase { 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], ]; } diff --git a/tests/phpunit/api/v3/LoggingTest.php b/tests/phpunit/api/v3/LoggingTest.php index a25dbb863f..5e467d118d 100644 --- a/tests/phpunit/api/v3/LoggingTest.php +++ b/tests/phpunit/api/v3/LoggingTest.php @@ -145,7 +145,7 @@ class api_v3_LoggingTest extends CiviUnitTestCase { $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()); } /** @@ -165,7 +165,7 @@ class api_v3_LoggingTest extends CiviUnitTestCase { $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"); @@ -216,8 +216,8 @@ class api_v3_LoggingTest extends CiviUnitTestCase { $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; } @@ -226,9 +226,9 @@ class api_v3_LoggingTest extends CiviUnitTestCase { */ 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); } /** @@ -242,10 +242,10 @@ class api_v3_LoggingTest extends CiviUnitTestCase { 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); } } } diff --git a/tests/phpunit/api/v3/MailingTest.php b/tests/phpunit/api/v3/MailingTest.php index f2e325fe80..bc79443ade 100644 --- a/tests/phpunit/api/v3/MailingTest.php +++ b/tests/phpunit/api/v3/MailingTest.php @@ -289,10 +289,10 @@ class api_v3_MailingTest extends CiviUnitTestCase { $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("

This is $displayName.

", $previewResult['values']['body_html']); - $this->assertContains('Forward this email with no protocol', $previewResult['values']['body_html']); - $this->assertNotContains("http://http://", $previewResult['values']['body_html']); + $this->assertStringContainsString("This is $displayName", $previewResult['values']['body_text']); + $this->assertStringContainsString("

This is $displayName.

", $previewResult['values']['body_html']); + $this->assertStringContainsString('Forward this email with no protocol', $previewResult['values']['body_html']); + $this->assertStringNotContainsString("http://http://", $previewResult['values']['body_html']); } public function testMailerPreviewUnknownContact() { @@ -308,8 +308,8 @@ class api_v3_MailingTest extends CiviUnitTestCase { // 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("

This is .

", $previewResult['values']['body_html']); + $this->assertStringContainsString("This is .", $previewResult['values']['body_text']); + $this->assertStringContainsString("

This is .

", $previewResult['values']['body_html']); } public function testMailerPreviewRecipients() { @@ -846,7 +846,7 @@ SELECT event_queue_id, time_stamp FROM {$temporaryTableName}"; $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"); @@ -961,7 +961,7 @@ SELECT event_queue_id, time_stamp FROM {$temporaryTableName}"; 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'], ]); @@ -992,13 +992,13 @@ SELECT event_queue_id, time_stamp FROM {$temporaryTableName}"; $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'"; @@ -1028,13 +1028,13 @@ SELECT event_queue_id, time_stamp FROM {$temporaryTableName}"; $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); } /** diff --git a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php index 0b880963da..165c5b8043 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php @@ -43,7 +43,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { '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']); } /** @@ -155,7 +155,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { $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']); } /** diff --git a/tests/phpunit/api/v3/PledgePaymentTest.php b/tests/phpunit/api/v3/PledgePaymentTest.php index 4f1afba6c7..09bced8d99 100644 --- a/tests/phpunit/api/v3/PledgePaymentTest.php +++ b/tests/phpunit/api/v3/PledgePaymentTest.php @@ -345,7 +345,7 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { public function testGetFields() { $result = $this->callAPISuccess('PledgePayment', 'GetFields', []); - $this->assertType('array', $result); + $this->assertIsArray($result); } } diff --git a/tests/phpunit/api/v3/RelationshipTypeTest.php b/tests/phpunit/api/v3/RelationshipTypeTest.php index db1716cc2c..0548a97a24 100644 --- a/tests/phpunit/api/v3/RelationshipTypeTest.php +++ b/tests/phpunit/api/v3/RelationshipTypeTest.php @@ -156,8 +156,8 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { $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']); } /** diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index 02a1202dbe..a4f75257fb 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -52,7 +52,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $this->assertAPISuccess($result); $this->assertEquals(1, $result['count']); $entityId = $result['id']; - $this->assertInternalType('numeric', $entityId); + $this->assertIsNumeric($entityId); $this->assertEquals(7, $result['values'][$entityId]['component_id']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "CRM_Report_Form_Examplez" @@ -505,7 +505,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { GROUP BY contact_civireport.id'); // Exclude whitespace in comparison as we don't care if it changes & this allows us to make the above readable. $whitespacelessSql = preg_replace('/\s+/', ' ', $rows['metadata']['sql'][0]); - $this->assertContains($expected, $whitespacelessSql); + $this->assertStringContainsString($expected, $whitespacelessSql); } /** @@ -718,9 +718,9 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'options' => ['metadata' => ['sql']], ]; $rowsSql = $this->callAPISuccess('report_template', 'getrows', $params)['metadata']['sql']; - $this->assertContains('GROUP BY contribution_civireport.contribution_status_id WITH ROLLUP', $rowsSql[0]); + $this->assertStringContainsString('GROUP BY contribution_civireport.contribution_status_id WITH ROLLUP', $rowsSql[0]); $statsSql = $this->callAPISuccess('report_template', 'getstatistics', $params)['metadata']['sql']; - $this->assertContains('GROUP BY contribution_civireport.contribution_status_id, currency', $statsSql[2]); + $this->assertStringContainsString('GROUP BY contribution_civireport.contribution_status_id, currency', $statsSql[2]); } /** @@ -737,9 +737,9 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'options' => ['metadata' => ['sql']], ]; $rowsSql = $this->callAPISuccess('report_template', 'getrows', $params)['metadata']['sql']; - $this->assertContains('GROUP BY YEAR(contribution_civireport.receive_date) WITH ROLLUP', $rowsSql[0]); + $this->assertStringContainsString('GROUP BY YEAR(contribution_civireport.receive_date) WITH ROLLUP', $rowsSql[0]); $statsSql = $this->callAPISuccess('report_template', 'getstatistics', $params)['metadata']['sql']; - $this->assertContains('GROUP BY YEAR(contribution_civireport.receive_date), currency', $statsSql[2]); + $this->assertStringContainsString('GROUP BY YEAR(contribution_civireport.receive_date), currency', $statsSql[2]); } /** @@ -756,9 +756,9 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'options' => ['metadata' => ['sql']], ]; $rowsSql = $this->callAPISuccess('report_template', 'getrows', $params)['metadata']['sql']; - $this->assertContains('GROUP BY YEAR(contribution_civireport.receive_date), QUARTER(contribution_civireport.receive_date) WITH ROLLUP', $rowsSql[0]); + $this->assertStringContainsString('GROUP BY YEAR(contribution_civireport.receive_date), QUARTER(contribution_civireport.receive_date) WITH ROLLUP', $rowsSql[0]); $statsSql = $this->callAPISuccess('report_template', 'getstatistics', $params)['metadata']['sql']; - $this->assertContains('GROUP BY YEAR(contribution_civireport.receive_date), QUARTER(contribution_civireport.receive_date), currency', $statsSql[2]); + $this->assertStringContainsString('GROUP BY YEAR(contribution_civireport.receive_date), QUARTER(contribution_civireport.receive_date), currency', $statsSql[2]); } /** @@ -775,9 +775,9 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'options' => ['metadata' => ['sql']], ]; $rowsSql = $this->callAPISuccess('report_template', 'getrows', $params)['metadata']['sql']; - $this->assertContains('GROUP BY DATE(contribution_civireport.receive_date) WITH ROLLUP', $rowsSql[0]); + $this->assertStringContainsString('GROUP BY DATE(contribution_civireport.receive_date) WITH ROLLUP', $rowsSql[0]); $statsSql = $this->callAPISuccess('report_template', 'getstatistics', $params)['metadata']['sql']; - $this->assertContains('GROUP BY DATE(contribution_civireport.receive_date), currency', $statsSql[2]); + $this->assertStringContainsString('GROUP BY DATE(contribution_civireport.receive_date), currency', $statsSql[2]); } /** @@ -794,9 +794,9 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'options' => ['metadata' => ['sql']], ]; $rowsSql = $this->callAPISuccess('report_template', 'getrows', $params)['metadata']['sql']; - $this->assertContains('GROUP BY YEARWEEK(contribution_civireport.receive_date) WITH ROLLUP', $rowsSql[0]); + $this->assertStringContainsString('GROUP BY YEARWEEK(contribution_civireport.receive_date) WITH ROLLUP', $rowsSql[0]); $statsSql = $this->callAPISuccess('report_template', 'getstatistics', $params)['metadata']['sql']; - $this->assertContains('GROUP BY YEARWEEK(contribution_civireport.receive_date), currency', $statsSql[2]); + $this->assertStringContainsString('GROUP BY YEARWEEK(contribution_civireport.receive_date), currency', $statsSql[2]); } /** @@ -1153,13 +1153,13 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { case 'YEAR': // Year only contains one grouping. // Also note the extra space. - $this->assertContains('GROUP BY YEAR(activity_civireport.activity_date_time)', $rowsSql[1], "Failed for frequency $frequency"); - $this->assertContains('GROUP BY YEAR(activity_civireport.activity_date_time)', $statsSql[1], "Failed for frequency $frequency"); + $this->assertStringContainsString('GROUP BY YEAR(activity_civireport.activity_date_time)', $rowsSql[1], "Failed for frequency $frequency"); + $this->assertStringContainsString('GROUP BY YEAR(activity_civireport.activity_date_time)', $statsSql[1], "Failed for frequency $frequency"); break; default: - $this->assertContains("GROUP BY YEAR(activity_civireport.activity_date_time), {$frequency}(activity_civireport.activity_date_time)", $rowsSql[1], "Failed for frequency $frequency"); - $this->assertContains("GROUP BY YEAR(activity_civireport.activity_date_time), {$frequency}(activity_civireport.activity_date_time)", $statsSql[1], "Failed for frequency $frequency"); + $this->assertStringContainsString("GROUP BY YEAR(activity_civireport.activity_date_time), {$frequency}(activity_civireport.activity_date_time)", $rowsSql[1], "Failed for frequency $frequency"); + $this->assertStringContainsString("GROUP BY YEAR(activity_civireport.activity_date_time), {$frequency}(activity_civireport.activity_date_time)", $statsSql[1], "Failed for frequency $frequency"); break; } } @@ -1315,7 +1315,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'options' => ['metadata' => ['sql']], ]; $rows = $this->callAPISuccess('report_template', 'getrows', $params); - $this->assertContains("civicrm_contact_source.sort_name LIKE '%z%'", $rows['metadata']['sql'][3]); + $this->assertStringContainsString("civicrm_contact_source.sort_name LIKE '%z%'", $rows['metadata']['sql'][3]); } /** diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index bcc4326976..21a70740dd 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -788,7 +788,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { public function testNotImplemented_get($Entity) { $result = civicrm_api($Entity, 'Get', ['version' => 3]); $this->assertEquals(1, $result['is_error']); - // $this->assertContains("API ($Entity, Get) does not exist", $result['error_message']); + // $this->assertStringContainsString("API ($Entity, Get) does not exist", $result['error_message']); $this->assertRegExp('/API (.*) does not exist/', $result['error_message']); } @@ -820,7 +820,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { } $result = civicrm_api($Entity, 'Get', []); $this->assertEquals(1, $result['is_error']); - $this->assertContains("Unknown api version", $result['error_message']); + $this->assertStringContainsString("Unknown api version", $result['error_message']); } /** @@ -836,9 +836,9 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $result = civicrm_api($Entity, 'Get', ['version' => 3]); // @TODO: list the get that have mandatory params if ($result['is_error']) { - $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']); + $this->assertStringContainsString("Mandatory key(s) missing from params array", $result['error_message']); // either id or contact_id or entity_id is one of the field missing - $this->assertContains("id", $result['error_message']); + $this->assertStringContainsString("id", $result['error_message']); } else { $this->assertEquals(3, $result['version']); @@ -1236,15 +1236,15 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { public function testNotImplemented_create($Entity) { $result = civicrm_api($Entity, 'Create', ['version' => 3]); $this->assertEquals(1, $result['is_error']); - $this->assertContains(strtolower("API ($Entity, Create) does not exist"), strtolower($result['error_message'])); + $this->assertStringContainsString(strtolower("API ($Entity, Create) does not exist"), strtolower($result['error_message'])); } /** * @dataProvider entities - * @expectedException CiviCRM_API3_Exception * @param $Entity */ public function testWithoutParam_create($Entity) { + $this->expectException(CiviCRM_API3_Exception::class); if ($Entity === 'Setting') { $this->markTestSkipped('It seems OK for setting to skip here as it silently sips invalid params'); } @@ -1564,7 +1564,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { $nonExistantID = 151416349; $result = civicrm_api($Entity, 'Delete', ['version' => 3, 'id' => $nonExistantID]); $this->assertEquals(1, $result['is_error']); - $this->assertContains(strtolower("API ($Entity, Delete) does not exist"), strtolower($result['error_message'])); + $this->assertStringContainsString(strtolower("API ($Entity, Delete) does not exist"), strtolower($result['error_message'])); } /** @@ -1578,7 +1578,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { } $result = civicrm_api($Entity, 'Delete', []); $this->assertEquals(1, $result['is_error']); - $this->assertContains("Unknown api version", $result['error_message']); + $this->assertStringContainsString("Unknown api version", $result['error_message']); } /** diff --git a/tests/phpunit/api/v3/UFJoinTest.php b/tests/phpunit/api/v3/UFJoinTest.php index f7a76870f7..30581606f4 100644 --- a/tests/phpunit/api/v3/UFJoinTest.php +++ b/tests/phpunit/api/v3/UFJoinTest.php @@ -95,9 +95,9 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { 'is_active' => 1, ]; $result = $this->callAPIFailure('uf_join', 'create', $params); - $this->assertContains('Mandatory', $result['error_message']); - $this->assertContains('missing', $result['error_message']); - $this->assertContains('uf_group_id', $result['error_message']); + $this->assertStringContainsString('Mandatory', $result['error_message']); + $this->assertStringContainsString('missing', $result['error_message']); + $this->assertStringContainsString('uf_group_id', $result['error_message']); } /** @@ -167,10 +167,10 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { public function testFindUFJoinEmptyParams($version) { $this->_apiversion = $version; $result = $this->callAPIFailure('uf_join', 'create', []); - $this->assertContains('Mandatory', $result['error_message']); - $this->assertContains('missing', $result['error_message']); - $this->assertContains('module', $result['error_message']); - $this->assertContains('uf_group_id', $result['error_message']); + $this->assertStringContainsString('Mandatory', $result['error_message']); + $this->assertStringContainsString('missing', $result['error_message']); + $this->assertStringContainsString('module', $result['error_message']); + $this->assertStringContainsString('uf_group_id', $result['error_message']); } /** @@ -187,9 +187,9 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { 'is_active' => 1, ]; $result = $this->callAPIFailure('uf_join', 'create', $params); - $this->assertContains('Mandatory', $result['error_message']); - $this->assertContains('missing', $result['error_message']); - $this->assertContains('uf_group_id', $result['error_message']); + $this->assertStringContainsString('Mandatory', $result['error_message']); + $this->assertStringContainsString('missing', $result['error_message']); + $this->assertStringContainsString('uf_group_id', $result['error_message']); } /** -- 2.25.1