function runBookInsertion($i) { $book = new Book(); $book->setTitle('Hello' . $i); $book->setAuthorId($this->authors[array_rand($this->authors)]); $book->setISBN('1234'); $book->setPrice($i); $book->save($this->con); $this->books[] = $book->getId(); }
function runBookInsertion($i) { $rand = array_rand($this->authors); $book = new Book(); $book->setTitle('Hello' . $i); $book->setAuthor($this->authors[$rand]); $book->setISBN('1234'); $book->setPrice($i); $this->session->persist($book); $this->session->persist($this->authors[$rand]); $this->books[] = $book; $this->i++; if ($this->i >= 500) { $this->commit(); $this->beginTransaction(); } }
public function testCloneContainingObjects() { $a = new Author(); $b = new Book(); $b->setAuthor($a); $b->setISBN('ISBN1'); $b1 = new Book(); $b1->setPrice(5.55); $col = new PropelCollection(array($b, $b1)); $clone = clone $col; $orgCount = $col->getIterator()->count(); $cloneCount = $clone->getIterator()->count(); $this->assertEquals($orgCount, $cloneCount, 'cloned collections have the same size'); $this->assertEquals($b, $clone[0], 'cloned objects are equal'); $this->assertEquals($b1, $clone[1], 'cloned objects are equal'); $this->assertNotSame($b, $clone[0], 'cloned objects are copies, not identical'); $this->assertNotSame($b1, $clone[1], 'cloned objects are copies, not identical'); }
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; }
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 PropelObjectCollection(); $this->coll->setModel('Book'); $this->coll[] = $book1; $this->coll[] = $book2; }
public function testFindOneOrCreateMakesOneQueryWhenRecordExists() { $con = Propel::getConnection(BookPeer::DATABASE_NAME); BookQuery::create()->deleteAll($con); $book = new Book(); $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 testFindOneOrCreateExists() { BookQuery::create()->deleteAll(); $book = new Book(); $book->setTitle('foo'); $book->setPrice(125); $book->save(); $book = BookQuery::create('b')->where('b.Title = ?', 'foo')->filterByPrice(125)->findOneOrCreate(); $this->assertTrue($book instanceof Book, 'findOneOrCreate() returns an instance of the model when the request has one result'); $this->assertFalse($book->isNew(), 'findOneOrCreate() returns an existing instance of the model when the request has one result'); $this->assertEquals('foo', $book->getTitle(), 'findOneOrCreate() returns a populated objects based on the conditions'); $this->assertEquals(125, $book->getPrice(), 'findOneOrCreate() returns a populated objects based on the conditions'); }
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 PropelArrayCollection(); $coll->setModel('Book'); $coll[] = $book->toArray(BasePeer::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 static function populate($con = null) { if ($con === null) { $con = Propel::getConnection(BookPeer::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::getDB()) != "DBOracle") { $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); $bemp3 = new BookstoreCashier(); $bemp3->setName("Tim"); $bemp3->setJobTitle("Cashier"); $bemp3->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(); $con->commit(); }
public function testToKeyValue() { $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 PropelObjectCollection(); $coll->setModel('Book'); $coll->append($book); $this->assertCount(1, $coll); // This will call $book->getId() $this->assertEquals(array(9012 => 'Don Juan'), $coll->toKeyValue('Id', 'Title')); // This will call: $book->getAuthor()->getBooks()->getFirst()->getId() $this->assertEquals(array(9012 => 'Don Juan'), $coll->toKeyValue(array('Author', 'Books', 'First', 'Id'), 'Title')); }
public function testFindOneWithLeftJoinWithOneToManyAndNullObjectsAndWithAdditionalJoins() { BookPeer::clearInstancePool(); AuthorPeer::clearInstancePool(); BookOpinionPeer::clearInstancePool(); BookReaderPeer::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->findOne($this->con); $this->assertEquals(0, count($books->getBookOpinions())); }