MDL-67353 favourites: Random DB id matching solved

Depending on the tests executed it was possible to arrive
to favourites tests with 2 "concepts" (say userid and contextid,
or userid and itemid) having the same ID.

Then, the array_diff() operations used by some mock stuff in the
tests wrongly was returning matches by value, ultimately causing
the test to fail.

Now, the matching is performed using array_diff_assoc() that takes
keys into considation when performing the match.
This commit is contained in:
Eloy Lafuente (stronk7)
2020-01-30 12:41:04 +08:00
committed by Jun Pataleta
parent b2e08b7caa
commit 89a4d27f34
2 changed files with 9 additions and 9 deletions
@@ -88,7 +88,7 @@ class component_favourite_service_testcase extends advanced_testcase {
// Check the mockstore for all objects with properties matching the key => val pairs in $criteria.
foreach ($mockstore as $index => $mockrow) {
$mockrowarr = (array)$mockrow;
if (array_diff($criteria, $mockrowarr) == []) {
if (array_diff_assoc($criteria, $mockrowarr) == []) {
$returns[$index] = $mockrow;
}
}
@@ -107,7 +107,7 @@ class component_favourite_service_testcase extends advanced_testcase {
$crit = ['userid' => $userid, 'component' => $comp, 'itemtype' => $type, 'itemid' => $id, 'contextid' => $ctxid];
foreach ($mockstore as $fakerow) {
$fakerowarr = (array)$fakerow;
if (array_diff($crit, $fakerowarr) == []) {
if (array_diff_assoc($crit, $fakerowarr) == []) {
return $fakerow;
}
}
@@ -133,7 +133,7 @@ class component_favourite_service_testcase extends advanced_testcase {
// Check the mockstore for all objects with properties matching the key => val pairs in $criteria.
foreach ($mockstore as $index => $mockrow) {
$mockrowarr = (array)$mockrow;
if (array_diff($criteria, $mockrowarr) == []) {
if (array_diff_assoc($criteria, $mockrowarr) == []) {
$count++;
}
}
@@ -156,7 +156,7 @@ class component_favourite_service_testcase extends advanced_testcase {
// Check the mockstore for all objects with properties matching the key => val pairs in $criteria.
foreach ($mockstore as $index => $mockrow) {
$mockrowarr = (array)$mockrow;
if (array_diff($criteria, $mockrowarr) == []) {
if (array_diff_assoc($criteria, $mockrowarr) == []) {
unset($mockstore[$index]);
}
}
@@ -169,7 +169,7 @@ class component_favourite_service_testcase extends advanced_testcase {
foreach ($mockstore as $index => $mockrow) {
$mockrowarr = (array)$mockrow;
echo "Here";
if (array_diff($criteria, $mockrowarr) == []) {
if (array_diff_assoc($criteria, $mockrowarr) == []) {
return true;
}
}
@@ -88,7 +88,7 @@ class user_favourite_service_testcase extends advanced_testcase {
// Check the mockstore for all objects with properties matching the key => val pairs in $criteria.
foreach ($mockstore as $index => $mockrow) {
$mockrowarr = (array)$mockrow;
if (array_diff($criteria, $mockrowarr) == []) {
if (array_diff_assoc($criteria, $mockrowarr) == []) {
$returns[$index] = $mockrow;
}
}
@@ -107,7 +107,7 @@ class user_favourite_service_testcase extends advanced_testcase {
$crit = ['userid' => $userid, 'component' => $comp, 'itemtype' => $type, 'itemid' => $id, 'contextid' => $ctxid];
foreach ($mockstore as $fakerow) {
$fakerowarr = (array)$fakerow;
if (array_diff($crit, $fakerowarr) == []) {
if (array_diff_assoc($crit, $fakerowarr) == []) {
return $fakerow;
}
}
@@ -133,7 +133,7 @@ class user_favourite_service_testcase extends advanced_testcase {
// Check the mockstore for all objects with properties matching the key => val pairs in $criteria.
foreach ($mockstore as $index => $mockrow) {
$mockrowarr = (array)$mockrow;
if (array_diff($criteria, $mockrowarr) == []) {
if (array_diff_assoc($criteria, $mockrowarr) == []) {
$count++;
}
}
@@ -156,7 +156,7 @@ class user_favourite_service_testcase extends advanced_testcase {
// Check the mockstore for all objects with properties matching the key => val pairs in $criteria.
foreach ($mockstore as $index => $mockrow) {
$mockrowarr = (array)$mockrow;
if (array_diff($criteria, $mockrowarr) == []) {
if (array_diff_assoc($criteria, $mockrowarr) == []) {
return true;
}
}