From 465168112cad62eed15bb1604eb56c44cbe106cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 12 Oct 2022 00:41:17 +0200 Subject: [PATCH] Use FormatJson helper for outputting pretty JSON for tests Identical output, fewer constants and regexps. Change-Id: I50fd536d9122ac91a7261660405219e19d974047 --- tests/phpunit/TestUtils.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/TestUtils.php b/tests/phpunit/TestUtils.php index 5ee688bb0..bccebef0a 100644 --- a/tests/phpunit/TestUtils.php +++ b/tests/phpunit/TestUtils.php @@ -2,6 +2,7 @@ namespace MediaWiki\Extension\DiscussionTools\Tests; +use FormatJson; use MediaWiki\Extension\DiscussionTools\CommentParser; use MediaWiki\MediaWikiServices; use Wikimedia\Parsoid\DOM\Document; @@ -77,9 +78,7 @@ trait TestUtils { * @param array $data */ protected static function overwriteJsonFile( string $relativePath, array $data ): void { - $json = json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); - // Tabs instead of 4 spaces - $json = preg_replace( '/(?:\G|^) {4}/m', "\t", $json ); + $json = FormatJson::encode( $data, "\t", FormatJson::ALL_OK ); file_put_contents( __DIR__ . '/' . $relativePath, $json . "\n" ); }