aboutsummaryrefslogtreecommitdiff
path: root/tests/_support/Helper/Jsonapi.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2023-03-27 21:04:26 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2023-03-27 21:04:26 +0000
commit08e2d254385c36a28d4b1db21434b9022005597d (patch)
tree55d6f08b7387f58f74bf0a246abcfd0cc5ca72e2 /tests/_support/Helper/Jsonapi.php
parentf466ba75f9b410d9e0e2944a2b20b6c0aeb5820f (diff)
remove camspiers/json-pretty and indent json in jsonapi tests using a regex, fixes #2470
Closes #2470 Merge request studip/studip!1666
Diffstat (limited to 'tests/_support/Helper/Jsonapi.php')
-rw-r--r--tests/_support/Helper/Jsonapi.php8
1 files changed, 6 insertions, 2 deletions
diff --git a/tests/_support/Helper/Jsonapi.php b/tests/_support/Helper/Jsonapi.php
index e435cad..93750d9 100644
--- a/tests/_support/Helper/Jsonapi.php
+++ b/tests/_support/Helper/Jsonapi.php
@@ -203,8 +203,12 @@ class Jsonapi extends \Codeception\Module
}
}
- $jsonPretty = new \Camspiers\JsonPretty\JsonPretty();
- $json = $jsonPretty->prettify($jsonBody, JSON_UNESCAPED_SLASHES, ' ');
+ $json = json_encode($jsonBody, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
+
+ // This converts the default indentation of 4 spaces to 2 spaces
+ $json = preg_replace_callback('/^( +)(?=\S)/m', function ($match) {
+ return str_pad('', strlen($match[1]) / 2, ' ');
+ }, $json);
$dirname = codecept_output_dir() . 'json-for-slate/';
if (!file_exists($dirname)) {