MDL-67673 phpunit: Remove deprecated assertArraySubset()
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Sun, 2 Aug 2020 11:43:32 +0000 (13:43 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 21 Oct 2020 10:46:05 +0000 (12:46 +0200)
While this is not strictly required, because removal will
happen in PHPUnit 9.0, we are already getting rid of all
uses in core.

From release notes:https://phpunit.de/announcements/phpunit-8.html

assertArraySubset() is deprecated and will be removed in PHPUnit 9.

lib/tests/accesslib_test.php
mod/forum/tests/grades_gradeitems_test.php

index 568db66..42d147a 100644 (file)
@@ -3567,9 +3567,12 @@ class core_accesslib_testcase extends advanced_testcase {
     protected function assert_capability_list_contains($expected, $actual) {
         $actualnames = [];
         foreach ($actual as $cap) {
     protected function assert_capability_list_contains($expected, $actual) {
         $actualnames = [];
         foreach ($actual as $cap) {
-            $actualnames[$cap->name] = $cap->name;
+            $actualnames[] = $cap->name;
+        }
+        // Verify each expected element exists.
+        foreach ($expected as $key => $value) {
+            $this->assertContains($value, $actualnames);
         }
         }
-        $this->assertArraySubset(array_combine($expected, $expected), $actualnames);
     }
 
     /**
     }
 
     /**
index 40df165..b68c84c 100644 (file)
@@ -48,8 +48,12 @@ class gradeitems_test extends advanced_testcase {
         $mappings = component_gradeitems::get_itemname_mapping_for_component('mod_forum');
         $this->assertIsArray($mappings);
         $this->assertCount(2, $mappings);
         $mappings = component_gradeitems::get_itemname_mapping_for_component('mod_forum');
         $this->assertIsArray($mappings);
         $this->assertCount(2, $mappings);
-        $this->assertArraySubset([0 => 'rating'], $mappings);
-        $this->assertArraySubset([1 => 'forum'], $mappings);
+        $expected = [0 => 'rating', 1 => 'forum'];
+        // Verify each expected element exists and its value matches.
+        foreach ($expected as $key => $value) {
+            $this->assertArrayHasKey($key, $mappings);
+            $this->assertSame($value, $mappings[$key]);
+        }
     }
 
     /**
     }
 
     /**