(dev/core#4188) Update APIv3 tests for phpunit9 compatibility
authorTim Otten <totten@civicrm.org>
Tue, 28 Mar 2023 23:42:21 +0000 (16:42 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 28 Mar 2023 23:42:21 +0000 (16:42 -0700)
These tests failed on `phpunit9` because upstream swapped out around the semantics of `assertContains()`.

The specific issue is whether an array like `["1","2","3"]` contains the value `2`.

* `assertContains()` in phpunit8 says yes.
* `assertContains()` in phpunit9 says no.
* `assertContainsEquals()` in both phpunit8+phpunit9 says yes.

tests/phpunit/api/v3/CaseTest.php
tests/phpunit/api/v3/ContactTest.php
tests/phpunit/api/v3/JobTest.php
tests/phpunit/api/v3/RelationshipTest.php

index 0af14d90f329a907052c07a54f9689b885a7f774..23cc82aeeb13965502e253d5bdf907a7f3cd1968 100644 (file)
@@ -492,7 +492,7 @@ class api_v3_CaseTest extends CiviCaseTestCase {
       'subject' => 'Test followup 123',
       'return' => ['case_id'],
     ]);
-    $this->assertContains($case['id'], $result['case_id']);
+    $this->assertContainsEquals($case['id'], $result['case_id']);
   }
 
   public function testCaseGetByStatus() {
index bc72dcc2fcdd7f200c11342fee12df5dbfa6c7e7..e3631bea742a7f3b6fdfe9ad2c1abf311de50018 100644 (file)
@@ -4553,7 +4553,7 @@ class api_v3_ContactTest extends CiviUnitTestCase {
     // Ensure they are shown as being in each created group.
     $contact_group_ids = explode(',', $contact_get['values'][$created_contact_id]['groups']);
     foreach ($created_group_ids as $created_group_id) {
-      $this->assertContains($created_group_id, $contact_group_ids);
+      $this->assertContainsEquals($created_group_id, $contact_group_ids);
     }
   }
 
index 72292b6a6e964e4bb4defb5460faf7c928bbbdf2..9e05e563bf68c6fe2ef7b3ef731f23767716ae91 100644 (file)
@@ -602,7 +602,7 @@ class api_v3_JobTest extends CiviUnitTestCase {
     foreach ($groupResult['values'] as $groupValues) {
       $this->assertEquals($contactID, $groupValues['contact_id']);
       $this->assertEquals('Added', $groupValues['status']);
-      $this->assertContains($groupValues['group_id'], $expectedGroups);
+      $this->assertContainsEquals($groupValues['group_id'], $expectedGroups);
 
     }
   }
index e34a143e3b7fac2c4f68a5ba889a530ac75d87af..d28887429bd45736ca984fa2dbf19d1765287a63 100644 (file)
@@ -1094,7 +1094,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase {
 
     $this->assertEquals(2, $result['count']);
     foreach ($result['values'] as $value) {
-      $this->assertContains($value['relationship_type_id'], [$this->relationshipTypeID, $relType3]);
+      $this->assertContainsEquals($value['relationship_type_id'], [$this->relationshipTypeID, $relType3]);
     }
   }
 
@@ -1202,7 +1202,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase {
     // although our contact has more than one relationship we have passed them in as contact_id_a & can't get reciprocal
     $this->assertEquals(1, $result['count']);
     foreach ($result['values'] as $key => $value) {
-      $this->assertContains($value['relationship_type_id'], [$relType1]);
+      $this->assertContainsEquals($value['relationship_type_id'], [$relType1]);
     }
   }