Skip to content

Commit cd909b8

Browse files
committed
Fixes Unit and Integration test
Integration test still needs to move to mocked usage Unit test still includes several skipped and incomplete test Signed-off-by: Joey Smith <jsmith@webinertia.net> Signed-off-by: Joey Smith <jsmith@webinertia.net>
1 parent 53163b6 commit cd909b8

File tree

6 files changed

+39
-31
lines changed

6 files changed

+39
-31
lines changed

src/Platform/Mysql.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ protected function quoteViaDriver(string $value): ?string
8888
if ($resource instanceof \mysqli) {
8989
return '\'' . $resource->real_escape_string($value) . '\'';
9090
}
91+
9192
if ($resource instanceof \PDO) {
9293
return $resource->quote($value);
9394
}

test/unit/Driver/Pdo/ConnectionTest.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Exception;
88
use Laminas\Db\Adapter\Exception\InvalidConnectionParametersException;
9+
use Laminas\Db\Adapter\Exception\RuntimeException;
910
use Laminas\Db\Adapter\Mysql\Driver\Pdo\Connection;
1011
use Override;
1112
use PHPUnit\Framework\Attributes\CoversMethod;
@@ -33,7 +34,7 @@ protected function setUp(): void
3334
*/
3435
public function testResource(): void
3536
{
36-
$this->expectException(InvalidConnectionParametersException::class);
37+
$this->expectException(RuntimeException::class);
3738
$this->connection->getResource();
3839
}
3940

@@ -92,26 +93,4 @@ public function testHostnameAndUnixSocketThrowsInvalidConnectionParametersExcept
9293
]);
9394
$this->connection->connect();
9495
}
95-
96-
public function testDblibArrayOfConnectionParametersCreatesCorrectDsn(): void
97-
{
98-
$this->connection->setConnectionParameters([
99-
'driver' => 'pdo_dblib',
100-
'charset' => 'UTF-8',
101-
'dbname' => 'foo',
102-
'port' => '1433',
103-
'version' => '7.3',
104-
]);
105-
try {
106-
$this->connection->connect();
107-
} catch (Exception) {
108-
}
109-
$responseString = $this->connection->getDsn();
110-
111-
$this->assertStringStartsWith('dblib:', $responseString);
112-
$this->assertStringContainsString('charset=UTF-8', $responseString);
113-
$this->assertStringContainsString('dbname=foo', $responseString);
114-
$this->assertStringContainsString('port=1433', $responseString);
115-
$this->assertStringContainsString('version=7.3', $responseString);
116-
}
11796
}

test/unit/Driver/Pdo/PdoTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66

77
use Laminas\Db\Adapter\Driver\DriverInterface;
88
use Laminas\Db\Adapter\Driver\Pdo\Result;
9-
use Laminas\Db\Adapter\Mysql\Driver\Pdo\Pdo;
9+
use Laminas\Db\Adapter\Driver\Pdo\Statement;
10+
use Laminas\Db\Adapter\Mysql\Driver\Pdo;
1011
use Laminas\Db\Exception\RuntimeException;
1112
use Override;
1213
use PHPUnit\Framework\Attributes\CoversMethod;
1314
use PHPUnit\Framework\Attributes\DataProvider;
1415
use PHPUnit\Framework\TestCase;
1516

16-
#[CoversMethod(Pdo::class, 'getDatabasePlatformName')]
17-
#[CoversMethod(Pdo::class, 'getResultPrototype')]
17+
#[CoversMethod(Pdo\Pdo::class, 'getDatabasePlatformName')]
18+
#[CoversMethod(Pdo\Pdo::class, 'getResultPrototype')]
1819
final class PdoTest extends TestCase
1920
{
20-
protected Pdo $pdo;
21+
protected Pdo\Pdo $pdo;
2122

2223
/**
2324
* Sets up the fixture, for example, opens a network connection.
@@ -26,13 +27,20 @@ final class PdoTest extends TestCase
2627
#[Override]
2728
protected function setUp(): void
2829
{
29-
$this->pdo = new Pdo([]);
30+
$connection = $this->createMock(Pdo\Connection::class);
31+
$statement = $this->createMock(Statement::class);
32+
$result = $this->createMock(Result::class);
33+
$this->pdo = new Pdo\Pdo(
34+
$connection,
35+
$statement,
36+
$result
37+
);
3038
}
3139

3240
public function testGetDatabasePlatformName(): void
3341
{
3442
// Test platform name for SqlServer
35-
$this->pdo->getConnection()->setConnectionParameters(['pdodriver' => 'pdo_mysql']);
43+
//$this->pdo->getConnection()->setConnectionParameters(['driver' => 'pdo_mysql']);
3644
self::assertEquals('Mysql', $this->pdo->getDatabasePlatformName());
3745
self::assertEquals('MySQL', $this->pdo->getDatabasePlatformName(DriverInterface::NAME_FORMAT_NATURAL));
3846
}

test/unit/Driver/Pdo/StatementIntegrationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
use Override;
1111
use PDO;
1212
use PDOStatement;
13+
use PHPUnit\Framework\Attributes\CoversMethod;
1314
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516

17+
#[CoversMethod(Statement::class, 'execute')]
1618
final class StatementIntegrationTest extends TestCase
1719
{
1820
protected Statement $statement;

test/unit/Driver/Pdo/StatementTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#[CoversMethod(Statement::class, 'execute')]
2525
final class StatementTest extends TestCase
2626
{
27+
protected ?Pdo $pdo = null;
2728
protected Statement $statement;
2829

2930
/**
@@ -34,6 +35,11 @@ final class StatementTest extends TestCase
3435
protected function setUp(): void
3536
{
3637
$this->statement = new Statement();
38+
$this->pdo = new Pdo(
39+
$this->createMock(Connection::class),
40+
$this->statement,
41+
$this->createMock(Result::class),
42+
);
3743
}
3844

3945
/**
@@ -46,7 +52,7 @@ protected function tearDown(): void
4652

4753
public function testSetDriver(): void
4854
{
49-
self::assertEquals($this->statement, $this->statement->setDriver(new Pdo([])));
55+
self::assertEquals($this->statement, $this->statement->setDriver($this->pdo));
5056
}
5157

5258
public function testSetParameterContainer(): void

test/unit/Platform/MysqlTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace LaminasTest\Db\Adapter\Mysql\Platform;
66

7+
use Laminas\Db\Adapter\Driver\Pdo\Result;
8+
use Laminas\Db\Adapter\Driver\Pdo\Statement;
9+
use Laminas\Db\Adapter\Mysql\Driver\Pdo;
710
use Laminas\Db\Adapter\Mysql\Platform\Mysql;
811
use Override;
912
use PHPUnit\Framework\Attributes\CoversMethod;
@@ -30,7 +33,12 @@ final class MysqlTest extends TestCase
3033
#[Override]
3134
protected function setUp(): void
3235
{
33-
$this->platform = new Mysql();
36+
$pdo = new Pdo\Pdo(
37+
$this->createMock(Pdo\Connection::class),
38+
$this->createMock(Statement::class),
39+
$this->createMock(Result::class),
40+
);
41+
$this->platform = new Mysql($pdo);
3442
}
3543

3644
public function testGetName(): void
@@ -73,6 +81,10 @@ public function testQuoteValueRaisesNoticeWithoutPlatformSupport(): void
7381
{
7482
/**
7583
* @todo Determine if vulnerability warning is required during unit testing
84+
*
85+
* @todo This testing needs expanded to cover all possible driver types
86+
* since using \PDO currently causes a TypeError to be raised due to the
87+
* underlying quoteViaDriver method returning false instead of ?string
7688
*/
7789
//$this->expectNotice();
7890
//$this->expectExceptionMessage(

0 commit comments

Comments
 (0)