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

tests/unit/Entity/BasicEntityIdParserTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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' );
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...
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