Addshore has uploaded a new change for review.

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


Change subject: Refactor SetClaimTest
......................................................................

Refactor SetClaimTest

This means each test case actually runs as
a seperate test meaning we can get seperate
output for each!

Change-Id: Iab6dcd8f757febdda07c542d2a90c6072673c2b7
---
M repo/tests/phpunit/includes/api/SetClaimTest.php
1 file changed, 59 insertions(+), 64 deletions(-)


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

diff --git a/repo/tests/phpunit/includes/api/SetClaimTest.php 
b/repo/tests/phpunit/includes/api/SetClaimTest.php
index 08b7732..dd09006 100644
--- a/repo/tests/phpunit/includes/api/SetClaimTest.php
+++ b/repo/tests/phpunit/includes/api/SetClaimTest.php
@@ -1,6 +1,7 @@
 <?php
 
 namespace Wikibase\Test\Api;
+
 use Wikibase\Claim;
 use Wikibase\Claims;
 use Wikibase\DataModel\Entity\PropertyId;
@@ -26,8 +27,6 @@
  *
  * @since 0.4
  *
- * @ingroup WikibaseRepoTest
- *
  * @group API
  * @group Database
  * @group Wikibase
@@ -40,13 +39,14 @@
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
  * @author Daniel Kinzler
+ * @author Adam Shorland
  */
 class SetClaimTest extends WikibaseApiTestCase {
 
        /**
         * @return Snak[]
         */
-       protected function snakProvider() {
+       protected static function snakProvider() {
                static $hasProperties = false;
 
                $prop42 = new PropertyId( 'P42' );
@@ -81,34 +81,8 @@
                return $snaks;
        }
 
-       /**
-        * @return Claim[]
-        */
-       protected function claimProvider() {
-               $statements = array();
-
-               $snaks = $this->snakProvider();
-               $mainSnak = $snaks[0];
-               $statement = new Statement( $mainSnak );
-               $statements[] = $statement;
-
-               foreach ( $snaks as $snak ) {
-                       $statement = clone $statement;
-                       $snaks = new SnakList( array( $snak ) );
-                       $statement->getReferences()->addReference( new 
Reference( $snaks ) );
-                       $statements[] = $statement;
-               }
-
-               $statement = clone $statement;
-               $snaks = new SnakList( $this->snakProvider() );
-               $statement->getReferences()->addReference( new Reference( 
$snaks ) );
-               $statements[] = $statement;
-
-               $statement = clone $statement;
-               $snaks = new SnakList( $this->snakProvider() );
-               $statement->setQualifiers( $snaks );
-               $statement->getReferences()->addReference( new Reference( 
$snaks ) );
-               $statements[] = $statement;
+       public static function provideClaims() {
+               $testCases = array();
 
                $ranks = array(
                        Statement::RANK_DEPRECATED,
@@ -116,49 +90,70 @@
                        Statement::RANK_PREFERRED
                );
 
-               /**
-                * @var Statement[] $statements
-                */
-               foreach ( $statements as &$statement ) {
+               $snaks = self::snakProvider();
+               $mainSnak = $snaks[0];
+               $statement = new Statement( $mainSnak );
+               $statement->setRank( $ranks[array_rand( $ranks )] );
+               $testCases[] = array( $statement );
+
+               foreach ( $snaks as $snak ) {
+                       $statement = clone $statement;
+                       $snaks = new SnakList( array( $snak ) );
+                       $statement->getReferences()->addReference( new 
Reference( $snaks ) );
                        $statement->setRank( $ranks[array_rand( $ranks )] );
+                       $testCases[] = array( $statement );
                }
 
-               return $statements;
+               $statement = clone $statement;
+               $snaks = new SnakList( self::snakProvider() );
+               $statement->getReferences()->addReference( new Reference( 
$snaks ) );
+               $statement->setRank( $ranks[array_rand( $ranks )] );
+               $testCases[] = array( $statement );
+
+               $statement = clone $statement;
+               $snaks = new SnakList( self::snakProvider() );
+               $statement->setQualifiers( $snaks );
+               $statement->getReferences()->addReference( new Reference( 
$snaks ) );
+               $statement->setRank( $ranks[array_rand( $ranks )] );
+               $testCases[] = array( $statement );
+
+               return $testCases ;
        }
 
-       public function testAddClaim() {
-               foreach ( $this->claimProvider() as $claim ) {
-                       $item = Item::newEmpty();
-                       $content = new ItemContent( $item );
-                       $content->save( '', null, EDIT_NEW );
+       /**
+        * @dataProvider provideClaims
+        */
+       public function testAddClaim( Claim $claim ) {
+               $item = Item::newEmpty();
+               $content = new ItemContent( $item );
+               $content->save( '', null, EDIT_NEW );
 
-                       $guidGenerator = new ClaimGuidGenerator( $item->getId() 
);
-                       $guid = $guidGenerator->newGuid();
+               $guidGenerator = new ClaimGuidGenerator( $item->getId() );
+               $guid = $guidGenerator->newGuid();
 
-                       $claim->setGuid( $guid );
+               $claim->setGuid( $guid );
 
-                       // Addition request
-                       $this->makeRequest( $claim, $item->getId(), 1 );
+               // Addition request
+               $this->makeRequest( $claim, $item->getId(), 1 );
 
-                       // Reorder qualifiers:
-                       if( count( $claim->getQualifiers() ) > 0 ) {
-                               // Simply reorder the qualifiers by putting the 
first qualifier to the end. This is
-                               // supposed to be done in the serialized 
representation since changing the actual
-                               // object might apply intrinsic sorting.
-                               $serializerFactory = new SerializerFactory();
-                               $serializer = 
$serializerFactory->newSerializerForObject( $claim );
-                               $serializedClaim = $serializer->getSerialized( 
$claim );
-                               $firstPropertyId = array_shift( 
$serializedClaim['qualifiers-order'] );
-                               array_push( 
$serializedClaim['qualifiers-order'], $firstPropertyId );
-                               $this->makeRequest( $serializedClaim, 
$item->getId(), 1 );
-                       }
-
-                       $claim = new Statement( new PropertyNoValueSnak( 9001 ) 
);
-                       $claim->setGuid( $guid );
-
-                       // Update request
-                       $this->makeRequest( $claim, $item->getId(), 1 );
+               // Reorder qualifiers
+               if( count( $claim->getQualifiers() ) > 0 ) {
+                       // Simply reorder the qualifiers by putting the first 
qualifier to the end. This is
+                       // supposed to be done in the serialized representation 
since changing the actual
+                       // object might apply intrinsic sorting.
+                       $serializerFactory = new SerializerFactory();
+                       $serializer = 
$serializerFactory->newSerializerForObject( $claim );
+                       $serializedClaim = $serializer->getSerialized( $claim );
+                       $firstPropertyId = array_shift( 
$serializedClaim['qualifiers-order'] );
+                       array_push( $serializedClaim['qualifiers-order'], 
$firstPropertyId );
+                       $this->makeRequest( $serializedClaim, $item->getId(), 1 
);
                }
+
+               $claim = new Statement( new PropertyNoValueSnak( 9001 ) );
+               $claim->setGuid( $guid );
+
+               // Update request
+               $this->makeRequest( $claim, $item->getId(), 1 );
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iab6dcd8f757febdda07c542d2a90c6072673c2b7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to