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');
 }
 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);
 }
 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);
 }
Exemplo n.º 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();
 }
Exemplo n.º 5
0
 protected function getSelector()
 {
     return AbstractSelector::fromConnection($this->getConn(), 'books');
 }
 public function __construct(AbstractSelector $selector, $entity_class)
 {
     $this->entity_class = $entity_class;
     $this->selector = $selector;
     $this->connection = $selector->getConnection();
 }