From 0b654b6f45977f61165969d829f06bb870a2901c Mon Sep 17 00:00:00 2001 From: Simon Mundy Date: Wed, 25 Feb 2026 19:27:58 +1100 Subject: [PATCH 1/8] Fixed tests in Unit and Integration Signed-off-by: Simon Mundy --- phpstan-baseline.neon | 152 +++++++++--------- phpunit.xml.dist | 4 +- src/Connection.php | 19 +-- src/Container/ConnectionInterfaceFactory.php | 2 + src/Container/DriverInterfaceFactory.php | 8 +- src/Container/MysqliResultFactory.php | 17 ++ src/Container/PdoDriverInterfaceFactory.php | 2 +- src/Container/PdoResultFactory.php | 17 ++ src/Driver.php | 7 +- src/Pdo/{Pdo.php => Driver.php} | 2 +- src/Statement.php | 5 +- .../Container/MysqlMetadataFactoryTest.php | 18 +-- .../Container/MysqliConnectionFactoryTest.php | 14 +- .../Container/MysqliDriverFactoryTest.php | 16 +- .../Container/MysqliResultFactoryTest.php | 6 +- .../Container/MysqliStatementFactoryTest.php | 14 +- .../Container/PdoConnectionFactoryTest.php | 12 +- .../Container/PdoDriverFactoryTest.php | 8 +- .../Container/PdoResultFactoryTest.php | 4 +- .../Container/PdoStatementFactoryTest.php | 4 +- .../PlatformInterfaceFactoryTest.php | 8 +- .../Container/TestAsset/SetupTrait.php | 17 +- .../Driver/Mysqli/ConnectionTest.php | 6 +- .../Driver/Mysqli/TableGatewayTest.php | 8 +- .../Driver/Pdo/AbstractAdapterTestCase.php | 8 +- test/integration/Driver/Pdo/AdapterTest.php | 5 +- .../integration/Driver/Pdo/ConnectionTest.php | 6 +- test/integration/Driver/Pdo/QueryTest.php | 4 +- .../Driver/Pdo/TableGatewayAndAdapterTest.php | 6 +- .../Driver/Pdo/TableGatewayTest.php | 8 +- .../IntegrationTestStartedListener.php | 6 +- .../IntegrationTestStoppedListener.php | 4 +- .../Extension/ListenerExtension.php | 2 +- .../FixtureLoader/FixtureLoaderInterface.php | 2 +- .../FixtureLoader/MysqlFixtureLoader.php | 2 +- test/integration/Platform/MysqlTest.php | 32 ++-- test/unit/Driver/Mysqli/ConnectionTest.php | 4 +- test/unit/Driver/Pdo/ConnectionTest.php | 4 +- .../Driver/Pdo/ConnectionTransactionsTest.php | 8 +- test/unit/Driver/Pdo/PdoTest.php | 12 +- test/unit/Driver/Pdo/ResultTest.php | 2 +- .../Driver/Pdo/StatementIntegrationTest.php | 6 +- test/unit/Driver/Pdo/StatementTest.php | 10 +- .../unit/Driver/Pdo/TestAsset/CtorlessPdo.php | 2 +- test/unit/Driver/TestAsset/PdoMock.php | 2 +- test/unit/Platform/MysqlTest.php | 8 +- test/unit/TestAsset/ConnectionWrapper.php | 6 +- test/unit/TestAsset/PdoStubDriver.php | 2 +- 48 files changed, 288 insertions(+), 233 deletions(-) create mode 100644 src/Container/MysqliResultFactory.php create mode 100644 src/Container/PdoResultFactory.php rename src/Pdo/{Pdo.php => Driver.php} (96%) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index af96370..ab56072 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4,169 +4,175 @@ parameters: message: '#^Method PhpDb\\Adapter\\Profiler\\ProfilerInterface\:\:profilerFinish\(\) invoked with 1 parameter, 0 required\.$#' identifier: arguments.count count: 1 - path: src/Driver/Mysqli/Connection.php + path: src/Connection.php - - message: '#^Property PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Connection\:\:\$driver \(PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Mysqli\) does not accept PhpDb\\Adapter\\Driver\\DriverInterface\.$#' + message: '#^Property PhpDb\\Mysql\\Connection\:\:\$driver \(PhpDb\\Mysql\\Driver\) does not accept PhpDb\\Adapter\\Driver\\DriverInterface\.$#' identifier: assign.propertyType count: 1 - path: src/Driver/Mysqli/Connection.php + path: src/Connection.php - - message: '#^Property PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Connection\:\:\$resource \(mysqli\) does not accept null\.$#' + message: '#^Property PhpDb\\Mysql\\Connection\:\:\$resource \(mysqli\) does not accept null\.$#' identifier: assign.propertyType count: 1 - path: src/Driver/Mysqli/Connection.php + path: src/Connection.php - message: '#^Strict comparison using \!\=\= between null and null will always evaluate to false\.$#' identifier: notIdentical.alwaysFalse count: 1 - path: src/Driver/Mysqli/Connection.php + path: src/Connection.php - message: '#^Variable \$names in PHPDoc tag @var does not match assigned variable \$findParameterValue\.$#' identifier: varTag.differentVariable count: 1 - path: src/Driver/Mysqli/Connection.php + path: src/Connection.php - - message: '#^Instanceof between PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Connection and PhpDb\\Adapter\\Driver\\DriverAwareInterface will always evaluate to true\.$#' + message: '#^Instanceof between PhpDb\\Mysql\\Connection and PhpDb\\Adapter\\Driver\\DriverAwareInterface will always evaluate to true\.$#' identifier: instanceof.alwaysTrue count: 1 - path: src/Driver/Mysqli/Mysqli.php + path: src/Driver.php - - message: '#^Instanceof between PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Connection and PhpDb\\Adapter\\Profiler\\ProfilerAwareInterface will always evaluate to true\.$#' + message: '#^Instanceof between PhpDb\\Mysql\\Connection and PhpDb\\Adapter\\Profiler\\ProfilerAwareInterface will always evaluate to true\.$#' identifier: instanceof.alwaysTrue count: 1 - path: src/Driver/Mysqli/Mysqli.php + path: src/Driver.php - - message: '#^Instanceof between PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Statement and PhpDb\\Adapter\\Driver\\DriverAwareInterface will always evaluate to true\.$#' + message: '#^Instanceof between PhpDb\\Mysql\\Statement and PhpDb\\Adapter\\Driver\\DriverAwareInterface will always evaluate to true\.$#' identifier: instanceof.alwaysTrue count: 1 - path: src/Driver/Mysqli/Mysqli.php + path: src/Driver.php - - message: '#^Instanceof between PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Statement and PhpDb\\Adapter\\Profiler\\ProfilerAwareInterface will always evaluate to true\.$#' + message: '#^Instanceof between PhpDb\\Mysql\\Statement and PhpDb\\Adapter\\Profiler\\ProfilerAwareInterface will always evaluate to true\.$#' identifier: instanceof.alwaysTrue count: 1 - path: src/Driver/Mysqli/Mysqli.php + path: src/Driver.php - - message: '#^Method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Mysqli\:\:getResultPrototype\(\) should return PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Result but returns PhpDb\\Adapter\\Driver\\ResultInterface\.$#' + message: '#^Method PhpDb\\Mysql\\Driver\:\:getResultPrototype\(\) should return PhpDb\\Mysql\\Result but returns PhpDb\\Adapter\\Driver\\ResultInterface\.$#' identifier: return.type count: 1 - path: src/Driver/Mysqli/Mysqli.php + path: src/Driver.php - - message: '#^Parameter \#1 \$resource \(mysqli\|mysqli_stmt\|PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\mysqli_result\) of method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Mysqli\:\:createResult\(\) should be compatible with parameter \$resource \(resource\) of method PhpDb\\Adapter\\Driver\\DriverInterface\:\:createResult\(\)$#' + message: '#^Parameter \#1 \$resource \(mysqli\|mysqli_stmt\|PhpDb\\Mysql\\mysqli_result\) of method PhpDb\\Mysql\\Driver\:\:createResult\(\) should be compatible with parameter \$resource \(resource\) of method PhpDb\\Adapter\\Driver\\DriverInterface\:\:createResult\(\)$#' identifier: method.childParameterType count: 1 - path: src/Driver/Mysqli/Mysqli.php + path: src/Driver.php - - message: '#^Parameter \$resource of method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Mysqli\:\:createResult\(\) has invalid type PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\mysqli_result\.$#' + message: '#^Parameter \$resource of method PhpDb\\Mysql\\Driver\:\:createResult\(\) has invalid type PhpDb\\Mysql\\mysqli_result\.$#' identifier: class.notFound count: 1 - path: src/Driver/Mysqli/Mysqli.php + path: src/Driver.php + + - + message: '#^Parameter \#2 \$array of function implode expects array\, array\\> given\.$#' + identifier: argument.type + count: 2 + path: src/Metadata/Source.php + + - + message: '#^Parameter \#2 \$array of function implode expects array\, array\\> given\.$#' + identifier: argument.type + count: 4 + path: src/Metadata/Source.php + + - + message: '#^Variable \$isFK might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: src/Metadata/Source.php + + - + message: '#^Variable \$name might not be defined\.$#' + identifier: variable.undefined + count: 2 + path: src/Metadata/Source.php + + - + message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType + count: 1 + path: src/Pdo/Connection.php + + - + message: '#^Parameter \#1 \$resource \(PDOStatement\) of method PhpDb\\Mysql\\Pdo\\Driver\:\:createResult\(\) should be compatible with parameter \$resource \(resource\) of method PhpDb\\Adapter\\Driver\\DriverInterface\:\:createResult\(\)$#' + identifier: method.childParameterType + count: 3 + path: src/Pdo/Driver.php + + - + message: '#^Parameter \#3 \$rowCount of method PhpDb\\Adapter\\Driver\\Pdo\\Result\:\:initialize\(\) expects Closure\|int, null given\.$#' + identifier: argument.type + count: 1 + path: src/Pdo/Driver.php - message: '#^Instanceof between mysqli_stmt and mysqli_stmt will always evaluate to true\.$#' identifier: instanceof.alwaysTrue count: 2 - path: src/Driver/Mysqli/Result.php + path: src/Result.php - - message: '#^Method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Result\:\:initialize\(\) has PhpDb\\Adapter\\Exception\\InvalidArgumentException in PHPDoc @throws tag but it''s not thrown\.$#' + message: '#^Method PhpDb\\Mysql\\Result\:\:initialize\(\) has PhpDb\\Adapter\\Exception\\InvalidArgumentException in PHPDoc @throws tag but it''s not thrown\.$#' identifier: throws.unusedType count: 1 - path: src/Driver/Mysqli/Result.php + path: src/Result.php - - message: '#^Method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Result\:\:isBuffered\(\) never returns null so it can be removed from the return type\.$#' + message: '#^Method PhpDb\\Mysql\\Result\:\:isBuffered\(\) never returns null so it can be removed from the return type\.$#' identifier: return.unusedType count: 1 - path: src/Driver/Mysqli/Result.php + path: src/Result.php - message: '#^Result of && is always false\.$#' identifier: booleanAnd.alwaysFalse count: 1 - path: src/Driver/Mysqli/Result.php + path: src/Result.php - message: '#^Instanceof between PhpDb\\Adapter\\ParameterContainer and PhpDb\\Adapter\\ParameterContainer will always evaluate to true\.$#' identifier: instanceof.alwaysTrue count: 1 - path: src/Driver/Mysqli/Statement.php + path: src/Statement.php - message: '#^Instanceof between mysqli_stmt and mysqli_stmt will always evaluate to true\.$#' identifier: instanceof.alwaysTrue count: 1 - path: src/Driver/Mysqli/Statement.php + path: src/Statement.php - - message: '#^Method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Statement\:\:execute\(\) never returns null so it can be removed from the return type\.$#' + message: '#^Method PhpDb\\Mysql\\Statement\:\:execute\(\) never returns null so it can be removed from the return type\.$#' identifier: return.unusedType count: 1 - path: src/Driver/Mysqli/Statement.php + path: src/Statement.php - - message: '#^Method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Statement\:\:getParameterContainer\(\) never returns null so it can be removed from the return type\.$#' + message: '#^Method PhpDb\\Mysql\\Statement\:\:getParameterContainer\(\) never returns null so it can be removed from the return type\.$#' identifier: return.unusedType count: 1 - path: src/Driver/Mysqli/Statement.php + path: src/Statement.php - - message: '#^Method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Statement\:\:getSql\(\) never returns null so it can be removed from the return type\.$#' + message: '#^Method PhpDb\\Mysql\\Statement\:\:getSql\(\) never returns null so it can be removed from the return type\.$#' identifier: return.unusedType count: 1 - path: src/Driver/Mysqli/Statement.php + path: src/Statement.php - - message: '#^Property PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Statement\:\:\$driver \(PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Mysqli\) does not accept PhpDb\\Adapter\\Driver\\DriverInterface\.$#' + message: '#^Property PhpDb\\Mysql\\Statement\:\:\$driver \(PhpDb\\Mysql\\Driver\) does not accept PhpDb\\Adapter\\Driver\\DriverInterface\.$#' identifier: assign.propertyType count: 1 - path: src/Driver/Mysqli/Statement.php - - - - message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: src/Driver/Pdo/Connection.php - - - - message: '#^Parameter \#1 \$resource \(PDOStatement\) of method PhpDb\\Adapter\\Mysql\\Driver\\Pdo\\Pdo\:\:createResult\(\) should be compatible with parameter \$resource \(resource\) of method PhpDb\\Adapter\\Driver\\DriverInterface\:\:createResult\(\)$#' - identifier: method.childParameterType - count: 3 - path: src/Driver/Pdo/Pdo.php - - - - message: '#^Parameter \#2 \$array of function implode expects array\, array\\> given\.$#' - identifier: argument.type - count: 2 - path: src/Metadata/Source/MysqlMetadata.php - - - - message: '#^Parameter \#2 \$array of function implode expects array\, array\\> given\.$#' - identifier: argument.type - count: 4 - path: src/Metadata/Source/MysqlMetadata.php - - - - message: '#^Variable \$isFK might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: src/Metadata/Source/MysqlMetadata.php - - - - message: '#^Variable \$name might not be defined\.$#' - identifier: variable.undefined - count: 2 - path: src/Metadata/Source/MysqlMetadata.php + path: src/Statement.php - message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsInt\(\) with int will always evaluate to true\.$#' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index dc7fc0e..179647f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,7 +11,7 @@ failOnWarning="true"> - + @@ -27,7 +27,7 @@ - + diff --git a/src/Connection.php b/src/Connection.php index fd18080..1cd009f 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -5,6 +5,7 @@ namespace PhpDb\Mysql; use Exception as GenericException; +use mysqli; use Override; use PhpDb\Adapter\Driver\AbstractConnection; use PhpDb\Adapter\Driver\ConnectionInterface; @@ -27,7 +28,7 @@ class Connection extends AbstractConnection implements DriverAwareInterface { protected Driver $driver; - /** @var \mysqli */ + /** @var mysqli */ protected $resource; /** @@ -36,11 +37,11 @@ class Connection extends AbstractConnection implements DriverAwareInterface * @throws InvalidArgumentException */ public function __construct( - array|\mysqli|null $connectionInfo = null + array|mysqli|null $connectionInfo = null ) { if (is_array($connectionInfo)) { $this->setConnectionParameters($connectionInfo); - } elseif ($connectionInfo instanceof \mysqli) { + } elseif ($connectionInfo instanceof mysqli) { $this->setResource($connectionInfo); } elseif (null !== $connectionInfo) { throw new Exception\InvalidArgumentException( @@ -75,7 +76,7 @@ public function getCurrentSchema(): string|false * * @return $this Provides a fluent interface */ - public function setResource(\mysqli $resource): static + public function setResource(mysqli $resource): static { $this->resource = $resource; @@ -86,7 +87,7 @@ public function setResource(\mysqli $resource): static #[Override] public function connect(): ConnectionInterface { - if ($this->resource instanceof \mysqli) { + if ($this->resource instanceof mysqli) { return $this; } @@ -185,14 +186,14 @@ public function connect(): ConnectionInterface /** @inheritDoc */ public function isConnected(): bool { - return $this->resource instanceof \mysqli; + return $this->resource instanceof mysqli; } /** @inheritDoc */ #[Override] public function disconnect(): ConnectionInterface { - if ($this->resource instanceof \mysqli) { + if ($this->resource instanceof mysqli) { $this->resource->close(); } $this->resource = null; @@ -285,10 +286,10 @@ public function getLastGeneratedValue(?string $name = null): string|int|false|nu * * todo: why do we have this random method here? * - * @return \mysqli + * @return mysqli */ protected function createResource() { - return new \mysqli(); + return new mysqli(); } } diff --git a/src/Container/ConnectionInterfaceFactory.php b/src/Container/ConnectionInterfaceFactory.php index 148a492..51bca53 100644 --- a/src/Container/ConnectionInterfaceFactory.php +++ b/src/Container/ConnectionInterfaceFactory.php @@ -9,6 +9,8 @@ use PhpDb\Mysql\Connection; use Psr\Container\ContainerInterface; +use function is_array; + final class ConnectionInterfaceFactory { public function __invoke( diff --git a/src/Container/DriverInterfaceFactory.php b/src/Container/DriverInterfaceFactory.php index 2b4dd2e..70353d3 100644 --- a/src/Container/DriverInterfaceFactory.php +++ b/src/Container/DriverInterfaceFactory.php @@ -5,8 +5,10 @@ namespace PhpDb\Mysql\Container; use Laminas\ServiceManager\ServiceManager; +use PhpDb\Adapter\Driver\ConnectionInterface; use PhpDb\Adapter\Driver\DriverInterface; use PhpDb\Adapter\Driver\ResultInterface; +use PhpDb\Adapter\Driver\StatementInterface; use PhpDb\Exception\ContainerException; use PhpDb\Mysql\Connection; use PhpDb\Mysql\Driver; @@ -29,16 +31,16 @@ public function __invoke( ); } - /** @var Driver\ConnectionInterface&Connection $connectionInstance */ + /** @var ConnectionInterface&Connection $connectionInstance */ $connectionInstance = $container->build(Connection::class, $options); - /** @var Driver\StatementInterface&Statement $statementInstance */ + /** @var StatementInterface&Statement $statementInstance */ $statementInstance = $container->build( Statement::class, $options['options'] ?? [] ); - /** @var Driver\ResultInterface&Result $resultInstance */ + /** @var ResultInterface&Result $resultInstance */ $resultInstance = $container->has(ResultInterface::class) ? $container->get(ResultInterface::class) : new Result(); diff --git a/src/Container/MysqliResultFactory.php b/src/Container/MysqliResultFactory.php new file mode 100644 index 0000000..f5bc80c --- /dev/null +++ b/src/Container/MysqliResultFactory.php @@ -0,0 +1,17 @@ +connection->isConnected()) { $this->connection->connect(); } - /** @var \mysqli $resource */ + /** @var mysqli $resource */ $resource = $this->connection->getResource(); $statement->initialize($resource); } @@ -127,7 +128,7 @@ public function createStatement($sqlOrResource = null): StatementInterface&State /** * Create result * - * @param \mysqli|mysqli_result|mysqli_stmt $resource + * @param mysqli|mysqli_result|mysqli_stmt $resource */ public function createResult($resource, ?bool $isBuffered = null): ResultInterface&Result { diff --git a/src/Pdo/Pdo.php b/src/Pdo/Driver.php similarity index 96% rename from src/Pdo/Pdo.php rename to src/Pdo/Driver.php index 924e255..4bb69d8 100644 --- a/src/Pdo/Pdo.php +++ b/src/Pdo/Driver.php @@ -24,7 +24,7 @@ public function createResult($resource): ResultInterface /** @var ResultInterface&Result $result */ $result = clone $this->resultPrototype; - $rowCount = 0; + $rowCount = null; $lastGeneratedValue = $this->getLastGeneratedValue(); diff --git a/src/Statement.php b/src/Statement.php index ed51854..24c63b1 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -4,6 +4,7 @@ namespace PhpDb\Mysql; +use mysqli; use mysqli_stmt; use Override; use PhpDb\Adapter\Driver\DriverAwareInterface; @@ -22,7 +23,7 @@ final class Statement implements StatementInterface, DriverAwareInterface, ProfilerAwareInterface { - protected \mysqli $mysqli; + protected mysqli $mysqli; protected Driver $driver; @@ -59,7 +60,7 @@ public function getProfiler(): ?ProfilerInterface return $this->profiler; } - public function initialize(\mysqli $mysqli): static + public function initialize(mysqli $mysqli): static { $this->mysqli = $mysqli; return $this; diff --git a/test/integration/Container/MysqlMetadataFactoryTest.php b/test/integration/Container/MysqlMetadataFactoryTest.php index e29858d..aa3327e 100644 --- a/test/integration/Container/MysqlMetadataFactoryTest.php +++ b/test/integration/Container/MysqlMetadataFactoryTest.php @@ -2,27 +2,27 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Container; +namespace PhpDbIntegrationTest\Mysql\Container; -use PhpDb\Adapter\Mysql\Container\MysqlMetadataFactory; -use PhpDb\Adapter\Mysql\Metadata\Source\MysqlMetadata; use PhpDb\Metadata\MetadataInterface; -use PhpDbIntegrationTest\Adapter\Mysql\Container\TestAsset\SetupTrait; +use PhpDb\Mysql\Container\MetadataInterfaceFactory; +use PhpDb\Mysql\Metadata\Source; +use PhpDbIntegrationTest\Mysql\Container\TestAsset\SetupTrait; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\TestCase; -#[CoversClass(MysqlMetadataFactory::class)] -#[CoversMethod(MysqlMetadataFactory::class, '__invoke')] +#[CoversClass(MetadataInterfaceFactory::class)] +#[CoversMethod(MetadataInterfaceFactory::class, '__invoke')] final class MysqlMetadataFactoryTest extends TestCase { use SetupTrait; public function testFactoryReturnsMysqlMetadata(): void { - $factory = new MysqlMetadataFactory(); - $metadata = $factory($this->container); + $factory = new MetadataInterfaceFactory(); + $metadata = $factory($this->container, Source::class); self::assertInstanceOf(MetadataInterface::class, $metadata); - self::assertInstanceOf(MysqlMetadata::class, $metadata); + self::assertInstanceOf(Source::class, $metadata); } } diff --git a/test/integration/Container/MysqliConnectionFactoryTest.php b/test/integration/Container/MysqliConnectionFactoryTest.php index ba5ad21..6b087fa 100644 --- a/test/integration/Container/MysqliConnectionFactoryTest.php +++ b/test/integration/Container/MysqliConnectionFactoryTest.php @@ -2,16 +2,16 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Container; +namespace PhpDbIntegrationTest\Mysql\Container; use PhpDb\Adapter\Driver\ConnectionInterface; -use PhpDb\Adapter\Mysql\Container\MysqliConnectionFactory; -use PhpDb\Adapter\Mysql\Driver\Mysqli\Connection; +use PhpDb\Mysql\Connection; +use PhpDb\Mysql\Container\ConnectionInterfaceFactory; use PHPUnit\Framework\Attributes; use PHPUnit\Framework\TestCase; -#[Attributes\CoversClass(MysqliConnectionFactory::class)] -#[Attributes\CoversMethod(MysqliConnectionFactory::class, '__invoke')] +#[Attributes\CoversClass(ConnectionInterfaceFactory::class)] +#[Attributes\CoversMethod(ConnectionInterfaceFactory::class, '__invoke')] #[Attributes\Group('container')] #[Attributes\Group('integration')] #[Attributes\Group('integration-mysqli')] @@ -27,8 +27,8 @@ public function testInvokeReturnsMysqliConnection(): void ], ]); - $factory = new MysqliConnectionFactory(); - $connection = $factory($this->container, Connection::class); + $factory = new ConnectionInterfaceFactory(); + $connection = $factory($this->container, Connection::class, $this->config['db']); self::assertInstanceOf(ConnectionInterface::class, $connection); self::assertInstanceOf(Connection::class, $connection); diff --git a/test/integration/Container/MysqliDriverFactoryTest.php b/test/integration/Container/MysqliDriverFactoryTest.php index 4bcf801..7412e74 100644 --- a/test/integration/Container/MysqliDriverFactoryTest.php +++ b/test/integration/Container/MysqliDriverFactoryTest.php @@ -2,16 +2,16 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Container; +namespace PhpDbIntegrationTest\Mysql\Container; use PhpDb\Adapter\Driver\DriverInterface; -use PhpDb\Adapter\Mysql\Container\MysqliDriverFactory; -use PhpDb\Adapter\Mysql\Driver\Mysqli\Mysqli; +use PhpDb\Mysql\Container\DriverInterfaceFactory; +use PhpDb\Mysql\Driver; use PHPUnit\Framework\Attributes; use PHPUnit\Framework\TestCase; -#[Attributes\CoversClass(MysqliDriverFactory::class)] -#[Attributes\CoversMethod(MysqliDriverFactory::class, '__invoke')] +#[Attributes\CoversClass(DriverInterfaceFactory::class)] +#[Attributes\CoversMethod(DriverInterfaceFactory::class, '__invoke')] #[Attributes\Group('container')] #[Attributes\Group('integration')] #[Attributes\Group('integration-mysqli')] @@ -26,9 +26,9 @@ public function testFactoryReturnsMysqliDriver(): void 'driver' => 'Mysqli', ], ]); - $factory = new MysqliDriverFactory(); - $driver = $factory($this->container); + $factory = new DriverInterfaceFactory(); + $driver = $factory($this->container, Driver::class, $this->config['db']); self::assertInstanceOf(DriverInterface::class, $driver); - $this->assertInstanceOf(Mysqli::class, $driver); + $this->assertInstanceOf(Driver::class, $driver); } } diff --git a/test/integration/Container/MysqliResultFactoryTest.php b/test/integration/Container/MysqliResultFactoryTest.php index 30ed58a..7c854aa 100644 --- a/test/integration/Container/MysqliResultFactoryTest.php +++ b/test/integration/Container/MysqliResultFactoryTest.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Container; +namespace PhpDbIntegrationTest\Mysql\Container; use PhpDb\Adapter\Driver\ResultInterface; -use PhpDb\Adapter\Mysql\Container\MysqliResultFactory; -use PhpDb\Adapter\Mysql\Driver\Mysqli\Result; +use PhpDb\Mysql\Container\MysqliResultFactory; +use PhpDb\Mysql\Result; use PHPUnit\Framework\Attributes; use PHPUnit\Framework\TestCase; diff --git a/test/integration/Container/MysqliStatementFactoryTest.php b/test/integration/Container/MysqliStatementFactoryTest.php index 419a0c1..9b86e5f 100644 --- a/test/integration/Container/MysqliStatementFactoryTest.php +++ b/test/integration/Container/MysqliStatementFactoryTest.php @@ -2,16 +2,16 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Container; +namespace PhpDbIntegrationTest\Mysql\Container; use PhpDb\Adapter\Driver\StatementInterface; -use PhpDb\Adapter\Mysql\Container\MysqliStatementFactory; -use PhpDb\Adapter\Mysql\Driver\Mysqli\Statement; +use PhpDb\Mysql\Container\StatementInterfaceFactory; +use PhpDb\Mysql\Statement; use PHPUnit\Framework\Attributes; use PHPUnit\Framework\TestCase; -#[Attributes\CoversClass(MysqliStatementFactory::class)] -#[Attributes\CoversMethod(MysqliStatementFactory::class, '__invoke')] +#[Attributes\CoversClass(StatementInterfaceFactory::class)] +#[Attributes\CoversMethod(StatementInterfaceFactory::class, '__invoke')] #[Attributes\Group('container')] #[Attributes\Group('integration')] #[Attributes\Group('integration-mysqli')] @@ -30,8 +30,8 @@ public function testInvokeReturnsMysqliStatement(): void ], ]); - $factory = new MysqliStatementFactory(); - $statement = $factory($this->container); + $factory = new StatementInterfaceFactory(); + $statement = $factory($this->container, Statement::class, $this->config['db']['options'] ?? []); self::assertInstanceOf(StatementInterface::class, $statement); self::assertInstanceOf(Statement::class, $statement); diff --git a/test/integration/Container/PdoConnectionFactoryTest.php b/test/integration/Container/PdoConnectionFactoryTest.php index 463e463..0033553 100644 --- a/test/integration/Container/PdoConnectionFactoryTest.php +++ b/test/integration/Container/PdoConnectionFactoryTest.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Container; +namespace PhpDbIntegrationTest\Mysql\Container; use PhpDb\Adapter\Driver\ConnectionInterface; use PhpDb\Adapter\Driver\PdoConnectionInterface; -use PhpDb\Adapter\Mysql\Container\PdoConnectionFactory; -use PhpDb\Adapter\Mysql\Driver\Pdo\Connection; +use PhpDb\Mysql\Container\PdoConnectionInterfaceFactory; +use PhpDb\Mysql\Pdo\Connection; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\Group; @@ -15,15 +15,15 @@ #[Group('container')] #[Group('integration')] -#[CoversClass(PdoConnectionFactory::class)] -#[CoversMethod(PdoConnectionFactory::class, '__invoke')] +#[CoversClass(PdoConnectionInterfaceFactory::class)] +#[CoversMethod(PdoConnectionInterfaceFactory::class, '__invoke')] final class PdoConnectionFactoryTest extends TestCase { use TestAsset\SetupTrait; public function testInvokeReturnsPdoConnection(): void { - $factory = new PdoConnectionFactory(); + $factory = new PdoConnectionInterfaceFactory(); $instance = $factory($this->container); self::assertInstanceOf(ConnectionInterface::class, $instance); self::assertInstanceOf(PdoConnectionInterface::class, $instance); diff --git a/test/integration/Container/PdoDriverFactoryTest.php b/test/integration/Container/PdoDriverFactoryTest.php index 2606306..0e4e778 100644 --- a/test/integration/Container/PdoDriverFactoryTest.php +++ b/test/integration/Container/PdoDriverFactoryTest.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Container; +namespace PhpDbIntegrationTest\Mysql\Container; use PhpDb\Adapter\Driver\PdoDriverInterface; -use PhpDb\Adapter\Mysql\Container\PdoDriverInterfaceFactory; -use PhpDb\Adapter\Mysql\Driver\Pdo\Pdo; +use PhpDb\Mysql\Container\PdoDriverInterfaceFactory; +use PhpDb\Mysql\Pdo\Driver as PdoDriver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\Group; @@ -26,6 +26,6 @@ public function testInvokeReturnsPdoDriver(): void $instance = $factory($this->container); self::assertInstanceOf(PdoDriverInterface::class, $instance); - self::assertInstanceOf(Pdo::class, $instance); + self::assertInstanceOf(PdoDriver::class, $instance); } } diff --git a/test/integration/Container/PdoResultFactoryTest.php b/test/integration/Container/PdoResultFactoryTest.php index 81d3177..9409bb8 100644 --- a/test/integration/Container/PdoResultFactoryTest.php +++ b/test/integration/Container/PdoResultFactoryTest.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Container; +namespace PhpDbIntegrationTest\Mysql\Container; use PhpDb\Adapter\Driver\Pdo\Result; use PhpDb\Adapter\Driver\ResultInterface; -use PhpDb\Adapter\Mysql\Container\PdoResultFactory; +use PhpDb\Mysql\Container\PdoResultFactory; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\Group; diff --git a/test/integration/Container/PdoStatementFactoryTest.php b/test/integration/Container/PdoStatementFactoryTest.php index 21e8712..b48edd0 100644 --- a/test/integration/Container/PdoStatementFactoryTest.php +++ b/test/integration/Container/PdoStatementFactoryTest.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Container; +namespace PhpDbIntegrationTest\Mysql\Container; use PhpDb\Adapter\Driver\Pdo\Statement; use PhpDb\Adapter\Driver\StatementInterface; -use PhpDb\Adapter\Mysql\Container\PdoStatementFactory; +use PhpDb\Mysql\Container\PdoStatementFactory; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\Group; diff --git a/test/integration/Container/PlatformInterfaceFactoryTest.php b/test/integration/Container/PlatformInterfaceFactoryTest.php index a5e1cf5..74b199a 100644 --- a/test/integration/Container/PlatformInterfaceFactoryTest.php +++ b/test/integration/Container/PlatformInterfaceFactoryTest.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Container; +namespace PhpDbIntegrationTest\Mysql\Container; -use PhpDb\Adapter\Mysql\Container\PlatformInterfaceFactory; -use PhpDb\Adapter\Mysql\Platform\Mysql; use PhpDb\Adapter\Platform\PlatformInterface; +use PhpDb\Mysql\AdapterPlatform as Mysql; +use PhpDb\Mysql\Container\PlatformInterfaceFactory; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\Group; @@ -23,7 +23,7 @@ final class PlatformInterfaceFactoryTest extends TestCase public function testInvokeReturnsPlatformInterfaceWhenDbDriverIsPdo(): void { $factory = new PlatformInterfaceFactory(); - $instance = $factory($this->container); + $instance = $factory($this->container, Mysql::class, ['driver' => $this->adapter->getDriver()]); self::assertInstanceOf(PlatformInterface::class, $instance); self::assertInstanceOf(Mysql::class, $instance); } diff --git a/test/integration/Container/TestAsset/SetupTrait.php b/test/integration/Container/TestAsset/SetupTrait.php index aff2cf1..25cfc7d 100644 --- a/test/integration/Container/TestAsset/SetupTrait.php +++ b/test/integration/Container/TestAsset/SetupTrait.php @@ -2,16 +2,15 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Container\TestAsset; +namespace PhpDbIntegrationTest\Mysql\Container\TestAsset; use Laminas\ServiceManager\ServiceManager; use Laminas\Stdlib\ArrayUtils; use PhpDb\Adapter\AdapterInterface; use PhpDb\Adapter\Driver\DriverInterface; -use PhpDb\Adapter\Mysql\ConfigProvider; -use PhpDb\Adapter\Mysql\Driver\Pdo\Pdo; use PhpDb\ConfigProvider as LaminasDbConfigProvider; -use Psr\Container\ContainerInterface; +use PhpDb\Mysql\ConfigProvider; +use PhpDb\Mysql\Pdo\Driver as PdoDriver; use function getenv; @@ -27,14 +26,18 @@ trait SetupTrait { protected array $config = ['db' => []]; - protected ?AdapterInterface $adapter; + protected ?AdapterInterface $adapter = null; - protected ContainerInterface $container; + protected ServiceManager $container; protected DriverInterface|string|null $driver = null; protected function setUp(): void { + if (getenv('TESTS_PHPDB_ADAPTER_MYSQL') !== 'true') { + self::markTestSkipped('Integration tests require TESTS_PHPDB_ADAPTER_MYSQL=true'); + } + $this->getAdapter(); parent::setUp(); } @@ -43,7 +46,7 @@ protected function getAdapter(array $config = []): AdapterInterface { $connectionConfig = [ 'db' => [ - 'driver' => $this->driver ?? Pdo::class, + 'driver' => $this->driver ?? PdoDriver::class, 'connection' => [ 'hostname' => (string) getenv('TESTS_PHPDB_ADAPTER_MYSQL_HOSTNAME') ?: 'localhost', 'username' => (string) getenv('TESTS_PHPDB_ADAPTER_MYSQL_USERNAME'), diff --git a/test/integration/Driver/Mysqli/ConnectionTest.php b/test/integration/Driver/Mysqli/ConnectionTest.php index 7d679b3..4c796e2 100644 --- a/test/integration/Driver/Mysqli/ConnectionTest.php +++ b/test/integration/Driver/Mysqli/ConnectionTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Driver\Mysqli; +namespace PhpDbIntegrationTest\Mysql\Driver\Mysqli; -use PhpDb\Adapter\Mysql\Driver\Mysqli\Connection; -use PhpDbIntegrationTest\Adapter\Mysql\Container\TestAsset\SetupTrait; +use PhpDb\Mysql\Connection; +use PhpDbIntegrationTest\Mysql\Container\TestAsset\SetupTrait; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; diff --git a/test/integration/Driver/Mysqli/TableGatewayTest.php b/test/integration/Driver/Mysqli/TableGatewayTest.php index de68b5e..8d8238c 100644 --- a/test/integration/Driver/Mysqli/TableGatewayTest.php +++ b/test/integration/Driver/Mysqli/TableGatewayTest.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Driver\Mysqli; +namespace PhpDbIntegrationTest\Mysql\Driver\Mysqli; use PhpDb\Adapter\Adapter; use PhpDb\Adapter\AdapterInterface; -use PhpDb\Adapter\Mysql\Driver\Mysqli\Mysqli; +use PhpDb\Mysql\Driver; use PhpDb\ResultSet\AbstractResultSet; use PhpDb\TableGateway\TableGateway; -use PhpDbIntegrationTest\Adapter\Mysql\Container\TestAsset\SetupTrait; +use PhpDbIntegrationTest\Mysql\Container\TestAsset\SetupTrait; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\TestCase; @@ -28,7 +28,7 @@ public function testSelectWithEmptyCurrentWithBufferResult(): void /** @var AdapterInterface&Adapter $adapter */ $adapter = $this->getAdapter([ 'db' => [ - 'driver' => Mysqli::class, + 'driver' => Driver::class, 'options' => [ 'buffer_results' => true, ], diff --git a/test/integration/Driver/Pdo/AbstractAdapterTestCase.php b/test/integration/Driver/Pdo/AbstractAdapterTestCase.php index 061332c..1b8e8f1 100644 --- a/test/integration/Driver/Pdo/AbstractAdapterTestCase.php +++ b/test/integration/Driver/Pdo/AbstractAdapterTestCase.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Driver\Pdo; +namespace PhpDbIntegrationTest\Mysql\Driver\Pdo; use PhpDb\Adapter\Adapter; use PhpDb\Adapter\AdapterInterface; use PhpDb\Adapter\Driver\ConnectionInterface; -use PhpDb\Adapter\Mysql\Driver\Pdo\Pdo; use PhpDb\Adapter\SchemaAwareInterface; -use PhpDbIntegrationTest\Adapter\Mysql\Container\TestAsset\SetupTrait; +use PhpDb\Mysql\Pdo\Driver as PdoDriver; +use PhpDbIntegrationTest\Mysql\Container\TestAsset\SetupTrait; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\TestCase; @@ -46,7 +46,7 @@ public function testDriverDisconnectAfterQuoteWithPlatform(): void /** @var AdapterInterface&Adapter $adapter */ $adapter = $this->getAdapter([ 'db' => [ - 'driver' => Pdo::class, + 'driver' => PdoDriver::class, ], ]); $adapter->getDriver()->getConnection()->connect(); diff --git a/test/integration/Driver/Pdo/AdapterTest.php b/test/integration/Driver/Pdo/AdapterTest.php index 66b4ffc..57274f3 100644 --- a/test/integration/Driver/Pdo/AdapterTest.php +++ b/test/integration/Driver/Pdo/AdapterTest.php @@ -2,10 +2,9 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Driver\Pdo; +namespace PhpDbIntegrationTest\Mysql\Driver\Pdo; -use PhpDbIntegrationTest\Adapter\Mysql\Container\TestAsset\SetupTrait; -use PhpDbIntegrationTest\Adapter\Mysql\Driver\Pdo\AbstractAdapterTestCase; +use PhpDbIntegrationTest\Mysql\Container\TestAsset\SetupTrait; use PHPUnit\Framework\Attributes\CoversNothing; #[CoversNothing] diff --git a/test/integration/Driver/Pdo/ConnectionTest.php b/test/integration/Driver/Pdo/ConnectionTest.php index 7b9c5aa..2df969b 100644 --- a/test/integration/Driver/Pdo/ConnectionTest.php +++ b/test/integration/Driver/Pdo/ConnectionTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Driver\Pdo; +namespace PhpDbIntegrationTest\Mysql\Driver\Pdo; use PDO; use PhpDb\Adapter\Driver\AbstractConnection; @@ -13,8 +13,8 @@ use PhpDb\Adapter\Driver\PdoConnectionInterface; use PhpDb\Adapter\Driver\ResultInterface; use PhpDb\Adapter\Driver\StatementInterface; -use PhpDb\Adapter\Mysql\Driver\Pdo\Connection; -use PhpDbIntegrationTest\Adapter\Mysql\Container\TestAsset\SetupTrait; +use PhpDb\Mysql\Pdo\Connection; +use PhpDbIntegrationTest\Mysql\Container\TestAsset\SetupTrait; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\Group; diff --git a/test/integration/Driver/Pdo/QueryTest.php b/test/integration/Driver/Pdo/QueryTest.php index 9cc2c26..ff38564 100644 --- a/test/integration/Driver/Pdo/QueryTest.php +++ b/test/integration/Driver/Pdo/QueryTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Driver\Pdo; +namespace PhpDbIntegrationTest\Mysql\Driver\Pdo; use Exception; use PhpDb\Adapter\Adapter; @@ -11,7 +11,7 @@ use PhpDb\Adapter\Exception\RuntimeException; use PhpDb\ResultSet\ResultSet; use PhpDb\Sql\Sql; -use PhpDbIntegrationTest\Adapter\Mysql\Container\TestAsset\SetupTrait; +use PhpDbIntegrationTest\Mysql\Container\TestAsset\SetupTrait; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; diff --git a/test/integration/Driver/Pdo/TableGatewayAndAdapterTest.php b/test/integration/Driver/Pdo/TableGatewayAndAdapterTest.php index 97cab1b..50cfbaf 100644 --- a/test/integration/Driver/Pdo/TableGatewayAndAdapterTest.php +++ b/test/integration/Driver/Pdo/TableGatewayAndAdapterTest.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Driver\Pdo; +namespace PhpDbIntegrationTest\Mysql\Driver\Pdo; use Exception; use PhpDb\Adapter\Driver\ConnectionInterface; use PhpDb\ResultSet\AbstractResultSet; use PhpDb\TableGateway\TableGateway; -use PhpDbIntegrationTest\Adapter\Mysql\Container\TestAsset\SetupTrait; +use PhpDbIntegrationTest\Mysql\Container\TestAsset\SetupTrait; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -46,7 +46,7 @@ public function testGetOutOfConnections(): void protected function tearDown(): void { - if ($this->adapter->getDriver()->getConnection()->isConnected()) { + if ($this->adapter?->getDriver()->getConnection()->isConnected()) { $this->adapter->getDriver()->getConnection()->disconnect(); } $this->adapter = null; diff --git a/test/integration/Driver/Pdo/TableGatewayTest.php b/test/integration/Driver/Pdo/TableGatewayTest.php index bfdf50e..f454238 100644 --- a/test/integration/Driver/Pdo/TableGatewayTest.php +++ b/test/integration/Driver/Pdo/TableGatewayTest.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Driver\Pdo; +namespace PhpDbIntegrationTest\Mysql\Driver\Pdo; use Laminas\Stdlib\ArrayObject; use PhpDb\Adapter\Adapter; use PhpDb\Adapter\AdapterInterface; -use PhpDb\Adapter\Mysql\Metadata\Source\MysqlMetadata; use PhpDb\Adapter\SchemaAwareInterface; +use PhpDb\Mysql\Metadata\Source; use PhpDb\ResultSet\ResultSet; use PhpDb\Sql\TableIdentifier; use PhpDb\TableGateway\Feature\MetadataFeature; use PhpDb\TableGateway\TableGateway; -use PhpDbIntegrationTest\Adapter\Mysql\Container\TestAsset\SetupTrait; +use PhpDbIntegrationTest\Mysql\Container\TestAsset\SetupTrait; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Depends; @@ -118,7 +118,7 @@ public function testTableGatewayWithMetadataFeature(array|string|TableIdentifier $table, $adapter, new MetadataFeature( - new MysqlMetadata($adapter), + new Source($adapter), ) ); diff --git a/test/integration/Extension/IntegrationTestStartedListener.php b/test/integration/Extension/IntegrationTestStartedListener.php index 23b0646..615816d 100644 --- a/test/integration/Extension/IntegrationTestStartedListener.php +++ b/test/integration/Extension/IntegrationTestStartedListener.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Extension; +namespace PhpDbIntegrationTest\Mysql\Extension; use Exception; -use PhpDbIntegrationTest\Adapter\Mysql\FixtureLoader\FixtureLoaderInterface; -use PhpDbIntegrationTest\Adapter\Mysql\FixtureLoader\MysqlFixtureLoader; +use PhpDbIntegrationTest\Mysql\FixtureLoader\FixtureLoaderInterface; +use PhpDbIntegrationTest\Mysql\FixtureLoader\MysqlFixtureLoader; use PHPUnit\Event\TestSuite\Started; use PHPUnit\Event\TestSuite\StartedSubscriber; diff --git a/test/integration/Extension/IntegrationTestStoppedListener.php b/test/integration/Extension/IntegrationTestStoppedListener.php index 974ec2a..135e69a 100644 --- a/test/integration/Extension/IntegrationTestStoppedListener.php +++ b/test/integration/Extension/IntegrationTestStoppedListener.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Extension; +namespace PhpDbIntegrationTest\Mysql\Extension; -use PhpDbIntegrationTest\Adapter\Mysql\FixtureLoader\FixtureLoaderInterface; +use PhpDbIntegrationTest\Mysql\FixtureLoader\FixtureLoaderInterface; use PHPUnit\Event\TestSuite\Finished; use PHPUnit\Event\TestSuite\FinishedSubscriber; diff --git a/test/integration/Extension/ListenerExtension.php b/test/integration/Extension/ListenerExtension.php index 3ebd817..2357037 100644 --- a/test/integration/Extension/ListenerExtension.php +++ b/test/integration/Extension/ListenerExtension.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Extension; +namespace PhpDbIntegrationTest\Mysql\Extension; use PHPUnit\Runner\Extension\Extension; use PHPUnit\Runner\Extension\Facade; diff --git a/test/integration/FixtureLoader/FixtureLoaderInterface.php b/test/integration/FixtureLoader/FixtureLoaderInterface.php index c30fc41..e21f22f 100644 --- a/test/integration/FixtureLoader/FixtureLoaderInterface.php +++ b/test/integration/FixtureLoader/FixtureLoaderInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\FixtureLoader; +namespace PhpDbIntegrationTest\Mysql\FixtureLoader; interface FixtureLoaderInterface { diff --git a/test/integration/FixtureLoader/MysqlFixtureLoader.php b/test/integration/FixtureLoader/MysqlFixtureLoader.php index 4b2565f..8f3e7bb 100644 --- a/test/integration/FixtureLoader/MysqlFixtureLoader.php +++ b/test/integration/FixtureLoader/MysqlFixtureLoader.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\FixtureLoader; +namespace PhpDbIntegrationTest\Mysql\FixtureLoader; use Exception; use PDO; diff --git a/test/integration/Platform/MysqlTest.php b/test/integration/Platform/MysqlTest.php index d79aba7..f2a97ff 100644 --- a/test/integration/Platform/MysqlTest.php +++ b/test/integration/Platform/MysqlTest.php @@ -2,14 +2,18 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Mysql\Platform; +namespace PhpDbIntegrationTest\Mysql\Platform; +use mysqli; use Override; use PhpDb\Adapter\Driver\Pdo; -use PhpDb\Adapter\Mysql\Driver\Mysqli; -use PhpDb\Adapter\Mysql\Driver\Pdo\Connection; -use PhpDb\Adapter\Mysql\Driver\Pdo\Pdo as PdoDriver; -use PhpDb\Adapter\Mysql\Platform\Mysql; +use PhpDb\Mysql\AdapterPlatform as Mysql; +use PhpDb\Mysql\Connection as MysqliConnection; +use PhpDb\Mysql\Driver as MysqliDriver; +use PhpDb\Mysql\Pdo\Connection; +use PhpDb\Mysql\Pdo\Driver as PdoDriver; +use PhpDb\Mysql\Result as MysqliResult; +use PhpDb\Mysql\Statement as MysqliStatement; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; @@ -18,11 +22,11 @@ use function getenv; #[Group('integration')] -#[CoversMethod(Mysqli\Mysqli::class, 'quoteValue')] +#[CoversMethod(MysqliDriver::class, 'quoteValue')] #[CoversMethod(PdoDriver::class, 'quoteValue')] final class MysqlTest extends TestCase { - /** @var array */ + /** @var array */ public array $adapters = []; protected array $mysqliParams; @@ -32,7 +36,9 @@ final class MysqlTest extends TestCase #[Override] protected function setUp(): void { - //$this->markTestSkipped(self::class . ' test need refactored'); + if (getenv('TESTS_PHPDB_ADAPTER_MYSQL') !== 'true') { + self::markTestSkipped('Integration tests require TESTS_PHPDB_ADAPTER_MYSQL=true'); + } if (extension_loaded('mysqli')) { $this->mysqliParams = [ @@ -42,7 +48,7 @@ protected function setUp(): void 'database' => getenv('TESTS_PHPDB_ADAPTER_MYSQL_DATABASE'), ]; - $this->adapters['mysqli'] = new \mysqli( + $this->adapters['mysqli'] = new mysqli( $this->mysqliParams['hostname'], $this->mysqliParams['username'], $this->mysqliParams['password'], @@ -80,10 +86,10 @@ public function testQuoteValueWithMysqli() self::assertEquals('\'value\'', $value); $mysql = new Mysql( - new Mysqli\Mysqli( - new Mysqli\Connection($this->mysqliParams), - new Mysqli\Statement(), - new Mysqli\Result() + new MysqliDriver( + new MysqliConnection($this->mysqliParams), + new MysqliStatement(), + new MysqliResult() ) ); $value = $mysql->quoteValue('value'); diff --git a/test/unit/Driver/Mysqli/ConnectionTest.php b/test/unit/Driver/Mysqli/ConnectionTest.php index 5a30ee0..749df47 100644 --- a/test/unit/Driver/Mysqli/ConnectionTest.php +++ b/test/unit/Driver/Mysqli/ConnectionTest.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Mysql\Driver\Mysqli; +namespace PhpDbTest\Mysql\Driver\Mysqli; use mysqli; use Override; -use PhpDb\Adapter\Mysql\Driver\Mysqli\Connection; use PhpDb\Exception\RuntimeException; +use PhpDb\Mysql\Connection; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use PHPUnit\Framework\MockObject\MockObject; diff --git a/test/unit/Driver/Pdo/ConnectionTest.php b/test/unit/Driver/Pdo/ConnectionTest.php index 17d53bc..e298839 100644 --- a/test/unit/Driver/Pdo/ConnectionTest.php +++ b/test/unit/Driver/Pdo/ConnectionTest.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Mysql\Driver\Pdo; +namespace PhpDbTest\Mysql\Driver\Pdo; use Exception; use Override; use PhpDb\Adapter\Driver\PdoConnectionInterface; use PhpDb\Adapter\Exception\InvalidConnectionParametersException; use PhpDb\Adapter\Exception\RuntimeException; -use PhpDb\Adapter\Mysql\Driver\Pdo\Connection; +use PhpDb\Mysql\Pdo\Connection; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; diff --git a/test/unit/Driver/Pdo/ConnectionTransactionsTest.php b/test/unit/Driver/Pdo/ConnectionTransactionsTest.php index efc6f94..12c58ce 100644 --- a/test/unit/Driver/Pdo/ConnectionTransactionsTest.php +++ b/test/unit/Driver/Pdo/ConnectionTransactionsTest.php @@ -2,19 +2,19 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Mysql\Driver\Pdo; +namespace PhpDbTest\Mysql\Driver\Pdo; use Override; use PhpDb\Adapter\Driver\AbstractConnection; use PhpDb\Adapter\Exception\RuntimeException; -use PhpDb\Adapter\Mysql\Driver\Pdo\Connection; -use PhpDbTest\Adapter\Mysql\TestAsset\ConnectionWrapper; +use PhpDb\Mysql\Pdo\Connection; +use PhpDbTest\Mysql\TestAsset\ConnectionWrapper; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\TestCase; /** - * Tests for {@see \PhpDb\Adapter\Mysql\Driver\Pdo\Connection} transaction support + * Tests for {@see \PhpDb\Mysql\Pdo\Connection} transaction support */ #[CoversClass(Connection::class)] #[CoversClass(AbstractConnection::class)] diff --git a/test/unit/Driver/Pdo/PdoTest.php b/test/unit/Driver/Pdo/PdoTest.php index cb45b81..588d1b0 100644 --- a/test/unit/Driver/Pdo/PdoTest.php +++ b/test/unit/Driver/Pdo/PdoTest.php @@ -2,23 +2,23 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Mysql\Driver\Pdo; +namespace PhpDbTest\Mysql\Driver\Pdo; use Override; use PhpDb\Adapter\Driver\DriverInterface; use PhpDb\Adapter\Driver\Pdo\Result; use PhpDb\Adapter\Driver\Pdo\Statement; -use PhpDb\Adapter\Mysql\Driver\Pdo; use PhpDb\Exception\RuntimeException; +use PhpDb\Mysql\Pdo; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -#[CoversMethod(Pdo\Pdo::class, 'getDatabasePlatformName')] -#[CoversMethod(Pdo\Pdo::class, 'getResultPrototype')] +#[CoversMethod(Pdo\Driver::class, 'getDatabasePlatformName')] +#[CoversMethod(Pdo\Driver::class, 'getResultPrototype')] final class PdoTest extends TestCase { - protected Pdo\Pdo $pdo; + protected Pdo\Driver $pdo; /** * Sets up the fixture, for example, opens a network connection. @@ -30,7 +30,7 @@ protected function setUp(): void $connection = $this->createMock(Pdo\Connection::class); $statement = $this->createMock(Statement::class); $result = $this->createMock(Result::class); - $this->pdo = new Pdo\Pdo( + $this->pdo = new Pdo\Driver( $connection, $statement, $result diff --git a/test/unit/Driver/Pdo/ResultTest.php b/test/unit/Driver/Pdo/ResultTest.php index a29a4b8..b9bcd3a 100644 --- a/test/unit/Driver/Pdo/ResultTest.php +++ b/test/unit/Driver/Pdo/ResultTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Mysql\Driver\Pdo; +namespace PhpDbTest\Mysql\Driver\Pdo; use PDO; use PDOStatement; diff --git a/test/unit/Driver/Pdo/StatementIntegrationTest.php b/test/unit/Driver/Pdo/StatementIntegrationTest.php index b2f28aa..3c6a1e9 100644 --- a/test/unit/Driver/Pdo/StatementIntegrationTest.php +++ b/test/unit/Driver/Pdo/StatementIntegrationTest.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Mysql\Driver\Pdo; +namespace PhpDbTest\Mysql\Driver\Pdo; use Override; use PDO; use PDOStatement; use PhpDb\Adapter\Driver\Pdo\Statement; -use PhpDb\Adapter\Mysql\Driver\Pdo\Pdo as PdoDriver; -use PhpDbTest\Adapter\Mysql\Driver\Pdo\TestAsset; +use PhpDb\Mysql\Pdo\Driver as PdoDriver; +use PhpDbTest\Mysql\Driver\Pdo\TestAsset; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/test/unit/Driver/Pdo/StatementTest.php b/test/unit/Driver/Pdo/StatementTest.php index ae59589..6d56e34 100644 --- a/test/unit/Driver/Pdo/StatementTest.php +++ b/test/unit/Driver/Pdo/StatementTest.php @@ -2,16 +2,16 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Mysql\Driver\Pdo; +namespace PhpDbTest\Mysql\Driver\Pdo; use Override; use PDOStatement; use PhpDb\Adapter\Driver\Pdo\Result; use PhpDb\Adapter\Driver\Pdo\Statement; use PhpDb\Adapter\Driver\PdoDriverInterface; -use PhpDb\Adapter\Mysql\Driver\Pdo\Connection; -use PhpDb\Adapter\Mysql\Driver\Pdo\Pdo; use PhpDb\Adapter\ParameterContainer; +use PhpDb\Mysql\Pdo\Connection; +use PhpDb\Mysql\Pdo\Driver as PdoDriver; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\TestCase; @@ -26,7 +26,7 @@ #[CoversMethod(Statement::class, 'execute')] final class StatementTest extends TestCase { - protected ?Pdo $pdo; + protected ?PdoDriver $pdo; protected Statement $statement; /** @@ -37,7 +37,7 @@ final class StatementTest extends TestCase protected function setUp(): void { $this->statement = new Statement(); - $this->pdo = new Pdo( + $this->pdo = new PdoDriver( $this->createMock(Connection::class), $this->statement, $this->createMock(Result::class), diff --git a/test/unit/Driver/Pdo/TestAsset/CtorlessPdo.php b/test/unit/Driver/Pdo/TestAsset/CtorlessPdo.php index f0cc479..700cdef 100644 --- a/test/unit/Driver/Pdo/TestAsset/CtorlessPdo.php +++ b/test/unit/Driver/Pdo/TestAsset/CtorlessPdo.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Mysql\Driver\Pdo\TestAsset; +namespace PhpDbTest\Mysql\Driver\Pdo\TestAsset; use Override; use PDO; diff --git a/test/unit/Driver/TestAsset/PdoMock.php b/test/unit/Driver/TestAsset/PdoMock.php index 5bf2a82..91aa414 100644 --- a/test/unit/Driver/TestAsset/PdoMock.php +++ b/test/unit/Driver/TestAsset/PdoMock.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Mysql\Driver\TestAsset; +namespace PhpDbTest\Mysql\Driver\TestAsset; use PDO; diff --git a/test/unit/Platform/MysqlTest.php b/test/unit/Platform/MysqlTest.php index 2da029c..4833bd5 100644 --- a/test/unit/Platform/MysqlTest.php +++ b/test/unit/Platform/MysqlTest.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Mysql\Platform; +namespace PhpDbTest\Mysql\Platform; use Override; use PhpDb\Adapter\Driver\Pdo\Result; use PhpDb\Adapter\Driver\Pdo\Statement; -use PhpDb\Adapter\Mysql\Driver\Pdo; -use PhpDb\Adapter\Mysql\Platform\Mysql; +use PhpDb\Mysql\AdapterPlatform as Mysql; +use PhpDb\Mysql\Pdo; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\TestCase; @@ -33,7 +33,7 @@ final class MysqlTest extends TestCase #[Override] protected function setUp(): void { - $pdo = new Pdo\Pdo( + $pdo = new Pdo\Driver( $this->createMock(Pdo\Connection::class), $this->createMock(Statement::class), $this->createMock(Result::class), diff --git a/test/unit/TestAsset/ConnectionWrapper.php b/test/unit/TestAsset/ConnectionWrapper.php index 26fe813..6ef0d2a 100644 --- a/test/unit/TestAsset/ConnectionWrapper.php +++ b/test/unit/TestAsset/ConnectionWrapper.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Mysql\TestAsset; +namespace PhpDbTest\Mysql\TestAsset; -use PhpDb\Adapter\Mysql\Driver\Pdo\Connection; +use PhpDb\Mysql\Pdo\Connection; /** - * Test asset class used only by {@see \PhpDbTest\Adapter\Driver\Pdo\ConnectionTransactionsTest} + * Test asset class used only by {@see \PhpDbTest\Mysql\Driver\Pdo\ConnectionTransactionsTest} */ final class ConnectionWrapper extends Connection { diff --git a/test/unit/TestAsset/PdoStubDriver.php b/test/unit/TestAsset/PdoStubDriver.php index ce57aff..fa7afcf 100644 --- a/test/unit/TestAsset/PdoStubDriver.php +++ b/test/unit/TestAsset/PdoStubDriver.php @@ -1,6 +1,6 @@ Date: Wed, 25 Feb 2026 22:11:11 +1100 Subject: [PATCH 2/8] - Resolves skipped/incomplete tests - Added unit/integration tests for count() - Various minor code cleanups --- composer.lock | 76 ++++++++------ phpstan-baseline.neon | 78 --------------- test/integration/AdapterPlatformTest.php | 117 ++++++---------------- test/integration/Pdo/QueryTest.php | 23 ++++- test/integration/Pdo/TableGatewayTest.php | 2 - test/integration/TableGatewayTest.php | 3 - test/unit/ConnectionTest.php | 7 +- test/unit/Pdo/DriverTest.php | 19 ++++ test/unit/Pdo/ResultTest.php | 50 +++++++++ test/unit/Pdo/StatementTest.php | 40 ++++---- 10 files changed, 192 insertions(+), 223 deletions(-) diff --git a/composer.lock b/composer.lock index 2f2ad59..a0b6714 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f2dedce35c8d1cedeb14af8229afaf8d", + "content-hash": "9d2d01c20515ddf6f3b141bf12b661fc", "packages": [ { "name": "brick/varexporter", @@ -263,12 +263,12 @@ "source": { "type": "git", "url": "https://github.com/php-db/phpdb.git", - "reference": "003ff3440af8d2b51c6f190f1d256f5185b84819" + "reference": "cb328d33d1290df05568793d519d2bac23faa34f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-db/phpdb/zipball/003ff3440af8d2b51c6f190f1d256f5185b84819", - "reference": "003ff3440af8d2b51c6f190f1d256f5185b84819", + "url": "https://api.github.com/repos/php-db/phpdb/zipball/cb328d33d1290df05568793d519d2bac23faa34f", + "reference": "cb328d33d1290df05568793d519d2bac23faa34f", "shasum": "" }, "require": { @@ -324,7 +324,7 @@ "issues": "https://github.com/php-db/phpdb/issues", "source": "https://github.com/php-db/phpdb" }, - "time": "2026-01-25T20:41:58+00:00" + "time": "2026-02-25T10:50:24+00:00" }, { "name": "psr/container", @@ -757,11 +757,11 @@ }, { "name": "phpstan/phpstan", - "version": "2.1.37", + "version": "2.1.40", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/28cd424c5ea984128c95cfa7ea658808e8954e49", - "reference": "28cd424c5ea984128c95cfa7ea658808e8954e49", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/9b2c7aeb83a75d8680ea5e7c9b7fca88052b766b", + "reference": "9b2c7aeb83a75d8680ea5e7c9b7fca88052b766b", "shasum": "" }, "require": { @@ -806,20 +806,20 @@ "type": "github" } ], - "time": "2026-01-24T08:21:55+00:00" + "time": "2026-02-23T15:04:35+00:00" }, { "name": "phpstan/phpstan-phpunit", - "version": "2.0.12", + "version": "2.0.16", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "e4c5a22bf43d3d2bd5a780ad261a622ff62c49a4" + "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/e4c5a22bf43d3d2bd5a780ad261a622ff62c49a4", - "reference": "e4c5a22bf43d3d2bd5a780ad261a622ff62c49a4", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/6ab598e1bc106e6827fd346ae4a12b4a5d634c32", + "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32", "shasum": "" }, "require": { @@ -855,11 +855,14 @@ "MIT" ], "description": "PHPUnit extensions and rules for PHPStan", + "keywords": [ + "static analysis" + ], "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.12" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.16" }, - "time": "2026-01-22T13:40:00+00:00" + "time": "2026-02-14T09:05:21+00:00" }, { "name": "phpunit/php-code-coverage", @@ -953,28 +956,28 @@ }, { "name": "phpunit/php-file-iterator", - "version": "5.1.0", + "version": "5.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "118cfaaa8bc5aef3287bf315b6060b1174754af6" + "reference": "2f3a64888c814fc235386b7387dd5b5ed92ad903" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/118cfaaa8bc5aef3287bf315b6060b1174754af6", - "reference": "118cfaaa8bc5aef3287bf315b6060b1174754af6", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/2f3a64888c814fc235386b7387dd5b5ed92ad903", + "reference": "2f3a64888c814fc235386b7387dd5b5ed92ad903", "shasum": "" }, "require": { "php": ">=8.2" }, "require-dev": { - "phpunit/phpunit": "^11.0" + "phpunit/phpunit": "^11.3" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "5.0-dev" + "dev-main": "5.1-dev" } }, "autoload": { @@ -1002,15 +1005,27 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.1.0" + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.1.1" }, "funding": [ { "url": "https://github.com/sebastianbergmann", "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/php-file-iterator", + "type": "tidelift" } ], - "time": "2024-08-27T05:02:59+00:00" + "time": "2026-02-02T13:52:54+00:00" }, { "name": "phpunit/php-invoker", @@ -1198,16 +1213,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.5.49", + "version": "11.5.55", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "4f1750675ba411dd6c2d5fa8a3cca07f6742020e" + "reference": "adc7262fccc12de2b30f12a8aa0b33775d814f00" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4f1750675ba411dd6c2d5fa8a3cca07f6742020e", - "reference": "4f1750675ba411dd6c2d5fa8a3cca07f6742020e", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/adc7262fccc12de2b30f12a8aa0b33775d814f00", + "reference": "adc7262fccc12de2b30f12a8aa0b33775d814f00", "shasum": "" }, "require": { @@ -1222,7 +1237,7 @@ "phar-io/version": "^3.2.1", "php": ">=8.2", "phpunit/php-code-coverage": "^11.0.12", - "phpunit/php-file-iterator": "^5.1.0", + "phpunit/php-file-iterator": "^5.1.1", "phpunit/php-invoker": "^5.0.1", "phpunit/php-text-template": "^4.0.1", "phpunit/php-timer": "^7.0.1", @@ -1234,6 +1249,7 @@ "sebastian/exporter": "^6.3.2", "sebastian/global-state": "^7.0.2", "sebastian/object-enumerator": "^6.0.1", + "sebastian/recursion-context": "^6.0.3", "sebastian/type": "^5.1.3", "sebastian/version": "^5.0.2", "staabm/side-effects-detector": "^1.0.5" @@ -1279,7 +1295,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.49" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.55" }, "funding": [ { @@ -1303,7 +1319,7 @@ "type": "tidelift" } ], - "time": "2026-01-24T16:09:28+00:00" + "time": "2026-02-18T12:37:06+00:00" }, { "name": "sebastian/cli-parser", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5f70edc..4be4a26 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -30,24 +30,6 @@ parameters: count: 1 path: src/Connection.php - - - message: '#^PHPDoc tag @var for variable \$connectionInstance contains unknown class PhpDb\\Mysql\\Driver\\ConnectionInterface\.$#' - identifier: class.notFound - count: 1 - path: src/Container/DriverInterfaceFactory.php - - - - message: '#^PHPDoc tag @var for variable \$resultInstance contains unknown class PhpDb\\Mysql\\Driver\\ResultInterface\.$#' - identifier: class.notFound - count: 1 - path: src/Container/DriverInterfaceFactory.php - - - - message: '#^PHPDoc tag @var for variable \$statementInstance contains unknown class PhpDb\\Mysql\\Driver\\StatementInterface\.$#' - identifier: class.notFound - count: 1 - path: src/Container/DriverInterfaceFactory.php - - message: '#^Instanceof between PhpDb\\Mysql\\Connection and PhpDb\\Adapter\\Driver\\DriverAwareInterface will always evaluate to true\.$#' identifier: instanceof.alwaysTrue @@ -126,12 +108,6 @@ parameters: count: 3 path: src/Pdo/Driver.php - - - message: '#^Parameter \#3 \$rowCount of method PhpDb\\Adapter\\Driver\\Pdo\\Result\:\:initialize\(\) expects Closure\|int, null given\.$#' - identifier: argument.type - count: 1 - path: src/Pdo/Driver.php - - message: '#^Instanceof between mysqli_stmt and mysqli_stmt will always evaluate to true\.$#' identifier: instanceof.alwaysTrue @@ -192,42 +168,6 @@ parameters: count: 1 path: src/Statement.php - - - message: '#^Call to an undefined method PhpDb\\Mysql\\Driver\:\:quoteValue\(\)\.$#' - identifier: method.notFound - count: 2 - path: test/integration/AdapterPlatformTest.php - - - - message: '#^Parameter \#1 \$connection of class PhpDb\\Mysql\\Driver constructor expects PhpDb\\Mysql\\Connection, PDO given\.$#' - identifier: argument.type - count: 1 - path: test/integration/AdapterPlatformTest.php - - - - message: '#^Parameter \#1 \$connection of class PhpDb\\Mysql\\Driver constructor expects PhpDb\\Mysql\\Connection, mysqli given\.$#' - identifier: argument.type - count: 1 - path: test/integration/AdapterPlatformTest.php - - - - message: '#^Parameter \#2 \$statementPrototype of class PhpDb\\Mysql\\Driver constructor expects PhpDb\\Mysql\\Statement, PhpDb\\Adapter\\Driver\\Pdo\\Statement given\.$#' - identifier: argument.type - count: 1 - path: test/integration/AdapterPlatformTest.php - - - - message: '#^Property PhpDbIntegrationTest\\Mysql\\Platform\\AdapterPlatformTest\:\:\$adapters \(array\\) does not accept array\\.$#' - identifier: assign.propertyType - count: 1 - path: test/integration/AdapterPlatformTest.php - - - - message: '#^Property PhpDbIntegrationTest\\Mysql\\Platform\\AdapterPlatformTest\:\:\$adapters \(array\\) does not accept array\\.$#' - identifier: assign.propertyType - count: 1 - path: test/integration/AdapterPlatformTest.php - - message: '#^Parameter \#1 \$container of callable PhpDb\\Mysql\\Container\\DriverInterfaceFactory expects Laminas\\ServiceManager\\ServiceManager, Psr\\Container\\ContainerInterface given\.$#' identifier: argument.type @@ -246,21 +186,3 @@ parameters: count: 1 path: test/integration/Pdo/ConnectionTest.php - - - message: '#^Unreachable statement \- code above always terminates\.$#' - identifier: deadCode.unreachable - count: 1 - path: test/integration/Pdo/QueryTest.php - - - - message: '#^Unreachable statement \- code above always terminates\.$#' - identifier: deadCode.unreachable - count: 1 - path: test/integration/Pdo/TableGatewayTest.php - - - - message: '#^Unreachable statement \- code above always terminates\.$#' - identifier: deadCode.unreachable - count: 1 - path: test/integration/TableGatewayTest.php - diff --git a/test/integration/AdapterPlatformTest.php b/test/integration/AdapterPlatformTest.php index 8c28d22..757785f 100644 --- a/test/integration/AdapterPlatformTest.php +++ b/test/integration/AdapterPlatformTest.php @@ -4,114 +4,53 @@ namespace PhpDbIntegrationTest\Mysql\Platform; -use mysqli; -use Override; -use PhpDb\Adapter\Driver\Pdo; use PhpDb\Mysql\AdapterPlatform; -use PhpDb\Mysql\Connection; use PhpDb\Mysql\Driver; -use PhpDb\Mysql\Pdo\Connection as PdoConnection; use PhpDb\Mysql\Pdo\Driver as PdoDriver; -use PhpDb\Mysql\Result; -use PhpDb\Mysql\Statement; +use PhpDbIntegrationTest\Mysql\Container\TestAsset\SetupTrait; use PHPUnit\Framework\Attributes\CoversMethod; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -use function extension_loaded; -use function getenv; - #[Group('integration')] -#[CoversMethod(Driver::class, 'quoteValue')] -#[CoversMethod(PdoDriver::class, 'quoteValue')] +#[CoversMethod(AdapterPlatform::class, 'quoteValue')] final class AdapterPlatformTest extends TestCase { - /** @var array */ - public array $adapters = []; - - protected array $mysqliParams; + use SetupTrait; - protected array $pdoParams; - - #[Override] - protected function setUp(): void + /** @return array */ + public static function quoteValueProvider(): array { - //$this->markTestSkipped(self::class . ' test need refactored'); - - if (extension_loaded('mysqli')) { - $this->mysqliParams = [ - 'hostname' => getenv('TESTS_PHPDB_ADAPTER_MYSQL_HOSTNAME'), - 'username' => getenv('TESTS_PHPDB_ADAPTER_MYSQL_USERNAME'), - 'password' => getenv('TESTS_PHPDB_ADAPTER_MYSQL_PASSWORD'), - 'database' => getenv('TESTS_PHPDB_ADAPTER_MYSQL_DATABASE'), - ]; - - $this->adapters['mysqli'] = new Connection($this->mysqliParams); - } - - if (extension_loaded('pdo')) { - $this->pdoParams = [ - 'hostname' => getenv('TESTS_PHPDB_ADAPTER_MYSQL_HOSTNAME'), - 'username' => getenv('TESTS_PHPDB_ADAPTER_MYSQL_USERNAME'), - 'password' => getenv('TESTS_PHPDB_ADAPTER_MYSQL_PASSWORD'), - 'database' => getenv('TESTS_PHPDB_ADAPTER_MYSQL_DATABASE'), - ]; - - $this->adapters['pdo_mysql'] = new PdoConnection($this->pdoParams); - } + return [ + 'plain string' => ['value', '\'value\''], + 'single quote' => ["it's", "'it\\'s'"], + 'backslash' => ['val\\ue', "'val\\\\ue'"], + 'empty string' => ['', "''"], + 'double quote' => ['say "hello"', "'say \\\"hello\\\"'"], + 'null byte' => ["val\x00ue", "'val\\0ue'"], + ]; } - /** - * @return void - */ - public function testQuoteValueWithMysqli() + #[DataProvider('quoteValueProvider')] + public function testQuoteValueWithMysqli(string $input, string $expected): void { - if (! $this->adapters['mysqli'] instanceof Mysqli) { - $this->markTestSkipped('MySQL (Mysqli) not configured in unit test configuration file'); - } - $mysql = new Driver( - $this->adapters['mysqli'], - new Statement(), - new Result() - ); - $value = $mysql->quoteValue('value'); - self::assertEquals('\'value\'', $value); + $this->driver = Driver::class; + $adapter = $this->getAdapter(); - $mysql = new AdapterPlatform( - new Driver( - new Connection($this->mysqliParams), - new Statement(), - new Result() - ) - ); - $value = $mysql->quoteValue('value'); - self::assertEquals('\'value\'', $value); + $platform = new AdapterPlatform($adapter->getDriver()); + $value = $platform->quoteValue($input); + self::assertSame($expected, $value); } - /** - * @return void - */ - public function testQuoteValueWithPdoMysql() + #[DataProvider('quoteValueProvider')] + public function testQuoteValueWithPdoMysql(string $input, string $expected): void { - if (! $this->adapters['pdo_mysql'] instanceof \PDO) { - $this->markTestSkipped('MySQL (PDO_Mysql) not configured in unit test configuration file'); - } - $mysql = new Driver( - $this->adapters['pdo_mysql'], - new Pdo\Statement(), - new Pdo\Result() - ); - $value = $mysql->quoteValue('value'); - self::assertEquals('\'value\'', $value); + $this->driver = PdoDriver::class; + $adapter = $this->getAdapter(); - $mysql = new AdapterPlatform( - new PdoDriver( - new PdoConnection($this->pdoParams), - new Pdo\Statement(), - new Pdo\Result() - ) - ); - $value = $mysql->quoteValue('value'); - self::assertEquals('\'value\'', $value); + $platform = new AdapterPlatform($adapter->getDriver()); + $value = $platform->quoteValue($input); + self::assertSame($expected, $value); } } diff --git a/test/integration/Pdo/QueryTest.php b/test/integration/Pdo/QueryTest.php index 3894988..4d8b5e0 100644 --- a/test/integration/Pdo/QueryTest.php +++ b/test/integration/Pdo/QueryTest.php @@ -80,12 +80,31 @@ public function testSetSessionTimeZone(): void */ public function testSelectWithNotPermittedBindParamName(): void { - $this->markTestIncomplete('Incorrect bound param name characters are not caught in a raw query.'); - $this->expectException(RuntimeException::class); $this->getAdapter()->query('SET @@session.time_zone = :tz$', [':tz$' => 'SYSTEM']); } + public function testSelectResultCountReturnsActualRowCount(): void + { + $result = $this->getAdapter()->query('SELECT * FROM test WHERE value = ?', ['bar']); + $this->assertInstanceOf(ResultSet::class, $result); + self::assertSame(3, $result->count()); + } + + public function testSelectResultCountWithWhereClause(): void + { + $result = $this->getAdapter()->query('SELECT * FROM test WHERE name = ?', ['foo']); + $this->assertInstanceOf(ResultSet::class, $result); + self::assertSame(1, $result->count()); + } + + public function testSelectResultCountReturnsZeroForNoResults(): void + { + $result = $this->getAdapter()->query('SELECT * FROM test WHERE name = ?', ['nonexistent']); + $this->assertInstanceOf(ResultSet::class, $result); + self::assertSame(0, $result->count()); + } + /** * @see https://github.com/laminas/laminas-db/issues/47 */ diff --git a/test/integration/Pdo/TableGatewayTest.php b/test/integration/Pdo/TableGatewayTest.php index 875bd7a..e564a30 100644 --- a/test/integration/Pdo/TableGatewayTest.php +++ b/test/integration/Pdo/TableGatewayTest.php @@ -39,8 +39,6 @@ public function testConstructor(): void public function testSelect(): void { - $this->markTestIncomplete('Unsure how resultset would ever have count without buffered results.'); - $tableGateway = new TableGateway('test', $this->getAdapter(['db' => ['driver' => Driver::class]])); /** @var ResultSet $rowset */ $rowset = $tableGateway->select(); diff --git a/test/integration/TableGatewayTest.php b/test/integration/TableGatewayTest.php index 2083fda..7573fb6 100644 --- a/test/integration/TableGatewayTest.php +++ b/test/integration/TableGatewayTest.php @@ -25,8 +25,6 @@ final class TableGatewayTest extends TestCase */ public function testSelectWithEmptyCurrentWithBufferResult(): void { - $this->markTestSkipped('Unsure as to how rowset could ever be buffered with empty result'); - /** @var AdapterInterface&Adapter $adapter */ $adapter = $this->getAdapter([ 'db' => [ @@ -40,7 +38,6 @@ public function testSelectWithEmptyCurrentWithBufferResult(): void $tableGateway = new TableGateway('test', $adapter); /** @var AbstractResultSet $rowset */ $rowset = $tableGateway->select('id = 0'); - $this->assertEquals(true, $rowset->isBuffered()); $this->assertNull($rowset->current()); diff --git a/test/unit/ConnectionTest.php b/test/unit/ConnectionTest.php index 8648437..d1f7e2a 100644 --- a/test/unit/ConnectionTest.php +++ b/test/unit/ConnectionTest.php @@ -8,6 +8,9 @@ use Override; use PhpDb\Exception\RuntimeException; use PhpDb\Mysql\Connection; +use PhpDb\Mysql\Driver; +use PhpDb\Mysql\Result; +use PhpDb\Mysql\Statement; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use PHPUnit\Framework\MockObject\MockObject; @@ -47,8 +50,8 @@ protected function tearDown(): void public function testSetDriver(): void { - $this->markTestIncomplete('This test needs refactored'); - //self::assertEquals($this->connection, $this->connection->setDriver(new Mysqli([]))); + $driver = new Driver($this->connection, new Statement(), new Result()); + self::assertSame($this->connection, $this->connection->setDriver($driver)); } public function testSetConnectionParameters(): void diff --git a/test/unit/Pdo/DriverTest.php b/test/unit/Pdo/DriverTest.php index 0096646..934f4de 100644 --- a/test/unit/Pdo/DriverTest.php +++ b/test/unit/Pdo/DriverTest.php @@ -5,6 +5,7 @@ namespace PhpDbTest\Mysql\Pdo; use Override; +use PDOStatement; use PhpDb\Adapter\Driver\DriverInterface; use PhpDb\Adapter\Driver\Pdo\Result; use PhpDb\Adapter\Driver\Pdo\Statement; @@ -17,6 +18,7 @@ #[CoversMethod(Driver::class, 'getDatabasePlatformName')] #[CoversMethod(Driver::class, 'getResultPrototype')] +#[CoversMethod(Driver::class, 'createResult')] final class DriverTest extends TestCase { protected Driver $pdo; @@ -95,4 +97,21 @@ public function testGetResultPrototype(): void self::assertInstanceOf(Result::class, $resultPrototype); } + + public function testCreateResultPassesNullRowCount(): void + { + $pdoStatement = $this->getMockBuilder(PDOStatement::class)->getMock(); + $pdoStatement->expects($this->once()) + ->method('rowCount') + ->willReturn(4); + + $connection = $this->createMock(Connection::class); + $statement = $this->createMock(Statement::class); + $driver = new Driver($connection, $statement, new Result()); + + $result = $driver->createResult($pdoStatement); + + self::assertInstanceOf(Result::class, $result); + self::assertSame(4, $result->count()); + } } diff --git a/test/unit/Pdo/ResultTest.php b/test/unit/Pdo/ResultTest.php index 2e67947..a2778e1 100644 --- a/test/unit/Pdo/ResultTest.php +++ b/test/unit/Pdo/ResultTest.php @@ -17,6 +17,7 @@ use function uniqid; #[CoversMethod(Result::class, 'current')] +#[CoversMethod(Result::class, 'count')] #[Group('result-pdo')] final class ResultTest extends TestCase { @@ -78,6 +79,55 @@ public function testFetchModeRange(): void self::assertInstanceOf('stdClass', $result->current()); } + public function testCountWithNullRowCountDelegatesToPdoStatement(): void + { + $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); + $stub->expects($this->once()) + ->method('rowCount') + ->willReturn(4); + + $result = new Result(); + $result->initialize($stub, null, null); + + self::assertSame(4, $result->count()); + } + + public function testCountWithZeroRowCountReturnsZeroWithoutQueryingPdo(): void + { + $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); + $stub->expects($this->never()) + ->method('rowCount'); + + $result = new Result(); + $result->initialize($stub, null, 0); + + self::assertSame(0, $result->count()); + } + + public function testCountWithIntRowCountReturnsValueWithoutQueryingPdo(): void + { + $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); + $stub->expects($this->never()) + ->method('rowCount'); + + $result = new Result(); + $result->initialize($stub, null, 7); + + self::assertSame(7, $result->count()); + } + + public function testCountWithClosureRowCountInvokesClosure(): void + { + $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); + $stub->expects($this->never()) + ->method('rowCount'); + + $result = new Result(); + $result->initialize($stub, null, fn() => 3); + + self::assertSame(3, $result->count()); + } + public function testMultipleRewind(): void { $data = [ diff --git a/test/unit/Pdo/StatementTest.php b/test/unit/Pdo/StatementTest.php index 1ff8be7..7c6ceb3 100644 --- a/test/unit/Pdo/StatementTest.php +++ b/test/unit/Pdo/StatementTest.php @@ -9,6 +9,7 @@ use PhpDb\Adapter\Driver\Pdo\Result; use PhpDb\Adapter\Driver\Pdo\Statement; use PhpDb\Adapter\Driver\PdoDriverInterface; +use PhpDb\Adapter\Driver\ResultInterface; use PhpDb\Adapter\ParameterContainer; use PhpDb\Mysql\Pdo\Connection; use PhpDb\Mysql\Pdo\Driver; @@ -40,7 +41,7 @@ protected function setUp(): void $this->pdo = new Driver( $this->createMock(Connection::class), $this->statement, - $this->createMock(Result::class), + new Result(), ); } @@ -93,31 +94,36 @@ public function testGetSql(): void self::assertEquals('SELECT 1', $this->statement->getSql()); } - /** - * @todo Implement testPrepare(). - */ public function testPrepare(): void { - $this->markTestSkipped('Needs to be covered by integration group'); - // $this->statement->initialize(new TestAsset\SqliteMemoryPdo()); - // self::assertNull($this->statement->prepare('SELECT 1')); + $mockPdoStatement = $this->createMock(PDOStatement::class); + $pdo = new TestAsset\CtorlessPdo($mockPdoStatement); + $this->statement->initialize($pdo); + + $result = $this->statement->prepare('SELECT 1'); + self::assertInstanceOf(Statement::class, $result); } public function testIsPrepared(): void { - $this->markTestSkipped('Needs to be covered by integration group'); - // self::assertFalse($this->statement->isPrepared()); - // $this->statement->initialize(new TestAsset\SqliteMemoryPdo()); - // $this->statement->prepare('SELECT 1'); - // self::assertTrue($this->statement->isPrepared()); + self::assertFalse($this->statement->isPrepared()); + + $mockPdoStatement = $this->createMock(PDOStatement::class); + $pdo = new TestAsset\CtorlessPdo($mockPdoStatement); + $this->statement->initialize($pdo); + $this->statement->prepare('SELECT 1'); + + self::assertTrue($this->statement->isPrepared()); } public function testExecute(): void { - $this->markTestSkipped('Needs to be covered by integration group'); - // $this->statement->setDriver(new Pdo(new Connection($pdo = new TestAsset\SqliteMemoryPdo()))); - // $this->statement->initialize($pdo); - // $this->statement->prepare('SELECT 1'); - // self::assertInstanceOf(Result::class, $this->statement->execute()); + $mockPdoStatement = $this->createMock(PDOStatement::class); + $pdo = new TestAsset\CtorlessPdo($mockPdoStatement); + $this->statement->initialize($pdo); + $this->statement->prepare('SELECT 1'); + + $result = $this->statement->execute(); + self::assertInstanceOf(ResultInterface::class, $result); } } From b0cf3bcc8a3df2236c6a8a74479e4c64029e360c Mon Sep 17 00:00:00 2001 From: Simon Mundy Date: Wed, 25 Feb 2026 22:32:14 +1100 Subject: [PATCH 3/8] - Adds phpunit.xml overrides for Integration testing --- .laminas-ci/phpunit.xml | 37 +++++++++++++++++++++++++++++++++++++ .laminas-ci/pre-run.sh | 2 ++ 2 files changed, 39 insertions(+) create mode 100644 .laminas-ci/phpunit.xml create mode 100644 .laminas-ci/pre-run.sh diff --git a/.laminas-ci/phpunit.xml b/.laminas-ci/phpunit.xml new file mode 100644 index 0000000..a2f9255 --- /dev/null +++ b/.laminas-ci/phpunit.xml @@ -0,0 +1,37 @@ + + + + + + + + + test/unit + + + test/integration + + + + + src + + + + + + + + + + + diff --git a/.laminas-ci/pre-run.sh b/.laminas-ci/pre-run.sh new file mode 100644 index 0000000..872dd05 --- /dev/null +++ b/.laminas-ci/pre-run.sh @@ -0,0 +1,2 @@ +#!/bin/bash +cp .laminas-ci/phpunit.xml phpunit.xml From f51237559ad9c2ed30ababa858e7932c0f2cc5f3 Mon Sep 17 00:00:00 2001 From: Simon Mundy Date: Wed, 25 Feb 2026 22:44:02 +1100 Subject: [PATCH 4/8] - Adds phpunit.xml overrides for Integration testing --- .laminas-ci/pre-run.sh | 8 ++++++++ 1 file changed, 8 insertions(+) mode change 100644 => 100755 .laminas-ci/pre-run.sh diff --git a/.laminas-ci/pre-run.sh b/.laminas-ci/pre-run.sh old mode 100644 new mode 100755 index 872dd05..e4ceca1 --- a/.laminas-ci/pre-run.sh +++ b/.laminas-ci/pre-run.sh @@ -1,2 +1,10 @@ #!/bin/bash +set -e + +JOB=$3 +COMMAND=$(echo "${JOB}" | jq -r '.command') +if [[ ! ${COMMAND} =~ phpunit ]]; then + exit 0 +fi + cp .laminas-ci/phpunit.xml phpunit.xml From 059bfb8005bd20ecce4eb5ec40dc2377d57ee2fa Mon Sep 17 00:00:00 2001 From: Simon Mundy <46739456+simon-mundy@users.noreply.github.com> Date: Thu, 26 Feb 2026 09:43:09 +1100 Subject: [PATCH 5/8] Update ResultTest.php Changed 'stub' to 'mock' Signed-off-by: Simon Mundy <46739456+simon-mundy@users.noreply.github.com> --- test/unit/Pdo/ResultTest.php | 50 ++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/test/unit/Pdo/ResultTest.php b/test/unit/Pdo/ResultTest.php index a2778e1..34b2685 100644 --- a/test/unit/Pdo/ResultTest.php +++ b/test/unit/Pdo/ResultTest.php @@ -26,13 +26,13 @@ final class ResultTest extends TestCase */ public function testCurrent(): void { - $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); - $stub->expects($this->any()) + $mock = $this->getMockBuilder(PDOStatement::class)->getMock(); + $mock->expects($this->any()) ->method('fetch') ->willReturnCallback(fn() => uniqid()); $result = new Result(); - $result->initialize($stub, null); + $result->initialize($mock, null); self::assertEquals($result->current(), $result->current()); } @@ -50,13 +50,13 @@ public function testFetchModeException(): void */ public function testFetchModeAnonymousObject(): void { - $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); - $stub->expects($this->any()) + $mock = $this->getMockBuilder(PDOStatement::class)->getMock(); + $mock->expects($this->any()) ->method('fetch') ->willReturnCallback(fn() => new stdClass()); $result = new Result(); - $result->initialize($stub, null); + $result->initialize($mock, null); $result->setFetchMode(PDO::FETCH_OBJ); self::assertEquals(5, $result->getFetchMode()); @@ -68,12 +68,12 @@ public function testFetchModeAnonymousObject(): void */ public function testFetchModeRange(): void { - $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); - $stub->expects($this->any()) + $mock = $this->getMockBuilder(PDOStatement::class)->getMock(); + $mock->expects($this->any()) ->method('fetch') ->willReturnCallback(fn() => new stdClass()); $result = new Result(); - $result->initialize($stub, null); + $result->initialize($mock, null); $result->setFetchMode(PDO::FETCH_NAMED); self::assertEquals(11, $result->getFetchMode()); self::assertInstanceOf('stdClass', $result->current()); @@ -81,49 +81,49 @@ public function testFetchModeRange(): void public function testCountWithNullRowCountDelegatesToPdoStatement(): void { - $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); - $stub->expects($this->once()) + $mock = $this->getMockBuilder(PDOStatement::class)->getMock(); + $mock->expects($this->once()) ->method('rowCount') ->willReturn(4); $result = new Result(); - $result->initialize($stub, null, null); + $result->initialize($mock, null, null); self::assertSame(4, $result->count()); } public function testCountWithZeroRowCountReturnsZeroWithoutQueryingPdo(): void { - $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); - $stub->expects($this->never()) + $mock = $this->getMockBuilder(PDOStatement::class)->getMock(); + $mock->expects($this->never()) ->method('rowCount'); $result = new Result(); - $result->initialize($stub, null, 0); + $result->initialize($mock, null, 0); self::assertSame(0, $result->count()); } public function testCountWithIntRowCountReturnsValueWithoutQueryingPdo(): void { - $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); - $stub->expects($this->never()) + $mock = $this->getMockBuilder(PDOStatement::class)->getMock(); + $mock->expects($this->never()) ->method('rowCount'); $result = new Result(); - $result->initialize($stub, null, 7); + $result->initialize($mock, null, 7); self::assertSame(7, $result->count()); } public function testCountWithClosureRowCountInvokesClosure(): void { - $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); - $stub->expects($this->never()) + $mock = $this->getMockBuilder(PDOStatement::class)->getMock(); + $mock->expects($this->never()) ->method('rowCount'); $result = new Result(); - $result->initialize($stub, null, fn() => 3); + $result->initialize($mock, null, fn() => 3); self::assertSame(3, $result->count()); } @@ -136,15 +136,15 @@ public function testMultipleRewind(): void ]; $position = 0; - $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); - assert($stub instanceof PDOStatement); // to suppress IDE type warnings - $stub->expects($this->any()) + $mock = $this->getMockBuilder(PDOStatement::class)->getMock(); + assert($mock instanceof PDOStatement); // to suppress IDE type warnings + $mock->expects($this->any()) ->method('fetch') ->willReturnCallback(function () use ($data, &$position) { return $data[$position++]; }); $result = new Result(); - $result->initialize($stub, null); + $result->initialize($mock, null); $result->rewind(); $result->rewind(); From 408a236614f49e375738be3a6688eaafa62ad449 Mon Sep 17 00:00:00 2001 From: Simon Mundy <46739456+simon-mundy@users.noreply.github.com> Date: Thu, 26 Feb 2026 09:45:57 +1100 Subject: [PATCH 6/8] Delete .laminas-ci/pre-run.sh Signed-off-by: Simon Mundy <46739456+simon-mundy@users.noreply.github.com> --- .laminas-ci/pre-run.sh | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100755 .laminas-ci/pre-run.sh diff --git a/.laminas-ci/pre-run.sh b/.laminas-ci/pre-run.sh deleted file mode 100755 index e4ceca1..0000000 --- a/.laminas-ci/pre-run.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -JOB=$3 -COMMAND=$(echo "${JOB}" | jq -r '.command') -if [[ ! ${COMMAND} =~ phpunit ]]; then - exit 0 -fi - -cp .laminas-ci/phpunit.xml phpunit.xml From 6d701ecf6bacf6babce9811d7f97009e1ce3afae Mon Sep 17 00:00:00 2001 From: Simon Mundy <46739456+simon-mundy@users.noreply.github.com> Date: Thu, 26 Feb 2026 09:46:32 +1100 Subject: [PATCH 7/8] Delete .laminas-ci directory Signed-off-by: Simon Mundy <46739456+simon-mundy@users.noreply.github.com> --- .laminas-ci/phpunit.xml | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 .laminas-ci/phpunit.xml diff --git a/.laminas-ci/phpunit.xml b/.laminas-ci/phpunit.xml deleted file mode 100644 index a2f9255..0000000 --- a/.laminas-ci/phpunit.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - test/unit - - - test/integration - - - - - src - - - - - - - - - - - From 8ff2157e8211cf70bdd8072803928b625ff80bca Mon Sep 17 00:00:00 2001 From: Simon Mundy <46739456+simon-mundy@users.noreply.github.com> Date: Thu, 26 Feb 2026 09:46:56 +1100 Subject: [PATCH 8/8] Update phpunit.xml.dist Signed-off-by: Simon Mundy <46739456+simon-mundy@users.noreply.github.com> --- phpunit.xml.dist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 179647f..a2f9255 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -27,11 +27,11 @@ - + - \ No newline at end of file +