Completed
Push — coverageversiong ( 2761c4 )
by Jeroen De
12:52 queued 07:07
created

testCannotParseInvalidId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 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' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
69
		$parser->parse( 'Q1' );
70
	}
71
72
}
73