Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

## Version 1.1 (dev)

#### Breaking changes

* Changed the constructor signature of `Statement`

#### Additions

* The `Property` constructor now accepts an optional `StatementList` parameter
* Added `Property::getStatements` and `Property::setStatements`
* Added `StatementList::getAllSnaks` to use instead of `Entity::getAllSnaks`
* Added `Statement::setClaim`

## Version 1.0 (2014-09-02)

Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function getType() {
* @return Statement
*/
public function newClaim( Snak $mainSnak ) {
return new Statement( $mainSnak );
return new Statement( new Claim( $mainSnak ) );
}

/**
Expand Down
25 changes: 14 additions & 11 deletions src/Statement/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

use InvalidArgumentException;
use Wikibase\DataModel\Claim\Claim;
use Wikibase\DataModel\Reference;
use Wikibase\DataModel\ReferenceList;
use Wikibase\DataModel\References;
use Wikibase\DataModel\Snak\Snak;
use Wikibase\DataModel\Snak\Snaks;

/**
* Class representing a Wikibase statement.
Expand All @@ -18,6 +16,7 @@
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
* @author Bene* < benestar.wikimedia@gmail.com >
*/
class Statement extends Claim {

Expand All @@ -31,15 +30,8 @@ class Statement extends Claim {
*/
private $rank = self::RANK_NORMAL;

/**
* @since 0.1
*
* @param Snak $mainSnak
* @param Snaks|null $qualifiers
* @param References|null $references
*/
public function __construct( Snak $mainSnak, Snaks $qualifiers = null, References $references = null ) {
parent::__construct( $mainSnak, $qualifiers );
public function __construct( Claim $claim, References $references = null ) {
$this->setClaim( $claim );
$this->references = $references === null ? new ReferenceList() : $references;
}

Expand Down Expand Up @@ -150,6 +142,17 @@ public function equals( $target ) {
&& $this->references->equals( $target->references );
}

/**
* @since 1.1
*
* @param Claim $claim
*/
public function setClaim( Claim $claim ) {
$this->mainSnak = $claim->getMainSnak();
$this->qualifiers = $claim->getQualifiers();
$this->guid = $claim->getGuid();
}

/**
* @since 1.0
*
Expand Down
3 changes: 2 additions & 1 deletion src/Statement/StatementList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use InvalidArgumentException;
use Traversable;
use Wikibase\DataModel\Claim\Claim;
use Wikibase\DataModel\Claim\Claims;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Reference;
Expand Down Expand Up @@ -106,7 +107,7 @@ public function addNewStatement( Snak $mainSnak, $qualifiers = null, $references
$qualifiers = is_array( $qualifiers ) ? new SnakList( $qualifiers ) : $qualifiers;
$references = is_array( $references ) ? new ReferenceList( $references ) : $references;

$statement = new Statement( $mainSnak, $qualifiers, $references );
$statement = new Statement( new Claim( $mainSnak, $qualifiers ), $references );
$statement->setGuid( $guid );

$this->addStatement( $statement );
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ByPropertyIdArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function( Snak $snak ) {

$lists[] = array_map(
function( Snak $snak ) {
return new Statement( $snak );
return new Statement( new Claim( $snak ) );
},
$snaks
);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Claim/ClaimStandaloneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testGivenClaimWithDifferentGuids_equalsReturnsFalse() {

public function testGivenSimilarStatement_equalsReturnsFalse() {
$claim = new Claim( new PropertyNoValueSnak( 42 ) );
$this->assertFalse( $claim->equals( new Statement( new PropertyNoValueSnak( 42 ) ) ) );
$this->assertFalse( $claim->equals( new Statement( new Claim( new PropertyNoValueSnak( 42 ) ) ) ) );
}

}
2 changes: 1 addition & 1 deletion tests/unit/Claim/ClaimsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function makeStatement( Snak $mainSnak, $guid = null ) {
$guid = 'TEST$statement-' . $this->guidCounter;
}

$claim = new Statement( $mainSnak );
$claim = new Statement( new Claim( $mainSnak ) );
$claim->setGuid( $guid );

return $claim;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Entity/Diff/EntityDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function diffProvider() {

$diffs[] = new EntityDiff( $diffOps );

$statement = new Statement( new PropertyNoValueSnak( 42 ) );
$statement = new Statement( new Claim( new PropertyNoValueSnak( 42 ) ) );
$statement->setGuid( 'EntityDiffTest$foo' );

$statementListDiffer = new StatementListDiffer();
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/Entity/Diff/ItemDifferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use Diff\DiffOp\DiffOpAdd;
use Diff\DiffOp\DiffOpChange;
use Diff\DiffOp\DiffOpRemove;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Claim\Claim;
use Wikibase\DataModel\Entity\Diff\ItemDiffer;
use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Snak\PropertySomeValueSnak;
use Wikibase\DataModel\Statement\Statement;

/**
* @covers Wikibase\DataModel\Entity\Diff\ItemDiffer
Expand Down Expand Up @@ -61,7 +62,7 @@ public function testClaimsAreDiffed() {
$firstItem = Item::newEmpty();

$secondItem = Item::newEmpty();
$statement = new Statement( new PropertySomeValueSnak( 42 ) );
$statement = new Statement( new Claim( new PropertySomeValueSnak( 42 ) ) );
$statement->setGuid( 'kittens' );
$secondItem->addClaim( $statement );

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/Entity/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
use Diff\DiffOp\DiffOpAdd;
use Diff\DiffOp\DiffOpChange;
use Diff\DiffOp\DiffOpRemove;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Claim\Claim;
use Wikibase\DataModel\Entity\Diff\EntityDiff;
use Wikibase\DataModel\Entity\Entity;
use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Reference;
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Term\AliasGroup;
use Wikibase\DataModel\Term\AliasGroupList;
use Wikibase\DataModel\Term\Fingerprint;
Expand Down Expand Up @@ -441,7 +441,7 @@ public function testNewClaim( Entity $entity ) {
}

$snak = new PropertyNoValueSnak( 42 );
$claim = new Statement( $snak );
$claim = new Statement( new Claim( $snak ) );
$claim->setGuid( 'q42$foobarbaz' );

$this->assertInstanceOf( 'Wikibase\DataModel\Claim\Claim', $claim );
Expand Down
23 changes: 11 additions & 12 deletions tests/unit/Entity/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public function makeClaims() {
$claims[] = new Claim( new PropertyNoValueSnak( 42 ) );

$claims[] = new Statement(
new PropertyNoValueSnak( 42 ),
null,
new Claim( new PropertyNoValueSnak( 42 ), null ),
new ReferenceList( array(
new Reference( new SnakList( array(
new PropertyNoValueSnak( 24 ),
Expand Down Expand Up @@ -154,9 +153,9 @@ public function itemProvider() {
* @var Item $item;
*/
$item = $item->copy();
$item->addClaim( new Statement(
$item->addClaim( new Statement( new Claim(
new PropertyNoValueSnak( new PropertyId( 'P42' ) )
) );
) ) );
$items[] = $item;

$argLists = array();
Expand Down Expand Up @@ -448,10 +447,10 @@ public function diffProvider() {
public function patchProvider() {
$argLists = parent::patchProvider();

$statement0 = new Statement( new PropertyNoValueSnak( 42 ) );
$statement1 = new Statement( new PropertySomeValueSnak( 42 ) );
$statement2 = new Statement( new PropertyValueSnak( 42, new StringValue( 'ohi' ) ) );
$statement3 = new Statement( new PropertyNoValueSnak( 1 ) );
$statement0 = new Statement( new Claim( new PropertyNoValueSnak( 42 ) ) );
$statement1 = new Statement( new Claim( new PropertySomeValueSnak( 42 ) ) );
$statement2 = new Statement( new Claim( new PropertyValueSnak( 42, new StringValue( 'ohi' ) ) ) );
$statement3 = new Statement( new Claim( new PropertyNoValueSnak( 1 ) ) );

$statement0->setGuid( 'claim0' );
$statement1->setGuid( 'claim1' );
Expand Down Expand Up @@ -698,10 +697,10 @@ public function testNewClaimReturnsStatementWithProvidedMainSnak() {
public function testSetClaims() {
$item = Item::newEmpty();

$statement0 = new Statement( new PropertyNoValueSnak( 42 ) );
$statement0 = new Statement( new Claim( new PropertyNoValueSnak( 42 ) ) );
$statement0->setGuid( 'TEST$NVS42' );

$statement1 = new Statement( new PropertySomeValueSnak( 42 ) );
$statement1 = new Statement( new Claim( new PropertySomeValueSnak( 42 ) ) );
$statement1->setGuid( 'TEST$SVS42' );

$statements = array( $statement0, $statement1 );
Expand Down Expand Up @@ -765,7 +764,7 @@ public function testItemWithoutSitelinksHasNoSitelinks() {
}

private function newStatement() {
$statement = new Statement( new PropertyNoValueSnak( 42 ) );
$statement = new Statement( new Claim( new PropertyNoValueSnak( 42 ) ) );
$statement->setGuid( 'kittens' );
return $statement;
}
Expand All @@ -787,7 +786,7 @@ public function testClearRemovesAllButId() {
}

public function testCanConstructWithStatementList() {
$statement = new Statement( new PropertyNoValueSnak( 42 ) );
$statement = new Statement( new Claim( new PropertyNoValueSnak( 42 ) ) );
$statement->setGuid( 'meh' );

$statements = new StatementList( array( $statement ) );
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/Statement/StatementListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function testGetAllSnaksReturnsAllSnaks() {

private function getStatementWithSnak( $propertyId, $stringValue ) {
$snak = $this->newSnak( $propertyId, $stringValue );
$statement = new Statement( $snak );
$statement = new Statement( new Claim( $snak ) );
$statement->setGuid( sha1( $snak->getHash() ) );
return $statement;
}
Expand All @@ -158,7 +158,7 @@ public function testAddStatementWithOnlyMainSnak() {

$this->assertEquals(
new StatementList( array(
new Statement( $this->newSnak( 42, 'foo' ) )
new Statement( new Claim( $this->newSnak( 42, 'foo' ) ) )
) ),
$list
);
Expand All @@ -176,12 +176,12 @@ public function testAddStatementWithQualifiersAsSnakArray() {

$this->assertEquals(
new StatementList( array(
new Statement(
new Statement( new Claim(
$this->newSnak( 42, 'foo' ),
new SnakList( array(
$this->newSnak( 1, 'bar' )
) )
)
) )
) ),
$list
);
Expand All @@ -200,10 +200,10 @@ public function testAddStatementWithQualifiersAsSnakList() {

$this->assertEquals(
new StatementList( array(
new Statement(
new Statement( new Claim(
$this->newSnak( 42, 'foo' ),
$snakList
)
) )
) ),
$list
);
Expand All @@ -219,10 +219,10 @@ public function testAddStatementWithGuid() {
'kittens'
);

$statement = new Statement(
$statement = new Statement( new Claim(
$this->newSnak( 42, 'foo' ),
null
);
) );

$statement->setGuid( 'kittens' );

Expand Down
Loading