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
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion src/Php8/FakePdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/EndToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading