From 08e2d254385c36a28d4b1db21434b9022005597d Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Mon, 27 Mar 2023 21:04:26 +0000 Subject: [PATCH] remove camspiers/json-pretty and indent json in jsonapi tests using a regex, fixes #2470 Closes #2470 Merge request studip/studip!1666 --- composer.json | 1 - composer.lock | 43 +------------------------------ tests/_support/Helper/Jsonapi.php | 8 ++++-- 3 files changed, 7 insertions(+), 45 deletions(-) diff --git a/composer.json b/composer.json index c117f278998..70725412420 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,6 @@ }, "require-dev": { "adlawson/vfs": "~0.12.1", - "camspiers/json-pretty": "~1.0.2", "php-http/curl-client": "~1.7.0", "woohoolabs/yang": "2.3.2", "codeception/codeception": "^4.2", diff --git a/composer.lock b/composer.lock index 38dd4759083..d9dc6237935 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4b87251e3dbe4f1e9674d2cab3ebfe02", + "content-hash": "4b5b02516381975e2210afd87a34a165", "packages": [ { "name": "algo26-matthias/idna-convert", @@ -4402,47 +4402,6 @@ }, "time": "2021-10-12T13:05:09+00:00" }, - { - "name": "camspiers/json-pretty", - "version": "1.0.2", - "source": { - "type": "git", - "url": "https://github.com/camspiers/json-pretty.git", - "reference": "17be37cb83af8014658da48fa0012604179039a7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/camspiers/json-pretty/zipball/17be37cb83af8014658da48fa0012604179039a7", - "reference": "17be37cb83af8014658da48fa0012604179039a7", - "shasum": "" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "autoload": { - "psr-0": { - "Camspiers": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Cam Spiers", - "email": "cameron@heyday.co.nz" - } - ], - "description": "Provides support for json pretty printing", - "support": { - "issues": "https://github.com/camspiers/json-pretty/issues", - "source": "https://github.com/camspiers/json-pretty/tree/master" - }, - "abandoned": true, - "time": "2016-02-06T01:25:58+00:00" - }, { "name": "clue/stream-filter", "version": "v1.6.0", diff --git a/tests/_support/Helper/Jsonapi.php b/tests/_support/Helper/Jsonapi.php index e435cad1c72..93750d979c5 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)) { -- GitLab