wiki.techinc.nl/tests/phpunit/includes/api/format/ApiFormatDumpTest.php
Brad Jorsch 39703e9318 Improve testing for ApiFormatBase subclasses
I7b37295e is going to be changing around how ApiResult works,
which is going to need corresponding changes in the formatters. So it
would probably be a good idea to have a decent starting point to catch
any breakage. The non-backwards-compatible changes to ApiFormatTestBase
shouldn't be a concern, as no extensions in Gerrit reference this class
or any /ApiFormat.*Test/ class.

This also fixes two small bugs in ApiFormatWddx (null handling and
spacing for non-fm slow path) discovered during testing, and works
around some HHVM wddx extension bugs.

Bug: T85236
Change-Id: I9cdf896e7070ed51e42625d61609ad9ef91cd567
2014-12-23 14:55:23 -05:00

46 lines
1.9 KiB
PHP

<?php
/**
* @group API
* @covers ApiFormatDump
*/
class ApiFormatDumpTest extends ApiFormatTestBase {
protected $printerName = 'dump';
public static function provideGeneralEncoding() {
// Sigh. Docs claim it's a boolean, but can have values 0, 1, or 2.
// Fortunately wfIniGetBool does the right thing.
if ( wfIniGetBool( 'xdebug.overload_var_dump' ) ) {
return array(
array( array(), 'Cannot test ApiFormatDump when xDebug overloads var_dump', array( 'SKIP' => true ) ),
);
}
$warning = "\n [\"warnings\"]=>\n array(1) {\n [\"dump\"]=>\n array(1) {\n [\"*\"]=>\n" .
" string(64) \"format=dump has been deprecated. Please use format=json instead.\"\n" .
" }\n }";
return array(
// Basic types
array( array( null ), "array(2) {{$warning}\n [0]=>\n NULL\n}\n" ),
array( array( true ), "array(2) {{$warning}\n [0]=>\n bool(true)\n}\n" ),
array( array( false ), "array(2) {{$warning}\n [0]=>\n bool(false)\n}\n" ),
array( array( 42 ), "array(2) {{$warning}\n [0]=>\n int(42)\n}\n" ),
array( array( 42.5 ), "array(2) {{$warning}\n [0]=>\n float(42.5)\n}\n" ),
array( array( 1e42 ), "array(2) {{$warning}\n [0]=>\n float(1.0E+42)\n}\n" ),
array( array( 'foo' ), "array(2) {{$warning}\n [0]=>\n string(3) \"foo\"\n}\n" ),
array( array( 'fóo' ), "array(2) {{$warning}\n [0]=>\n string(4) \"fóo\"\n}\n" ),
// Arrays
array( array( array() ), "array(2) {{$warning}\n [0]=>\n array(0) {\n }\n}\n" ),
array( array( array( 1 ) ), "array(2) {{$warning}\n [0]=>\n array(1) {\n [0]=>\n int(1)\n }\n}\n" ),
array( array( array( 'x' => 1 ) ), "array(2) {{$warning}\n [0]=>\n array(1) {\n [\"x\"]=>\n int(1)\n }\n}\n" ),
array( array( array( 2 => 1 ) ), "array(2) {{$warning}\n [0]=>\n array(1) {\n [2]=>\n int(1)\n }\n}\n" ),
// Content
array( array( '*' => 'foo' ), "array(2) {{$warning}\n [\"*\"]=>\n string(3) \"foo\"\n}\n" ),
);
}
}