コード例 #1
0
 public function testFromConnectionThrowsException()
 {
     $driver = $this->getMock('Doctrine\\DBAL\\Driver');
     $driver->expects($this->once())->method('getName')->will($this->returnValue('foo'));
     $conn = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
     $conn->expects($this->once())->method('getDriver')->will($this->returnValue($driver));
     $this->setExpectedException('Doctrine\\DBAL\\DBALException');
     AbstractSelector::fromConnection($conn, 'table');
 }
コード例 #2
0
 public function testSelectSQLSingleId()
 {
     $this->loadData('bookshop');
     $conn = $this->getConn();
     $s = AbstractSelector::fromConnection($conn, 'books')->where('id', '=', 3);
     $sql = $s->getSQL();
     $params = $s->getParams();
     $book = Book::selectOneSQL($this->getConn(), $sql, $params);
     $this->assertInstanceOf('ActiveDoctrine\\Tests\\Fixtures\\Bookshop\\Book', $book);
     $this->assertSame('3', $book->id);
 }
コード例 #3
0
 public function testSelectSQL()
 {
     $conn = $this->getConn();
     $this->loadData('bookshop');
     $sql = AbstractSelector::fromConnection($conn, 'books')->getSQL();
     $books = Book::selectSQL($this->getConn(), $sql);
     $this->assertInstanceOf('ActiveDoctrine\\Entity\\EntityCollection', $books);
     $this->assertSame(50, count($books));
     $book = $books[0];
     $this->assertInstanceOf('ActiveDoctrine\\Tests\\Fixtures\\Bookshop\\Book', $book);
     $this->assertSame('Book 1', $book->name);
     $this->assertSame('The very first book', $book->description);
     $this->assertSame('1', $book->authors_id);
 }
コード例 #4
0
 /**
  * Select a single entity using an EntitySelector instance.
  *
  * @param  Connection     $connection A connection instance
  * @return EntitySelector A selector instance
  */
 public static function selectOne(Connection $connection)
 {
     $selector = new EntitySelector(AbstractSelector::fromConnection($connection, static::$table, static::$types), get_called_class());
     return $selector->one();
 }
コード例 #5
0
 protected function getSelector()
 {
     return AbstractSelector::fromConnection($this->getConn(), 'books');
 }