Skip to content

Commit

Permalink
[ui-module] Added tabs to dashboards (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Aug 3, 2024
1 parent 3868711 commit 8c572d9
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion tests/tools/JsonAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public static function assertMatch(
$decodedExpectedJson = self::jsonDecode($expectedJson, 'Expected-json');
$decodedInput = self::jsonDecode($actualJson, 'Actual-json');

self::recursiveSort($decodedExpectedJson);
self::recursiveSort($decodedInput);

try {
TestCase::assertEquals($decodedExpectedJson, $decodedInput);

Expand Down Expand Up @@ -93,7 +96,58 @@ public static function jsonDecode(string $input, string $nameForMessage): array
*/
private static function makeJsonPretty(string $jsonString): string
{
return Utils\Json::encode(Utils\Json::decode($jsonString), Utils\Json::PRETTY);
return Utils\Json::encode(Utils\Json::decode($jsonString), pretty: true);
}

/**
* @throws Utils\JsonException
*/
private static function recursiveSort(mixed &$array): void
{
if (!is_array($array)) {
return;
}

foreach ($array as &$value) {
if (is_array($value)) {
self::recursiveSort($value);
}
}

// Sort by keys for associative arrays
if (self::isAssoc($array)) {
ksort($array);

} else {
// Sort by values for indexed arrays
usort($array, function ($a, $b): int {
if (is_array($a) && is_array($b)) {
return strcmp(Utils\Json::encode($a), Utils\Json::encode($b));
}

if (is_array($a)) {
return strcmp(Utils\Json::encode($a), strval($b));
}

if (is_array($b)) {
return strcmp(strval($a), Utils\Json::encode($b));
}

return strcmp(strval($a), strval($b));
});
}
}

/**
* @param array<mixed> $array
*
* @return bool
*/
private static function isAssoc(array $array): bool
{
if ($array === []) return false;

return array_keys($array) !== range(0, count($array) - 1);
}

}

0 comments on commit 8c572d9

Please sign in to comment.