public function testFormatOneNoResult() { $con = Propel::getConnection(BookPeer::DATABASE_NAME); $stmt = $con->query('SELECT * FROM book WHERE book.TITLE = "foo"'); $formatter = new PropelObjectFormatter(); $formatter->init(new ModelCriteria('bookstore', 'Book')); $book = $formatter->formatOne($stmt); $this->assertNull($book, 'PropelObjectFormatter::formatOne() returns null when no result'); }
public function testFormatOneWithRelatedObjects() { $con = Propel::getConnection(BookPeer::DATABASE_NAME); $con->useDebug(false); $con->useDebug(true); $this->assertEquals(0, $con->getQueryCount()); $stmt = $con->query('SELECT * FROM author LEFT JOIN book ON (author.id = book.author_id) WHERE author.id = (SELECT author_id FROM book WHERE title = "The Tin Drum 2")'); $formatter = new PropelObjectFormatter(); $criteria = new ModelCriteria('bookstore', 'Author'); $criteria->joinWith('Book'); $formatter->init($criteria); $author = $formatter->formatOne($stmt); $this->assertEquals(1, $con->getQueryCount()); $this->assertTrue($author instanceof Author, 'PropelObjectFormatter::formatOne() returns a model object'); $this->assertTrue($author->getBooks() instanceof PropelCollection); $this->assertEquals(2, $author->countBooks()); $this->assertEquals(1, $con->getQueryCount()); }