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 testFormatNoResult() { $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')); $books = $formatter->format($stmt); $this->assertTrue($books instanceof PropelCollection, 'PropelObjectFormatter::format() returns a PropelCollection'); $this->assertEquals(0, count($books), 'PropelObjectFormatter::format() returns as many rows as the results in the query'); }