public function testSelectOneWithFieldMappings() { $query = 'SELECT b.id as i, b.name as n, b.description as d, b.authors_id as a FROM books b JOIN authors a ON b.authors_id = a.id'; $book = Book::selectOneSQL($this->getConn(), $query, [], ['i' => 'id', 'n' => 'name', 'd' => 'description', 'a' => 'authors_id']); $expectedValues = ['id' => '1', 'name' => 'Book 1', 'description' => 'The very first book', 'authors_id' => '1']; $this->assertSame($expectedValues, $book->getValues()); }
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 testSelectOneSQLReturnsNull() { $statement = $this->getMockBuilder('Doctrine\\DBAL\\Statement')->disableOriginalConstructor()->getMock(); $sql = 'select * from books where id = ?'; $this->conn->expects($this->once())->method('prepare')->with($sql)->will($this->returnValue($statement)); $statement->expects($this->once())->method('fetch')->will($this->returnValue(false)); $this->assertNull(Book::selectOneSQL($this->conn, $sql, [1])); }