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

TestConnection: Add return type to setFetchMode #89

Merged
merged 1 commit into from
Dec 17, 2024
Merged
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
35 changes: 25 additions & 10 deletions src/Test/TestConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,30 @@ public function rollbackTransaction()

public function prepexec($stmt, $values = null)
{
return new class extends \PDOStatement {
public function getIterator(): \Iterator
{
return new \ArrayIterator([]);
}

public function setFetchMode($mode, ...$args)
{
}
};
if (PHP_MAJOR_VERSION >= 8) {
return new class extends \PDOStatement {
public function getIterator(): \Iterator
{
return new \ArrayIterator([]);
}

public function setFetchMode($mode, ...$args): bool
{
return true;
}
};
} else {
return new class extends \PDOStatement {
public function getIterator(): \Iterator
{
return new \ArrayIterator([]);
}

public function setFetchMode($mode, $params = null): bool
{
return true;
}
};
}
}
}
37 changes: 37 additions & 0 deletions tests/TestConnectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace ipl\Tests\Sql;

use ipl\Sql\Test\TestConnection;

class TestConnectionTest extends \PHPUnit\Framework\TestCase
{
public function testPrepexec()
{
$connection = new TestConnection();
$stmt = $connection->prepexec('SELECT * FROM foo');
$this->assertEmpty(iterator_to_array($stmt));
$this->assertTrue($stmt->setFetchMode(\PDO::FETCH_ASSOC));
}

public function testBeginTransaction()
{
$connection = new TestConnection();
$this->expectException(\LogicException::class);
$connection->beginTransaction();
}

public function testCommitTransaction()
{
$connection = new TestConnection();
$this->expectException(\LogicException::class);
$connection->commitTransaction();
}

public function testRollbackTransaction()
{
$connection = new TestConnection();
$this->expectException(\LogicException::class);
$connection->rollbackTransaction();
}
}
Loading