public function testFormat() { $con = Propel::getConnection(BookPeer::DATABASE_NAME); BookstoreEmployeePeer::clearInstancePool(); $stmt = $con->query('SELECT * FROM bookstore_employee'); $formatter = new PropelObjectFormatter(); $formatter->init(new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\BookstoreEmployee')); $emps = $formatter->format($stmt); $expectedClass = array('b1' => 'BookstoreEmployee', 'b2' => 'BookstoreManager', 'b3' => 'BookstoreCashier'); foreach ($emps as $emp) { $this->assertEquals($expectedClass[$emp->getName()], get_class($emp), 'format() creates objects of the correct class when using inheritance'); } }
public function init(ModelCriteria $criteria) { parent::init($criteria); $this->isSingleTableInheritance = $criteria->getTableMap()->isSingleTableInheritance(); return $this; }
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', '\\Propel\\Tests\\Bookstore\\Book')); $book = $formatter->formatOne($stmt); $this->assertNull($book, 'PropelObjectFormatter::formatOne() returns null when no result'); }