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

ItemIdParserTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

4 Methods

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