Skip to content

Commit

Permalink
TestConnection: Add return type to setFetchMode
Browse files Browse the repository at this point in the history
Slipped through in #88 as it's not used at all here.
Now a test exists which does.
  • Loading branch information
nilmerg committed Dec 17, 2024
1 parent b1e028b commit 87c8890
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
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();
}
}

0 comments on commit 87c8890

Please sign in to comment.