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

DispatchingEntityIdParserTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 55
c 1
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getBasicParser() 0 3 1
A testCanParseEntityId() 0 6 1
A entityIdProvider() 0 8 1
A testCannotParseInvalidId() 0 6 1
A invalidIdSerializationProvider() 0 11 1
A testCannotParseWithoutBuilders() 0 6 1
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