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

fix: use default fetch mode for PHP8 PDO implementation #45

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Changes from 1 commit
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
Next Next commit
fix: use default fetch mode for PHP8 PDO implementation
This is a copy of the changes from PR#15 (0e864b2), making the
two versions of `FakePdo` behave the same WRT respecting
`->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, *)`.

Made sure to add an appropriate test.
Kenneth-Sills committed Jun 26, 2024
commit 1309f7c330253ca67b2e2c9e97f39969e6025855
8 changes: 7 additions & 1 deletion src/Php8/FakePdo.php
Original file line number Diff line number Diff line change
@@ -17,7 +17,13 @@ class FakePdo extends PDO implements FakePdoInterface
#[\ReturnTypeWillChange]
public function prepare($statement, array $options = [])
{
return new FakePdoStatement($this, $statement, $this->real);
$statement = new FakePdoStatement($this, $statement, $this->real);

if ($this->defaultFetchMode) {
$statement->setFetchMode($this->defaultFetchMode);
}

return $statement;
}

/**
18 changes: 18 additions & 0 deletions tests/EndToEndTest.php
Original file line number Diff line number Diff line change
@@ -34,6 +34,24 @@ public function testInvalidQuery()
$this->assertSame([], $query->fetchAll(\PDO::FETCH_ASSOC));
}

public function testSelectWithDefaultFetchAssoc()
{
$pdo = self::getConnectionToFullDB();
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);

$query = $pdo->prepare("SELECT id FROM `video_game_characters` WHERE `id` > :id ORDER BY `id` ASC");
$query->bindValue(':id', 14);
$query->execute();

$this->assertSame(
[
['id' => '15'],
['id' => '16']
],
$query->fetchAll()
);
}

public function testSelectFetchAssoc()
{
$pdo = self::getConnectionToFullDB();