示例#1
0
 public function testFindOneBy()
 {
     try {
         $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
         $book = $c->findOneBy('Foo', 'Bar');
         $this->fail('findOneBy() throws an exception when called on an unknown column name');
     } catch (UnknownColumnException $e) {
         $this->assertTrue(true, 'findOneBy() throws an exception when called on an unknown column name');
     }
     $con = Propel::getServiceContainer()->getConnection(BookPeer::DATABASE_NAME);
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $book = $c->findOneBy('Title', 'Don Juan', $con);
     $expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` WHERE book.TITLE='Don Juan' LIMIT 1";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'findOneBy() adds simple column conditions');
     $this->assertTrue($book instanceof Book, 'findOneBy() returns a Model object by default');
     $this->assertEquals('Don Juan', $book->getTitle(), 'findOneBy() returns the model object matching the query');
 }