Skip to content

Commit f60bb18

Browse files
JeroenDeDauwthiemowmde
authored andcommitted
Change StatementList::getIndexByGuid to take a guid rather than a Statement
1 parent 028ed44 commit f60bb18

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/Statement/StatementList.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,19 @@ public function isEmpty() {
285285
/**
286286
* @since 3.0
287287
*
288-
* @param Statement $statement
288+
* @param string|null $statementGuid
289289
*
290290
* @return int|bool
291291
*/
292-
public function getIndexByGuid( Statement $statement ) {
292+
public function getIndexByGuid( $statementGuid ) {
293+
if ( !is_string( $statementGuid ) && !is_null( $statementGuid ) ) {
294+
throw new InvalidArgumentException( '$statementGuid needs to be string or null' );
295+
}
296+
293297
$index = 0;
294298

295299
foreach ( $this->statements as $s ) {
296-
if ( $s->getGuid() === $statement->getGuid() ) {
300+
if ( $s->getGuid() === $statementGuid ) {
297301
return $index;
298302
}
299303
$index++;

tests/unit/Statement/StatementListTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ public function testWhenNoPreferredStatements_getBestStatementsReturnsOnlyNormal
543543
public function testGivenNotPresentStatement_getIndexByGuidReturnsFalse() {
544544
$statements = new StatementList();
545545

546-
$this->assertFalse( $statements->getIndexByGuid( $this->getStatement( 1, 'kittens' ) ) );
546+
$this->assertFalse( $statements->getIndexByGuid( 'kittens' ) );
547547
}
548548

549549
public function testGivenPresentStatement_getIndexByGuidReturnsItsIndex() {
@@ -555,7 +555,7 @@ public function testGivenPresentStatement_getIndexByGuidReturnsItsIndex() {
555555

556556
$this->assertSame(
557557
1,
558-
$statements->getIndexByGuid( $this->getStatement( 42, 'kittens42' ) )
558+
$statements->getIndexByGuid( 'kittens42' )
559559
);
560560
}
561561

@@ -569,7 +569,7 @@ public function testGivenDoublyPresentStatement_getIndexByGuidReturnsTheFirstInd
569569

570570
$this->assertSame(
571571
1,
572-
$statements->getIndexByGuid( $this->getStatement( 42, 'kittens42' ) )
572+
$statements->getIndexByGuid( 'kittens42' )
573573
);
574574
}
575575

@@ -582,8 +582,15 @@ public function testGivenDifferentStatementWithSameGuid_getIndexByGuidReturnsIts
582582

583583
$this->assertSame(
584584
2,
585-
$statements->getIndexByGuid( $this->getStatement( 42, 'kittens41' ) )
585+
$statements->getIndexByGuid( 'kittens41' )
586586
);
587587
}
588588

589+
public function testGivenInvalidGuid_getIndexByGuidThrowsException() {
590+
$statements = new StatementList();
591+
592+
$this->setExpectedException( 'InvalidArgumentException' );
593+
$statements->getIndexByGuid( false );
594+
}
595+
589596
}

0 commit comments

Comments
 (0)