Skip to content

Commit 539f636

Browse files
author
Dominik Liebler
committed
Merge pull request DesignPatternsPHP#123 from ftwbzhao/feature/iterator/booklist/remove
fix booklist remove function
2 parents 12145c5 + 53f4d36 commit 539f636

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Behavioral/Iterator/BookList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function addBook(Book $book)
2525

2626
public function removeBook(Book $bookToRemove)
2727
{
28-
foreach ($this as $key => $book) {
28+
foreach ($this->books as $key => $book) {
2929
/** @var Book $book */
3030
if ($book->getAuthorAndTitle() === $bookToRemove->getAuthorAndTitle()) {
3131
unset($this->books[$key]);

Behavioral/Iterator/Tests/IteratorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,13 @@ public function testUseAReverseIteratorAndValidateAuthors($expected)
6363
$iterator->next();
6464
}
6565
}
66+
67+
/**
68+
* Test BookList Remove
69+
*/
70+
public function testBookRemove()
71+
{
72+
$this->bookList->removeBook($this->bookList->getBook(0));
73+
$this->assertEquals($this->bookList->count(), 2);
74+
}
6675
}

0 commit comments

Comments
 (0)