'Expected exception'
);
}
+ try {
+ ApiResult::setValue( $arr, null, $fh );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add resource(stream) to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
try {
$obj->file = $fh;
ApiResult::setValue( $arr, 'sub', $obj );
'Expected exception'
);
}
+ try {
+ $obj->file = $fh;
+ ApiResult::setValue( $arr, null, $obj );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add resource(stream) to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
fclose( $fh );
try {
'Expected exception'
);
}
+ try {
+ ApiResult::setValue( $arr, null, INF );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add non-finite floats to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
try {
ApiResult::setValue( $arr, 'nan', NAN );
$this->fail( 'Expected exception not thrown' );
'Expected exception'
);
}
+ try {
+ ApiResult::setValue( $arr, null, NAN );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add non-finite floats to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
$arr = array();
$result2 = new ApiResult( 8388608 );
ApiResult::setValue( $arr, 'foo', "foo\x80bar" );
ApiResult::setValue( $arr, 'bar', "a\xcc\x81" );
ApiResult::setValue( $arr, 'baz', 74 );
+ ApiResult::setValue( $arr, null, "foo\x80bar" );
+ ApiResult::setValue( $arr, null, "a\xcc\x81" );
$this->assertSame( array(
'foo' => "foo\xef\xbf\xbdbar",
'bar' => "\xc3\xa1",
'baz' => 74,
+ 0 => "foo\xef\xbf\xbdbar",
+ 1 => "\xc3\xa1",
), $arr );
}
'Expected exception'
);
}
+ try {
+ $result->addValue( null, null, $fh );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add resource(stream) to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
try {
$obj->file = $fh;
$result->addValue( null, 'sub', $obj );
'Expected exception'
);
}
+ try {
+ $obj->file = $fh;
+ $result->addValue( null, null, $obj );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add resource(stream) to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
fclose( $fh );
try {
'Expected exception'
);
}
+ try {
+ $result->addValue( null, null, INF );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add non-finite floats to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
try {
$result->addValue( null, 'nan', NAN );
$this->fail( 'Expected exception not thrown' );
'Expected exception'
);
}
+ try {
+ $result->addValue( null, null, NAN );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add non-finite floats to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
$result->reset();
$result->addParsedLimit( 'foo', 12 );
$result->addValue( null, 'foo', "foo\x80bar" );
$result->addValue( null, 'bar', "a\xcc\x81" );
$result->addValue( null, 'baz', 74 );
+ $result->addValue( null, null, "foo\x80bar" );
+ $result->addValue( null, null, "a\xcc\x81" );
$this->assertSame( array(
'foo' => "foo\xef\xbf\xbdbar",
'bar' => "\xc3\xa1",
'baz' => 74,
+ 0 => "foo\xef\xbf\xbdbar",
+ 1 => "\xc3\xa1",
ApiResult::META_TYPE => 'assoc',
), $result->getResultData() );
}
array( 'Types' => array( 'AssocAsObject' => true ) ),
(object)array(
'defaultArray' => array( 'b', 'c', 'a', ApiResult::META_TYPE => 'array' ),
- 'defaultAssoc' => (object)array( 'x' => 'a', 1 => 'b', 0 => 'c', ApiResult::META_TYPE => 'assoc' ),
- 'defaultAssoc2' => (object)array( 2 => 'a', 3 => 'b', 0 => 'c', ApiResult::META_TYPE => 'assoc' ),
+ 'defaultAssoc' => (object)array( 'x' => 'a',
+ 1 => 'b', 0 => 'c', ApiResult::META_TYPE => 'assoc'
+ ),
+ 'defaultAssoc2' => (object)array( 2 => 'a', 3 => 'b',
+ 0 => 'c', ApiResult::META_TYPE => 'assoc'
+ ),
'array' => array( 'a', 'c', 'b', ApiResult::META_TYPE => 'array' ),
'BCarray' => array( 'a', 'c', 'b', ApiResult::META_TYPE => 'array' ),
'BCassoc' => (object)array( 'a', 'b', 'c', ApiResult::META_TYPE => 'assoc' ),
array( 'Types' => array( 'ArmorKVP' => 'name', 'AssocAsObject' => true ) ),
(object)array(
'defaultArray' => array( 'b', 'c', 'a', ApiResult::META_TYPE => 'array' ),
- 'defaultAssoc' => (object)array( 'x' => 'a', 1 => 'b', 0 => 'c', ApiResult::META_TYPE => 'assoc' ),
- 'defaultAssoc2' => (object)array( 2 => 'a', 3 => 'b', 0 => 'c', ApiResult::META_TYPE => 'assoc' ),
+ 'defaultAssoc' => (object)array( 'x' => 'a', 1 => 'b',
+ 0 => 'c', ApiResult::META_TYPE => 'assoc'
+ ),
+ 'defaultAssoc2' => (object)array( 2 => 'a', 3 => 'b',
+ 0 => 'c', ApiResult::META_TYPE => 'assoc'
+ ),
'array' => array( 'a', 'c', 'b', ApiResult::META_TYPE => 'array' ),
'BCarray' => array( 'a', 'c', 'b', ApiResult::META_TYPE => 'array' ),
'BCassoc' => (object)array( 'a', 'b', 'c', ApiResult::META_TYPE => 'assoc' ),
$data[ApiResult::META_CONTENT] = 'bar';
}
+ /**
+ * @covers ApiResult
+ */
+ public function testAddMetadataToResultVars() {
+ $arr = array(
+ 'a' => "foo",
+ 'b' => false,
+ 'c' => 10,
+ 'sequential_numeric_keys' => array( 'a', 'b', 'c' ),
+ 'non_sequential_numeric_keys' => array( 'a', 'b', 4 => 'c' ),
+ 'string_keys' => array(
+ 'one' => 1,
+ 'two' => 2
+ ),
+ 'object_sequential_keys' => (object)array( 'a', 'b', 'c' ),
+ '_type' => "should be overwritten in result",
+ );
+ $this->assertSame( array(
+ ApiResult::META_TYPE => 'kvp',
+ ApiResult::META_KVP_KEY_NAME => 'key',
+ ApiResult::META_PRESERVE_KEYS => array(
+ 'a', 'b', 'c',
+ 'sequential_numeric_keys', 'non_sequential_numeric_keys',
+ 'string_keys', 'object_sequential_keys'
+ ),
+ ApiResult::META_BC_BOOLS => array( 'b' ),
+ ApiResult::META_INDEXED_TAG_NAME => 'var',
+ 'a' => "foo",
+ 'b' => false,
+ 'c' => 10,
+ 'sequential_numeric_keys' => array(
+ ApiResult::META_TYPE => 'array',
+ ApiResult::META_BC_BOOLS => array(),
+ ApiResult::META_INDEXED_TAG_NAME => 'value',
+ 0 => 'a',
+ 1 => 'b',
+ 2 => 'c',
+ ),
+ 'non_sequential_numeric_keys' => array(
+ ApiResult::META_TYPE => 'kvp',
+ ApiResult::META_KVP_KEY_NAME => 'key',
+ ApiResult::META_PRESERVE_KEYS => array( 0, 1, 4 ),
+ ApiResult::META_BC_BOOLS => array(),
+ ApiResult::META_INDEXED_TAG_NAME => 'var',
+ 0 => 'a',
+ 1 => 'b',
+ 4 => 'c',
+ ),
+ 'string_keys' => array(
+ ApiResult::META_TYPE => 'kvp',
+ ApiResult::META_KVP_KEY_NAME => 'key',
+ ApiResult::META_PRESERVE_KEYS => array( 'one', 'two' ),
+ ApiResult::META_BC_BOOLS => array(),
+ ApiResult::META_INDEXED_TAG_NAME => 'var',
+ 'one' => 1,
+ 'two' => 2,
+ ),
+ 'object_sequential_keys' => array(
+ ApiResult::META_TYPE => 'kvp',
+ ApiResult::META_KVP_KEY_NAME => 'key',
+ ApiResult::META_PRESERVE_KEYS => array( 0, 1, 2 ),
+ ApiResult::META_BC_BOOLS => array(),
+ ApiResult::META_INDEXED_TAG_NAME => 'var',
+ 0 => 'a',
+ 1 => 'b',
+ 2 => 'c',
+ ),
+ ), ApiResult::addMetadataToResultVars( $arr ) );
+ }
+
/**
* @covers ApiResult
*/
if ( preg_match( '/Use of ApiResult::\S+ was deprecated in MediaWiki \d+.\d+\./', $errstr ) ) {
return true;
}
+ if ( preg_match( '/Use of ApiMain to ApiResult::__construct ' .
+ 'was deprecated in MediaWiki \d+.\d+\./', $errstr ) ) {
+ return true;
+ }
return false;
} );
$reset = new ScopedCallback( 'restore_error_handler' );
$result = new ApiResult( 8388608 );
$result->setMainForContinuation( $main );
- $result->beginContinuation( '||mock2', array_slice( $allModules, 0, 2 ), array( 'mock1', 'mock2' ) );
+ $result->beginContinuation( '||mock2', array_slice( $allModules, 0, 2 ),
+ array( 'mock1', 'mock2' ) );
try {
$result->setContinueParam( $allModules[1], 'm2continue', 1 );
$this->fail( 'Expected exception not thrown' );
$this->fail( 'Expected exception not thrown' );
} catch ( UnexpectedValueException $ex ) {
$this->assertSame(
- 'Module \'mocklist\' called ApiContinuationManager::addContinueParam but was not passed to ApiContinuationManager::__construct',
+ 'Module \'mocklist\' called ApiContinuationManager::addContinueParam ' .
+ 'but was not passed to ApiContinuationManager::__construct',
$ex->getMessage(),
'Expected exception'
);
try {
$arr = array();
- ApiResult::setValue( $arr, 'foo', new ApiResultTestSerializableObject(
+ ApiResult::setValue( $arr, 'foo', new ApiResultTestSerializableObject(
new ApiResultTestStringifiableObject()
) );
$this->fail( 'Expected exception not thrown' );
} catch ( UnexpectedValueException $ex ) {
$this->assertSame(
- 'ApiResultTestSerializableObject::serializeForApiResult() returned an object of class ApiResultTestStringifiableObject',
+ 'ApiResultTestSerializableObject::serializeForApiResult() ' .
+ 'returned an object of class ApiResultTestStringifiableObject',
$ex->getMessage(),
'Expected exception'
);
try {
$arr = array();
- ApiResult::setValue( $arr, 'foo', new ApiResultTestSerializableObject( NAN ) );
+ ApiResult::setValue( $arr, 'foo', new ApiResultTestSerializableObject( NAN ) );
$this->fail( 'Expected exception not thrown' );
} catch ( UnexpectedValueException $ex ) {
$this->assertSame(
- 'ApiResultTestSerializableObject::serializeForApiResult() returned an invalid value: Cannot add non-finite floats to ApiResult',
+ 'ApiResultTestSerializableObject::serializeForApiResult() ' .
+ 'returned an invalid value: Cannot add non-finite floats to ApiResult',
$ex->getMessage(),
'Expected exception'
);
}
$arr = array();
- ApiResult::setValue( $arr, 'foo', new ApiResultTestSerializableObject(
+ ApiResult::setValue( $arr, 'foo', new ApiResultTestSerializableObject(
array(
'one' => new ApiResultTestStringifiableObject( '1' ),
'two' => new ApiResultTestSerializableObject( 2 ),