Thiemo Mättig (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371111 )

Change subject: Greatly improve type safety when using TestingAccessWrapper
......................................................................

Greatly improve type safety when using TestingAccessWrapper

This makes it possible to search for usages of the private properties
and methods that are accessed in tests, and IDEs are now actually able
to understand what's happening. Without this I found this code to be
very confusing.

Change-Id: I6b70713b444811c076a13f627e6d98c8aa0b8aae
---
M client/tests/phpunit/includes/Hooks/ChangesListSpecialPageHookHandlersTest.php
M client/tests/phpunit/includes/Hooks/MagicWordHookHandlersTest.php
M lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
M repo/tests/phpunit/maintenance/dumpRdfTest.php
4 files changed, 27 insertions(+), 13 deletions(-)


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

diff --git 
a/client/tests/phpunit/includes/Hooks/ChangesListSpecialPageHookHandlersTest.php
 
b/client/tests/phpunit/includes/Hooks/ChangesListSpecialPageHookHandlersTest.php
index ca3fc33..fe662bc 100644
--- 
a/client/tests/phpunit/includes/Hooks/ChangesListSpecialPageHookHandlersTest.php
+++ 
b/client/tests/phpunit/includes/Hooks/ChangesListSpecialPageHookHandlersTest.php
@@ -2,10 +2,12 @@
 
 namespace Wikibase\Client\Tests\Hooks;
 
+use ChangesListBooleanFilter;
 use ExtensionRegistry;
 use FauxRequest;
 use FormOptions;
 use SpecialPageFactory;
+use SpecialRecentChanges;
 use User;
 use Wikibase\Client\Hooks\ChangesListSpecialPageHookHandlers;
 use Wikimedia\Rdbms\IDatabase;
@@ -23,8 +25,15 @@
  * @author Matthew Flaschen < mflasc...@wikimedia.org >
  */
 class ChangesListSpecialPageHookHandlersTest extends 
\PHPUnit_Framework_TestCase {
+
+       /**
+        * @var ExtensionRegistry
+        */
        protected $extensionRegistry;
 
+       /**
+        * @var array
+        */
        protected $oldExtensionRegistryLoaded;
 
        public function setUp() {
@@ -55,13 +64,13 @@
                        ]
                );
 
-               /** @var \ChangesListSpecialPage $specialPage */
+               /** @var SpecialRecentChanges $specialPage */
                $specialPage = SpecialPageFactory::getPage( 'Recentchanges' );
 
-               $wrappedSpecialPage = TestingAccessWrapper::newFromObject(
-                       $specialPage
-               );
+               /** @var SpecialRecentChanges $wrappedSpecialPage */
+               $wrappedSpecialPage = TestingAccessWrapper::newFromObject( 
$specialPage );
 
+               /** @var ChangesListSpecialPageHookHandlers $hookHandler */
                $hookHandler = TestingAccessWrapper::newFromObject( new 
ChangesListSpecialPageHookHandlers(
                        $this->getRequest( [] ),
                        $this->getUser( [] ),
@@ -77,11 +86,10 @@
                        $wrappedSpecialPage->filterGroupDefinitions
                );
 
-               $hookHandler->addFilter(
-                       $specialPage
-               );
+               $hookHandler->addFilter( $specialPage );
 
                $changeType = $specialPage->getFilterGroup( 'changeType' );
+               /** @var ChangesListBooleanFilter $filter */
                $filter = $changeType->getFilter( 'hideWikibase' );
 
                // I could do all of getJsData(), but that would make it 
brittle to
@@ -184,6 +192,7 @@
         * @dataProvider getOptionNameProvider
         */
        public function testGetOptionName( $expected, $pageName ) {
+               /** @var ChangesListSpecialPageHookHandlers $hookHandler */
                $hookHandler = TestingAccessWrapper::newFromObject( new 
ChangesListSpecialPageHookHandlers(
                        $this->getRequest( [] ),
                        $this->getUser( [] ),
@@ -246,6 +255,7 @@
                $pageName,
                $message
        ) {
+               /** @var ChangesListSpecialPageHookHandlers $hookHandler */
                $hookHandler = TestingAccessWrapper::newFromObject( new 
ChangesListSpecialPageHookHandlers(
                        $this->getRequest( $requestParams ),
                        $this->getUser( $userOptions ),
@@ -312,6 +322,7 @@
                $expectedToggleDefault,
                $specialPageName
        ) {
+               /** @var ChangesListSpecialPageHookHandlers $hookHandler */
                $hookHandler = TestingAccessWrapper::newFromObject( new 
ChangesListSpecialPageHookHandlers(
                        $this->getRequest( $requestParams ),
                        $this->getUser( $userOptions ),
@@ -383,6 +394,7 @@
                $expectedToggleDefault,
                $specialPageName
        ) {
+               /** @var ChangesListSpecialPageHookHandlers $hookHandler */
                $hookHandler = TestingAccessWrapper::newFromObject( new 
ChangesListSpecialPageHookHandlers(
                        $this->getRequest( $requestParams ),
                        $this->getUser( $userOptions ),
@@ -441,6 +453,7 @@
         * @dataProvider 
hasWikibaseChangesEnabledWhenExternalRecentChangesDisabledProvider() {
         */
        public function 
testHasWikibaseChangesEnabledWhenExternalRecentChangesDisabled( 
$specialPageName ) {
+               /** @var ChangesListSpecialPageHookHandlers $hookHandler */
                $hookHandler = TestingAccessWrapper::newFromObject( new 
ChangesListSpecialPageHookHandlers(
                        $this->getRequest( [] ),
                        $this->getUser( [ 'usenewrc' => 0 ] ),
diff --git a/client/tests/phpunit/includes/Hooks/MagicWordHookHandlersTest.php 
b/client/tests/phpunit/includes/Hooks/MagicWordHookHandlersTest.php
index 4ac9553..7bd78d8 100644
--- a/client/tests/phpunit/includes/Hooks/MagicWordHookHandlersTest.php
+++ b/client/tests/phpunit/includes/Hooks/MagicWordHookHandlersTest.php
@@ -29,9 +29,8 @@
                $settings = new SettingsArray();
                $settings->setSetting( 'repoSiteName', $siteName );
 
-               $handler = TestingAccessWrapper::newFromObject(
-                       new MagicWordHookHandlers( $settings )
-               );
+               /** @var MagicWordHookHandlers $handler */
+               $handler = TestingAccessWrapper::newFromObject( new 
MagicWordHookHandlers( $settings ) );
 
                $actual = $handler->getRepoName(
                        Language::factory( $langCode )
@@ -82,9 +81,8 @@
                $settings = new SettingsArray();
                $settings->setSetting( 'repoSiteName', 'wikibase-client-desc' );
 
-               $handler = TestingAccessWrapper::newFromObject(
-                       new MagicWordHookHandlers( $settings )
-               );
+               /** @var MagicWordHookHandlers $handler */
+               $handler = TestingAccessWrapper::newFromObject( new 
MagicWordHookHandlers( $settings ) );
 
                $cache = [];
                $word = 'wbreponame';
@@ -109,6 +107,7 @@
                $parser->method( 'getTitle' )
                        ->willReturn( Title::newMainPage() );
 
+               /** @var MagicWordHookHandlers $handler */
                $handler = TestingAccessWrapper::newFromObject(
                        new MagicWordHookHandlers( new SettingsArray() )
                );
diff --git a/lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php 
b/lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
index 7586901..3b29e1e 100644
--- a/lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
+++ b/lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
@@ -652,6 +652,7 @@
 
                $termIndex = $this->getTermIndex();
                $termIndex->setReadFullEntityIdColumn( true );
+               /** @var TermSqlIndex $termIndex */
                $termIndex = TestingAccessWrapper::newFromObject( $termIndex );
 
                $this->assertTrue(
diff --git a/repo/tests/phpunit/maintenance/dumpRdfTest.php 
b/repo/tests/phpunit/maintenance/dumpRdfTest.php
index f4ff0a7..def7c4d 100644
--- a/repo/tests/phpunit/maintenance/dumpRdfTest.php
+++ b/repo/tests/phpunit/maintenance/dumpRdfTest.php
@@ -205,6 +205,7 @@
         * @dataProvider getRedirectModeProvider
         */
        public function testGetRedirectMode( $expected, $redirectOnly ) {
+               /** @var DumpRdf $dumpScript */
                $dumpScript = TestingAccessWrapper::newFromObject( new 
DumpRdf() );
 
                $dumpArgv = [ 0 => 'foo' ];

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b70713b444811c076a13f627e6d98c8aa0b8aae
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