mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-28 10:40:17 +02:00
Merge pull request #123 from ftwbzhao/feature/iterator/booklist/remove
fix booklist remove function
This commit is contained in:
@@ -25,7 +25,7 @@ class BookList implements \Countable
|
||||
|
||||
public function removeBook(Book $bookToRemove)
|
||||
{
|
||||
foreach ($this as $key => $book) {
|
||||
foreach ($this->books as $key => $book) {
|
||||
/** @var Book $book */
|
||||
if ($book->getAuthorAndTitle() === $bookToRemove->getAuthorAndTitle()) {
|
||||
unset($this->books[$key]);
|
||||
|
@@ -63,4 +63,13 @@ class IteratorTest extends \PHPUnit_Framework_TestCase
|
||||
$iterator->next();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test BookList Remove
|
||||
*/
|
||||
public function testBookRemove()
|
||||
{
|
||||
$this->bookList->removeBook($this->bookList->getBook(0));
|
||||
$this->assertEquals($this->bookList->count(), 2);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user