Skip to content

Commit 87c8890

Browse files
committed
TestConnection: Add return type to setFetchMode
Slipped through in #88 as it's not used at all here. Now a test exists which does.
1 parent b1e028b commit 87c8890

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

src/Test/TestConnection.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,30 @@ public function rollbackTransaction()
3636

3737
public function prepexec($stmt, $values = null)
3838
{
39-
return new class extends \PDOStatement {
40-
public function getIterator(): \Iterator
41-
{
42-
return new \ArrayIterator([]);
43-
}
44-
45-
public function setFetchMode($mode, ...$args)
46-
{
47-
}
48-
};
39+
if (PHP_MAJOR_VERSION >= 8) {
40+
return new class extends \PDOStatement {
41+
public function getIterator(): \Iterator
42+
{
43+
return new \ArrayIterator([]);
44+
}
45+
46+
public function setFetchMode($mode, ...$args): bool
47+
{
48+
return true;
49+
}
50+
};
51+
} else {
52+
return new class extends \PDOStatement {
53+
public function getIterator(): \Iterator
54+
{
55+
return new \ArrayIterator([]);
56+
}
57+
58+
public function setFetchMode($mode, $params = null): bool
59+
{
60+
return true;
61+
}
62+
};
63+
}
4964
}
5065
}

tests/TestConnectionTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace ipl\Tests\Sql;
4+
5+
use ipl\Sql\Test\TestConnection;
6+
7+
class TestConnectionTest extends \PHPUnit\Framework\TestCase
8+
{
9+
public function testPrepexec()
10+
{
11+
$connection = new TestConnection();
12+
$stmt = $connection->prepexec('SELECT * FROM foo');
13+
$this->assertEmpty(iterator_to_array($stmt));
14+
$this->assertTrue($stmt->setFetchMode(\PDO::FETCH_ASSOC));
15+
}
16+
17+
public function testBeginTransaction()
18+
{
19+
$connection = new TestConnection();
20+
$this->expectException(\LogicException::class);
21+
$connection->beginTransaction();
22+
}
23+
24+
public function testCommitTransaction()
25+
{
26+
$connection = new TestConnection();
27+
$this->expectException(\LogicException::class);
28+
$connection->commitTransaction();
29+
}
30+
31+
public function testRollbackTransaction()
32+
{
33+
$connection = new TestConnection();
34+
$this->expectException(\LogicException::class);
35+
$connection->rollbackTransaction();
36+
}
37+
}

0 commit comments

Comments
 (0)