Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/225036

Change subject: Drop some unused code from ResultBuilder and related
......................................................................

Drop some unused code from ResultBuilder and related

This fixes some minor issues I found while reviewing Ied35ad3.

Bug: T92970
Change-Id: If5ae3950a260178c6ba81a8571b7c74c1c7803b0
---
M repo/includes/LinkedData/EntityDataSerializationService.php
M repo/includes/api/ResultBuilder.php
M repo/tests/phpunit/includes/api/ApiXmlFormatTest.php
M repo/tests/phpunit/includes/api/ResultBuilderTest.php
4 files changed, 68 insertions(+), 81 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/36/225036/1

diff --git a/repo/includes/LinkedData/EntityDataSerializationService.php 
b/repo/includes/LinkedData/EntityDataSerializationService.php
index c82f98d..90b8547 100644
--- a/repo/includes/LinkedData/EntityDataSerializationService.php
+++ b/repo/includes/LinkedData/EntityDataSerializationService.php
@@ -440,17 +440,13 @@
                // function gets called multiple times during testing, etc.
                $res->reset();
 
-               //TODO: apply language filter/Fallback via options!
-               $options = new SerializationOptions();
-
                $resultBuilder = new ResultBuilder(
                        $res,
                        $this->entityTitleLookup,
                        $this->libSerializerFactory,
-                       $this->serializerFactory,
-                       false // Never index tags for this service as we dont 
output XML
+                       $this->serializerFactory
                );
-               $resultBuilder->addEntityRevision( null, $entityRevision, 
$options );
+               $resultBuilder->addEntityRevision( null, $entityRevision );
 
                return $res;
        }
diff --git a/repo/includes/api/ResultBuilder.php 
b/repo/includes/api/ResultBuilder.php
index 3263509..f8897b0 100644
--- a/repo/includes/api/ResultBuilder.php
+++ b/repo/includes/api/ResultBuilder.php
@@ -34,9 +34,9 @@
        private $result;
 
        /**
-        * @var int
+        * @var EntityTitleLookup
         */
-       private $missingEntityCounter;
+       private $entityTitleLookup;
 
        /**
         * @var LibSerializerFactory
@@ -49,19 +49,19 @@
        private $serializerFactory;
 
        /**
-        * @var EntityTitleLookup
+        * @var bool when special elements such as '_element' are needed by the 
formatter.
         */
-       private $entityTitleLookup;
+       private $isRawMode;
+
+       /**
+        * @var int
+        */
+       private $missingEntityCounter = -1;
 
        /**
         * @var SerializationOptions
         */
        private $options;
-
-       /**
-        * @var bool when special elements such as '_element' are needed by the 
formatter.
-        */
-       private $isRawMode;
 
        /**
         * @param ApiResult $result
@@ -77,7 +77,7 @@
                EntityTitleLookup $entityTitleLookup,
                LibSerializerFactory $libSerializerFactory,
                SerializerFactory $serializerFactory,
-               $isRawMode
+               $isRawMode = false
        ) {
                if ( !$result instanceof ApiResult ) {
                        throw new InvalidArgumentException( 'Result builder 
must be constructed with an ApiResult' );
@@ -87,7 +87,6 @@
                $this->entityTitleLookup = $entityTitleLookup;
                $this->libSerializerFactory = $libSerializerFactory;
                $this->serializerFactory = $serializerFactory;
-               $this->missingEntityCounter = -1;
                $this->isRawMode = $isRawMode;
        }
 
diff --git a/repo/tests/phpunit/includes/api/ApiXmlFormatTest.php 
b/repo/tests/phpunit/includes/api/ApiXmlFormatTest.php
index ee90ddf..ba8efc9 100644
--- a/repo/tests/phpunit/includes/api/ApiXmlFormatTest.php
+++ b/repo/tests/phpunit/includes/api/ApiXmlFormatTest.php
@@ -158,7 +158,6 @@
                        'claim' => $json,
                );
 
-               /** @var SetSiteLink $module */
                $module = $this->getApiModule( '\Wikibase\Repo\Api\SetClaim', 
'wbsetclaim', $params, true );
                $result = $this->doApiRequest( $module );
                $actual = $this->removePageInfoAttributes( $result );
@@ -178,7 +177,6 @@
                        'snaks' => $json,
                );
 
-               /** @var SetSiteLink $module */
                $module = $this->getApiModule( 
'\Wikibase\Repo\Api\SetReference', 'wbsetreference', $params, true );
                $result = $this->doApiRequest( $module );
                $actual = $this->removePageInfoAttributes( $result );
@@ -199,7 +197,6 @@
                        'snaktype' => 'value',
                );
 
-               /** @var SetSiteLink $module */
                $module = $this->getApiModule( 
'\Wikibase\Repo\Api\SetQualifier', 'wbsetqualifier', $params, true );
                $result = $this->doApiRequest( $module );
                $actual = $this->removePageInfoAttributes( $result );
@@ -296,8 +293,8 @@
                $main = new ApiMain( $request );
 
                /**
-                * This has to be set before the Wikibase Api module is 
instansiated due to the ApiHelperFactory
-                * using $api->getResult()->getIsRawMode().
+                * This has to be set before the Wikibase API module is 
instantiated due to the
+                * ApiHelperFactory using $api->getResult()->getIsRawMode().
                 */
                $main->getResult()->setRawMode( true );
 
diff --git a/repo/tests/phpunit/includes/api/ResultBuilderTest.php 
b/repo/tests/phpunit/includes/api/ResultBuilderTest.php
index 3f883f5..13c4e1d 100644
--- a/repo/tests/phpunit/includes/api/ResultBuilderTest.php
+++ b/repo/tests/phpunit/includes/api/ResultBuilderTest.php
@@ -35,11 +35,11 @@
  */
 class ResultBuilderTest extends \PHPUnit_Framework_TestCase {
 
-       protected function getDefaultResult() {
+       private function getDefaultResult() {
                return new ApiResult( false );
        }
 
-       protected function getResultBuilder( $result, $options = null, 
$indexedMode = false ) {
+       private function getResultBuilder( $result, $isRawMode = false ) {
                $mockTitle = $this->getMockBuilder( '\Title' )
                        ->disableOriginalConstructor()
                        ->getMock();
@@ -77,14 +77,8 @@
                        $mockEntityTitleLookup,
                        $libSerializerFactory,
                        $serializerFactory,
-                       $indexedMode
+                       $isRawMode
                );
-
-               if ( is_array( $options ) ) {
-                       $builder->getOptions()->setOptions( $options );
-               } elseif ( $options instanceof SerializationOptions ) {
-                       $builder->getOptions()->merge( $options );
-               }
 
                return $builder;
        }
@@ -371,7 +365,7 @@
         * @see https://phabricator.wikimedia.org/T68181
         */
        public function testAddEntityRevisionInIndexedModeWithSiteLinksFilter() 
{
-               $indexedMode = true;
+               $isRawMode = true;
 
                $item = new Item( new ItemId( 'Q123100' ) );
                $item->getSiteLinkList()->addNewSiteLink( 'enwiki', 'Berlin' );
@@ -379,12 +373,12 @@
                $entityRevision = new EntityRevision( $item );
 
                $options = new SerializationOptions();
-               $options->setIndexTags( $indexedMode );
+               $options->setIndexTags( $isRawMode );
                $props = array( 'sitelinks' );
                $siteIds = array( 'enwiki' );
 
                $result = $this->getDefaultResult();
-               $resultBuilder = $this->getResultBuilder( $result, null, 
$indexedMode );
+               $resultBuilder = $this->getResultBuilder( $result, $isRawMode );
                $resultBuilder->addEntityRevision( null, $entityRevision, 
$options, $props, $siteIds );
 
                $expected = array( 'entities' => array(
@@ -420,7 +414,7 @@
                $data = $result->getResultData( null, array(
                        'BC' => array(),
                        'Types' => array(),
-                       'Strip' => $indexedMode ? 'bc' : 'all',
+                       'Strip' => $isRawMode ? 'bc' : 'all',
                ) );
                $this->assertEquals( $expected, $data );
        }
@@ -870,52 +864,51 @@
        public function provideSetList() {
                return array(
                        'null path' => array( null, 'foo', array(), 'letter', 
false, array( 'foo' => array() ) ),
-
                        'empty path' => array( array(), 'foo', array( 'x', 'y' 
), 'letter', false,
                                array(
                                        'foo' => array( 'x', 'y' )
-                       ) ),
-
+                               )
+                       ),
                        'string path' => array( 'ROOT', 'foo', array( 'x', 'y' 
), 'letter', false,
                                array(
                                        'ROOT' => array(
                                                'foo' => array( 'x', 'y' ) )
-                               ) ),
-
+                               )
+                       ),
                        'actual path' => array( array( 'one', 'two' ), 'foo', 
array( 'X' => 'x', 'Y' => 'y' ), 'letter', false,
                                array(
                                        'one' => array(
                                                'two' => array(
                                                        'foo' => array( 'X' => 
'x', 'Y' => 'y' ) ) )
-                               ) ),
-
+                               )
+                       ),
                        'indexed' => array( 'ROOT', 'foo', array( 'X' => 'x', 
'Y' => 'y' ), 'letter', true,
                                array(
                                        'ROOT' => array(
                                                'foo' => array( 'x', 'y', 
'_element' => 'letter' ) )
-                               ) ),
-
+                               )
+                       ),
                        'pre-set element name' => array( 'ROOT', 'foo', array( 
'x', 'y', '_element' => '_thingy' ), 'letter', true,
                                array(
                                        'ROOT' => array(
                                                'foo' => array( 'x', 'y', 
'_element' => 'letter' ) )
-                               ) ),
-
+                               )
+                       ),
                );
        }
 
        /**
         * @dataProvider provideSetList
         */
-       public function testSetList( $path, $name, array $values, $tag, 
$indexed, $expected ) {
+       public function testSetList( $path, $name, array $values, $tag, 
$isRawMode, $expected ) {
                $result = $this->getDefaultResult();
-               $builder = $this->getResultBuilder( $result, null, $indexed );
+               $builder = $this->getResultBuilder( $result, $isRawMode );
 
                $builder->setList( $path, $name, $values, $tag );
                $data = $result->getResultData( null, array(
                        'BC' => array(),
                        'Types' => array(),
-                       'Strip' => $indexed ? 'bc' : 'all',
+                       'Strip' => $isRawMode ? 'bc' : 'all',
                ) );
                $this->assertResultStructure( $expected, $data );
        }
@@ -946,43 +939,45 @@
        public function provideSetValue() {
                return array(
                        'null path' => array( null, 'foo', 'value', false, 
array( 'foo' => 'value' ) ),
-
                        'empty path' => array( array(), 'foo', 'value', false,
                                array(
                                        'foo' => 'value'
-                               ) ),
-
+                               )
+                       ),
                        'string path' => array( 'ROOT', 'foo', 'value', false,
                                array(
                                        'ROOT' => array( 'foo' => 'value' )
-                               ) ),
-
+                               )
+                       ),
                        'actual path' => array( array( 'one', 'two' ), 'foo', 
array( 'X' => 'x', 'Y' => 'y' ), true,
                                array(
                                        'one' => array(
                                                'two' => array(
-                                                       'foo' => array( 'X' => 
'x', 'Y' => 'y' ) ) )
-                               ) ),
-
+                                                       'foo' => array( 'X' => 
'x', 'Y' => 'y' )
+                                               )
+                                       )
+                               )
+                       ),
                        'indexed' => array( 'ROOT', 'foo', 'value', true,
                                array(
                                        'ROOT' => array( 'foo' => 'value' )
-                               ) ),
+                               )
+                       ),
                );
        }
 
        /**
         * @dataProvider provideSetValue
         */
-       public function testSetValue( $path, $name, $value, $indexed, $expected 
) {
+       public function testSetValue( $path, $name, $value, $isRawMode, 
$expected ) {
                $result = $this->getDefaultResult();
-               $builder = $this->getResultBuilder( $result, null, $indexed );
+               $builder = $this->getResultBuilder( $result, $isRawMode );
 
                $builder->setValue( $path, $name, $value );
                $data = $result->getResultData( null, array(
                        'BC' => array(),
                        'Types' => array(),
-                       'Strip' => $indexed ? 'bc' : 'all',
+                       'Strip' => $isRawMode ? 'bc' : 'all',
                ) );
                $this->assertResultStructure( $expected, $data );
        }
@@ -1011,61 +1006,61 @@
        public function provideAppendValue() {
                return array(
                        'null path' => array( null, null, 'value', 'letter', 
false, array( 'value' ) ),
-
                        'empty path' => array( array(), null, 'value', 
'letter', false,
                                array( 'value' )
                        ),
-
                        'string path' => array( 'ROOT', null, 'value', 
'letter', false,
                                array(
                                        'ROOT' => array( 'value' )
-                               ) ),
-
+                               )
+                       ),
                        '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' ) )
+                                       )
+                               )
+                       ),
                        'int key' => array( 'ROOT', -2, 'value', 'letter', 
false,
                                array(
                                        'ROOT' => array( -2 => 'value' )
-                               ) ),
-
+                               )
+                       ),
                        'string key' => array( 'ROOT', 'Q7', 'value', 'letter', 
false,
                                array(
                                        'ROOT' => array( 'Q7' => 'value' )
-                               ) ),
-
+                               )
+                       ),
                        'null key indexed' => array( 'ROOT', null, 'value', 
'letter', true,
                                array(
                                        'ROOT' => array( 'value', '_element' => 
'letter' )
-                               ) ),
-
+                               )
+                       ),
                        'int key indexed' => array( 'ROOT', -2, 'value', 
'letter', true,
                                array(
                                        'ROOT' => array( 'value', '_element' => 
'letter' )
-                               ) ),
-
+                               )
+                       ),
                        'string key indexed' => array( 'ROOT', 'Q7', 'value', 
'letter', true,
                                array(
                                        'ROOT' => array( 'value', '_element' => 
'letter' )
-                               ) ),
+                               )
+                       ),
                );
        }
 
        /**
         * @dataProvider provideAppendValue
         */
-       public function testAppendValue( $path, $key, $value, $tag, $indexed, 
$expected ) {
+       public function testAppendValue( $path, $key, $value, $tag, $isRawMode, 
$expected ) {
                $result = $this->getDefaultResult();
-               $builder = $this->getResultBuilder( $result, null, $indexed );
+               $builder = $this->getResultBuilder( $result, $isRawMode );
 
                $builder->appendValue( $path, $key, $value, $tag );
                $data = $result->getResultData( null, array(
                        'BC' => array(),
                        'Types' => array(),
-                       'Strip' => $indexed ? 'bc' : 'all',
+                       'Strip' => $isRawMode ? 'bc' : 'all',
                ) );
                $this->assertResultStructure( $expected, $data );
        }
@@ -1092,7 +1087,7 @@
                $builder->appendValue( $path, $key, $value, $tag );
        }
 
-       protected function assertResultStructure( $expected, $actual, $path = 
null ) {
+       private function assertResultStructure( $expected, $actual, $path = 
null ) {
                foreach ( $expected as $key => $value ) {
                        $this->assertArrayHasKey( $key, $actual, $path );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/225036
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If5ae3950a260178c6ba81a8571b7c74c1c7803b0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to