[MediaWiki-commits] [Gerrit] mediawiki...WikibaseQualityConstraints[master]: Add tests for ItemIdSnakValue
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/406041 ) Change subject: Add tests for ItemIdSnakValue .. Add tests for ItemIdSnakValue Change-Id: Ic3e84dfe44983a80499049472e3b62047223f7c9 --- M src/ConstraintCheck/ItemIdSnakValue.php A tests/phpunit/ItemIdSnakValueTest.php 2 files changed, 166 insertions(+), 0 deletions(-) Approvals: jenkins-bot: Verified Thiemo Kreuz (WMDE): Looks good to me, approved diff --git a/src/ConstraintCheck/ItemIdSnakValue.php b/src/ConstraintCheck/ItemIdSnakValue.php index 977dbb1..706e27f 100644 --- a/src/ConstraintCheck/ItemIdSnakValue.php +++ b/src/ConstraintCheck/ItemIdSnakValue.php @@ -130,6 +130,7 @@ * Get the item ID contained in this {@link ItemIdSnakValue}. * Only valid if {@link isValue} is true. * +* @throws DomainException if this value does not contain an item ID * @return ItemId */ public function getItemId() { diff --git a/tests/phpunit/ItemIdSnakValueTest.php b/tests/phpunit/ItemIdSnakValueTest.php new file mode 100644 index 000..fda55a1 --- /dev/null +++ b/tests/phpunit/ItemIdSnakValueTest.php @@ -0,0 +1,165 @@ +assertTrue( $value->isValue() ); + $this->assertFalse( $value->isSomeValue() ); + $this->assertFalse( $value->isNoValue() ); + $this->assertSame( $itemId, $value->getItemId() ); + } + + public function testSomeValue() { + $value = ItemIdSnakValue::someValue(); + + $this->assertFalse( $value->isValue() ); + $this->assertTrue( $value->isSomeValue() ); + $this->assertFalse( $value->isNoValue() ); + + $this->setExpectedException( DomainException::class ); + $value->getItemId(); + } + + public function testNoValue() { + $value = ItemIdSnakValue::noValue(); + + $this->assertFalse( $value->isValue() ); + $this->assertFalse( $value->isSomeValue() ); + $this->assertTrue( $value->isNoValue() ); + + $this->setExpectedException( DomainException::class ); + $value->getItemId(); + } + + public function testFromSnak_ItemId() { + $itemId = new ItemId( 'Q1' ); + $snak = new PropertyValueSnak( + new PropertyId( 'P100' ), + new EntityIdValue( $itemId ) + ); + + $value = ItemIdSnakValue::fromSnak( $snak ); + + $this->assertTrue( $value->isValue() ); + $this->assertSame( $itemId, $value->getItemId() ); + } + + public function testFromSnak_PropertyId() { + $propertyId = new PropertyId( 'P1' ); + $snak = new PropertyValueSnak( + new PropertyId( 'P100' ), + new EntityIdValue( $propertyId ) + ); + + $this->setExpectedException( InvalidArgumentException::class ); + $value = ItemIdSnakValue::fromSnak( $snak ); + } + + public function testFromSnak_String() { + $snak = new PropertyValueSnak( + new PropertyId( 'P100' ), + new StringValue( 'Q1' ) + ); + + $this->setExpectedException( InvalidArgumentException::class ); + $value = ItemIdSnakValue::fromSnak( $snak ); + } + + public function testFromSnak_SomeValue() { + $snak = new PropertySomeValueSnak( new PropertyId( 'P100' ) ); + + $value = ItemIdSnakValue::fromSnak( $snak ); + + $this->assertTrue( $value->isSomeValue() ); + } + + public function testFromSnak_NoValue() { + $snak = new PropertyNoValueSnak( new PropertyId( 'P100' ) ); + + $value = ItemIdSnakValue::fromSnak( $snak ); + + $this->assertTrue( $value->isNoValue() ); + } + + public function testMatchesSnak_ItemId() { + $itemId = new ItemId( 'Q1' ); + $snak = new PropertyValueSnak( + new PropertyId( 'P100' ), + new EntityIdValue( $itemId ) + ); + + $this->assertTrue( ItemIdSnakValue::fromItemId( $itemId )->matchesSnak( $snak ) ); + $this->assertFalse( ItemIdSnakValue::someValue()->matchesSnak( $snak ) ); + $this->assertFalse( ItemIdSnakValue::noValue()->matchesSnak( $snak ) ); + } + + public function testMatchesSnak_PropertyId() { + $itemId = new ItemId( 'Q1' ); + $propertyId = new PropertyId( 'P1' ); + $snak = new PropertyValueSnak( + new PropertyId( 'P100' ), + new EntityIdValue( $propertyId ) + ); + +
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseQualityConstraints[master]: Add tests for ItemIdSnakValue
Lucas Werkmeister (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/406041 ) Change subject: Add tests for ItemIdSnakValue .. Add tests for ItemIdSnakValue Change-Id: Ic3e84dfe44983a80499049472e3b62047223f7c9 --- M src/ConstraintCheck/ItemIdSnakValue.php A tests/phpunit/ItemIdSnakValueTest.php 2 files changed, 166 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints refs/changes/41/406041/1 diff --git a/src/ConstraintCheck/ItemIdSnakValue.php b/src/ConstraintCheck/ItemIdSnakValue.php index 977dbb1..706e27f 100644 --- a/src/ConstraintCheck/ItemIdSnakValue.php +++ b/src/ConstraintCheck/ItemIdSnakValue.php @@ -130,6 +130,7 @@ * Get the item ID contained in this {@link ItemIdSnakValue}. * Only valid if {@link isValue} is true. * +* @throws DomainException if this value does not contain an item ID * @return ItemId */ public function getItemId() { diff --git a/tests/phpunit/ItemIdSnakValueTest.php b/tests/phpunit/ItemIdSnakValueTest.php new file mode 100644 index 000..fda55a1 --- /dev/null +++ b/tests/phpunit/ItemIdSnakValueTest.php @@ -0,0 +1,165 @@ +assertTrue( $value->isValue() ); + $this->assertFalse( $value->isSomeValue() ); + $this->assertFalse( $value->isNoValue() ); + $this->assertSame( $itemId, $value->getItemId() ); + } + + public function testSomeValue() { + $value = ItemIdSnakValue::someValue(); + + $this->assertFalse( $value->isValue() ); + $this->assertTrue( $value->isSomeValue() ); + $this->assertFalse( $value->isNoValue() ); + + $this->setExpectedException( DomainException::class ); + $value->getItemId(); + } + + public function testNoValue() { + $value = ItemIdSnakValue::noValue(); + + $this->assertFalse( $value->isValue() ); + $this->assertFalse( $value->isSomeValue() ); + $this->assertTrue( $value->isNoValue() ); + + $this->setExpectedException( DomainException::class ); + $value->getItemId(); + } + + public function testFromSnak_ItemId() { + $itemId = new ItemId( 'Q1' ); + $snak = new PropertyValueSnak( + new PropertyId( 'P100' ), + new EntityIdValue( $itemId ) + ); + + $value = ItemIdSnakValue::fromSnak( $snak ); + + $this->assertTrue( $value->isValue() ); + $this->assertSame( $itemId, $value->getItemId() ); + } + + public function testFromSnak_PropertyId() { + $propertyId = new PropertyId( 'P1' ); + $snak = new PropertyValueSnak( + new PropertyId( 'P100' ), + new EntityIdValue( $propertyId ) + ); + + $this->setExpectedException( InvalidArgumentException::class ); + $value = ItemIdSnakValue::fromSnak( $snak ); + } + + public function testFromSnak_String() { + $snak = new PropertyValueSnak( + new PropertyId( 'P100' ), + new StringValue( 'Q1' ) + ); + + $this->setExpectedException( InvalidArgumentException::class ); + $value = ItemIdSnakValue::fromSnak( $snak ); + } + + public function testFromSnak_SomeValue() { + $snak = new PropertySomeValueSnak( new PropertyId( 'P100' ) ); + + $value = ItemIdSnakValue::fromSnak( $snak ); + + $this->assertTrue( $value->isSomeValue() ); + } + + public function testFromSnak_NoValue() { + $snak = new PropertyNoValueSnak( new PropertyId( 'P100' ) ); + + $value = ItemIdSnakValue::fromSnak( $snak ); + + $this->assertTrue( $value->isNoValue() ); + } + + public function testMatchesSnak_ItemId() { + $itemId = new ItemId( 'Q1' ); + $snak = new PropertyValueSnak( + new PropertyId( 'P100' ), + new EntityIdValue( $itemId ) + ); + + $this->assertTrue( ItemIdSnakValue::fromItemId( $itemId )->matchesSnak( $snak ) ); + $this->assertFalse( ItemIdSnakValue::someValue()->matchesSnak( $snak ) ); + $this->assertFalse( ItemIdSnakValue::noValue()->matchesSnak( $snak ) ); + } + + public function testMatchesSnak_PropertyId() { + $itemId = new ItemId( 'Q1' ); + $propertyId = new PropertyId( 'P1' ); + $snak = new PropertyValueSnak( + new PropertyId( 'P100' ), + new EntityIdValue( $propertyId ) +