Completed
Push — detect-covers-fails ( bd35c8...c3f051 )
by no
16:27 queued 12:25
created

DispatchingEntityIdParserTest::entityIdProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
c 1
b 0
f 0
rs 9.4286
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Entity;
4
5
use Wikibase\DataModel\Entity\BasicEntityIdParser;
6
use Wikibase\DataModel\Entity\DispatchingEntityIdParser;
7
use Wikibase\DataModel\Entity\EntityId;
8
use Wikibase\DataModel\Entity\ItemId;
9
use Wikibase\DataModel\Entity\PropertyId;
10
11
/**
12
 * @covers Wikibase\DataModel\Entity\DispatchingEntityIdParser
13
 *
14
 * @licence GNU GPL v2+
15
 * @author Jeroen De Dauw < [email protected] >
16
 * @author Thiemo Mättig
17
 */
18
class DispatchingEntityIdParserTest extends \PHPUnit_Framework_TestCase {
19
20
	private function getBasicParser() {
21
		return new DispatchingEntityIdParser( BasicEntityIdParser::getBuilders() );
22
	}
23
24
	/**
25
	 * @dataProvider entityIdProvider
26
	 */
27
	public function testCanParseEntityId( $idString, EntityId $expected ) {
28
		$parser = $this->getBasicParser();
29
		$actual = $parser->parse( $idString );
30
31
		$this->assertEquals( $actual, $expected );
32
	}
33
34
	public function entityIdProvider() {
35
		return array(
36
			array( 'q42', new ItemId( 'q42' ) ),
37
			array( 'Q1337', new ItemId( 'Q1337' ) ),
38
			array( 'p1', new PropertyId( 'p1' ) ),
39
			array( 'P100000', new PropertyId( 'P100000' ) ),
40
		);
41
	}
42
43
	/**
44
	 * @dataProvider invalidIdSerializationProvider
45
	 */
46
	public function testCannotParseInvalidId( $invalidIdSerialization ) {
47
		$parser = $this->getBasicParser();
48
49
		$this->setExpectedException( 'Wikibase\DataModel\Entity\EntityIdParsingException' );
50
		$parser->parse( $invalidIdSerialization );
51
	}
52
53
	public function invalidIdSerializationProvider() {
54
		return array(
55
			array( 'FOO' ),
56
			array( null ),
57
			array( 42 ),
58
			array( array() ),
59
			array( '' ),
60
			array( 'q0' ),
61
			array( '1p' ),
62
		);
63
	}
64
65
	public function testCannotParseWithoutBuilders() {
66
		$parser = new DispatchingEntityIdParser( array() );
67
68
		$this->setExpectedException( 'Wikibase\DataModel\Entity\EntityIdParsingException' );
69
		$parser->parse( 'Q1' );
70
	}
71
72
}
73