From: Aryeh Gregor Date: Mon, 8 Oct 2018 10:42:20 +0000 (+0300) Subject: Improve ApiFormatJson test coverage X-Git-Tag: 1.34.0-rc.0~3867^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=edb52e7338ae6e4ac02f6fb61123c74905474837;p=lhc%2Fweb%2Fwiklou.git 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 --- 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 ); }