From edb52e7338ae6e4ac02f6fb61123c74905474837 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Mon, 8 Oct 2018 13:42:20 +0300 Subject: [PATCH] Improve ApiFormatJson test coverage The only thing missing is tests for the rawfm paths, which I don't understand well enough to test easily. Change-Id: I08779391798b9d2d5eeb7e19ec4764059336069c --- includes/api/ApiFormatJson.php | 2 ++ .../includes/api/format/ApiFormatJsonTest.php | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php index 2f63faffe8..9dcde8f32b 100644 --- a/includes/api/ApiFormatJson.php +++ b/includes/api/ApiFormatJson.php @@ -81,7 +81,9 @@ class ApiFormatJson extends ApiFormatBase { default: // Should have been caught during parameter validation + // @codeCoverageIgnoreStart $this->dieDebug( __METHOD__, 'Unknown value for \'formatversion\'' ); + // @codeCoverageIgnoreEnd } } $data = $this->getResult()->getResultData( null, $transform ); diff --git a/tests/phpunit/includes/api/format/ApiFormatJsonTest.php b/tests/phpunit/includes/api/format/ApiFormatJsonTest.php index 7eb2a35ecf..2408518356 100644 --- a/tests/phpunit/includes/api/format/ApiFormatJsonTest.php +++ b/tests/phpunit/includes/api/format/ApiFormatJsonTest.php @@ -9,14 +9,20 @@ class ApiFormatJsonTest extends ApiFormatTestBase { protected $printerName = 'json'; private static function addFormatVersion( $format, $arr ) { - foreach ( $arr as &$p ) { - if ( !isset( $p[2] ) ) { - $p[2] = [ 'formatversion' => $format ]; - } else { - $p[2]['formatversion'] = $format; + $ret = []; + foreach ( $arr as $val ) { + if ( !isset( $val[2] ) ) { + $val[2] = []; + } + $val[2]['formatversion'] = $format; + $ret[] = $val; + if ( $format === 2 ) { + // Add a test for 'latest' as well + $val[2]['formatversion'] = 'latest'; + $ret[] = $val; } } - return $arr; + return $ret; } public static function provideGeneralEncoding() { @@ -123,6 +129,7 @@ class ApiFormatJsonTest extends ApiFormatTestBase { // Cross-domain mangling [ [ '< Cross-Domain-Policy >' ], '["\u003C Cross-Domain-Policy >"]' ], ] ) + // @todo Test rawfm ); } -- 2.20.1