Skip to content

Commit 4c289d0

Browse files
authored
Merge pull request #751 from wmde/strictTypes
Add strict type hint to StatementGuid constructor
2 parents de1d3d4 + 73fd77c commit 4c289d0

3 files changed

Lines changed: 27 additions & 44 deletions

File tree

src/Statement/StatementGuid.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ class StatementGuid implements Comparable {
3939
*
4040
* @throws InvalidArgumentException
4141
*/
42-
public function __construct( $entityId, $guid ) {
43-
if ( !( $entityId instanceof EntityId ) ) {
44-
throw new InvalidArgumentException( '$entityId must be an instance of EntityId' );
45-
}
42+
public function __construct( EntityId $entityId, $guid ) {
4643
if ( !is_string( $guid ) ) {
4744
throw new InvalidArgumentException( '$guid must be a string' );
4845
}

tests/unit/Entity/EntityRedirectTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function equalsProvider() {
7070
* @param mixed $b
7171
* @param bool $expected
7272
*/
73-
public function testEquals( $a, $b, $expected ) {
73+
public function testEquals( EntityRedirect $a, $b, $expected ) {
7474
$this->assertEquals( $expected, $a->equals( $b ), '$a->equals( $b )' );
7575

7676
if ( $b instanceof EntityRedirect ) {

tests/unit/Statement/StatementGuidTest.php

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Wikibase\DataModel\Tests\Statement;
44

5-
use Exception;
65
use InvalidArgumentException;
76
use Wikibase\DataModel\Statement\StatementGuid;
87
use Wikibase\DataModel\Entity\EntityId;
@@ -21,74 +20,63 @@ class StatementGuidTest extends \PHPUnit_Framework_TestCase {
2120

2221
/**
2322
* @dataProvider provideConstructionData
24-
* @param EntityId $entityId
25-
* @param string $guid
26-
* @param string $expected
2723
*/
2824
public function testConstructor( EntityId $entityId, $guid, $expected ) {
2925
$statementGuid = new StatementGuid( $entityId, $guid );
3026

31-
$this->assertEquals( $expected, $statementGuid->getSerialization() );
27+
$this->assertSame( $expected, $statementGuid->getSerialization() );
3228
$this->assertEquals( $entityId, $statementGuid->getEntityId() );
3329
}
3430

3531
public function provideConstructionData() {
36-
$argLists = [];
37-
38-
$argLists[] = [
39-
new ItemId( 'q42' ),
40-
'D8404CDA-25E4-4334-AF13-A3290BCD9C0N' ,
41-
'Q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0N'
42-
];
43-
$argLists[] = [
44-
new ItemId( 'Q1234567' ),
45-
'D4FDE516-F20C-4154-ADCE-7C5B609DFDFF',
46-
'Q1234567$D4FDE516-F20C-4154-ADCE-7C5B609DFDFF'
32+
return [
33+
[
34+
new ItemId( 'q42' ),
35+
'D8404CDA-25E4-4334-AF13-A3290BCD9C0N' ,
36+
'Q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0N'
37+
],
38+
[
39+
new ItemId( 'Q1234567' ),
40+
'D4FDE516-F20C-4154-ADCE-7C5B609DFDFF',
41+
'Q1234567$D4FDE516-F20C-4154-ADCE-7C5B609DFDFF'
42+
],
43+
[
44+
new ItemId( 'Q1' ),
45+
'foo',
46+
'Q1$foo'
47+
],
4748
];
48-
$argLists[] = [
49-
new ItemId( 'Q1' ),
50-
'foo',
51-
'Q1$foo'
52-
];
53-
54-
return $argLists;
5549
}
5650

5751
/**
5852
* @dataProvider provideBadConstruction
5953
*/
60-
public function testBadConstruction( $entityId, $guid ) {
54+
public function testBadConstruction( EntityId $entityId, $guid ) {
6155
$this->setExpectedException( InvalidArgumentException::class );
6256
new StatementGuid( $entityId, $guid );
6357
}
6458

6559
public function provideBadConstruction() {
66-
$argLists = [];
67-
68-
$argLists[] = [ 'foobar', 'foobar' ];
69-
$argLists[] = [ 'q123', 'foo' ];
70-
$argLists[] = [ [], 'foo' ];
71-
$argLists[] = [ new Exception(), 'foo' ];
72-
$argLists[] = [ 'bar', 12345 ];
60+
$id = new ItemId( 'Q1' );
7361

74-
return $argLists;
62+
return [
63+
[ $id, null ],
64+
[ $id, 12345 ],
65+
];
7566
}
7667

7768
public function provideStatementGuids() {
78-
$constructionDatas = $this->provideConstructionData();
7969
$argLists = [];
8070

81-
foreach ( $constructionDatas as $constructionData ) {
82-
$argLists[] = [ new StatementGuid( $constructionData[0], $constructionData[1] ) ];
71+
foreach ( $this->provideConstructionData() as $data ) {
72+
$argLists[] = [ new StatementGuid( $data[0], $data[1] ) ];
8373
}
8474

8575
return $argLists;
8676
}
8777

8878
/**
8979
* @dataProvider provideStatementGuids
90-
*
91-
* @param StatementGuid $statementGuid
9280
*/
9381
public function testEquals( StatementGuid $statementGuid ) {
9482
$statementGuidCopy = clone $statementGuid;
@@ -98,8 +86,6 @@ public function testEquals( StatementGuid $statementGuid ) {
9886

9987
/**
10088
* @dataProvider provideStatementGuids
101-
*
102-
* @param StatementGuid $statementGuid
10389
*/
10490
public function testNotEquals( StatementGuid $statementGuid ) {
10591
$notEqualStatementGuid = new StatementGuid( new ItemId( 'q9999' ), 'someguid' );

0 commit comments

Comments
 (0)