Skip to content

Commit 9c861bc

Browse files
committed
Merge pull request #402 from wmde/idParserTests
Test coverage of {Basic|Dispatching}EntityIdParserTest
2 parents 9be0193 + 9f001fd commit 9c861bc

2 files changed

Lines changed: 48 additions & 19 deletions

File tree

tests/unit/Entity/BasicEntityIdParserTest.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,55 @@
99

1010
/**
1111
* @covers Wikibase\DataModel\Entity\BasicEntityIdParser
12-
* @covers Wikibase\DataModel\Entity\DispatchingEntityIdParser
12+
* @uses Wikibase\DataModel\Entity\DispatchingEntityIdParser
1313
*
1414
* @group Wikibase
1515
* @group WikibaseDataModel
1616
*
1717
* @licence GNU GPL v2+
1818
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
19+
* @author Thiemo Mättig
1920
*/
2021
class BasicEntityIdParserTest extends \PHPUnit_Framework_TestCase {
2122

2223
/**
23-
* @dataProvider idProvider
24+
* @dataProvider entityIdProvider
2425
*/
25-
public function testCanParseEntityId( EntityId $expected ) {
26+
public function testCanParseEntityId( $idString, EntityId $expected ) {
2627
$parser = new BasicEntityIdParser();
27-
28-
$actual = $parser->parse( $expected->getSerialization() );
28+
$actual = $parser->parse( $idString );
2929

3030
$this->assertEquals( $actual, $expected );
3131
}
3232

33-
public function idProvider() {
33+
public function entityIdProvider() {
34+
return array(
35+
array( 'q42', new ItemId( 'q42' ) ),
36+
array( 'Q1337', new ItemId( 'Q1337' ) ),
37+
array( 'p1', new PropertyId( 'p1' ) ),
38+
array( 'P100000', new PropertyId( 'P100000' ) ),
39+
);
40+
}
41+
42+
/**
43+
* @dataProvider invalidIdSerializationProvider
44+
*/
45+
public function testCannotParseInvalidId( $invalidIdSerialization ) {
46+
$parser = new BasicEntityIdParser();
47+
48+
$this->setExpectedException( 'Wikibase\DataModel\Entity\EntityIdParsingException' );
49+
$parser->parse( $invalidIdSerialization );
50+
}
51+
52+
public function invalidIdSerializationProvider() {
3453
return array(
35-
array( new ItemId( 'q42' ) ),
36-
array( new ItemId( 'Q1337' ) ),
37-
array( new PropertyId( 'p1' ) ),
38-
array( new PropertyId( 'P100000' ) ),
54+
array( 'FOO' ),
55+
array( null ),
56+
array( 42 ),
57+
array( array() ),
58+
array( '' ),
59+
array( 'q0' ),
60+
array( '1p' ),
3961
);
4062
}
4163

tests/unit/Entity/DispatchingEntityIdParserTest.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010

1111
/**
1212
* @covers Wikibase\DataModel\Entity\DispatchingEntityIdParser
13-
* @covers Wikibase\DataModel\Entity\EntityIdParser
14-
*
1513
* @uses Wikibase\DataModel\Entity\BasicEntityIdParser
1614
*
1715
* @group Wikibase
1816
* @group WikibaseDataModel
1917
*
2018
* @licence GNU GPL v2+
2119
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
20+
* @author Thiemo Mättig
2221
*/
2322
class DispatchingEntityIdParserTest extends \PHPUnit_Framework_TestCase {
2423

@@ -29,28 +28,29 @@ private function getBasicParser() {
2928
/**
3029
* @dataProvider entityIdProvider
3130
*/
32-
public function testCanParseEntityId( EntityId $expected ) {
31+
public function testCanParseEntityId( $idString, EntityId $expected ) {
3332
$parser = $this->getBasicParser();
34-
$actual = $parser->parse( $expected->getSerialization() );
33+
$actual = $parser->parse( $idString );
3534

3635
$this->assertEquals( $actual, $expected );
3736
}
3837

3938
public function entityIdProvider() {
4039
return array(
41-
array( new ItemId( 'q42' ) ),
42-
array( new ItemId( 'Q1337' ) ),
43-
array( new PropertyId( 'p1' ) ),
44-
array( new PropertyId( 'P100000' ) ),
40+
array( 'q42', new ItemId( 'q42' ) ),
41+
array( 'Q1337', new ItemId( 'Q1337' ) ),
42+
array( 'p1', new PropertyId( 'p1' ) ),
43+
array( 'P100000', new PropertyId( 'P100000' ) ),
4544
);
4645
}
4746

4847
/**
4948
* @dataProvider invalidIdSerializationProvider
50-
* @expectedException \Wikibase\DataModel\Entity\EntityIdParsingException
5149
*/
5250
public function testCannotParseInvalidId( $invalidIdSerialization ) {
5351
$parser = $this->getBasicParser();
52+
53+
$this->setExpectedException( 'Wikibase\DataModel\Entity\EntityIdParsingException' );
5454
$parser->parse( $invalidIdSerialization );
5555
}
5656

@@ -66,4 +66,11 @@ public function invalidIdSerializationProvider() {
6666
);
6767
}
6868

69+
public function testCannotParseWithoutBuilders() {
70+
$parser = new DispatchingEntityIdParser( array() );
71+
72+
$this->setExpectedException( 'Wikibase\DataModel\Entity\EntityIdParsingException' );
73+
$parser->parse( 'Q1' );
74+
}
75+
6976
}

0 commit comments

Comments
 (0)