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

BasicEntityIdParserTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanParseEntityId() 0 6 1
A entityIdProvider() 0 8 1
A testCannotParseInvalidId() 0 6 1
A invalidIdSerializationProvider() 0 11 1
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Entity;
4
5
use Wikibase\DataModel\Entity\BasicEntityIdParser;
6
use Wikibase\DataModel\Entity\EntityId;
7
use Wikibase\DataModel\Entity\ItemId;
8
use Wikibase\DataModel\Entity\PropertyId;
9
10
/**
11
 * @covers Wikibase\DataModel\Entity\BasicEntityIdParser
12
 *
13
 * @licence GNU GPL v2+
14
 * @author Jeroen De Dauw < [email protected] >
15
 * @author Thiemo Mättig
16
 */
17
class BasicEntityIdParserTest extends \PHPUnit_Framework_TestCase {
18
19
	/**
20
	 * @dataProvider entityIdProvider
21
	 */
22
	public function testCanParseEntityId( $idString, EntityId $expected ) {
23
		$parser = new BasicEntityIdParser();
24
		$actual = $parser->parse( $idString );
25
26
		$this->assertEquals( $actual, $expected );
27
	}
28
29
	public function entityIdProvider() {
30
		return array(
31
			array( 'q42', new ItemId( 'q42' ) ),
32
			array( 'Q1337', new ItemId( 'Q1337' ) ),
33
			array( 'p1', new PropertyId( 'p1' ) ),
34
			array( 'P100000', new PropertyId( 'P100000' ) ),
35
		);
36
	}
37
38
	/**
39
	 * @dataProvider invalidIdSerializationProvider
40
	 */
41
	public function testCannotParseInvalidId( $invalidIdSerialization ) {
42
		$parser = new BasicEntityIdParser();
43
44
		$this->setExpectedException( 'Wikibase\DataModel\Entity\EntityIdParsingException' );
45
		$parser->parse( $invalidIdSerialization );
46
	}
47
48
	public function invalidIdSerializationProvider() {
49
		return array(
50
			array( 'FOO' ),
51
			array( null ),
52
			array( 42 ),
53
			array( array() ),
54
			array( '' ),
55
			array( 'q0' ),
56
			array( '1p' ),
57
		);
58
	}
59
60
}
61