diff --git a/src/Adapter/Driver/Pdo/Result.php b/src/Adapter/Driver/Pdo/Result.php index 7a810d43..3a297b13 100644 --- a/src/Adapter/Driver/Pdo/Result.php +++ b/src/Adapter/Driver/Pdo/Result.php @@ -38,7 +38,7 @@ class Result implements Iterator, ResultInterface PDO::FETCH_BOTH, // 4 PDO::FETCH_OBJ, // 5 PDO::FETCH_BOUND, // 6 - // \PDO::FETCH_COLUMN, // 7 (not a valid fetch mode) + PDO::FETCH_COLUMN, // 7 (not a valid fetch mode) PDO::FETCH_CLASS, // 8 PDO::FETCH_INTO, // 9 PDO::FETCH_FUNC, // 10 diff --git a/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php b/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php index 072f79a8..da417ebe 100644 --- a/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php +++ b/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php @@ -6,6 +6,7 @@ use Laminas\Db\TableGateway\Feature\MetadataFeature; use Laminas\Db\TableGateway\TableGateway; use PHPUnit\Framework\TestCase; +use Laminas\Db\Sql\Select; use function count; @@ -38,6 +39,28 @@ public function testSelect() } } + /** + * @covers \Laminas\Db\TableGateway\TableGateway::select + */ + public function testSelectFetchColumn() + { + $tableGateway = new TableGateway('test', $this->adapter); + + $select = new Select(); + $select->from('test'); + $select->columns([ + 'myid' => 'id' + ]); + $select->limit(1); + + $statement = $tableGateway->getSql() + ->prepareStatementForSqlObject($select); + + $result = $statement->execute(); + $result->setFetchMode(\PDO::FETCH_COLUMN); + $this->assertSame('1', $result->next()); + } + /** * @covers \Laminas\Db\TableGateway\TableGateway::insert * @covers \Laminas\Db\TableGateway\TableGateway::select diff --git a/test/integration/Adapter/Driver/Pdo/Postgresql/TableGatewayTest.php b/test/integration/Adapter/Driver/Pdo/Postgresql/TableGatewayTest.php index c35422b1..565c4455 100644 --- a/test/integration/Adapter/Driver/Pdo/Postgresql/TableGatewayTest.php +++ b/test/integration/Adapter/Driver/Pdo/Postgresql/TableGatewayTest.php @@ -7,6 +7,7 @@ use Laminas\Db\TableGateway\Feature\SequenceFeature; use Laminas\Db\TableGateway\TableGateway; use PHPUnit\Framework\TestCase; +use Laminas\Db\Sql\Select; class TableGatewayTest extends TestCase { @@ -26,4 +27,26 @@ public function testLastInsertValue() $tableGateway->insert(['foo' => 'baz']); self::assertSame(2, $tableGateway->getLastInsertValue()); } + + /** + * @covers \Laminas\Db\TableGateway\TableGateway::select + */ + public function testSelectFetchColumn() + { + $tableGateway = new TableGateway('test', $this->adapter); + + $select = new Select(); + $select->from('test'); + $select->columns([ + 'myid' => 'id' + ]); + $select->limit(1); + + $statement = $tableGateway->getSql() + ->prepareStatementForSqlObject($select); + + $result = $statement->execute(); + $result->setFetchMode(\PDO::FETCH_COLUMN); + $this->assertSame(1, $result->next()); + } } diff --git a/test/unit/Adapter/Driver/Pdo/ResultTest.php b/test/unit/Adapter/Driver/Pdo/ResultTest.php index 4ca159b3..fc277067 100644 --- a/test/unit/Adapter/Driver/Pdo/ResultTest.php +++ b/test/unit/Adapter/Driver/Pdo/ResultTest.php @@ -80,4 +80,19 @@ public function testFetchModeRange() self::assertEquals(11, $result->getFetchMode()); self::assertInstanceOf('stdClass', $result->current()); } + + public function testFetchModeColumn() + { + $stub = $this->getMockBuilder('PDOStatement')->getMock(); + $stub->expects($this->any()) + ->method('fetch') + ->will($this->returnCallback(function () { + return 'column_value'; + })); + $result = new Result(); + $result->initialize($stub, null); + $result->setFetchMode(PDO::FETCH_COLUMN); + self::assertEquals(7, $result->getFetchMode()); + self::assertSame('column_value', $result->current()); + } }