Improve ApiFormatJson test coverage
authorAryeh Gregor <ayg@aryeh.name>
Mon, 8 Oct 2018 10:42:20 +0000 (13:42 +0300)
committerAryeh Gregor <ayg@aryeh.name>
Mon, 8 Oct 2018 10:42:20 +0000 (13:42 +0300)
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
tests/phpunit/includes/api/format/ApiFormatJsonTest.php

index 2f63faf..9dcde8f 100644 (file)
@@ -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 );
index 7eb2a35..2408518 100644 (file)
@@ -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
                );
        }