コード例 #1
0
 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));
 }
コード例 #2
0
 public function setUp()
 {
     parent::setUp();
     $a = new Author();
     $a->setFirstName("Douglas");
     $a->setLastName("Adams");
     $b1 = new Book();
     $b1->setTitle("The Hitchhikers Guide To The Galaxy");
     $a->addBook($b1);
     $b2 = new Book();
     $b2->setTitle("The Restaurant At The End Of The Universe");
     $a->addBook($b2);
     $a->save();
     $this->author = $a;
     $this->books = array($b1, $b2);
     Propel::enableInstancePooling();
     // Clear author instance pool so the object would be fetched from the database
     AuthorTableMap::clearInstancePool();
 }
コード例 #3
0
 public function testRefFKAddReturnsCurrentObject()
 {
     $author = new Author();
     $author->setFirstName('Leo');
     $ret = $author->addBook(new Book());
     $this->assertSame($author, $ret);
 }
コード例 #4
0
 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']);
 }
コード例 #5
0
 public function testFindOneWithEmptyLeftJoinOneToMany()
 {
     // non-empty relation
     $a1 = new Author();
     $a1->setFirstName('Foo');
     $a1->setLastName('Bar');
     $b1 = new Book();
     $b1->setTitle('Foo1');
     $b1->setISBN('FA404-1');
     $a1->addBook($b1);
     $b2 = new Book();
     $b2->setTitle('Foo2');
     $b2->setISBN('FA404-2');
     $a1->addBook($b2);
     $a1->save();
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     $author = AuthorQuery::create()->filterByFirstName('Foo')->leftJoinWith('Propel\\Tests\\Bookstore\\Author.Book')->find($con)->get(0);
     $count = $con->getQueryCount();
     $books = $author->getBooks(null, $con);
     $this->assertEquals(2, $books->count());
     $this->assertEquals($count, $con->getQueryCount());
     // empty relation
     $a2 = new Author();
     $a2->setFirstName('Bar');
     $a2->setLastName('Bar');
     $a2->save();
     $author = AuthorQuery::create()->filterByFirstName('Bar')->leftJoinWith('Propel\\Tests\\Bookstore\\Author.Book')->find($con)->get(0);
     $count = $con->getQueryCount();
     $books = $author->getBooks(null, $con);
     $this->assertEquals(0, $books->count());
     $this->assertEquals($count, $con->getQueryCount());
 }
コード例 #6
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());
 }
コード例 #7
0
 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());
 }
コード例 #8
0
 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');
 }
コード例 #9
0
 public function testFindOneWithEmptyLeftJoinOneToMany()
 {
     // non-empty relation
     $a1 = new Author();
     $a1->setFirstName('Foo');
     $b1 = new Book();
     $b1->setTitle('Foo1');
     $a1->addBook($b1);
     $b2 = new Book();
     $b2->setTitle('Foo2');
     $a1->addBook($b2);
     $a1->save();
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $author = AuthorQuery::create()->filterByFirstName('Foo')->leftJoinWith('Author.Book')->findOne($con);
     $count = $con->getQueryCount();
     $books = $author->getBooks(null, $con);
     $this->assertEquals(2, $books->count());
     $this->assertEquals($count, $con->getQueryCount());
     // empty relation
     $a2 = new Author();
     $a2->setFirstName('Bar');
     $a2->save();
     $author = AuthorQuery::create()->filterByFirstName('Bar')->leftJoinWith('Author.Book')->findOne($con);
     $count = $con->getQueryCount();
     $books = $author->getBooks(null, $con);
     $this->assertEquals(0, $books->count());
     $this->assertEquals($count, $con->getQueryCount());
 }