public function testGetLatestQuery() { $con = Propel::getConnection(BookPeer::DATABASE_NAME); $con->setLastExecutedQuery(123); $this->assertEquals(123, $con->getLastExecutedQuery(), 'DebugPDO has getter and setter for last executed query'); $c = new Criteria(); $c->add(BookPeer::TITLE, 'Harry%s', Criteria::LIKE); $books = BookPeer::doSelect($c, $con); $latestExecutedQuery = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` WHERE book.TITLE LIKE 'Harry%s'"; if (!Propel::getDB(BookPeer::DATABASE_NAME)->useQuoteIdentifier()) { $latestExecutedQuery = str_replace('`', '', $latestExecutedQuery); } $this->assertEquals($latestExecutedQuery, $con->getLastExecutedQuery(), 'PropelPDO updates the last executed query on every request'); BookPeer::doDeleteAll($con); $latestExecutedQuery = "DELETE FROM book"; $this->assertEquals($latestExecutedQuery, $con->getLastExecutedQuery(), 'PropelPDO updates the last executed query on every request'); }
/** * @see http://www.propelorm.org/ticket/959 */ public function testFindOneWithSameRelatedObject() { BookPeer::doDeleteAll(); AuthorPeer::doDeleteAll(); $auth = new Author(); $auth->setFirstName('John'); $auth->save(); $book1 = new Book(); $book1->setTitle('Hello'); $book1->setAuthor($auth); $book1->save(); $book2 = new Book(); $book2->setTitle('World'); $book2->setAuthor($auth); $book2->save(); BookPeer::clearInstancePool(); AuthorPeer::clearInstancePool(); $c = new ModelCriteria('bookstore', 'Book'); $c->setFormatter(ModelCriteria::FORMAT_ARRAY); $c->join('Book.Author'); $c->with('Author'); $books = $c->find(); $this->assertEquals(2, count($books)); $firstBook = $books[0]; $this->assertTrue(isset($firstBook['Author'])); $secondBook = $books[1]; $this->assertTrue(isset($secondBook['Author'])); }
public function testDebugLog() { $con = Propel::getConnection(BookPeer::DATABASE_NAME); $config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT); // save data to return to normal state after test $logger = $con->getLogger(); $testLog = new myLogger(); $con->setLogger($testLog); $logEverything = array('PropelPDO::exec', 'PropelPDO::query', 'PropelPDO::beginTransaction', 'PropelPDO::commit', 'PropelPDO::rollBack', 'DebugPDOStatement::execute'); Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT)->setParameter("debugpdo.logging.methods", $logEverything, false); $con->useDebug(true); // test transaction log $con->beginTransaction(); $this->assertEquals('log: Begin transaction', $testLog->latestMessage, 'PropelPDO logs begin transation in debug mode'); $con->commit(); $this->assertEquals('log: Commit transaction', $testLog->latestMessage, 'PropelPDO logs commit transation in debug mode'); $con->beginTransaction(); $con->rollBack(); $this->assertEquals('log: Rollback transaction', $testLog->latestMessage, 'PropelPDO logs rollback transation in debug mode'); $con->beginTransaction(); $testLog->latestMessage = ''; $con->beginTransaction(); $this->assertEquals('', $testLog->latestMessage, 'PropelPDO does not log nested begin transation in debug mode'); $con->commit(); $this->assertEquals('', $testLog->latestMessage, 'PropelPDO does not log nested commit transation in debug mode'); $con->beginTransaction(); $con->rollBack(); $this->assertEquals('', $testLog->latestMessage, 'PropelPDO does not log nested rollback transation in debug mode'); $con->rollback(); // test query log $con->beginTransaction(); $c = new Criteria(); $c->add(BookPeer::TITLE, 'Harry%s', Criteria::LIKE); $books = BookPeer::doSelect($c, $con); $latestExecutedQuery = "SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM `book` WHERE book.title LIKE 'Harry%s'"; $this->assertEquals('log: ' . $latestExecutedQuery, $testLog->latestMessage, 'PropelPDO logs queries and populates bound parameters in debug mode'); BookPeer::doDeleteAll($con); $latestExecutedQuery = "DELETE FROM `book`"; $this->assertEquals('log: ' . $latestExecutedQuery, $testLog->latestMessage, 'PropelPDO logs deletion queries in debug mode'); $latestExecutedQuery = 'DELETE FROM book WHERE 1=1'; $con->exec($latestExecutedQuery); $this->assertEquals('log: ' . $latestExecutedQuery, $testLog->latestMessage, 'PropelPDO logs exec queries in debug mode'); $con->commit(); // return to normal state after test $con->setLogger($logger); $config->setParameter("debugpdo.logging.methods", array('PropelPDO::exec', 'PropelPDO::query', 'DebugPDOStatement::execute')); }
/** * Test doCountJoin*() methods. */ public function testDoCountJoin() { BookPeer::doDeleteAll(); for ($i = 0; $i < 25; $i++) { $b = new Book(); $b->setTitle("Book {$i}"); $b->setISBN("ISBN {$i}"); $b->save(); } $c = new Criteria(); $totalCount = BookPeer::doCount($c); $this->assertEquals($totalCount, BookPeer::doCountJoinAuthor($c)); $this->assertEquals($totalCount, BookPeer::doCountJoinPublisher($c)); }
public static function depopulate() { AcctAccessRolePeer::doDeleteAll(); AuthorPeer::doDeleteAll(); BookstorePeer::doDeleteAll(); BookstoreContestPeer::doDeleteAll(); BookstoreContestEntryPeer::doDeleteAll(); BookstoreEmployeePeer::doDeleteAll(); BookstoreEmployeeAccountPeer::doDeleteAll(); BookstoreSalePeer::doDeleteAll(); BookClubListPeer::doDeleteAll(); BookOpinionPeer::doDeleteAll(); BookReaderPeer::doDeleteAll(); BookListRelPeer::doDeleteAll(); BookPeer::doDeleteAll(); ContestPeer::doDeleteAll(); CustomerPeer::doDeleteAll(); MediaPeer::doDeleteAll(); PublisherPeer::doDeleteAll(); ReaderFavoritePeer::doDeleteAll(); ReviewPeer::doDeleteAll(); }
public static function depopulate($con = null) { if ($con === null) { $con = Propel::getConnection(BookPeer::DATABASE_NAME); } $con->beginTransaction(); AuthorPeer::doDeleteAll($con); BookstorePeer::doDeleteAll($con); BookstoreContestPeer::doDeleteAll($con); BookstoreContestEntryPeer::doDeleteAll($con); BookstoreEmployeePeer::doDeleteAll($con); BookstoreEmployeeAccountPeer::doDeleteAll($con); BookstoreSalePeer::doDeleteAll($con); BookClubListPeer::doDeleteAll($con); BookOpinionPeer::doDeleteAll($con); BookReaderPeer::doDeleteAll($con); BookListRelPeer::doDeleteAll($con); BookPeer::doDeleteAll($con); ContestPeer::doDeleteAll($con); CustomerPeer::doDeleteAll($con); MediaPeer::doDeleteAll($con); PublisherPeer::doDeleteAll($con); ReaderFavoritePeer::doDeleteAll($con); ReviewPeer::doDeleteAll($con); $con->commit(); }