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

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

Change subject: Favor assertSame over assertRegex in EntityContentTest
......................................................................

Favor assertSame over assertRegex in EntityContentTest

I wonder why this was doing regex matches in the first place. No need
as far as I can see.

Change-Id: I11128c6a1f920dbc71bdc41db2e38315aa2a80f5
---
M repo/tests/phpunit/includes/Content/EntityContentTest.php
M repo/tests/phpunit/includes/Content/ItemContentTest.php
2 files changed, 16 insertions(+), 48 deletions(-)


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

diff --git a/repo/tests/phpunit/includes/Content/EntityContentTest.php 
b/repo/tests/phpunit/includes/Content/EntityContentTest.php
index 050f58e..a59fcb5 100644
--- a/repo/tests/phpunit/includes/Content/EntityContentTest.php
+++ b/repo/tests/phpunit/includes/Content/EntityContentTest.php
@@ -6,7 +6,6 @@
 use Diff\DiffOp\DiffOpChange;
 use Diff\Patcher\PatcherException;
 use ParserOutput;
-use PHPUnit_Framework_Assert;
 use Title;
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Entity\EntityId;
@@ -84,13 +83,9 @@
 
        /**
         * @dataProvider getTextForSearchIndexProvider
-        *
-        * @param EntityContent $entityContent
-        * @param string $pattern
         */
-       public function testGetTextForSearchIndex( EntityContent 
$entityContent, $pattern ) {
-               $text = $entityContent->getTextForSearchIndex();
-               $this->assertRegExp( $pattern . 'm', $text );
+       public function testGetTextForSearchIndex( EntityContent 
$entityContent, $expected ) {
+               $this->assertSame( $expected, 
$entityContent->getTextForSearchIndex() );
        }
 
        private function setLabel( EntityDocument $entity, $lang, $text ) {
@@ -106,7 +101,7 @@
                $this->setLabel( $entityContent->getEntity(), 'en', "cake" );
 
                return array(
-                       array( $entityContent, '/^cake$/' )
+                       array( $entityContent, 'cake' )
                );
        }
 
@@ -117,8 +112,8 @@
                $this->mergeMwGlobalArrayValue( 'wgHooks', array(
                        'WikibaseTextForSearchIndex' => array(
                                function ( $actualEntityContent, &$text ) use ( 
$entityContent ) {
-                                       PHPUnit_Framework_Assert::assertSame( 
$entityContent, $actualEntityContent );
-                                       PHPUnit_Framework_Assert::assertRegExp( 
'/cake/m', $text );
+                                       $this->assertSame( $entityContent, 
$actualEntityContent );
+                                       $this->assertSame( 'cake', $text );
 
                                        $text .= "\nHOOK";
                                        return true;
@@ -127,7 +122,7 @@
                ) );
 
                $text = $entityContent->getTextForSearchIndex();
-               $this->assertRegExp( '/cake.*HOOK/s', $text, 'Text for search 
index should be updated by the hook' );
+               $this->assertSame( "cake\nHOOK", $text, 'Text for search index 
should be updated by the hook' );
        }
 
        public function testWikibaseTextForSearchIndex_abort() {
@@ -143,7 +138,7 @@
                ) );
 
                $text = $entityContent->getTextForSearchIndex();
-               $this->assertEquals( '', $text, 'Text for search index should 
be empty if the hook returned false' );
+               $this->assertSame( '', $text, 'Text for search index should be 
empty if the hook returned false' );
        }
 
        public function testGetParserOutput() {
@@ -168,7 +163,7 @@
                );
 
                $this->assertInstanceOf( ParserOutput::class, $parserOutput );
-               $this->assertEquals( EntityContent::STATUS_EMPTY, 
$parserOutput->getProperty( 'wb-status' ) );
+               $this->assertSame( EntityContent::STATUS_EMPTY, 
$parserOutput->getProperty( 'wb-status' ) );
        }
 
        public function providePageProperties() {
@@ -200,7 +195,7 @@
 
                foreach ( $expectedProps as $name => $expected ) {
                        $actual = $parserOutput->getProperty( $name );
-                       $this->assertEquals( $expected, $actual, "page property 
$name" );
+                       $this->assertSame( $expected, $actual, "page property 
$name" );
                }
        }
 
@@ -223,10 +218,8 @@
        /**
         * @dataProvider provideGetEntityStatus
         */
-       public function testGetEntityStatus( EntityContent $content, $status ) {
-               $actual = $content->getEntityStatus();
-
-               $this->assertEquals( $status, $actual );
+       public function testGetEntityStatus( EntityContent $content, $expected 
) {
+               $this->assertSame( $expected, $content->getEntityStatus() );
        }
 
        abstract public function provideGetEntityId();
@@ -272,7 +265,7 @@
 
                foreach ( $pageProps as $key => $value ) {
                        $this->assertArrayHasKey( $key, $actual );
-                       $this->assertEquals( $value, $actual[$key], $key );
+                       $this->assertSame( $value, $actual[$key], $key );
                }
 
                $this->assertArrayEquals( array_keys( $pageProps ), array_keys( 
$actual ) );
@@ -301,10 +294,6 @@
 
        /**
         * @dataProvider diffProvider
-        *
-        * @param EntityContent $a
-        * @param EntityContent $b
-        * @param EntityContentDiff $expected
         */
        public function testGetDiff( EntityContent $a, EntityContent $b, 
EntityContentDiff $expected ) {
                $actual = $a->getDiff( $b );
@@ -347,10 +336,6 @@
 
        /**
         * @dataProvider patchedCopyProvider
-        *
-        * @param EntityContent $base
-        * @param EntityContentDiff $patch
-        * @param EntityContent|null $expected
         */
        public function testGetPatchedCopy( EntityContent $base, 
EntityContentDiff $patch, EntityContent $expected = null ) {
                if ( $expected === null ) {
@@ -378,7 +363,6 @@
 
        /**
         * @dataProvider copyProvider
-        * @param EntityContent $content
         */
        public function testCopy( EntityContent $content ) {
                $copy = $content->copy();
@@ -407,13 +391,9 @@
        /**
         * @dataProvider equalsProvider
         */
-       public function testEquals( EntityContent $a, EntityContent $b, $equals 
) {
-
-               $actual = $a->equals( $b );
-               $this->assertEquals( $equals, $actual );
-
-               $actual = $b->equals( $a );
-               $this->assertEquals( $equals, $actual );
+       public function testEquals( EntityContent $a, EntityContent $b, 
$expected ) {
+               $this->assertSame( $expected, $a->equals( $b ) );
+               $this->assertSame( $expected, $b->equals( $a ) );
        }
 
        private function createTitleForEntity( EntityDocument $entity ) {
diff --git a/repo/tests/phpunit/includes/Content/ItemContentTest.php 
b/repo/tests/phpunit/includes/Content/ItemContentTest.php
index 79d478b..dcde565 100644
--- a/repo/tests/phpunit/includes/Content/ItemContentTest.php
+++ b/repo/tests/phpunit/includes/Content/ItemContentTest.php
@@ -97,25 +97,13 @@
                return ItemContent::newFromRedirect( new EntityRedirect( 
$itemId, $targetId ), $title );
        }
 
-       /**
-        * @dataProvider getTextForSearchIndexProvider
-        *
-        * @param EntityContent $itemContent
-        * @param string $pattern
-        */
-       public function testGetTextForSearchIndex( EntityContent $itemContent, 
$pattern ) {
-               $text = $itemContent->getTextForSearchIndex();
-               $this->assertRegExp( $pattern . 'm', $text );
-       }
-
        public function getTextForSearchIndexProvider() {
                $itemContent = $this->newEmpty();
                $itemContent->getEntity()->setLabel( 'en', "cake" );
                $itemContent->getEntity()->getSiteLinkList()->addNewSiteLink( 
'dewiki', 'Berlin' );
 
                return array(
-                       array( $itemContent, '!^cake$!' ),
-                       array( $itemContent, '!^Berlin$!' )
+                       array( $itemContent, "cake\nBerlin" ),
                );
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I11128c6a1f920dbc71bdc41db2e38315aa2a80f5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to