本文整理汇总了PHP中Propel\Tests\Bookstore\Book::countReviews方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::countReviews方法的具体用法?PHP Book::countReviews怎么用?PHP Book::countReviews使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Tests\Bookstore\Book
的用法示例。
在下文中一共展示了Book::countReviews方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCountRefFk
public function testCountRefFk()
{
$book = new Book();
$book->setTitle("Test Book");
$book->setISBN("TT-EE-SS-TT");
$num = 5;
for ($i = 2; $i < $num + 2; $i++) {
$r = new Review();
$r->setReviewedBy('Hans ' . $num);
$dt = new DateTime("now");
$dt->modify("-" . $i . " weeks");
$r->setReviewDate($dt);
$r->setRecommended($i % 2 == 0);
$book->addReview($r);
}
$this->assertEquals($num, $book->countReviews(), "Expected countReviews to return {$num}");
$this->assertEquals($num, count($book->getReviews()), "Expected getReviews to return {$num} reviews");
$book->save();
BookTableMap::clearInstancePool();
ReviewTableMap::clearInstancePool();
$book = BookQuery::create()->findPk($book->getId());
$this->assertEquals($num, $book->countReviews(), "Expected countReviews() to return {$num} (after save)");
$this->assertEquals($num, count($book->getReviews()), "Expected getReviews() to return {$num} (after save)");
// Now set different criteria and expect different results
$c = new Criteria();
$c->add(ReviewTableMap::RECOMMENDED, false);
$this->assertEquals(floor($num / 2), $book->countReviews($c), "Expected " . floor($num / 2) . " results from countReviews(recomm=false)");
// Change Criteria, run again -- expect different.
$c = new Criteria();
$c->add(ReviewTableMap::RECOMMENDED, true);
$this->assertEquals(ceil($num / 2), count($book->getReviews($c)), "Expected " . ceil($num / 2) . " results from getReviews(recomm=true)");
$this->assertEquals($num, $book->countReviews(), "Expected countReviews to return {$num} with new empty Criteria");
}