public function testFormatALotOfResults()
 {
     $nbBooks = 50;
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     Propel::disableInstancePooling();
     $book = new Book();
     for ($i = 0; $i < $nbBooks; $i++) {
         $book->clear();
         $book->setTitle('BookTest' . $i);
         $book->save($con);
     }
     $stmt = $con->query('SELECT * FROM book');
     $formatter = new PropelOnDemandFormatter();
     $formatter->init(new ModelCriteria('bookstore', 'Book'));
     $books = $formatter->format($stmt);
     $this->assertTrue($books instanceof PropelOnDemandCollection, 'PropelOnDemandFormatter::format() returns a PropelOnDemandCollection');
     $this->assertEquals($nbBooks, count($books), 'PropelOnDemandFormatter::format() returns a collection that counts as many rows as the results in the query');
     $i = 0;
     foreach ($books as $book) {
         $this->assertTrue($book instanceof Book, 'PropelOnDemandFormatter::format() returns a collection of Model objects');
         $this->assertEquals('BookTest' . $i, $book->getTitle(), 'PropelOnDemandFormatter::format() returns the model objects matching the query');
         $i++;
     }
     Propel::enableInstancePooling();
 }
Example #2
0
 public function testClear()
 {
     $b = new Book();
     $b->setNew(false);
     $b->clear();
     $this->assertTrue($b->isNew(), 'clear() sets the object to new');
     $b = new Book();
     $b->setDeleted(true);
     $b->clear();
     $this->assertFalse($b->isDeleted(), 'clear() sets the object to not deleted');
 }
Example #3
0
 protected function createBooks($nb = 15, $con = null)
 {
     BookQuery::create()->deleteAll($con);
     $books = new ObjectCollection();
     $books->setModel('\\Propel\\Tests\\Bookstore\\Book');
     for ($i = 0; $i < $nb; $i++) {
         $b = new Book();
         $b->setTitle('Book' . $i);
         $books[] = $b;
     }
     $books->save($con);
 }
 public function testSerializeObjectWithCollections()
 {
     $book1 = new Book();
     $book1->setTitle('Foo5');
     $book1->setISBN('1234');
     $book2 = new Book();
     $book2->setTitle('Foo6');
     $book2->setISBN('1234');
     $author = new Author();
     $author->setFirstName('JAne');
     $author->addBook($book1);
     $author->addBook($book2);
     $author->save();
     $a = clone $author;
     $sa = serialize($a);
     $author->clearAllReferences();
     $this->assertEquals($author, unserialize($sa));
 }
 public function testGroupByArray()
 {
     $stephenson = new Author();
     $stephenson->setFirstName("Neal");
     $stephenson->setLastName("Stephenson");
     $stephenson->save();
     $byron = new Author();
     $byron->setFirstName("George");
     $byron->setLastName("Byron");
     $byron->save();
     $phoenix = new Book();
     $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
     $phoenix->setISBN("043935806X");
     $phoenix->setAuthor($stephenson);
     $phoenix->save();
     $qs = new Book();
     $qs->setISBN("0380977427");
     $qs->setTitle("Quicksilver");
     $qs->setAuthor($stephenson);
     $qs->save();
     $dj = new Book();
     $dj->setISBN("0140422161");
     $dj->setTitle("Don Juan");
     $dj->setAuthor($stephenson);
     $dj->save();
     $td = new Book();
     $td->setISBN("067972575X");
     $td->setTitle("The Tin Drum");
     $td->setAuthor($byron);
     $td->save();
     $authors = AuthorQuery::create()->leftJoinBook()->select(array('FirstName', 'LastName'))->withColumn('COUNT(Book.Id)', 'nbBooks')->groupBy(array('FirstName', 'LastName'))->orderByLastName()->find();
     $expectedSql = 'SELECT COUNT(book.id) AS nbBooks, author.first_name AS "FirstName", author.last_name AS "LastName" FROM author LEFT JOIN book ON (author.id=book.author_id) GROUP BY author.first_name,author.last_name ORDER BY author.last_name ASC';
     $this->assertEquals($expectedSql, $this->con->getLastExecutedQuery());
     $this->assertEquals(2, count($authors));
     $this->assertEquals('George', $authors[0]['FirstName']);
     $this->assertEquals(1, $authors[0]['nbBooks']);
     $this->assertEquals('Neal', $authors[1]['FirstName']);
     $this->assertEquals(3, $authors[1]['nbBooks']);
 }
Example #6
0
 public function testUtf8()
 {
     $this->markTestSkipped('Skipped because of weird behavior on some platforms');
     $db = Propel::getServiceContainer()->getAdapter(BookPeer::DATABASE_NAME);
     $title = "Смерть на брудершафт. Младенец и черт";
     //        1234567890123456789012345678901234567
     //                 1         2         3
     $a = new Author();
     $a->setFirstName("Б.");
     $a->setLastName("АКУНИН");
     $p = new Publisher();
     $p->setName("Детектив российский, остросюжетная проза");
     $b = new Book();
     $b->setTitle($title);
     $b->setISBN("B-59246");
     $b->setAuthor($a);
     $b->setPublisher($p);
     $b->save();
     $b->reload();
     $this->assertEquals(37, iconv_strlen($b->getTitle(), 'utf-8'), "Expected 37 characters (not bytes) in title.");
     $this->assertTrue(strlen($b->getTitle()) > iconv_strlen($b->getTitle(), 'utf-8'), "Expected more bytes than characters in title.");
 }
Example #7
0
 protected function setUp()
 {
     parent::setUp();
     BookstoreDataPopulator::populate();
     $cr = new Criteria();
     $cr->add(AuthorPeer::LAST_NAME, "Rowling");
     $cr->add(AuthorPeer::FIRST_NAME, "J.K.");
     $rowling = AuthorPeer::doSelectOne($cr);
     $this->authorId = $rowling->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Philosopher's Stone");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Chamber of Secrets");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Prisoner of Azkaban");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Goblet of Fire");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Half-Blood Prince");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Deathly Hallows");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
 }
 protected function setUp()
 {
     parent::setUp();
     $book1 = new Book();
     $book1->setId(9012);
     $book1->setTitle('Don Juan');
     $book1->setISBN('0140422161');
     $book1->setPrice(12.99);
     $book1->setAuthorId(5678);
     $book1->setPublisherId(1234);
     $book1->resetModified();
     $book2 = new Book();
     $book2->setId(58);
     $book2->setTitle('Harry Potter and the Order of the Phoenix');
     $book2->setISBN('043935806X');
     $book2->setPrice(10.99);
     $book2->resetModified();
     $this->coll = new ObjectCollection();
     $this->coll->setModel('\\Propel\\Tests\\Bookstore\\Book');
     $this->coll[] = $book1;
     $this->coll[] = $book2;
 }
 public function testFindOneWithOneToManyCustomOrder()
 {
     $author1 = new Author();
     $author1->setFirstName('AA');
     $author2 = new Author();
     $author2->setFirstName('BB');
     $book1 = new Book();
     $book1->setTitle('Aaa');
     $book1->setAuthor($author1);
     $book1->save();
     $book2 = new Book();
     $book2->setTitle('Bbb');
     $book2->setAuthor($author2);
     $book2->save();
     $book3 = new Book();
     $book3->setTitle('Ccc');
     $book3->setAuthor($author1);
     $book3->save();
     $authors = AuthorQuery::create()->setFormatter(ModelCriteria::FORMAT_ARRAY)->leftJoin('Propel\\Tests\\Bookstore\\Author.Book')->orderBy('Book.Title')->with('Book')->find();
     $this->assertEquals(2, count($authors), 'with() used on a many-to-many doesn\'t change the main object count');
 }
 public function testFindPkDoesNotCallPreSelectWhenUsingInstancePool()
 {
     $b = new Book();
     $b->setTitle('foo');
     $b->setISBN('FA404');
     $b->save();
     $q = new mySecondBookQuery();
     $this->assertFalse($q::$preSelectWasCalled);
     $q->findPk($b->getId());
     $this->assertFalse($q::$preSelectWasCalled);
 }
 public static function populate($con = null)
 {
     if ($con === null) {
         $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     // Add publisher records
     // ---------------------
     $scholastic = new Publisher();
     $scholastic->setName("Scholastic");
     // do not save, will do later to test cascade
     $morrow = new Publisher();
     $morrow->setName("William Morrow");
     $morrow->save($con);
     $morrow_id = $morrow->getId();
     $penguin = new Publisher();
     $penguin->setName("Penguin");
     $penguin->save();
     $penguin_id = $penguin->getId();
     $vintage = new Publisher();
     $vintage->setName("Vintage");
     $vintage->save($con);
     $vintage_id = $vintage->getId();
     $rowling = new Author();
     $rowling->setFirstName("J.K.");
     $rowling->setLastName("Rowling");
     // no save()
     $stephenson = new Author();
     $stephenson->setFirstName("Neal");
     $stephenson->setLastName("Stephenson");
     $stephenson->save($con);
     $stephenson_id = $stephenson->getId();
     $byron = new Author();
     $byron->setFirstName("George");
     $byron->setLastName("Byron");
     $byron->save($con);
     $byron_id = $byron->getId();
     $grass = new Author();
     $grass->setFirstName("Gunter");
     $grass->setLastName("Grass");
     $grass->save($con);
     $grass_id = $grass->getId();
     $phoenix = new Book();
     $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
     $phoenix->setISBN("043935806X");
     $phoenix->setAuthor($rowling);
     $phoenix->setPublisher($scholastic);
     $phoenix->setPrice(10.99);
     $phoenix->save($con);
     $phoenix_id = $phoenix->getId();
     $qs = new Book();
     $qs->setISBN("0380977427");
     $qs->setTitle("Quicksilver");
     $qs->setPrice(11.99);
     $qs->setAuthor($stephenson);
     $qs->setPublisher($morrow);
     $qs->save($con);
     $qs_id = $qs->getId();
     $dj = new Book();
     $dj->setISBN("0140422161");
     $dj->setTitle("Don Juan");
     $dj->setPrice(12.99);
     $dj->setAuthor($byron);
     $dj->setPublisher($penguin);
     $dj->save($con);
     $dj_id = $dj->getId();
     $td = new Book();
     $td->setISBN("067972575X");
     $td->setTitle("The Tin Drum");
     $td->setPrice(13.99);
     $td->setAuthor($grass);
     $td->setPublisher($vintage);
     $td->save($con);
     $td_id = $td->getId();
     $r1 = new Review();
     $r1->setBook($phoenix);
     $r1->setReviewedBy("Washington Post");
     $r1->setRecommended(true);
     $r1->setReviewDate(time());
     $r1->save($con);
     $r1_id = $r1->getId();
     $r2 = new Review();
     $r2->setBook($phoenix);
     $r2->setReviewedBy("New York Times");
     $r2->setRecommended(false);
     $r2->setReviewDate(time());
     $r2->save($con);
     $r2_id = $r2->getId();
     $blob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.gif';
     $clob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.txt';
     $m1 = new Media();
     $m1->setBook($td);
     $m1->setCoverImage(file_get_contents($blob_path));
     // CLOB is broken in PDO OCI, see http://pecl.php.net/bugs/bug.php?id=7943
     if (get_class(Propel::getServiceContainer()->getAdapter()) != "OracleAdapter") {
         $m1->setExcerpt(file_get_contents($clob_path));
     }
     $m1->save($con);
     // Add book list records
     // ---------------------
     // (this is for many-to-many tests)
     $blc1 = new BookClubList();
     $blc1->setGroupLeader("Crazyleggs");
     $blc1->setTheme("Happiness");
     $brel1 = new BookListRel();
     $brel1->setBook($phoenix);
     $brel2 = new BookListRel();
     $brel2->setBook($dj);
     $blc1->addBookListRel($brel1);
     $blc1->addBookListRel($brel2);
     $blc1->save();
     $bemp1 = new BookstoreEmployee();
     $bemp1->setName("John");
     $bemp1->setJobTitle("Manager");
     $bemp2 = new BookstoreEmployee();
     $bemp2->setName("Pieter");
     $bemp2->setJobTitle("Clerk");
     $bemp2->setSupervisor($bemp1);
     $bemp2->save($con);
     $role = new AcctAccessRole();
     $role->setName("Admin");
     $bempacct = new BookstoreEmployeeAccount();
     $bempacct->setBookstoreEmployee($bemp1);
     $bempacct->setAcctAccessRole($role);
     $bempacct->setLogin("john");
     $bempacct->setPassword("johnp4ss");
     $bempacct->save($con);
     // Add bookstores
     $store = new Bookstore();
     $store->setStoreName("Amazon");
     $store->setPopulationServed(5000000000);
     // world population
     $store->setTotalBooks(300);
     $store->save($con);
     $store = new Bookstore();
     $store->setStoreName("Local Store");
     $store->setPopulationServed(20);
     $store->setTotalBooks(500000);
     $store->save($con);
     $summary = new BookSummary();
     $summary->setSummarizedBook($phoenix);
     $summary->setSummary("Harry Potter does some amazing magic!");
     $summary->save();
     // Add release_pool and record_label
     $acuna = new RecordLabel();
     $acuna->setAbbr('acuna');
     $acuna->setName('Acunadeep');
     $acuna->save();
     $fade = new RecordLabel();
     $fade->setAbbr('fade');
     $fade->setName('Fade Records');
     $fade->save();
     $pool = new ReleasePool();
     $pool->setName('D.Chmelyuk - Revert Me Back');
     $pool->setRecordLabel($acuna);
     $pool->save();
     $pool = new ReleasePool();
     $pool->setName('VIF & Lola Palmer - Dreamer');
     $pool->setRecordLabel($acuna);
     $pool->save();
     $pool = new ReleasePool();
     $pool->setName('Lola Palmer - Do You Belong To Me');
     $pool->setRecordLabel($acuna);
     $pool->save();
     $pool = new ReleasePool();
     $pool->setName('Chris Forties - Despegue (foem.info Runners Up Remixes)');
     $pool->setRecordLabel($fade);
     $pool->save();
     $con->commit();
 }
 /**
  * @dataProvider toCsvDataProvider
  */
 public function testfromCSV($expected)
 {
     $book = new Book();
     $book->fromCSV($expected);
     // FIXME: fromArray() doesn't take related objects into account
     $book->resetModified();
     $author = $this->book->getAuthor();
     $this->book->setAuthor(null);
     $this->book->setAuthorId($author->getId());
     $publisher = $this->book->getPublisher();
     $this->book->setPublisher(null);
     $this->book->setPublisherId($publisher->getId());
     $this->book->resetModified();
     $this->assertEquals($this->book, $book);
 }
 public function testFindOneWithEmptyLeftJoin()
 {
     // save a book with no author
     $b = new Book();
     $b->setTitle('Foo');
     $b->setISBN('FA404');
     $b->save();
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
     $c->where('Propel\\Tests\\Bookstore\\Book.Title = ?', 'Foo');
     $c->leftJoin('Propel\\Tests\\Bookstore\\Book.Author');
     $c->with('Author');
     $c->limit(1);
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     $books = $c->find($con);
     foreach ($books as $book) {
         break;
     }
     $count = $con->getQueryCount();
     $author = $book->getAuthor();
     $this->assertNull($author, 'Related object is not hydrated if empty');
 }
Example #14
0
 public function testSetterCollectionReplacesOldObjectsByNewObjects()
 {
     // Ensure no data
     BookQuery::create()->deleteAll();
     BookClubListQuery::create()->deleteAll();
     BookListRelQuery::create()->deleteAll();
     $books = new ObjectCollection();
     foreach (array('foo', 'bar') as $title) {
         $b = new Book();
         $b->setTitle($title);
         $books[] = $b;
     }
     $bookClubList = new BookClubList();
     $bookClubList->setBooks($books);
     $bookClubList->save();
     $books = $bookClubList->getBooks();
     $this->assertEquals('foo', $books[0]->getTitle());
     $this->assertEquals('bar', $books[1]->getTitle());
     $books = new ObjectCollection();
     foreach (array('bam', 'bom') as $title) {
         $b = new Book();
         $b->setTitle($title);
         $books[] = $b;
     }
     $bookClubList->setBooks($books);
     $bookClubList->save();
     $books = $bookClubList->getBooks();
     $this->assertEquals('bam', $books[0]->getTitle());
     $this->assertEquals('bom', $books[1]->getTitle());
     $this->assertEquals(1, BookClubListQuery::create()->count());
     $this->assertEquals(2, BookListRelQuery::create()->count());
     $this->assertEquals(4, BookQuery::create()->count());
 }
Example #15
0
 public function testFindPkComplexAddsObjectToInstancePool()
 {
     $b = new Book();
     $b->setTitle('foo');
     $b->setISBN('FA404');
     $b->save($this->con);
     BookTableMap::clearInstancePool();
     BookQuery::create('b')->findPk($b->getId(), $this->con);
     $count = $this->con->getQueryCount();
     $book = BookQuery::create()->findPk($b->getId(), $this->con);
     $this->assertEquals($b, $book);
     $this->assertEquals($count, $this->con->getQueryCount());
 }
Example #16
0
 /**
  * Primary key should differ
  */
 public function testSavedObjectCreatesDifferentHashForIdenticalObjects()
 {
     $book1 = new Book();
     $book1->setTitle('Foo5');
     $book1->setISBN('1234');
     $author1 = new Author();
     $author1->setFirstName('JAne');
     $author1->setLastName('JAne');
     $author1->addBook($book1);
     $author1->save();
     $author2 = new Author();
     $author2->setFirstName('JAne');
     $author2->setLastName('JAne');
     $author2->addBook($book1);
     $author2->save();
     $this->assertNotEquals($author1->hashCode(), $author2->hashCode());
 }
Example #17
0
 public function testDoValidate_CustomValidator()
 {
     $book = new Book();
     $book->setTitle("testDoValidate_CustomValidator");
     // (valid)
     $book->setISBN("Foo.Bar.Baz");
     // (invalid)
     $res = $book->validate();
     $this->assertFalse($res, "Expected validation to fail.");
     $failures = $book->getValidationFailures();
     $this->assertEquals(1, count($failures), "Expected 1 column to fail validation.");
     $this->assertEquals(array(BookPeer::ISBN), array_keys($failures), "Expected EMAIL to fail validation.");
     $validator = $failures[BookPeer::ISBN]->getValidator();
     $this->assertInstanceOf('Propel\\Tests\\Helpers\\Bookstore\\Validator\\ISBNValidator', $validator, "Expected validator that failed to be ISBNValidator");
 }
Example #18
0
 /**
  * Tests the Base[Object]::toArray() method
  */
 public function testToArray()
 {
     $types = array(BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM);
     $book = new Book();
     $book->fromArray(array('Title' => 'Harry Potter and the Order of the Phoenix', 'ISBN' => '043935806X'));
     $expecteds = array(BasePeer::TYPE_PHPNAME => array('Title' => 'Harry Potter and the Order of the Phoenix', 'ISBN' => '043935806X'), BasePeer::TYPE_STUDLYPHPNAME => array('title' => 'Harry Potter and the Order of the Phoenix', 'iSBN' => '043935806X'), BasePeer::TYPE_COLNAME => array('book.TITLE' => 'Harry Potter and the Order of the Phoenix', 'book.ISBN' => '043935806X'), BasePeer::TYPE_FIELDNAME => array('title' => 'Harry Potter and the Order of the Phoenix', 'isbn' => '043935806X'), BasePeer::TYPE_NUM => array('1' => 'Harry Potter and the Order of the Phoenix', '2' => '043935806X'));
     foreach ($types as $type) {
         $expected = $expecteds[$type];
         $result = $book->toArray($type);
         // remove ID since its autoincremented at each test iteration
         $result = array_slice($result, 1, 2, true);
         $this->assertEquals($expected, $result, 'expected was: ' . print_r($expected, 1) . 'but toArray() returned ' . print_r($result, 1));
     }
 }
 public function testToArrayWithForeignObjects()
 {
     $types = [TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM];
     $review = new Review();
     $review->setRecommended(true)->setReviewedBy('Someone')->setReviewDate(null);
     $book = new Book();
     $book->setTitle('Harry Potter and the Order of the Phoenix')->setISBN('043935806X')->addReview($review)->setPrice(10);
     $expecteds = array(TableMap::TYPE_PHPNAME => ['Id' => null, 'Title' => 'Harry Potter and the Order of the Phoenix', 'ISBN' => '043935806X', 'Price' => 10.0, 'PublisherId' => null, 'AuthorId' => null, 'Reviews' => [['Id' => null, 'ReviewedBy' => 'Someone', 'ReviewDate' => null, 'Recommended' => true, 'Status' => null, 'BookId' => null, 'Book' => '*RECURSION*']]], TableMap::TYPE_CAMELNAME => array('id' => null, 'title' => 'Harry Potter and the Order of the Phoenix', 'iSBN' => '043935806X', 'price' => 10.0, 'publisherId' => null, 'authorId' => null, 'reviews' => [['id' => null, 'reviewedBy' => 'Someone', 'reviewDate' => null, 'recommended' => true, 'status' => null, 'bookId' => null, 'book' => '*RECURSION*']]), TableMap::TYPE_COLNAME => array('book.ID' => null, 'book.TITLE' => 'Harry Potter and the Order of the Phoenix', 'book.ISBN' => '043935806X', 'book.PRICE' => 10.0, 'book.PUBLISHER_ID' => null, 'book.AUTHOR_ID' => null, 'Reviews' => [['review.ID' => null, 'review.REVIEWED_BY' => 'Someone', 'review.REVIEW_DATE' => null, 'review.RECOMMENDED' => true, 'review.STATUS' => null, 'review.BOOK_ID' => null, 'Book' => '*RECURSION*']]), TableMap::TYPE_FIELDNAME => array('id' => null, 'title' => 'Harry Potter and the Order of the Phoenix', 'isbn' => '043935806X', 'price' => 10.0, 'publisher_id' => null, 'author_id' => null, 'reviews' => [['id' => null, 'reviewed_by' => 'Someone', 'review_date' => null, 'recommended' => true, 'status' => null, 'book_id' => null, 'book' => '*RECURSION*']]), TableMap::TYPE_NUM => array('0' => null, '1' => 'Harry Potter and the Order of the Phoenix', '2' => '043935806X', '3' => 10.0, '4' => null, '5' => null, 'Reviews' => [['0' => null, '1' => 'Someone', '2' => null, '3' => 1, '4' => null, '5' => null, 'Book' => '*RECURSION*']]));
     foreach ($types as $type) {
         $expected = $expecteds[$type];
         $result = $book->toArray($type, true, [], true);
         $this->assertEquals($expected, $result, 'expected was: ' . print_r($expected, 1) . 'but toArray() returned ' . print_r($result, 1));
     }
 }
 public function testNewObjectsGetLostOnJoin()
 {
     /* While testNewObjectsAvailableWhenSaveNotCalled passed as of
        revision 851, in this case we call getBooksJoinPublisher() instead
        of just getBooks(). get...Join...() does not contain the check whether
        the current object is new, it will always consult the DB and lose the
        new objects entirely. Thus the test fails. (At least for Propel 1.2 ?!?) */
     $this->markTestSkipped();
     $a = new Author();
     $a->setFirstName("Douglas");
     $a->setLastName("Adams");
     $p = new Publisher();
     $p->setName('Pan Books Ltd.');
     $b1 = new Book();
     $b1->setTitle("The Hitchhikers Guide To The Galaxy");
     $b1->setISBN('FA404-1');
     $b1->setPublisher($p);
     // uh... did not check that :^)
     $a->addBook($b1);
     $b2 = new Book();
     $b2->setTitle("The Restaurant At The End Of The Universe");
     $b1->setISBN('FA404-2');
     $b2->setPublisher($p);
     $a->addBook($b2);
     $books = $a->getBooksJoinPublisher();
     $this->assertEquals(2, count($books));
     $this->assertContains($b1, $books);
     $this->assertContains($b2, $books);
     $a->save();
     $this->assertFalse($b1->isNew());
     $this->assertFalse($b2->isNew());
 }
Example #21
0
 public function testScenarioUsingQuery()
 {
     // Add publisher records
     // ---------------------
     try {
         $scholastic = new Publisher();
         $scholastic->setName("Scholastic");
         // do not save, will do later to test cascade
         $morrow = new Publisher();
         $morrow->setName("William Morrow");
         $morrow->save();
         $morrow_id = $morrow->getId();
         $penguin = new Publisher();
         $penguin->setName("Penguin");
         $penguin->save();
         $penguin_id = $penguin->getId();
         $vintage = new Publisher();
         $vintage->setName("Vintage");
         $vintage->save();
         $vintage_id = $vintage->getId();
         $this->assertTrue(true, 'Save Publisher records');
     } catch (Exception $e) {
         $this->fail('Save publisher records');
     }
     // Add author records
     // ------------------
     try {
         $rowling = new Author();
         $rowling->setFirstName("J.K.");
         $rowling->setLastName("Rowling");
         // do not save, will do later to test cascade
         $stephenson = new Author();
         $stephenson->setFirstName("Neal");
         $stephenson->setLastName("Stephenson");
         $stephenson->save();
         $stephenson_id = $stephenson->getId();
         $byron = new Author();
         $byron->setFirstName("George");
         $byron->setLastName("Byron");
         $byron->save();
         $byron_id = $byron->getId();
         $grass = new Author();
         $grass->setFirstName("Gunter");
         $grass->setLastName("Grass");
         $grass->save();
         $grass_id = $grass->getId();
         $this->assertTrue(true, 'Save Author records');
     } catch (Exception $e) {
         $this->fail('Save Author records');
     }
     // Add book records
     // ----------------
     try {
         $phoenix = new Book();
         $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
         $phoenix->setISBN("043935806X");
         $phoenix->setAuthor($rowling);
         $phoenix->setPublisher($scholastic);
         $phoenix->save();
         $phoenix_id = $phoenix->getId();
         $this->assertFalse($rowling->isNew(), 'saving book also saves related author');
         $this->assertFalse($scholastic->isNew(), 'saving book also saves related publisher');
         $qs = new Book();
         $qs->setISBN("0380977427");
         $qs->setTitle("Quicksilver");
         $qs->setAuthor($stephenson);
         $qs->setPublisher($morrow);
         $qs->save();
         $qs_id = $qs->getId();
         $dj = new Book();
         $dj->setISBN("0140422161");
         $dj->setTitle("Don Juan");
         $dj->setAuthor($byron);
         $dj->setPublisher($penguin);
         $dj->save();
         $dj_id = $qs->getId();
         $td = new Book();
         $td->setISBN("067972575X");
         $td->setTitle("The Tin Drum");
         $td->setAuthor($grass);
         $td->setPublisher($vintage);
         $td->save();
         $td_id = $td->getId();
         $this->assertTrue(true, 'Save Book records');
     } catch (Exception $e) {
         $this->fail('Save Author records');
     }
     // Add review records
     // ------------------
     try {
         $r1 = new Review();
         $r1->setBook($phoenix);
         $r1->setReviewedBy("Washington Post");
         $r1->setRecommended(true);
         $r1->setReviewDate(time());
         $r1->save();
         $r1_id = $r1->getId();
         $r2 = new Review();
         $r2->setBook($phoenix);
         $r2->setReviewedBy("New York Times");
         $r2->setRecommended(false);
         $r2->setReviewDate(time());
         $r2->save();
         $r2_id = $r2->getId();
         $this->assertTrue(true, 'Save Review records');
     } catch (Exception $e) {
         $this->fail('Save Review records');
     }
     // Perform a "complex" search
     // --------------------------
     $results = BookQuery::create()->filterByTitle('Harry%')->find();
     $this->assertEquals(1, count($results));
     $results = BookQuery::create()->where('Book.ISBN IN ?', array("0380977427", "0140422161"))->find();
     $this->assertEquals(2, count($results));
     // Perform a "limit" search
     // ------------------------
     $results = BookQuery::create()->limit(2)->offset(1)->orderByTitle()->find();
     $this->assertEquals(2, count($results));
     // we ordered on book title, so we expect to get
     $this->assertEquals("Harry Potter and the Order of the Phoenix", $results[0]->getTitle());
     $this->assertEquals("Quicksilver", $results[1]->getTitle());
     // Perform a lookup & update!
     // --------------------------
     // Updating just-created book title
     // First finding book by PK (=$qs_id) ....
     $qs_lookup = BookQuery::create()->findPk($qs_id);
     $this->assertNotNull($qs_lookup, 'just-created book can be found by pk');
     $new_title = "Quicksilver (" . crc32(uniqid(rand())) . ")";
     // Attempting to update found object
     $qs_lookup->setTitle($new_title);
     $qs_lookup->save();
     // Making sure object was correctly updated: ";
     $qs_lookup2 = BookQuery::create()->findPk($qs_id);
     $this->assertEquals($new_title, $qs_lookup2->getTitle());
     // Test some basic DATE / TIME stuff
     // ---------------------------------
     // that's the control timestamp.
     $control = strtotime('2004-02-29 00:00:00');
     // should be two in the db
     $r = ReviewQuery::create()->findOne();
     $r_id = $r->getId();
     $r->setReviewDate($control);
     $r->save();
     $r2 = ReviewQuery::create()->findPk($r_id);
     $this->assertEquals(new DateTime('2004-02-29 00:00:00'), $r2->getReviewDate(null), 'ability to fetch DateTime');
     $this->assertEquals($control, $r2->getReviewDate('U'), 'ability to fetch native unix timestamp');
     $this->assertEquals('2-29-2004', $r2->getReviewDate('n-j-Y'), 'ability to use date() formatter');
     // Handle BLOB/CLOB Columns
     // ------------------------
     $blob_path = __DIR__ . '/../../Fixtures/etc/lob/tin_drum.gif';
     $blob2_path = __DIR__ . '/../../Fixtures/etc/lob/propel.gif';
     $clob_path = __DIR__ . '/../../Fixtures/etc/lob/tin_drum.txt';
     $m1 = new Media();
     $m1->setBook($phoenix);
     $m1->setCoverImage(file_get_contents($blob_path));
     $m1->setExcerpt(file_get_contents($clob_path));
     $m1->save();
     $m1_id = $m1->getId();
     $m1_lookup = MediaQuery::create()->findPk($m1_id);
     $this->assertNotNull($m1_lookup, 'Can find just-created media item');
     $this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($m1_lookup->getCoverImage())), 'BLOB was correctly updated');
     $this->assertEquals(file_get_contents($clob_path), (string) $m1_lookup->getExcerpt(), 'CLOB was correctly updated');
     // now update the BLOB column and save it & check the results
     $m1_lookup->setCoverImage(file_get_contents($blob2_path));
     $m1_lookup->save();
     $m2_lookup = MediaQuery::create()->findPk($m1_id);
     $this->assertNotNull($m2_lookup, 'Can find just-created media item');
     $this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2_lookup->getCoverImage())), 'BLOB was correctly overwritten');
     // Test Validators
     // ---------------
     $bk1 = new Book();
     $bk1->setTitle("12345");
     // min length is 10
     $ret = $bk1->validate();
     $this->assertFalse($ret, 'validation failed');
     $failures = $bk1->getValidationFailures();
     $this->assertEquals(1, count($failures), '1 validation message was returned');
     $el = array_shift($failures);
     $this->assertContains("must be more than", $el->getMessage(), 'Expected validation message was returned');
     $bk2 = new Book();
     $bk2->setTitle("Don Juan");
     $ret = $bk2->validate();
     $this->assertFalse($ret, 'validation failed');
     $failures = $bk2->getValidationFailures();
     $this->assertEquals(1, count($failures), '1 validation message was returned');
     $el = array_shift($failures);
     $this->assertContains("Book title already in database.", $el->getMessage(), 'Expected validation message was returned');
     //Now trying some more complex validation.
     $auth1 = new Author();
     $auth1->setFirstName("Hans");
     // last name required; will fail
     $bk1->setAuthor($auth1);
     $rev1 = new Review();
     $rev1->setReviewDate("08/09/2001");
     // will fail: reviewed_by column required
     $bk1->addReview($rev1);
     $ret2 = $bk1->validate();
     $this->assertFalse($ret2, 'validation failed');
     $failures2 = $bk1->getValidationFailures();
     $this->assertEquals(3, count($failures2), '3 validation messages were returned');
     $expectedKeys = array(AuthorPeer::LAST_NAME, BookPeer::TITLE, ReviewPeer::REVIEWED_BY);
     $this->assertEquals($expectedKeys, array_keys($failures2), 'correct columns failed');
     $bk2 = new Book();
     $bk2->setTitle("12345678901");
     // passes
     $auth2 = new Author();
     $auth2->setLastName("Blah");
     //passes
     $auth2->setEmail("*****@*****.**");
     //passes
     $auth2->setAge(50);
     //passes
     $bk2->setAuthor($auth2);
     $rev2 = new Review();
     $rev2->setReviewedBy("Me!");
     // passes
     $rev2->setStatus("new");
     // passes
     $bk2->addReview($rev2);
     $ret3 = $bk2->validate();
     $this->assertTrue($ret3, 'complex validation can pass');
     // Testing doCount() functionality
     // -------------------------------
     // old way
     $c = new Criteria();
     $records = BookPeer::doSelect($c);
     $count = BookPeer::doCount($c);
     $this->assertEquals($count, count($records), 'correct number of results');
     // new way
     $count = BookQuery::create()->count();
     $this->assertEquals($count, count($records), 'correct number of results');
     // Test many-to-many relationships
     // ---------------
     // init book club list 1 with 2 books
     $blc1 = new BookClubList();
     $blc1->setGroupLeader("Crazyleggs");
     $blc1->setTheme("Happiness");
     $brel1 = new BookListRel();
     $brel1->setBook($phoenix);
     $brel2 = new BookListRel();
     $brel2->setBook($dj);
     $blc1->addBookListRel($brel1);
     $blc1->addBookListRel($brel2);
     $blc1->save();
     $this->assertNotNull($blc1->getId(), 'BookClubList 1 was saved');
     // init book club list 2 with 1 book
     $blc2 = new BookClubList();
     $blc2->setGroupLeader("John Foo");
     $blc2->setTheme("Default");
     $brel3 = new BookListRel();
     $brel3->setBook($phoenix);
     $blc2->addBookListRel($brel3);
     $blc2->save();
     $this->assertNotNull($blc2->getId(), 'BookClubList 2 was saved');
     // re-fetch books and lists from db to be sure that nothing is cached
     $crit = new Criteria();
     $crit->add(BookPeer::ID, $phoenix->getId());
     $phoenix = BookPeer::doSelectOne($crit);
     $this->assertNotNull($phoenix, "book 'phoenix' has been re-fetched from db");
     $crit = new Criteria();
     $crit->add(BookClubListPeer::ID, $blc1->getId());
     $blc1 = BookClubListPeer::doSelectOne($crit);
     $this->assertNotNull($blc1, 'BookClubList 1 has been re-fetched from db');
     $crit = new Criteria();
     $crit->add(BookClubListPeer::ID, $blc2->getId());
     $blc2 = BookClubListPeer::doSelectOne($crit);
     $this->assertNotNull($blc2, 'BookClubList 2 has been re-fetched from db');
     $relCount = $phoenix->countBookListRels();
     $this->assertEquals(2, $relCount, "book 'phoenix' has 2 BookListRels");
     $relCount = $blc1->countBookListRels();
     $this->assertEquals(2, $relCount, 'BookClubList 1 has 2 BookListRels');
     $relCount = $blc2->countBookListRels();
     $this->assertEquals(1, $relCount, 'BookClubList 2 has 1 BookListRel');
     // Cleanup (tests DELETE)
     // ----------------------
     // Removing books that were just created
     // First finding book by PK (=$phoenix_id) ....
     $hp = BookQuery::create()->findPk($phoenix_id);
     $this->assertNotNull($hp, 'Could find just-created book');
     // Attempting to delete [multi-table] by found pk
     $c = new Criteria();
     $c->add(BookPeer::ID, $hp->getId());
     // The only way for cascading to work currently
     // is to specify the author_id and publisher_id (i.e. the fkeys
     // have to be in the criteria).
     $c->add(AuthorPeer::ID, $hp->getAuthor()->getId());
     $c->add(PublisherPeer::ID, $hp->getPublisher()->getId());
     $c->setSingleRecord(true);
     BookPeer::doDelete($c);
     // Checking to make sure correct records were removed.
     $this->assertEquals(3, AuthorPeer::doCount(new Criteria()), 'Correct records were removed from author table');
     $this->assertEquals(3, PublisherPeer::doCount(new Criteria()), 'Correct records were removed from publisher table');
     $this->assertEquals(3, BookPeer::doCount(new Criteria()), 'Correct records were removed from book table');
     // Attempting to delete books by complex criteria
     BookQuery::create()->filterByISBN("043935806X")->orWhere('Book.ISBN = ?', "0380977427")->orWhere('Book.ISBN = ?', "0140422161")->delete();
     // Attempting to delete book [id = $td_id]
     $td->delete();
     // Attempting to delete authors
     AuthorQuery::create()->filterById($stephenson_id)->delete();
     AuthorQuery::create()->filterById($byron_id)->delete();
     $grass->delete();
     // Attempting to delete publishers
     PublisherQuery::create()->filterById($morrow_id)->delete();
     PublisherQuery::create()->filterById($penguin_id)->delete();
     $vintage->delete();
     // These have to be deleted manually also since we have onDelete
     // set to SETNULL in the foreign keys in book. Is this correct?
     $rowling->delete();
     $scholastic->delete();
     $blc1->delete();
     $blc2->delete();
     $this->assertEquals(array(), AuthorPeer::doSelect(new Criteria()), 'no records in [author] table');
     $this->assertEquals(array(), PublisherPeer::doSelect(new Criteria()), 'no records in [publisher] table');
     $this->assertEquals(array(), BookPeer::doSelect(new Criteria()), 'no records in [book] table');
     $this->assertEquals(array(), ReviewPeer::doSelect(new Criteria()), 'no records in [review] table');
     $this->assertEquals(array(), MediaPeer::doSelect(new Criteria()), 'no records in [media] table');
     $this->assertEquals(array(), BookClubListPeer::doSelect(new Criteria()), 'no records in [book_club_list] table');
     $this->assertEquals(array(), BookListRelPeer::doSelect(new Criteria()), 'no records in [book_x_list] table');
 }
 /**
  *
  * @group mysql
  * @group pgsql
  */
 public function testQueryJoins()
 {
     if ($this->runningOnSQLite()) {
         $this->markTestSkipped('SQLite does not support right joins');
     }
     $author = new Author();
     $author->setFirstName('Steve');
     $author->setLastName('Bla');
     $author->save();
     $author2 = new Author();
     $author2->setFirstName('Blumen');
     $author2->setLastName('Hosen');
     $author2->save();
     $book = new Book();
     $book->setTitle('Book 1');
     $book->setISBN('12313');
     $book->save();
     $log = new PolymorphicRelationLog();
     $log->setMessage('author added');
     $log->setAuthor($author);
     $log->save();
     $log = new PolymorphicRelationLog();
     $log->setMessage('author added');
     $log->setAuthor($author2);
     $log->save();
     $log = new PolymorphicRelationLog();
     $log->setMessage('author changed');
     $log->setAuthor($author);
     $log->save();
     $log = new PolymorphicRelationLog();
     $log->setMessage('book added 1');
     $log->setBook($book);
     $log->save();
     $this->assertEquals(4, PolymorphicRelationLogQuery::create()->count());
     $logs = PolymorphicRelationLogQuery::create()->rightJoinAuthor()->with('Author')->orderById()->find();
     $this->assertCount(3, $logs);
     $this->assertEquals($author, $logs[0]->getAuthor());
     $this->assertEquals($author2, $logs[1]->getAuthor());
     $this->assertEquals($author, $logs[2]->getAuthor());
     $this->assertNull($logs[0]->getBook());
     $this->assertNull($logs[1]->getBook());
     $logs = PolymorphicRelationLogQuery::create()->rightJoinBook()->with('Book')->find();
     $this->assertCount(1, $logs);
     $this->assertEquals($book, $logs[0]->getBook());
     $this->assertNull($logs[0]->getAuthor());
     $logs = PolymorphicRelationLogQuery::create()->useAuthorQuery(null, Criteria::RIGHT_JOIN)->filterByFirstName('Steve')->endUse()->with('Author')->find();
     $this->assertCount(2, $logs);
     $logs = PolymorphicRelationLogQuery::create()->useAuthorQuery(null, Criteria::RIGHT_JOIN)->filterByFirstName('Blumen')->endUse()->with('Author')->find();
     $this->assertCount(1, $logs);
     $this->assertEquals(2, PolymorphicRelationLogQuery::create()->filterByTargetId($author->getId())->filterByTargetType('author')->count());
     $this->assertEquals(4, PolymorphicRelationLogQuery::create()->count());
     AuthorTableMap::clearInstancePool();
     $author3 = AuthorQuery::create()->leftJoinPolymorphicRelationLog()->with('PolymorphicRelationLog')->filterById($author->getId())->find()->get(0);
     $this->assertCount(2, $author3->getPolymorphicRelationLogs());
 }
Example #23
0
 public function testToArrayDeep()
 {
     $author = new Author();
     $author->setId(5678);
     $author->setFirstName('George');
     $author->setLastName('Byron');
     $book = new Book();
     $book->setId(9012);
     $book->setTitle('Don Juan');
     $book->setISBN('0140422161');
     $book->setPrice(12.99);
     $book->setAuthor($author);
     $coll = new ArrayCollection();
     $coll->setModel('Propel\\Tests\\Bookstore\\Book');
     $coll[] = $book->toArray(TableMap::TYPE_PHPNAME, true, array(), true);
     $expected = array(array('Id' => 9012, 'Title' => 'Don Juan', 'ISBN' => '0140422161', 'Price' => 12.99, 'PublisherId' => null, 'AuthorId' => 5678, 'Author' => array('Id' => 5678, 'FirstName' => 'George', 'LastName' => 'Byron', 'Email' => null, 'Age' => null, 'Books' => array('Book_0' => '*RECURSION*'))));
     $this->assertEquals($expected, $coll->toArray());
 }
 public function testSearchMatchesNotSimilarNewObjects()
 {
     $col = new ObjectCollection();
     $b1 = new Book();
     $b1->setTitle('Bar');
     $b1->setISBN('012345');
     $b2 = clone $b1;
     $this->assertFalse($col->search($b1), 'search() returns false on an empty collection');
     $col = new ObjectCollection(array($b1));
     $this->assertTrue(0 === $col->search($b1));
     $this->assertFalse(0 === $col->search($b2));
 }
 public function testToArrayIncludesForeignReferrers()
 {
     $a1 = new Author();
     $a1->setFirstName('Leo');
     $a1->setLastName('Tolstoi');
     $arr = $a1->toArray(BasePeer::TYPE_PHPNAME, null, array(), true);
     $this->assertFalse(array_key_exists('Books', $arr));
     $b1 = new Book();
     $b1->setTitle('War and Peace');
     $b2 = new Book();
     $b2->setTitle('Anna Karenina');
     $a1->addBook($b1);
     $a1->addBook($b2);
     $arr = $a1->toArray(BasePeer::TYPE_PHPNAME, null, array(), true);
     $this->assertTrue(array_key_exists('Books', $arr));
     $this->assertEquals(2, count($arr['Books']));
     $this->assertEquals('War and Peace', $arr['Books']['Book_0']['Title']);
     $this->assertEquals('Anna Karenina', $arr['Books']['Book_1']['Title']);
     $this->assertEquals('*RECURSION*', $arr['Books']['Book_0']['Author']);
 }
 public function testManyToManySetterIsNotLoosingAnyReference()
 {
     $list1 = new BookClubList();
     $list2 = new BookClubList();
     $book = new Book();
     $book->addBookClubList($list1);
     $book->addBookClubList($list2);
     $lists = $book->getBookClubLists();
     $this->assertCount(2, $lists, 'setRelCol is losing references to referenced object');
     $rels = $book->getBookListRels();
     $this->assertCount(2, $rels, 'setRelCol is losing references to relation object');
     foreach ($rels as $rel) {
         $this->assertNotNull($rel->getBook(), 'setRelCol is losing backreference on set relation to local object');
         $this->assertNotNull($rel->getBookClubList(), 'setRelCol is losing backreference on set relation to referenced object');
     }
     foreach ($lists as $list) {
         $this->assertCount(1, $list->getBooks(), 'setRelCol is losing backreference on set objects');
     }
 }
 public function testFindOneOrCreateMakesOneQueryWhenRecordExists()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     BookQuery::create()->deleteAll($con);
     $book = new Book();
     $book->setTitle('Title');
     $book->setISBN('FA404');
     $book->setPrice(125);
     $book->save($con);
     $count = $con->getQueryCount();
     $book = BookQuery::create('b')->filterByPrice(125)->findOneOrCreate($con);
     $this->assertEquals($count + 1, $con->getQueryCount(), 'findOneOrCreate() makes only a single query when the record exists');
 }
 public function testFindOneWithLeftJoinWithOneToManyAndNullObjectsAndWithAdditionalJoins()
 {
     BookTableMap::clearInstancePool();
     AuthorTableMap::clearInstancePool();
     BookOpinionTableMap::clearInstancePool();
     BookReaderTableMap::clearInstancePool();
     $freud = new Author();
     $freud->setFirstName("Sigmund");
     $freud->setLastName("Freud");
     $freud->save($this->con);
     $publisher = new Publisher();
     $publisher->setName('Psycho Books');
     $publisher->save();
     $book = new Book();
     $book->setAuthor($freud);
     $book->setTitle('Weirdness');
     $book->setIsbn('abc123456');
     $book->setPrice('14.99');
     $book->setPublisher($publisher);
     $book->save();
     $query = BookQuery::create()->filterByTitle('Weirdness')->innerJoinAuthor()->useBookOpinionQuery(null, Criteria::LEFT_JOIN)->leftJoinBookReader()->endUse()->with('Author')->with('BookOpinion')->with('BookReader');
     $books = $query->find($this->con)->get(0);
     $this->assertEquals(0, count($books->getBookOpinions()));
 }
Example #29
0
 public function testAddingABook()
 {
     $author = AuthorQuery::create()->findPk($this->author->getId());
     $c1 = new Book();
     $c1->setTitle("ORM 101");
     $author->addBook($c1);
     $this->assertEquals(3, count($author->getBooks()));
     $this->assertEquals(3, $author->countBooks());
 }
Example #30
0
 public function testSetterOneToManyReplacesOldObjectsByNewObjects()
 {
     // Ensure no data
     BookQuery::create()->deleteAll();
     AuthorQuery::create()->deleteAll();
     $books = new ObjectCollection();
     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 ObjectCollection();
     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());
 }