Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed regression: PDO::FETCH_COLUMN was declared an unsupported fetch type #216

Open
wants to merge 1 commit into
base: 2.14.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Adapter/Driver/Pdo/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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());
}
}
15 changes: 15 additions & 0 deletions test/unit/Adapter/Driver/Pdo/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}