Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/344995 )

Change subject: Improve RDF test helpers.
......................................................................

Improve RDF test helpers.

This patch allows all RDF tests to match against a set of files,
instead of a single file. The idea is to modularize test data.

See the follow-up changes for the intended use.

Change-Id: I3b6ffe8bce3fa98951bea0e51954d63126d39be7
---
M repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
M repo/tests/phpunit/includes/Rdf/FullStatementRdfBuilderTest.php
M repo/tests/phpunit/includes/Rdf/NTriplesRdfTestHelper.php
M repo/tests/phpunit/includes/Rdf/RdfBuilderTest.php
M repo/tests/phpunit/includes/Rdf/RdfBuilderTestData.php
M repo/tests/phpunit/includes/Rdf/SiteLinksRdfBuilderTest.php
M repo/tests/phpunit/includes/Rdf/SnakRdfBuilderTest.php
M repo/tests/phpunit/includes/Rdf/TermsRdfBuilderTest.php
M repo/tests/phpunit/includes/Rdf/TruthyStatementRdfBuilderTest.php
M repo/tests/phpunit/maintenance/AddUnitsTest.php
10 files changed, 273 insertions(+), 192 deletions(-)


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

diff --git a/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php 
b/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
index c6fcca3..83797e3 100644
--- a/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
+++ b/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
@@ -47,7 +47,12 @@
        protected function setUp() {
                parent::setUp();
 
-               $this->helper = new NTriplesRdfTestHelper();
+               $this->helper = new NTriplesRdfTestHelper(
+                       new RdfBuilderTestData(
+                               __DIR__ . '/../../data/rdf/entities',
+                               __DIR__ . '/../../data/rdf/RdfDumpGenerator'
+                       )
+               );
        }
 
        /**
@@ -79,10 +84,7 @@
        }
 
        private function getTestData() {
-               return new RdfBuilderTestData(
-                       __DIR__ . '/../../data/rdf/entities',
-                       __DIR__ . '/../../data/rdf/RdfDumpGenerator'
-               );
+               return $this->helper->getTestData();
        }
 
        /**
@@ -194,8 +196,7 @@
                ob_start();
                $dumper->generateDump( $pager );
                $actual = ob_get_clean();
-               $expected = $this->getTestData()->getNTriples( $dumpname );
-               $this->helper->assertNTriplesEquals( $expected, $actual );
+               $this->helper->assertNTriplesEqualsDataset( $dumpname, $actual 
);
        }
 
        public function loadDataProvider() {
@@ -211,11 +212,10 @@
         */
        public function testReferenceDedup( array $ids, $dumpname ) {
                $entities = array();
-               $rdfTest = new RdfBuilderTest();
 
                foreach ( $ids as $id ) {
                        $id = $id->getSerialization();
-                       $entities[$id] = $rdfTest->getEntityData( $id );
+                       $entities[$id] = $this->getTestData()->getEntity( $id );
                }
 
                $dumper = $this->newDumpGenerator( $entities );
@@ -226,8 +226,7 @@
                ob_start();
                $dumper->generateDump( $pager );
                $actual = ob_get_clean();
-               $expected = $this->getTestData()->getNTriples( $dumpname );
-               $this->helper->assertNTriplesEquals( $expected, $actual );
+               $this->helper->assertNTriplesEqualsDataset( $dumpname, $actual 
);
        }
 
 }
diff --git a/repo/tests/phpunit/includes/Rdf/FullStatementRdfBuilderTest.php 
b/repo/tests/phpunit/includes/Rdf/FullStatementRdfBuilderTest.php
index 6054627..ccec8a5 100644
--- a/repo/tests/phpunit/includes/Rdf/FullStatementRdfBuilderTest.php
+++ b/repo/tests/phpunit/includes/Rdf/FullStatementRdfBuilderTest.php
@@ -30,15 +30,17 @@
         */
        private $helper;
 
-       /**
-        * @var RdfBuilderTestData|null
-        */
-       private $testData = null;
+       public function __construct() {
+               parent::__construct();
 
-       protected function setUp() {
-               parent::setUp();
+               $this->helper = new NTriplesRdfTestHelper(
+                       new RdfBuilderTestData(
+                               __DIR__ . '/../../data/rdf/entities',
+                               __DIR__ . 
'/../../data/rdf/FullStatementRdfBuilder'
+                       )
+               );
 
-               $this->helper = new NTriplesRdfTestHelper();
+               $this->helper->setAllBlanksEqual( true );
        }
 
        /**
@@ -47,14 +49,7 @@
         * @return RdfBuilderTestData
         */
        private function getTestData() {
-               if ( $this->testData === null ) {
-                       $this->testData = new RdfBuilderTestData(
-                               __DIR__ . '/../../data/rdf/entities',
-                               __DIR__ . 
'/../../data/rdf/FullStatementRdfBuilder'
-                       );
-               }
-
-               return $this->testData;
+               return $this->helper->getTestData();
        }
 
        /**
@@ -114,19 +109,16 @@
 
        private function assertOrCreateNTriples( $dataSetName, RdfWriter 
$writer ) {
                $actual = $writer->drain();
-               $expected = $this->getTestData()->getNTriples( $dataSetName );
-
-               if ( $expected === null ) {
-                       $this->getTestData()->putTestData( $dataSetName, 
$actual, '.actual' );
-                       $this->fail( "Data set $dataSetName not found! Created 
file with the current data using"
-                               . " the suffix .actual" );
-               }
-
-               $this->helper->assertNTriplesEquals( $expected, $actual, "Data 
set $dataSetName" );
+               $this->helper->assertNTriplesEqualsDataset( $dataSetName, 
$actual );
        }
 
        public function provideAddEntity() {
-               $props = [ 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 
'P10' ];
+               $props = array_map(
+                       function ( $row ) {
+                               return $row[0];
+                       },
+                       $this->getTestData()->getTestProperties()
+               );
 
                return array(
                        array( 'Q4', 0, 'Q4_minimal', array() ),
@@ -183,7 +175,7 @@
 
        public function provideAddStatements() {
                return array(
-                       array( 'Q4', 'Q4_all' ),
+                       array( 'Q4', [ 'Q4_statements', 'Q4_values' ] ),
                );
        }
 
diff --git a/repo/tests/phpunit/includes/Rdf/NTriplesRdfTestHelper.php 
b/repo/tests/phpunit/includes/Rdf/NTriplesRdfTestHelper.php
index 81f8a0c..ffdd2bd 100644
--- a/repo/tests/phpunit/includes/Rdf/NTriplesRdfTestHelper.php
+++ b/repo/tests/phpunit/includes/Rdf/NTriplesRdfTestHelper.php
@@ -2,10 +2,13 @@
 
 namespace Wikibase\Repo\Tests\Rdf;
 
+use InvalidArgumentException;
 use PHPUnit_Framework_Assert;
+use PHPUnit_Framework_AssertionFailedError;
+use RuntimeException;
 
 /**
- * Utility class to load, normalize and compare N-Triples in RDF builder tests.
+ * Utility class to normalize and compare N-Triples in RDF builder tests.
  *
  * @see https://en.wikipedia.org/wiki/N-Triples
  *
@@ -14,6 +17,49 @@
  * @author Thiemo Mättig
  */
 class NTriplesRdfTestHelper {
+
+       /**
+        * @var RdfBuilderTestData|null
+        */
+       private $testData;
+
+       /**
+        * @var bool
+        */
+       private $allBlanksEqual = false;
+
+       public function __construct( RdfBuilderTestData $testData = null ) {
+               $this->testData = $testData;
+       }
+
+       /**
+        * @return boolean whether all blank nodes are considered equal
+        */
+       public function getAllBlanksEqual() {
+               return $this->allBlanksEqual;
+       }
+
+       /**
+        * Setting all blank nodes to be equal allows tests to be robust 
against changes in the
+        * numbering of blank nodes. However, it also means that no test can 
reöly on the identity
+        * of a blank node.
+        *
+        * @param boolean $allBlanksEqual whether all blank nodes are 
considered equal
+        */
+       public function setAllBlanksEqual( $allBlanksEqual ) {
+               $this->allBlanksEqual = $allBlanksEqual;
+       }
+
+       /**
+        * @return RdfBuilderTestData|null
+        */
+       public function getTestData() {
+               if ( !$this->testData ) {
+                       throw new RuntimeException( 'No RdfBuilderTestData 
provided to constructor' );
+               }
+
+               return $this->testData;
+       }
 
        /**
         * @param string[]|string $nTriples
@@ -26,6 +72,16 @@
                        $nTriples = explode( "\n", rtrim( $nTriples, "\n" ) );
                }
 
+               if ( $this->allBlanksEqual ) {
+                       $nTriples = array_map(
+                               function ( $line ) {
+                                       return preg_replace( '/_:\w+/', 
'_:#####', $line );
+                               },
+                               $nTriples
+                       );
+               }
+
+               $nTriples = array_unique( $nTriples );
                sort( $nTriples );
 
                return $nTriples;
@@ -52,4 +108,78 @@
                PHPUnit_Framework_Assert::assertEquals( $missing, $extra, 
$message );
        }
 
+       /**
+        * Compares the actual data to the expected data, and records any 
differences by creating
+        * new files in the test data directory, with the suffixes .extra and 
.missing.
+        *
+        * @note This method is intended to be used when updating test data, or 
manually
+        * investigating test failures. Code using this method is typically not 
checked in.
+        *
+        * @param string|string[] $dataSetNames
+        * @param string|string[] $actual
+        */
+       public function recordNTriplesDatasetDifferences( $dataSetNames, 
$actual ) {
+               $testData = $this->getTestData();
+
+               $dataSetNames = (array)$dataSetNames;
+               $joinedName = join( '-', $dataSetNames );
+
+               $expected = $testData->getNTriples( $dataSetNames );
+               $expected = $this->normalizeNTriples( $expected );
+               $actual = $this->normalizeNTriples( $actual );
+
+               // Comparing $expected and $actual directly would show triples 
that are present in both but
+               // shifted in position. That makes the output hard to read. 
Calculating the $missing and
+               // $extra sets helps.
+               $extra = array_diff( $actual, $expected );
+               $missing = array_diff( $expected, $actual );
+
+               if ( !empty( $extra ) ) {
+                       $testData->putTestData( $joinedName, $extra, '.extra' );
+               }
+
+               if ( !empty( $missing ) ) {
+                       $testData->putTestData( $joinedName, $extra, '.missing' 
);
+               }
+       }
+
+       /**
+        * Creates a test data file from the given triples. The file will be 
created in the
+        * test data directory.
+        *
+        * @note This method is intended to be used when updating test data, or 
manually
+        * investigating test failures. Code using this method is typically not 
checked in.
+        *
+        * @param string|string[] $dataSetNames
+        * @param string|string[] $triples
+        * @param string $suffix File name suffix, including the leading dot. 
None per default.
+        */
+       public function createNTriplesDataset( $dataSetNames, $triples, $suffix 
= '' ) {
+               $testData = $this->getTestData();
+
+               $dataSetNames = (array)$dataSetNames;
+               $joinedName = join( '-', $dataSetNames );
+
+               $testData->putTestData( $joinedName, $triples, '.suffix' );
+       }
+
+       /**
+        * @param string|string[] $dataSetNames
+        * @param string|string[] $actual
+        * @param string $message
+        */
+       public function assertNTriplesEqualsDataset( $dataSetNames, $actual, 
$message = null ) {
+               $testData = $this->getTestData();
+
+               $dataSetNames = (array)$dataSetNames;
+               $prettyName = join( '+', $dataSetNames );
+
+               if ( $message === null ) {
+                       $message = "Data set $prettyName";
+               }
+
+               $expected = $testData->getNTriples( $dataSetNames );
+               $this->assertNTriplesEquals( $expected, $actual, $message );
+       }
+
 }
diff --git a/repo/tests/phpunit/includes/Rdf/RdfBuilderTest.php 
b/repo/tests/phpunit/includes/Rdf/RdfBuilderTest.php
index c497790..f3fa10a 100644
--- a/repo/tests/phpunit/includes/Rdf/RdfBuilderTest.php
+++ b/repo/tests/phpunit/includes/Rdf/RdfBuilderTest.php
@@ -33,15 +33,17 @@
         */
        private $helper;
 
-       /**
-        * @var RdfBuilderTestData
-        */
-       private $testData;
-
        protected function setUp() {
                parent::setUp();
 
-               $this->helper = new NTriplesRdfTestHelper();
+               $this->helper = new NTriplesRdfTestHelper(
+                       new RdfBuilderTestData(
+                               __DIR__ . '/../../data/rdf/entities',
+                               __DIR__ . '/../../data/rdf/RdfBuilder'
+                       )
+               );
+
+               $this->helper->setAllBlanksEqual( true );
        }
 
        /**
@@ -50,13 +52,7 @@
         * @return RdfBuilderTestData
         */
        private function getTestData() {
-               if ( empty( $this->testData ) ) {
-                       $this->testData =
-                               new RdfBuilderTestData( __DIR__ . 
'/../../data/rdf/entities',
-                                       __DIR__ . '/../../data/rdf/RdfBuilder' 
);
-               }
-
-               return $this->testData;
+               return $this->helper->getTestData();
        }
 
        /**
@@ -137,7 +133,6 @@
         */
        public function testAddEntity( $entityName, $dataSetName ) {
                $entity = $this->getEntityData( $entityName );
-               $expected = $this->getTestData()->getNTriples( $dataSetName );
 
                $builder =
                        $this->newRdfBuilder( 
RdfProducer::PRODUCE_ALL_STATEMENTS |
@@ -149,7 +144,7 @@
                $builder->addEntity( $entity );
                $builder->addEntityRevisionInfo( $entity->getId(), 42, 
"2014-11-04T03:11:05Z" );
 
-               $this->helper->assertNTriplesEquals( $expected, 
$builder->getRDF() );
+               $this->helper->assertNTriplesEqualsDataset( $dataSetName, 
$builder->getRDF() );
        }
 
        public function provideAddEntityStub() {
@@ -161,7 +156,6 @@
         */
        public function testAddEntityStub( $entityName, $dataSetName ) {
                $entity = $this->getEntityData( $entityName );
-               $expected = $this->getTestData()->getNTriples( $dataSetName );
 
                $builder =
                        $this->newRdfBuilder( 
RdfProducer::PRODUCE_ALL_STATEMENTS |
@@ -172,7 +166,7 @@
                                              RdfProducer::PRODUCE_FULL_VALUES 
);
                $builder->addEntityStub( $entity );
 
-               $this->helper->assertNTriplesEquals( $expected, 
$builder->getRDF() );
+               $this->helper->assertNTriplesEqualsDataset( $dataSetName, 
$builder->getRDF() );
        }
 
        public function testAddEntityRedirect() {
@@ -189,21 +183,16 @@
 
        public function getProduceOptions() {
                $produceTests = [
-                       [ 'Q4', RdfProducer::PRODUCE_ALL_STATEMENTS, 
'Q4_all_statements' ],
-                       [ 'Q4', RdfProducer::PRODUCE_TRUTHY_STATEMENTS, 
'Q4_truthy_statements' ],
-                       [ 'Q6', RdfProducer::PRODUCE_ALL_STATEMENTS, 
'Q6_no_qualifiers' ],
                        [
                                'Q6',
                                RdfProducer::PRODUCE_ALL_STATEMENTS | 
RdfProducer::PRODUCE_QUALIFIERS,
                                'Q6_with_qualifiers'
                        ],
-                       [ 'Q7', RdfProducer::PRODUCE_ALL_STATEMENTS, 
'Q7_no_refs' ],
                        [
                                'Q7',
                                RdfProducer::PRODUCE_ALL_STATEMENTS | 
RdfProducer::PRODUCE_REFERENCES,
                                'Q7_refs'
                        ],
-                       [ 'Q3', RdfProducer::PRODUCE_SITELINKS, 'Q3_sitelinks' 
],
                        [
                                'Q4',
                                RdfProducer::PRODUCE_ALL_STATEMENTS | 
RdfProducer::PRODUCE_PROPERTIES,
@@ -214,7 +203,6 @@
                                RdfProducer::PRODUCE_ALL_STATEMENTS | 
RdfProducer::PRODUCE_FULL_VALUES,
                                'Q4_values'
                        ],
-                       [ 'Q1', RdfProducer::PRODUCE_VERSION_INFO, 'Q1_info' ],
                        [
                                'Q4',
                                RdfProducer::PRODUCE_TRUTHY_STATEMENTS | 
RdfProducer::PRODUCE_RESOLVED_ENTITIES,
@@ -235,20 +223,19 @@
         */
        public function testRdfOptions( $entityName, $produceOption, 
$dataSetName ) {
                $entity = $this->getEntityData( $entityName );
-               $expected = $this->getTestData()->getNTriples( $dataSetName );
 
                $builder = $this->newRdfBuilder( $produceOption );
                $builder->addEntity( $entity );
                $builder->addEntityRevisionInfo( $entity->getId(), 42, 
"2013-10-04T03:31:05Z" );
                $builder->resolveMentionedEntities( 
$this->getTestData()->getMockRepository() );
-               $this->helper->assertNTriplesEquals( $expected, 
$builder->getRDF() );
+               $this->helper->assertNTriplesEqualsDataset( $dataSetName, 
$builder->getRDF() );
        }
 
        public function testDumpHeader() {
                $builder = $this->newRdfBuilder( 
RdfProducer::PRODUCE_VERSION_INFO );
                $builder->addDumpHeader( 1426110695 );
-               $expected = $this->getTestData()->getNTriples( 'dumpheader' );
-               $this->helper->assertNTriplesEquals( $expected, 
$builder->getRDF() );
+               $dataSetName = 'dumpheader';
+               $this->helper->assertNTriplesEqualsDataset( $dataSetName, 
$builder->getRDF() );
        }
 
        public function testDeduplication() {
@@ -262,8 +249,8 @@
                $builder->addEntity( $this->getEntityData( 'Q9' ) );
                $data2 = $builder->getRDF();
 
-               $expected = $this->getTestData()->getNTriples( 'Q7_Q9_dedup' );
-               $this->helper->assertNTriplesEquals( $expected, $data1 . $data2 
);
+               $dataSetName = 'Q7_Q9_dedup';
+               $this->helper->assertNTriplesEqualsDataset( $dataSetName, 
$data1 . $data2 );
        }
 
        public function getProps() {
@@ -298,6 +285,9 @@
                ];
        }
 
+       /**
+        * @return PageProps
+        */
        private function getPropsMock() {
                $propsMock =
                        $this->getMockBuilder( PageProps::class 
)->disableOriginalConstructor()->getMock();
@@ -332,8 +322,7 @@
                $builder->addEntityPageProps( $this->getEntityData( 'Q9' 
)->getId() );
                $data = $builder->getRDF();
 
-               $expected = $this->getTestData()->getNTriples( $name );
-               $this->helper->assertNTriplesEquals( $expected, $data );
+               $this->helper->assertNTriplesEqualsDataset( $name, $data );
        }
 
        public function testPagePropsNone() {
diff --git a/repo/tests/phpunit/includes/Rdf/RdfBuilderTestData.php 
b/repo/tests/phpunit/includes/Rdf/RdfBuilderTestData.php
index d1080d4..c149238 100644
--- a/repo/tests/phpunit/includes/Rdf/RdfBuilderTestData.php
+++ b/repo/tests/phpunit/includes/Rdf/RdfBuilderTestData.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Repo\Tests\Rdf;
 
+use InvalidArgumentException;
 use Site;
 use SiteList;
 use Wikibase\DataModel\Entity\EntityDocument;
@@ -15,6 +16,7 @@
 use Wikibase\Rdf\RdfVocabulary;
 use Wikibase\Repo\WikibaseRepo;
 use Wikibase\Lib\Tests\MockRepository;
+use Wikimedia\Purtle\BNodeLabeler;
 use Wikimedia\Purtle\NTriplesRdfWriter;
 
 /**
@@ -83,18 +85,48 @@
        }
 
        /**
+        * @param $dataSetName
+        * @return string
+        */
+       private function getDataSetFileName( $dataSetName ) {
+               return $filename = "{$this->dataDir}/$dataSetName.nt";
+       }
+
+       /**
+        * @param $dataSetName
+        * @return bool
+        */
+       public function hasDataSet( $dataSetName ) {
+               $filename = $this->getDataSetFileName( $dataSetName );
+               return file_exists( $filename );
+       }
+
+       /**
         * Load serialized ntriples.
         *
-        * @param string $dataSetName
-        * @return string|null N-Triples, or null if no data file was found 
with the given name.
+        * @param string|string[] $dataSetName one or more data set names
+        * @param string ... more data set names
+        * @return string N-Triples
         */
        public function getNTriples( $dataSetName ) {
-               $filename = "{$this->dataDir}/$dataSetName.nt";
-               if ( !file_exists( $filename ) ) {
-                       return null;
+               $dataSets =  is_array( $dataSetName ) ? $dataSetName : 
func_get_args();
+               $triples = [];
+
+               foreach ( $dataSets as $dataSetName ) {
+                       $filename = $this->getDataSetFileName( $dataSetName );
+
+                       if ( !file_exists( $filename ) || !is_readable( 
$filename ) ) {
+                               throw new InvalidArgumentException( 'No such 
file: ' . $filename );
+                       }
+
+                       $lines = file( $filename );
+                       $lines = array_map( 'trim', $lines );
+                       $triples = array_merge( $triples,  $lines );
                }
 
-               return file_get_contents( $filename );
+               $triples = array_unique( $triples );
+
+               return $triples;
        }
 
        /**
@@ -108,17 +140,15 @@
         * @param string[]|string $lines
         * @param string $suffix File name suffix
         *
-        * @return bool|int the number of bytes that were written to the file, 
or
-        *         false on failure.
+        * @return string The filename the data was written to, or false if no 
data was written.
         */
        public function putTestData( $dataSetName, $lines, $suffix = '' ) {
-               $filename = "{$this->dataDir}/$dataSetName.nt$suffix";
-               if ( file_exists( $filename ) ) {
-                       return false;
-               }
+               $filename = $this->getDataSetFileName( $dataSetName ) . $suffix;
 
                $data = join( "\n", (array)$lines );
-               return file_put_contents( $filename, $data );
+               file_put_contents( $filename, $data );
+
+               return $filename;
        }
 
        /**
@@ -177,19 +207,20 @@
 
        /**
         * Define a set of fake properties
-        * @return array
+        * @return array[] A list of properties used in the test data. Each 
element is a pair
+        *         of an PropertyId and a data type ID.
         */
-       private static function getTestProperties() {
+       public static function getTestProperties() {
                return array(
-                       array( 2, 'wikibase-item' ),
-                       array( 3, 'commonsMedia' ),
-                       array( 4, 'globe-coordinate' ),
-                       array( 5, 'monolingualtext' ),
-                       array( 6, 'quantity' ),
-                       array( 7, 'string' ),
-                       array( 8, 'time' ),
-                       array( 9, 'url' ),
-                       array( 10, 'geo-shape' ),
+                       array( new PropertyId( 'P2' ), 'wikibase-item' ),
+                       array( new PropertyId( 'P3' ), 'commonsMedia' ),
+                       array( new PropertyId( 'P4' ), 'globe-coordinate' ),
+                       array( new PropertyId( 'P5' ), 'monolingualtext' ),
+                       array( new PropertyId( 'P6' ), 'quantity' ),
+                       array( new PropertyId( 'P7' ), 'string' ),
+                       array( new PropertyId( 'P8' ), 'time' ),
+                       array( new PropertyId( 'P9' ), 'url' ),
+                       array( new PropertyId( 'P10' ), 'geo-shape' ),
                );
        }
 
@@ -207,11 +238,10 @@
 
                $repo = new MockRepository();
 
-               foreach ( self::getTestProperties() as $prop ) {
-                       list( $id, $type ) = $prop;
+               foreach ( self::getTestProperties() as list( $id, $type ) ) {
                        $fingerprint = new Fingerprint();
                        $fingerprint->setLabel( 'en', "Property$id" );
-                       $entity = new Property( new PropertyId( 'P' . $id ), 
$fingerprint, $type );
+                       $entity = new Property( $id, $fingerprint, $type );
                        $repo->putEntity( $entity );
                }
 
diff --git a/repo/tests/phpunit/includes/Rdf/SiteLinksRdfBuilderTest.php 
b/repo/tests/phpunit/includes/Rdf/SiteLinksRdfBuilderTest.php
index a75852f..a3b66fc 100644
--- a/repo/tests/phpunit/includes/Rdf/SiteLinksRdfBuilderTest.php
+++ b/repo/tests/phpunit/includes/Rdf/SiteLinksRdfBuilderTest.php
@@ -22,15 +22,15 @@
         */
        private $helper;
 
-       /**
-        * @var RdfBuilderTestData|null
-        */
-       private $testData = null;
-
        protected function setUp() {
                parent::setUp();
 
-               $this->helper = new NTriplesRdfTestHelper();
+               $this->helper = new NTriplesRdfTestHelper(
+                       new RdfBuilderTestData(
+                               __DIR__ . '/../../data/rdf/entities',
+                               __DIR__ . '/../../data/rdf/SiteLinksRdfBuilder'
+                       )
+               );
        }
 
        /**
@@ -39,14 +39,7 @@
         * @return RdfBuilderTestData
         */
        private function getTestData() {
-               if ( $this->testData === null ) {
-                       $this->testData = new RdfBuilderTestData(
-                               __DIR__ . '/../../data/rdf/entities',
-                               __DIR__ . '/../../data/rdf/SiteLinksRdfBuilder'
-                       );
-               }
-
-               return $this->testData;
+               return $this->helper->getTestData();
        }
 
        /**
@@ -70,15 +63,7 @@
 
        private function assertOrCreateNTriples( $dataSetName, RdfWriter 
$writer ) {
                $actual = $writer->drain();
-               $expected = $this->getTestData()->getNTriples( $dataSetName );
-
-               if ( $expected === null ) {
-                       $this->getTestData()->putTestData( $dataSetName, 
$actual, '.actual' );
-                       $this->fail( "Data set $dataSetName not found! Created 
file with the current data using"
-                               . " the suffix .actual" );
-               }
-
-               $this->helper->assertNTriplesEquals( $expected, $actual, "Data 
set $dataSetName" );
+               $this->helper->assertNTriplesEqualsDataset( $dataSetName, 
$actual );
        }
 
        public function provideAddEntity() {
diff --git a/repo/tests/phpunit/includes/Rdf/SnakRdfBuilderTest.php 
b/repo/tests/phpunit/includes/Rdf/SnakRdfBuilderTest.php
index 1e800dc..3bdf2c4 100644
--- a/repo/tests/phpunit/includes/Rdf/SnakRdfBuilderTest.php
+++ b/repo/tests/phpunit/includes/Rdf/SnakRdfBuilderTest.php
@@ -32,15 +32,15 @@
         */
        private $helper;
 
-       /**
-        * @var RdfBuilderTestData|null
-        */
-       private $testData = null;
-
        protected function setUp() {
                parent::setUp();
 
-               $this->helper = new NTriplesRdfTestHelper();
+               $this->helper = new NTriplesRdfTestHelper(
+                       new RdfBuilderTestData(
+                               __DIR__ . '/../../data/rdf/entities',
+                               __DIR__ . '/../../data/rdf/SnakRdfBuilder'
+                       )
+               );
        }
 
        /**
@@ -49,14 +49,7 @@
         * @return RdfBuilderTestData
         */
        private function getTestData() {
-               if ( $this->testData === null ) {
-                       $this->testData = new RdfBuilderTestData(
-                               __DIR__ . '/../../data/rdf/entities',
-                               __DIR__ . '/../../data/rdf/SnakRdfBuilder'
-                       );
-               }
-
-               return $this->testData;
+               return $this->helper->getTestData();
        }
 
        /**
diff --git a/repo/tests/phpunit/includes/Rdf/TermsRdfBuilderTest.php 
b/repo/tests/phpunit/includes/Rdf/TermsRdfBuilderTest.php
index e2a24ea..54d4919 100644
--- a/repo/tests/phpunit/includes/Rdf/TermsRdfBuilderTest.php
+++ b/repo/tests/phpunit/includes/Rdf/TermsRdfBuilderTest.php
@@ -22,15 +22,15 @@
         */
        private $helper;
 
-       /**
-        * @var RdfBuilderTestData|null
-        */
-       private $testData = null;
-
        protected function setUp() {
                parent::setUp();
 
-               $this->helper = new NTriplesRdfTestHelper();
+               $this->helper = new NTriplesRdfTestHelper(
+                       new RdfBuilderTestData(
+                               __DIR__ . '/../../data/rdf/entities',
+                               __DIR__ . '/../../data/rdf/TermsRdfBuilder'
+                       )
+               );
        }
 
        /**
@@ -39,14 +39,7 @@
         * @return RdfBuilderTestData
         */
        private function getTestData() {
-               if ( $this->testData === null ) {
-                       $this->testData = new RdfBuilderTestData(
-                               __DIR__ . '/../../data/rdf/entities',
-                               __DIR__ . '/../../data/rdf/TermsRdfBuilder'
-                       );
-               }
-
-               return $this->testData;
+               return $this->helper->getTestData();
        }
 
        /**
@@ -69,15 +62,7 @@
 
        private function assertOrCreateNTriples( $dataSetName, RdfWriter 
$writer ) {
                $actual = $writer->drain();
-               $expected = $this->getTestData()->getNTriples( $dataSetName );
-
-               if ( $expected === null ) {
-                       $this->getTestData()->putTestData( $dataSetName, 
$actual, '.actual' );
-                       $this->fail( "Data set $dataSetName not found! Created 
file with the current data using"
-                               . " the suffix .actual" );
-               }
-
-               $this->helper->assertNTriplesEquals( $expected, $actual, "Data 
set $dataSetName" );
+               $this->helper->assertNTriplesEqualsDataset( $dataSetName, 
$actual );
        }
 
        public function provideAddEntity() {
diff --git a/repo/tests/phpunit/includes/Rdf/TruthyStatementRdfBuilderTest.php 
b/repo/tests/phpunit/includes/Rdf/TruthyStatementRdfBuilderTest.php
index 1610768..bb1209b 100644
--- a/repo/tests/phpunit/includes/Rdf/TruthyStatementRdfBuilderTest.php
+++ b/repo/tests/phpunit/includes/Rdf/TruthyStatementRdfBuilderTest.php
@@ -29,15 +29,15 @@
         */
        private $helper;
 
-       /**
-        * @var RdfBuilderTestData|null
-        */
-       private $testData = null;
-
        protected function setUp() {
                parent::setUp();
 
-               $this->helper = new NTriplesRdfTestHelper();
+               $this->helper = new NTriplesRdfTestHelper(
+                       new RdfBuilderTestData(
+                               __DIR__ . '/../../data/rdf/entities',
+                               __DIR__ . 
'/../../data/rdf/TruthyStatementRdfBuilder'
+                       )
+               );
        }
 
        /**
@@ -46,14 +46,7 @@
         * @return RdfBuilderTestData
         */
        private function getTestData() {
-               if ( $this->testData === null ) {
-                       $this->testData = new RdfBuilderTestData(
-                               __DIR__ . '/../../data/rdf/entities',
-                               __DIR__ . 
'/../../data/rdf/TruthyStatementRdfBuilder'
-                       );
-               }
-
-               return $this->testData;
+               return $this->helper->getTestData();
        }
 
        /**
@@ -90,15 +83,7 @@
 
        private function assertOrCreateNTriples( $dataSetName, RdfWriter 
$writer ) {
                $actual = $writer->drain();
-               $expected = $this->getTestData()->getNTriples( $dataSetName );
-
-               if ( $expected === null ) {
-                       $this->getTestData()->putTestData( $dataSetName, 
$actual, '.actual' );
-                       $this->fail( "Data set $dataSetName not found! Created 
file with the current data using"
-                               . " the suffix .actual" );
-               }
-
-               $this->helper->assertNTriplesEquals( $expected, $actual, "Data 
set $dataSetName" );
+               $this->helper->assertNTriplesEqualsDataset( $dataSetName, 
$actual );
        }
 
        public function provideAddEntity() {
diff --git a/repo/tests/phpunit/maintenance/AddUnitsTest.php 
b/repo/tests/phpunit/maintenance/AddUnitsTest.php
index 794e4ea..064885c 100644
--- a/repo/tests/phpunit/maintenance/AddUnitsTest.php
+++ b/repo/tests/phpunit/maintenance/AddUnitsTest.php
@@ -46,13 +46,11 @@
                        $this->getMockBuilder( UnitConverter::class 
)->disableOriginalConstructor()->getMock();
                $this->script->setUnitConverter( $this->uc );
                $this->script->initializeBuilder();
-               $this->helper = new NTriplesRdfTestHelper();
-       }
-
-       private function getTestData() {
-               return new RdfBuilderTestData(
-                       __DIR__ . '/../data/maintenance',
-                       __DIR__ . '/../data/maintenance'
+               $this->helper = new NTriplesRdfTestHelper(
+                       new RdfBuilderTestData(
+                               __DIR__ . '/../data/maintenance',
+                               __DIR__ . '/../data/maintenance'
+                       )
                );
        }
 
@@ -167,12 +165,7 @@
 
                $values = 'Q1';
                $this->script->processUnit( $values );
-               $expected = $this->getTestData()->getNTriples( $result );
-               if ( !$expected ) {
-                       $this->getTestData()->putTestData( $result, 
$this->script->output, '.actual' );
-               } else {
-                       $this->helper->assertNTriplesEquals( $expected, 
$this->script->output );
-               }
+               $this->helper->assertNTriplesEqualsDataset( $result, 
$this->script->output );
        }
 
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3b6ffe8bce3fa98951bea0e51954d63126d39be7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>

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

Reply via email to