public function testFormatter() { $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book'); $this->assertTrue($c->getFormatter() instanceof AbstractFormatter, 'getFormatter() returns a PropelFormatter instance'); $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book'); $c->setFormatter(ModelCriteria::FORMAT_STATEMENT); $this->assertTrue($c->getFormatter() instanceof StatementFormatter, 'setFormatter() accepts the name of a AbstractFormatter class'); try { $c->setFormatter('Propel\\Tests\\Bookstore\\Book'); $this->fail('setFormatter() throws an exception when passed the name of a class not extending AbstractFormatter'); } catch (InvalidArgumentException $e) { $this->assertTrue(true, 'setFormatter() throws an exception when passed the name of a class not extending AbstractFormatter'); } $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book'); $formatter = new StatementFormatter(); $c->setFormatter($formatter); $this->assertTrue($c->getFormatter() instanceof StatementFormatter, 'setFormatter() accepts a AbstractFormatter instance'); try { $formatter = new Book(); $c->setFormatter($formatter); $this->fail('setFormatter() throws an exception when passed an object not extending AbstractFormatter'); } catch (InvalidArgumentException $e) { $this->assertTrue(true, 'setFormatter() throws an exception when passed an object not extending AbstractFormatter'); } }
public function testFormatterWithSelect() { $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book'); $c->keepQuery(false); // just for this test's purpose $c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND); $c->select(array('Id', 'Title')); $rows = $c->find($this->con); $this->assertTrue($c->getFormatter() instanceof \Propel\Runtime\Formatter\OnDemandFormatter, 'The formatter is preserved'); }