jenkins-bot has submitted this change and it was merged.
Change subject: Simplify use of Result::getResultData in ResultBuilderTest
......................................................................
Simplify use of Result::getResultData in ResultBuilderTest
This means that we no longer pass params to getResultData
Bug: T96353
Change-Id: Id1978037486264095390c5ff863051db849a97ff
---
M repo/tests/phpunit/includes/api/ResultBuilderTest.php
1 file changed, 69 insertions(+), 101 deletions(-)
Approvals:
Jonas Kress (WMDE): Looks good to me, but someone else must approve
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/tests/phpunit/includes/api/ResultBuilderTest.php
b/repo/tests/phpunit/includes/api/ResultBuilderTest.php
index 3f883f5..5820084 100644
--- a/repo/tests/phpunit/includes/api/ResultBuilderTest.php
+++ b/repo/tests/phpunit/includes/api/ResultBuilderTest.php
@@ -119,11 +119,9 @@
$result = $this->getDefaultResult();
$resultBuilder = $this->getResultBuilder( $result );
$resultBuilder->markSuccess( $param );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( array( 'success' => $expected ), $data );
}
@@ -295,17 +293,16 @@
'title' => 'User:Addshore',
'badges' => array()
),
+ ) ),
+ '_element' => 'entity',
),
- ) ) );
+ );
$resultBuilder = $this->getResultBuilder( $result );
$resultBuilder->addEntityRevision( 'Q1230000', $entityRevision,
new SerializationOptions(), $props );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -357,13 +354,11 @@
),
),
),
+ '_element' => 'entity',
) );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -417,11 +412,8 @@
'_element' => 'entity'
) );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => $indexedMode ? 'bc' : 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -436,11 +428,8 @@
$resultBuilder = $this->getResultBuilder( $result );
$resultBuilder->addBasicEntityInformation( $entityId, 'entity'
);
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -468,11 +457,8 @@
$resultBuilder = $this->getResultBuilder( $result );
$resultBuilder->addLabels( $labels, $path );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -500,11 +486,8 @@
$resultBuilder = $this->getResultBuilder( $result );
$resultBuilder->addDescriptions( $descriptions, $path );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -544,11 +527,8 @@
$resultBuilder = $this->getResultBuilder( $result );
$resultBuilder->addAliases( $aliases, $path );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -581,11 +561,8 @@
$resultBuilder = $this->getResultBuilder( $result );
$resultBuilder->addSiteLinks( $siteLinks, $path );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -609,11 +586,8 @@
$resultBuilder = $this->getResultBuilder( $result );
$resultBuilder->addClaims( $claims, $path );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -625,11 +599,8 @@
$resultBuilder = $this->getResultBuilder( $result );
$resultBuilder->addClaim( $statement );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -720,11 +691,8 @@
$resultBuilder = $this->getResultBuilder( $result );
$resultBuilder->addReference( $reference );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -744,11 +712,8 @@
$resultBuilder->addMissingEntity( $key, $missingDetails
);
}
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -764,7 +729,8 @@
'site' => 'enwiki',
'title' => 'Berlin',
'missing' => '',
- )
+ ),
+ '_element' => 'entity',
),
)
),
@@ -777,7 +743,8 @@
'Q77' => array(
'id' => 'Q77',
'missing' => '',
- )
+ ),
+ '_element' => 'entity',
),
)
),
@@ -790,7 +757,8 @@
'Q77' => array(
'foo' => 'bar',
'missing' => '',
- )
+ ),
+ '_element' => 'entity',
),
)
),
@@ -810,7 +778,8 @@
'site' => 'dewiki',
'title' => 'Foo',
'missing' => '',
- )
+ ),
+ '_element' => 'entity',
),
)
),
@@ -834,11 +803,8 @@
$resultBuilder = $this->getResultBuilder( $result );
$resultBuilder->addNormalizedTitle( $from, $to );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -859,11 +825,8 @@
$resultBuilder = $this->getResultBuilder( $result );
$resultBuilder->addRevisionIdFromStatusToResult( $mockStatus,
'entity' );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertEquals( $expected, $data );
}
@@ -912,11 +875,8 @@
$builder = $this->getResultBuilder( $result, null, $indexed );
$builder->setList( $path, $name, $values, $tag );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => $indexed ? 'bc' : 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertResultStructure( $expected, $data );
}
@@ -979,11 +939,8 @@
$builder = $this->getResultBuilder( $result, null, $indexed );
$builder->setValue( $path, $name, $value );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => $indexed ? 'bc' : 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertResultStructure( $expected, $data );
}
@@ -1010,31 +967,34 @@
public function provideAppendValue() {
return array(
- 'null path' => array( null, null, 'value', 'letter',
false, array( 'value' ) ),
+ 'null path' => array( null, null, 'value', 'letter',
false,
+ array( 'value', '_element' => 'letter' ),
+ ),
'empty path' => array( array(), null, 'value',
'letter', false,
- array( 'value' )
+ array( 'value', '_element' => 'letter' )
),
'string path' => array( 'ROOT', null, 'value',
'letter', false,
array(
- 'ROOT' => array( 'value' )
+ 'ROOT' => array( 'value', '_element' =>
'letter' )
) ),
'actual path' => array( array( 'one', 'two' ), null,
array( 'X' => 'x', 'Y' => 'y' ), 'letter', false,
array(
'one' => array(
- 'two' => array( array( 'X' =>
'x', 'Y' => 'y' ) ) )
+ 'two' => array( array( 'X' =>
'x', 'Y' => 'y' ), '_element' => 'letter' ),
+ )
) ),
'int key' => array( 'ROOT', -2, 'value', 'letter',
false,
array(
- 'ROOT' => array( -2 => 'value' )
+ 'ROOT' => array( -2 => 'value',
'_element' => 'letter' ),
) ),
'string key' => array( 'ROOT', 'Q7', 'value', 'letter',
false,
array(
- 'ROOT' => array( 'Q7' => 'value' )
+ 'ROOT' => array( 'Q7' => 'value',
'_element' => 'letter' ),
) ),
'null key indexed' => array( 'ROOT', null, 'value',
'letter', true,
@@ -1062,11 +1022,8 @@
$builder = $this->getResultBuilder( $result, null, $indexed );
$builder->appendValue( $path, $key, $value, $tag );
- $data = $result->getResultData( null, array(
- 'BC' => array(),
- 'Types' => array(),
- 'Strip' => $indexed ? 'bc' : 'all',
- ) );
+ $data = $result->getResultData();
+ $this->removeElementsWithKeysRecursively( $data, array( '_type'
) );
$this->assertResultStructure( $expected, $data );
}
@@ -1109,4 +1066,15 @@
$this->assertEquals( array_keys( $expected ), array_keys(
$actual ), "Keys of $path:" );
}
+ private function removeElementsWithKeysRecursively( array &$array,
array $unwantedKeys ) {
+ foreach ( $unwantedKeys as $unwantedKey ) {
+ unset( $array[$unwantedKey] );
+ foreach ( $array as &$value ) {
+ if ( is_array( $value ) ) {
+
$this->removeElementsWithKeysRecursively( $value, array( $unwantedKey ) );
+ }
+ }
+ }
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/224428
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id1978037486264095390c5ff863051db849a97ff
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits