作者:rouff
项目:Propel
public function testToStringUsesDefaultStringFormat()
{
$author = new Author();
$author->setFirstName('John');
$author->setLastName('Doe');
$expected = <<<EOF
Id: null
FirstName: John
LastName: Doe
Email: null
Age: null
EOF;
$this->assertEquals($expected, (string) $author, 'generated __toString() uses default string format and exportTo()');
$publisher = new Publisher();
$publisher->setId(345345);
$publisher->setName('Peguinoo');
$expected = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<data>
<Id>345345</Id>
<Name><![CDATA[Peguinoo]]></Name>
</data>
EOF;
$this->assertEquals($expected, (string) $publisher, 'generated __toString() uses default string format and exportTo()');
}
作者:norfi
项目:Propel
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));
}
作者:robin85
项目:Propel
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());
}
作者:diside
项目:Propel
protected function setUp()
{
parent::setUp();
$publisher = new Publisher();
$publisher->setId(1234);
$publisher->setName('Penguin');
$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);
$book->setPublisher($publisher);
$this->book = $book;
}
作者:norfi
项目:Propel
public function testInvalidCharset()
{
$this->markTestSkipped('Skipped because of weird behavior on some platforms');
$db = Propel::getServiceContainer()->getAdapter(BookPeer::DATABASE_NAME);
if ($db instanceof SqliteAdapter) {
$this->markTestSkipped();
}
$a = new Author();
$a->setFirstName("Б.");
$a->setLastName("АКУНИН");
$a->save();
$authorNameWindows1251 = iconv("utf-8", "windows-1251", $a->getLastName());
$a->setLastName($authorNameWindows1251);
// Different databases seem to handle invalid data differently (no surprise, I guess...)
if ($db instanceof PgsqlAdapter) {
try {
$a->save();
$this->fail("Expected an exception when saving non-UTF8 data to database.");
} catch (Exception $x) {
print $x;
}
} else {
// No exception is thrown by MySQL ... (others need to be tested still)
$a->save();
$a->reload();
$this->assertEquals("", $a->getLastName(), "Expected last_name to be empty (after inserting invalid charset data)");
}
}
作者:Swissalp
项目:Propel
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']);
}
作者:dracon
项目:forked-php-orm-benchmar
public function testFromArray()
{
$author = new Author();
$author->setFirstName('Jane');
$author->setLastName('Austen');
$author->save();
$books = array(array('Title' => 'Mansfield Park', 'ISBN' => 'FA404', 'AuthorId' => $author->getId()), array('Title' => 'Pride And Prejudice', 'ISBN' => 'FA404', 'AuthorId' => $author->getId()));
$col = new ObjectCollection();
$col->setModel('Propel\\Tests\\Bookstore\\Book');
$col->fromArray($books);
$col->save();
$nbBooks = PropelQuery::from('Propel\\Tests\\Bookstore\\Book')->count();
$this->assertEquals(6, $nbBooks);
$booksByJane = PropelQuery::from('Propel\\Tests\\Bookstore\\Book b')->join('b.Author a')->where('a.LastName = ?', 'Austen')->count();
$this->assertEquals(2, $booksByJane);
}
作者:diside
项目:Propel
public function testNestedTransactionForceRollBack()
{
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$driver = $con->getAttribute(PDO::ATTR_DRIVER_NAME);
// main transaction
$con->beginTransaction();
$a = new Author();
$a->setFirstName('Test');
$a->setLastName('User');
$a->save($con);
$authorId = $a->getId();
// nested transaction
$con->beginTransaction();
$a2 = new Author();
$a2->setFirstName('Test2');
$a2->setLastName('User2');
$a2->save($con);
$authorId2 = $a2->getId();
// force rollback
$con->forceRollback();
$this->assertEquals(0, $con->getNestedTransactionCount(), 'nested transaction is null after nested transaction forced rollback');
$this->assertFalse($con->isInTransaction(), 'PropelPDO is not in transaction after nested transaction force rollback');
AuthorTableMap::clearInstancePool();
$at = AuthorQuery::create()->findPk($authorId);
$this->assertNull($at, "Rolled back transaction is not persisted in database");
$at2 = AuthorQuery::create()->findPk($authorId2);
$this->assertNull($at2, "Forced Rolled back nested transaction is not persisted in database");
}
作者:kalaspuffa
项目:php-orm-benchmar
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
// ---------------------
//.........这里部分代码省略.........
作者:badela
项目:theli
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());
}
作者:norfi
项目:Propel
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");
//.........这里部分代码省略.........
作者:rouff
项目:Propel
public function testFindWithLeftJoinWithOneToManyAndNullObject()
{
BookPeer::clearInstancePool();
AuthorPeer::clearInstancePool();
ReviewPeer::clearInstancePool();
$freud = new Author();
$freud->setFirstName("Sigmund");
$freud->setLastName("Freud");
$freud->save($this->con);
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
$c->setFormatter(ModelCriteria::FORMAT_ARRAY);
$c->add(AuthorPeer::LAST_NAME, 'Freud');
$c->leftJoinWith('Propel\\Tests\\Bookstore\\Author.Book');
$c->leftJoinWith('Book.Review');
// should not raise a notice
$authors = $c->find($this->con);
$this->assertTrue(true);
}
作者:norfi
项目:Propel
public function testDoValidate_BasicValidatorObj()
{
$author = new Author();
$author->setFirstName("Malcolm");
// last name required, valid email format, age > 0
$author->setLastName("X");
$author->setEmail('malcolm@');
// fail
$res = $author->validate();
$this->assertFalse($res, "Expected validation to fail.");
$failures = $author->getValidationFailures();
$this->assertEquals(1, count($failures), "Expected 1 column to fail validation.");
$this->assertEquals(array(AuthorPeer::EMAIL), array_keys($failures), "Expected EMAIL to fail validation.");
$validator = $failures[AuthorPeer::EMAIL]->getValidator();
$this->assertTrue($validator instanceof MatchValidator, "Expected validator that failed to be MatchValidator");
}
作者:Swissalp
项目:Propel
/**
*
* @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());
}
作者:kalaspuffa
项目:php-orm-benchmar
public function testFindOneWithDuplicateRelation()
{
EssayTableMap::doDeleteAll();
$auth1 = new Author();
$auth1->setFirstName('John');
$auth1->setLastName('Doe');
$auth1->save();
$auth2 = new Author();
$auth2->setFirstName('Jack');
$auth2->setLastName('Sparrow');
$auth2->save();
$essay = new Essay();
$essay->setTitle('Foo');
$essay->setFirstAuthor($auth1->getId());
$essay->setSecondAuthor($auth2->getId());
$essay->save();
AuthorTableMap::clearInstancePool();
EssayTableMap::clearInstancePool();
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Essay');
$c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
$c->join('Propel\\Tests\\Bookstore\\Essay.AuthorRelatedByFirstAuthor');
$c->with('AuthorRelatedByFirstAuthor');
$c->where('Propel\\Tests\\Bookstore\\Essay.Title = ?', 'Foo');
$c->limit(1);
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$essays = $c->find($con);
foreach ($essays as $essay) {
break;
}
$count = $con->getQueryCount();
$this->assertEquals($essay->getTitle(), 'Foo', 'Main object is correctly hydrated');
$firstAuthor = $essay->getAuthorRelatedByFirstAuthor();
$this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query');
$this->assertEquals($firstAuthor->getFirstName(), 'John', 'Related object is correctly hydrated');
$secondAuthor = $essay->getAuthorRelatedBySecondAuthor();
$this->assertEquals($count + 1, $con->getQueryCount(), 'with() does not hydrate objects not in with');
}
作者:robin85
项目:Propel
/**
* 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());
}
作者:kalaspuffa
项目:php-orm-benchmar
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());
}
作者:diside
项目:Propel
public function testRemoveObjectOneToMany()
{
BookQuery::create()->deleteAll();
AuthorQuery::create()->deleteAll();
$book = new Book();
$book->setISBN('012345');
$book->setTitle('Propel Book');
$book2 = new Book();
$book2->setISBN('6789');
$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', $books->getFirst()->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');
}
作者:rouff
项目:Propel
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());
}
作者:rouff
项目:Propel
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']);
}