diff --git a/src/Test/TestConnection.php b/src/Test/TestConnection.php index bf03c12..913070f 100644 --- a/src/Test/TestConnection.php +++ b/src/Test/TestConnection.php @@ -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; + } + }; + } } } diff --git a/tests/TestConnectionTest.php b/tests/TestConnectionTest.php new file mode 100644 index 0000000..665b16b --- /dev/null +++ b/tests/TestConnectionTest.php @@ -0,0 +1,37 @@ +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(); + } +}