Skip to content

Commit 85ffd3a

Browse files
committed
Increase test coverage for id classes
1 parent af3dd07 commit 85ffd3a

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

tests/unit/Entity/ItemIdTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Wikibase\DataModel\Tests\Entity;
44

5+
use PHPUnit_Framework_TestCase;
56
use Wikibase\DataModel\Entity\ItemId;
67

78
/**
@@ -15,7 +16,7 @@
1516
* @licence GNU GPL v2+
1617
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
1718
*/
18-
class ItemIdTest extends \PHPUnit_Framework_TestCase {
19+
class ItemIdTest extends PHPUnit_Framework_TestCase {
1920

2021
/**
2122
* @dataProvider idSerializationProvider
@@ -68,6 +69,27 @@ public function invalidIdSerializationProvider() {
6869
);
6970
}
7071

72+
public function testGetNumericId() {
73+
$id = new ItemId( 'Q1' );
74+
$this->assertSame( 1, $id->getNumericId() );
75+
}
76+
77+
public function testGetEntityType() {
78+
$id = new ItemId( 'Q1' );
79+
$this->assertSame( 'item', $id->getEntityType() );
80+
}
81+
82+
public function testSerialize() {
83+
$id = new ItemId( 'Q1' );
84+
$this->assertSame( '["item","Q1"]', $id->serialize() );
85+
}
86+
87+
public function testUnserialize() {
88+
$id = new ItemId( 'Q1' );
89+
$id->unserialize( '["item","Q2"]' );
90+
$this->assertSame( 'Q2', $id->getSerialization() );
91+
}
92+
7193
/**
7294
* @dataProvider numericIdProvider
7395
*/
@@ -97,6 +119,7 @@ public function testNewFromNumberWithInvalidNumericId( $number ) {
97119

98120
public function invalidNumericIdProvider() {
99121
return array(
122+
array( 'Q1' ),
100123
array( '42.1' ),
101124
array( 42.1 ),
102125
array( 2147483648.1 ),

tests/unit/Entity/PropertyIdTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Wikibase\DataModel\Tests\Entity;
44

5+
use PHPUnit_Framework_TestCase;
56
use Wikibase\DataModel\Entity\PropertyId;
67

78
/**
@@ -15,7 +16,7 @@
1516
* @licence GNU GPL v2+
1617
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
1718
*/
18-
class PropertyIdTest extends \PHPUnit_Framework_TestCase {
19+
class PropertyIdTest extends PHPUnit_Framework_TestCase {
1920

2021
/**
2122
* @dataProvider idSerializationProvider
@@ -68,6 +69,27 @@ public function invalidIdSerializationProvider() {
6869
);
6970
}
7071

72+
public function testGetNumericId() {
73+
$id = new PropertyId( 'P1' );
74+
$this->assertSame( 1, $id->getNumericId() );
75+
}
76+
77+
public function testGetEntityType() {
78+
$id = new PropertyId( 'P1' );
79+
$this->assertSame( 'property', $id->getEntityType() );
80+
}
81+
82+
public function testSerialize() {
83+
$id = new PropertyId( 'P1' );
84+
$this->assertSame( '["property","P1"]', $id->serialize() );
85+
}
86+
87+
public function testUnserialize() {
88+
$id = new PropertyId( 'P1' );
89+
$id->unserialize( '["property","P2"]' );
90+
$this->assertSame( 'P2', $id->getSerialization() );
91+
}
92+
7193
/**
7294
* @dataProvider numericIdProvider
7395
*/
@@ -97,6 +119,7 @@ public function testNewFromNumberWithInvalidNumericId( $number ) {
97119

98120
public function invalidNumericIdProvider() {
99121
return array(
122+
array( 'P1' ),
100123
array( '42.1' ),
101124
array( 42.1 ),
102125
array( 2147483648.1 ),

0 commit comments

Comments
 (0)