Tobias Gritschacher has submitted this change and it was merged.

Change subject: Move SnakFactory to lib
......................................................................


Move SnakFactory to lib

Change-Id: I4003c6edb36b04d80ff71dd3a500aa3b30b10ab6
---
D DataModel/Snak/SnakFactory.php
M WikibaseDataModel.classes.php
D tests/phpunit/Snak/SnakFactoryTest.php
3 files changed, 0 insertions(+), 166 deletions(-)

Approvals:
  Tobias Gritschacher: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/DataModel/Snak/SnakFactory.php b/DataModel/Snak/SnakFactory.php
deleted file mode 100644
index 6e0c5a2..0000000
--- a/DataModel/Snak/SnakFactory.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-
-namespace Wikibase;
-
-use DataValues\DataValue;
-use DataValues\DataValueFactory;
-use DataValues\IllegalValueException;
-use InvalidArgumentException;
-use MWException;
-
-/**
- * Factory for creating new snaks.
- *
- * @since 0.3
- *
- * @ingroup WikibaseDataModel
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < jeroended...@gmail.com >
- * @author Daniel Kinzler
- */
-class SnakFactory {
-
-       /**
-        * Builds and returns a new snak from the provided property, snak type
-        * and optional snak value and value type.
-        *
-        * @since 0.4
-        *
-        * @param EntityId    $propertyId
-        * @param string      $snakType
-        * @param DataValue $value
-        *
-        * @return Snak
-        *
-        * @throws InvalidArgumentException
-        */
-       public function newSnak( EntityId $propertyId, $snakType, DataValue 
$value = null ) {
-               if ( $propertyId->getEntityType() !== Property::ENTITY_TYPE ) {
-                       throw new InvalidArgumentException( 'Expected an 
EntityId of a property' );
-               }
-
-               switch ( $snakType ) {
-                       case 'value':
-                               if ( $value === null ) {
-                                       throw new InvalidArgumentException( 
"`value` snaks require a the $value parameter to be set!" );
-                               }
-
-                               $snak = new PropertyValueSnak( $propertyId, 
$value );
-                               break;
-                       case 'novalue':
-                               $snak = new PropertyNoValueSnak( $propertyId );
-                               break;
-                       case 'somevalue':
-                               $snak = new PropertySomeValueSnak( $propertyId 
);
-                               break;
-                       default:
-                               throw new InvalidArgumentException( "bad snak 
type: $snakType" );
-               }
-
-               assert( isset( $snak ) );
-               assert( $snak instanceof Snak );
-
-               return $snak;
-       }
-
-}
\ No newline at end of file
diff --git a/WikibaseDataModel.classes.php b/WikibaseDataModel.classes.php
index 2f00bf3..2ed124b 100644
--- a/WikibaseDataModel.classes.php
+++ b/WikibaseDataModel.classes.php
@@ -31,7 +31,6 @@
                'Wikibase\PropertyValueSnak' => 
'DataModel/Snak/PropertyValueSnak.php',
                'Wikibase\PropertySomeValueSnak' => 
'DataModel/Snak/PropertySomeValueSnak.php',
                'Wikibase\Snak' => 'DataModel/Snak/Snak.php',
-               'Wikibase\SnakFactory' => 'DataModel/Snak/SnakFactory.php',
                'Wikibase\SnakList' => 'DataModel/Snak/SnakList.php',
                'Wikibase\SnakObject' => 'DataModel/Snak/SnakObject.php',
                'Wikibase\SnakRole' => 'DataModel/Snak/SnakRole.php',
diff --git a/tests/phpunit/Snak/SnakFactoryTest.php 
b/tests/phpunit/Snak/SnakFactoryTest.php
deleted file mode 100644
index bdede0d..0000000
--- a/tests/phpunit/Snak/SnakFactoryTest.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
- /**
- *
- * Copyright © 20.06.13 by the authors listed below.
- *
- * @since 0.4
- *
- * @ingroup WikibaseLib
- * @ingroup Test
- *
- * @group Wikibase
- * @group WikibaseDataModel
- * @group WikibaseSnak
- * @group Database
- *
- * @license GPL 2+
- * @file
- *
- * @author Daniel Kinzler
- */
-
-namespace Wikibase\Test;
-
-use DataValues\DataValueFactory;
-use Wikibase\EntityId;
-use Wikibase\Property;
-use Wikibase\PropertyContent;
-use Wikibase\PropertyValueSnak;
-use Wikibase\SnakFactory;
-
-/**
- * Class SnakFactoryTest
- * @covers Wikibase\SnakFactory
- * @package Wikibase\Test
- */
-class SnakFactoryTest extends \PHPUnit_Framework_TestCase {
-
-       public function setUp() {
-               static $isInitialized = false;
-
-               if ( !class_exists( 'Wikibase\PropertyContent' ) ) {
-                       //TODO: once SnakFactory uses a PropertyDataTypeLookup, 
we can get rid of this
-                       $this->markTestSkipped( 'Can\'t test without Wikibase 
repo, need PropertyContent for fixture.' );
-               }
-
-               if ( !$isInitialized ) {
-                       $p1 = Property::newEmpty();
-                       $p1->setDataTypeId( 'string' );
-                       $p1->setId( 1 );
-
-                       $p1content = PropertyContent::newFromProperty( $p1 );
-                       $p1content->save( 'testing ' );
-
-                       $isInitialized = true;
-               }
-       }
-
-       public static function provideNewSnak() {
-               return array(
-                       array( 1, 'somevalue', null, null, 
'Wikibase\PropertySomeValueSnak', null, null, 'some value' ),
-                       array( 1, 'novalue', null, null, 
'Wikibase\PropertyNoValueSnak', null, null, 'no value' ),
-                       array( 1, 'value', 'string', 'foo', 
'Wikibase\PropertyValueSnak', null, null, 'a value' ),
-                       array( 1, 'kittens', null, 'foo', null, null, 
'InvalidArgumentException', 'bad snak type' ),
-               );
-       }
-
-       /**
-        * @dataProvider provideNewSnak
-        */
-       public function testNewSnak( $propertyId, $snakType, $valueType, 
$snakValue, $expectedSnakClass, $expectedValueClass, $expectedException, 
$message ) {
-               if ( is_int( $propertyId ) ) {
-                       $propertyId = new EntityId( Property::ENTITY_TYPE, 
$propertyId );
-               }
-
-               if ( $valueType !== null ) {
-                       $dataValue = 
DataValueFactory::singleton()->newDataValue( $valueType, $snakValue );
-               } else {
-                       $dataValue = null;
-               }
-
-               if ( $expectedException !== null ) {
-                       $this->setExpectedException( $expectedException );
-               }
-
-               $factory = new SnakFactory();
-               $snak = $factory->newSnak( $propertyId, $snakType, $dataValue );
-
-               if ( $expectedSnakClass !== null ) {
-                       $this->assertInstanceOf( $expectedSnakClass, $snak, 
$message );
-               }
-
-               if ( $expectedValueClass !== null && $snak instanceof 
PropertyValueSnak ) {
-                       $dataValue = $snak->getDataValue();
-                       $this->assertInstanceOf( $expectedValueClass, 
$dataValue, $message );
-               }
-       }
-
-}
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4003c6edb36b04d80ff71dd3a500aa3b30b10ab6
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/WikibaseDataModel
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: Daniel Werner <daniel.wer...@wikimedia.de>
Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to