本文整理汇总了PHP中Author::getBooks方法的典型用法代码示例。如果您正苦于以下问题:PHP Author::getBooks方法的具体用法?PHP Author::getBooks怎么用?PHP Author::getBooks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Author
的用法示例。
在下文中一共展示了Author::getBooks方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddBook
function testAddBook()
{
//Arrange
$name = "Ben";
$test_author = new Author($name);
$test_author->save();
$book_name = "Intro to Art";
$test_book = new Book($book_name);
$test_book->save();
//Act
$test_author->addBook($test_book);
//Assert
$this->assertEquals($test_author->getBooks(), [$test_book]);
}
示例2: testRemoveObjectOneToMany
public function testRemoveObjectOneToMany()
{
BookQuery::create()->deleteAll();
AuthorQuery::create()->deleteAll();
$book = new Book();
$book->setTitle('Propel Book');
$book2 = new Book();
$book2->setTitle('Propel2 Book');
$author = new Author();
$author->setFirstName('François');
$author->setLastName('Z');
$author->addBook($book);
$author->addBook($book2);
$this->assertCount(2, $author->getBooks());
$author->removeBook($book);
$books = $author->getBooks();
$this->assertCount(1, $books);
$this->assertEquals('Propel2 Book', reset($books)->getTitle());
$author->save();
$book->save();
$book2->save();
$this->assertEquals(2, BookQuery::create()->count(), 'Two Book');
$this->assertEquals(1, AuthorQuery::create()->count(), 'One Author');
$this->assertEquals(1, BookQuery::create()->filterByAuthor($author)->count());
$author->addBook($book);
$author->save();
$this->assertEquals(2, BookQuery::create()->filterByAuthor($author)->count());
$author->removeBook($book2);
$author->save();
$this->assertEquals(1, BookQuery::create()->filterByAuthor($author)->count());
$this->assertEquals(2, BookQuery::create()->count(), 'Two Book because FK is not required so book is not delete when removed from author\'s book collection');
}
示例3: testSetUp
public function testSetUp()
{
$this->assertTrue(Propel::isInstancePoolingEnabled());
$this->assertEquals(2, count($this->author->getBooks()));
$this->assertEquals(2, $this->author->countBooks());
}
示例4: testGetBooks
function testGetBooks()
{
$title = "Kama Sutra";
$id = 1;
$test_book = new Book($title, $id);
$test_book->save();
$title2 = "Oh Yeah";
$id2 = 2;
$test_book2 = new Book($title2, $id2);
$test_book2->save();
$name = "Uncle Ben";
$id3 = 3;
$test_author = new Author($name, $id3);
$test_author->save();
//Act
$test_author->addBook($test_book);
$test_author->addBook($test_book2);
//Assert
$this->assertEquals($test_author->getBooks(), [$test_book, $test_book2]);
}
示例5: Author
function test_deleteAllBooks()
{
//Arrange
$name = "Benjamin";
// $id = 1;
$test_author = new Author($name);
$test_author->save();
$title = "Book Title";
// $id2 = 1;
$test_book = new Book($title);
$test_book->save();
$title = "Book Title2";
// $id3 = 2;
$test_book2 = new Book($title);
$test_book2->save();
$test_author->addBook($test_book);
$test_author->addBook($test_book2);
//Act
$test_author->deleteAllBooks();
$result = $test_author->getBooks();
//Assert
$this->assertEquals([], $result);
}
示例6: testSetterOneToManyReplacesOldObjectsByNewObjects
public function testSetterOneToManyReplacesOldObjectsByNewObjects()
{
// Ensure no data
BookQuery::create()->deleteAll();
AuthorQuery::create()->deleteAll();
$books = new PropelObjectCollection();
foreach (array('foo', 'bar') as $title) {
$b = new Book();
$b->setTitle($title);
$books[] = $b;
}
$a = new Author();
$a->setBooks($books);
$a->save();
$books = $a->getBooks();
$this->assertEquals('foo', $books[0]->getTitle());
$this->assertEquals('bar', $books[1]->getTitle());
$books = new PropelObjectCollection();
foreach (array('bam', 'bom') as $title) {
$b = new Book();
$b->setTitle($title);
$books[] = $b;
}
$a->setBooks($books);
$a->save();
$books = $a->getBooks();
$this->assertEquals('bam', $books[0]->getTitle());
$this->assertEquals('bom', $books[1]->getTitle());
$this->assertEquals(1, AuthorQuery::create()->count());
$this->assertEquals(2, BookQuery::create()->count());
}
示例7: testGetBooks
function testGetBooks()
{
//Arrange
$author_name = "Super Dog";
$id2 = 2;
$test_author = new Author($author_name, $id2);
$test_author->save();
$book_title = "Snow Crash";
$id = null;
$test_book = new Book($book_title, $id);
$test_book->save();
$book_title2 = "Ready Player One";
$id2 = null;
$test_book2 = new Book($book_title2, $id2);
$test_book2->save();
//Act
$test_author->addBook($test_book);
$test_author->addBook($test_book2);
$result = $test_author->getBooks();
//Assert
$this->assertEquals($result, [$test_book, $test_book2]);
}
示例8: testGetBooks
function testGetBooks()
{
$name = "Stephen King";
$test_author = new Author($name);
$test_author->save();
$title = "Carrie";
$test_book = new Book($title);
$test_book->save();
$test_author->addBook($test_book);
$title2 = "Misery";
$test_book2 = new Book($title2);
$test_book2->save();
$test_author->addBook($test_book2);
$this->assertEquals([$test_book, $test_book2], $test_author->getBooks());
}
示例9: testGetBooks
function testGetBooks()
{
//Arrange
$name = "JK Rowling";
$id = 1;
$test_author = new Author($name, $id);
$test_author->save();
$title = "Harry Potter";
$id = 1;
$test_book = new Book($title, $id);
$test_book->save();
$title2 = "Moby Dick";
$id2 = 2;
$test_book2 = new Book($title, $id);
$test_book2->save();
//Act
$test_author->addBook($test_book);
$test_author->addBook($test_book2);
$result = $test_author->getBooks();
//Assert
$this->assertEquals([$test_book, $test_book2], $result);
}
示例10: Author
function test_addBook_getBooks()
{
$name = "Jerry Garcia";
$test_author = new Author($name);
$test_author->save();
$name2 = "Frank Sinatra";
$test_author2 = new Author($name2);
$test_author2->save();
$book_title = "Three Blind Mice";
$test_book = new Book($book_title);
$test_book->save();
$test_author->addBook($test_book);
$result = $test_author->getBooks();
$this->assertEquals([$test_book], $result);
}
示例11: Author
function test_getBooks()
{
$name = "Roberto Bolano";
$test_author = new Author($name);
$test_author->save();
$title = "Infinite Jest";
$test_book = new Book($title);
$test_book->save();
$title2 = "Infinite Jest";
$test_book2 = new Book($title2);
$test_book2->save();
//Act
$test_author->addBook($test_book2);
$test_author->addBook($test_book);
$result = $test_author->getBooks();
//Assert
$this->assertEquals([$test_book, $test_book2], $result);
}
示例12: Author
function test_addBook()
{
//Arrange
$author_name = "Jack London";
$test_author = new Author($author_name);
$test_author->save();
$title = "Sea Wolf";
$test_book = new Book($title);
$test_book->save();
//Act
$result = [$test_book];
$test_author->addBook($test_book);
//Assert
$this->assertEquals($test_author->getBooks(), $result);
}
示例13: Author
function test_getBooks()
{
//Arrange
$name = "Bob";
$test_author = new Author($name);
$test_author->save();
$title = "dog book";
$test_book = new Book($title);
$test_book->save();
$title2 = "History of nothing";
$test_book2 = new Book($title2);
$test_book2->save();
//Act
$test_author->addBook($test_book);
$test_author->addBook($test_book2);
//Assert
$result = $test_author->getBooks();
$this->assertEquals([$test_book, $test_book2], $result);
}
示例14: testGetBooks
function testGetBooks()
{
//Arrange
$name = "Paul Jones";
$id = 1;
$test_author = new Author($name, $id);
$test_author->save();
$title = "Little Cat";
$id = 1;
$test_book = new Book($title, $id);
$test_book->save();
$title2 = "Little Dog";
$id2 = 2;
$test_book2 = new Book($title2, $id2);
$test_book2->save();
//Act
$test_author->addBook($test_book);
$test_author->addBook($test_book2);
$result = $test_author->getBooks();
//Assert
$this->assertEquals([$test_book, $test_book2], $result);
}
示例15: Author
function test_getBooks()
{
//Arrange
$name = "Pladoh";
$test_author = new Author($name);
$test_author->save();
$title = "Theory of Everything and Nothing at All";
$genre = "Nonsense";
$test_book = new Book($title, $genre);
$test_book->save();
$title2 = "Philosoraptor: A Memoir";
$genre2 = "Alternate History/Dinosaurs";
$test_book2 = new Book($title, $genre);
$test_book2->save();
//Act
$test_author->addBook($test_book);
$test_author->addBook($test_book2);
//Assert
$this->assertEquals($test_author->getBooks(), [$test_book, $test_book2]);
}