From 37d71e1d4e22f84983a3294e7fda746ea4b3c270 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Thu, 8 Jan 2026 02:27:40 -0600 Subject: [PATCH 1/2] Latest Revisions Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- composer.json | 9 +- composer.lock | 80 +++++----- phpstan-baseline.neon | 95 ------------ .../Sqlite.php => AdapterPlatform.php} | 13 +- src/ConfigProvider.php | 70 ++++----- ...actory.php => AdapterInterfaceFactory.php} | 2 +- .../ConnectionInterfaceFactoryFactory.php | 43 ------ .../DriverInterfaceFactoryFactory.php | 33 ----- src/Container/MetadataInterfaceFactory.php | 7 +- src/Container/PdoDriverFactory.php | 2 +- src/Container/PlatformInterfaceFactory.php | 10 +- .../PlatformInterfaceFactoryFactory.php | 16 -- .../DatabasePlatformNameTrait.php | 2 +- .../{Source/SqliteMetadata.php => Source.php} | 11 +- src/{Driver => }/Pdo/Connection.php | 2 +- src/{Driver/Pdo/Pdo.php => Pdo/Driver.php} | 6 +- .../Pdo/Feature/SqliteRowCounter.php | 2 +- .../Ddl/AlterTableDecorator.php | 6 +- .../Ddl/CreateTableDecorator.php | 6 +- src/Sql/{Platform/Sqlite.php => Platform.php} | 4 +- src/Sql/{Platform => }/SelectDecorator.php | 6 +- ...SqliteTest.php => AdapterPlatformTest.php} | 10 +- ...st.php => AdapterInterfaceFactoryTest.php} | 10 +- .../Container/PdoConnectionFactoryTest.php | 2 +- .../Container/PdoDriverFactoryTest.php | 4 +- .../PlatformInterfaceFactoryTest.php | 4 +- .../Container/SqliteMetadataFactoryTest.php | 4 +- .../Container/TestAsset/SetupTrait.php | 6 +- .../Pdo/AbstractAdapterTestCase.php | 2 +- .../Pdo/ConnectionIntegrationTest.php | 4 +- .../{Driver => }/Pdo/StatementTest.php | 2 +- ...apterTest.php => AdapterInterfaceTest.php} | 8 +- ...SqliteTest.php => AdapterPlatformTest.php} | 51 ++++--- test/unit/ConfigProviderTest.php | 83 +++-------- .../ConnectionInterfaceFactoryFactoryTest.php | 130 ----------------- .../DriverInterfaceFactoryFactoryTest.php | 137 ------------------ .../MetadataInterfaceFactoryTest.php | 4 +- .../Container/PdoConnectionFactoryTest.php | 2 +- .../PlatformInterfaceFactoryFactoryTest.php | 30 ---- .../PlatformInterfaceFactoryTest.php | 4 +- .../DatabasePlatformNameTraitTest.php | 4 +- test/unit/{Driver => }/Pdo/ConnectionTest.php | 4 +- .../Pdo/PdoTest.php => Pdo/DriverTest.php} | 14 +- .../Pdo/Feature/SqliteRowCounterTest.php | 4 +- .../Pdo/StatementIntegrationTest.php | 13 +- .../Pdo/TestAsset/CtorlessPdo.php | 0 .../Ddl/AlterTableDecoratorTest.php | 4 +- .../Ddl/CreateTableDecoratorTest.php | 4 +- .../SqliteTest.php => PlatformTest.php} | 20 +-- .../{Platform => }/SelectDecoratorTest.php | 2 +- 50 files changed, 236 insertions(+), 755 deletions(-) rename src/{Platform/Sqlite.php => AdapterPlatform.php} (85%) rename src/Container/{AdapterFactory.php => AdapterInterfaceFactory.php} (98%) delete mode 100644 src/Container/ConnectionInterfaceFactoryFactory.php delete mode 100644 src/Container/DriverInterfaceFactoryFactory.php delete mode 100644 src/Container/PlatformInterfaceFactoryFactory.php rename src/{Driver => }/DatabasePlatformNameTrait.php (95%) rename src/Metadata/{Source/SqliteMetadata.php => Source.php} (98%) rename src/{Driver => }/Pdo/Connection.php (98%) rename src/{Driver/Pdo/Pdo.php => Pdo/Driver.php} (86%) rename src/{Driver => }/Pdo/Feature/SqliteRowCounter.php (96%) rename src/Sql/{Platform => }/Ddl/AlterTableDecorator.php (97%) rename src/Sql/{Platform => }/Ddl/CreateTableDecorator.php (96%) rename src/Sql/{Platform/Sqlite.php => Platform.php} (83%) rename src/Sql/{Platform => }/SelectDecorator.php (92%) rename test/integration/{Platform/SqliteTest.php => AdapterPlatformTest.php} (71%) rename test/integration/Container/{AdapterFactoryTest.php => AdapterInterfaceFactoryTest.php} (63%) rename test/integration/{Driver => }/Pdo/AbstractAdapterTestCase.php (97%) rename test/integration/{Driver => }/Pdo/ConnectionIntegrationTest.php (97%) rename test/integration/{Driver => }/Pdo/StatementTest.php (98%) rename test/unit/{AdapterTest.php => AdapterInterfaceTest.php} (95%) rename test/unit/{Platform/SqliteTest.php => AdapterPlatformTest.php} (81%) delete mode 100644 test/unit/Container/ConnectionInterfaceFactoryFactoryTest.php delete mode 100644 test/unit/Container/DriverInterfaceFactoryFactoryTest.php delete mode 100644 test/unit/Container/PlatformInterfaceFactoryFactoryTest.php rename test/unit/{Driver => }/DatabasePlatformNameTraitTest.php (93%) rename test/unit/{Driver => }/Pdo/ConnectionTest.php (95%) rename test/unit/{Driver/Pdo/PdoTest.php => Pdo/DriverTest.php} (91%) rename test/unit/{Driver => }/Pdo/Feature/SqliteRowCounterTest.php (80%) rename test/unit/{Driver => }/Pdo/StatementIntegrationTest.php (90%) rename test/unit/{Driver => }/Pdo/TestAsset/CtorlessPdo.php (100%) rename test/unit/Sql/{Platform => }/Ddl/AlterTableDecoratorTest.php (98%) rename test/unit/Sql/{Platform => }/Ddl/CreateTableDecoratorTest.php (98%) rename test/unit/Sql/{Platform/SqliteTest.php => PlatformTest.php} (77%) rename test/unit/Sql/{Platform => }/SelectDecoratorTest.php (98%) diff --git a/composer.json b/composer.json index 8f6da85..e38575d 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "require": { "php": "~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0", - "php-db/phpdb": "^0.3.2", + "php-db/phpdb": "^0.6.0", "webmozart/assert": "^1.11" }, "require-dev": { @@ -59,7 +59,7 @@ "scripts": { "check": [ "@cs-check", - "@static-analysis", + "@sa", "@test", "@test-integration" ], @@ -68,8 +68,9 @@ "test": "phpunit --colors=always --testsuite \"unit test\"", "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", "test-integration": "phpunit --colors=always --testsuite \"integration test\"", - "static-analysis": "vendor/bin/phpstan analyse --memory-limit=256M", - "sa-generate-baseline": "vendor/bin/phpstan analyse --memory-limit=256M --generate-baseline", + "sa": "vendor/bin/phpstan analyse --memory-limit=256M", + "sa-gen-baseline": "vendor/bin/phpstan analyse --memory-limit=256M --generate-baseline", + "sa-verbose": "vendor/bin/phpstan analyse --memory-limit=256M -vv", "upload-coverage": "coveralls -v" } } diff --git a/composer.lock b/composer.lock index 454c489..6a476f9 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": "6471240f40c4970665b0372355c8197c", + "content-hash": "96e772d1f4c952e2b2398b32f186574d", "packages": [ { "name": "brick/varexporter", @@ -201,16 +201,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.6.2", + "version": "v5.7.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "3a454ca033b9e06b63282ce19562e892747449bb" + "reference": "dca41cd15c2ac9d055ad70dbfd011130757d1f82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/3a454ca033b9e06b63282ce19562e892747449bb", - "reference": "3a454ca033b9e06b63282ce19562e892747449bb", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/dca41cd15c2ac9d055ad70dbfd011130757d1f82", + "reference": "dca41cd15c2ac9d055ad70dbfd011130757d1f82", "shasum": "" }, "require": { @@ -253,22 +253,22 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.6.2" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.7.0" }, - "time": "2025-10-21T19:32:17+00:00" + "time": "2025-12-06T11:56:16+00:00" }, { "name": "php-db/phpdb", - "version": "0.3.2", + "version": "0.6.x-dev", "source": { "type": "git", "url": "https://github.com/php-db/phpdb.git", - "reference": "b3df2ff1f3d776f42f8d926b23535e4143a93996" + "reference": "358211307cf82dbc107d6f2759276c737b741117" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-db/phpdb/zipball/b3df2ff1f3d776f42f8d926b23535e4143a93996", - "reference": "b3df2ff1f3d776f42f8d926b23535e4143a93996", + "url": "https://api.github.com/repos/php-db/phpdb/zipball/358211307cf82dbc107d6f2759276c737b741117", + "reference": "358211307cf82dbc107d6f2759276c737b741117", "shasum": "" }, "require": { @@ -284,15 +284,17 @@ "laminas/laminas-coding-standard": "^3.0.1", "laminas/laminas-eventmanager": "^3.14.0", "laminas/laminas-hydrator": "^4.6.0", + "phpbench/phpbench": "^1.4", "phpstan/phpstan": "^2.1", "phpstan/phpstan-phpunit": "^2.0", - "phpunit/phpunit": "^11.5.15", + "phpunit/phpunit": "^11.5.42", "rector/rector": "^2.0" }, "suggest": { "laminas/laminas-eventmanager": "Laminas\\EventManager component", "laminas/laminas-hydrator": "(^5.0.0) Laminas\\Hydrator component for using HydratingResultSets" }, + "default-branch": true, "type": "library", "extra": { "laminas": { @@ -322,7 +324,7 @@ "issues": "https://github.com/php-db/phpdb/issues", "source": "https://github.com/php-db/phpdb" }, - "time": "2025-12-01T04:51:41+00:00" + "time": "2026-01-06T06:52:43+00:00" }, { "name": "psr/container", @@ -813,11 +815,11 @@ }, { "name": "phpstan/phpstan", - "version": "2.1.32", + "version": "2.1.33", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e126cad1e30a99b137b8ed75a85a676450ebb227", - "reference": "e126cad1e30a99b137b8ed75a85a676450ebb227", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/9e800e6bee7d5bd02784d4c6069b48032d16224f", + "reference": "9e800e6bee7d5bd02784d4c6069b48032d16224f", "shasum": "" }, "require": { @@ -862,20 +864,20 @@ "type": "github" } ], - "time": "2025-11-11T15:18:17+00:00" + "time": "2025-12-05T10:24:31+00:00" }, { "name": "phpstan/phpstan-phpunit", - "version": "2.0.8", + "version": "2.0.11", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "2fe9fbeceaf76dd1ebaa7bbbb25e2fb5e59db2fe" + "reference": "5e30669bef866eff70db8b58d72a5c185aa82414" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/2fe9fbeceaf76dd1ebaa7bbbb25e2fb5e59db2fe", - "reference": "2fe9fbeceaf76dd1ebaa7bbbb25e2fb5e59db2fe", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/5e30669bef866eff70db8b58d72a5c185aa82414", + "reference": "5e30669bef866eff70db8b58d72a5c185aa82414", "shasum": "" }, "require": { @@ -913,41 +915,41 @@ "description": "PHPUnit extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.8" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.11" }, - "time": "2025-11-11T07:55:22+00:00" + "time": "2025-12-19T09:05:35+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "11.0.11", + "version": "11.0.12", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "4f7722aa9a7b76aa775e2d9d4e95d1ea16eeeef4" + "reference": "2c1ed04922802c15e1de5d7447b4856de949cf56" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/4f7722aa9a7b76aa775e2d9d4e95d1ea16eeeef4", - "reference": "4f7722aa9a7b76aa775e2d9d4e95d1ea16eeeef4", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2c1ed04922802c15e1de5d7447b4856de949cf56", + "reference": "2c1ed04922802c15e1de5d7447b4856de949cf56", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^5.4.0", + "nikic/php-parser": "^5.7.0", "php": ">=8.2", "phpunit/php-file-iterator": "^5.1.0", "phpunit/php-text-template": "^4.0.1", "sebastian/code-unit-reverse-lookup": "^4.0.1", "sebastian/complexity": "^4.0.1", - "sebastian/environment": "^7.2.0", + "sebastian/environment": "^7.2.1", "sebastian/lines-of-code": "^3.0.1", "sebastian/version": "^5.0.2", - "theseer/tokenizer": "^1.2.3" + "theseer/tokenizer": "^1.3.1" }, "require-dev": { - "phpunit/phpunit": "^11.5.2" + "phpunit/phpunit": "^11.5.46" }, "suggest": { "ext-pcov": "PHP extension that provides line coverage", @@ -985,7 +987,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.11" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.12" }, "funding": [ { @@ -1005,7 +1007,7 @@ "type": "tidelift" } ], - "time": "2025-08-27T14:37:49+00:00" + "time": "2025-12-24T07:01:01+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1254,16 +1256,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.5.44", + "version": "11.5.46", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c346885c95423eda3f65d85a194aaa24873cda82" + "reference": "75dfe79a2aa30085b7132bb84377c24062193f33" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c346885c95423eda3f65d85a194aaa24873cda82", - "reference": "c346885c95423eda3f65d85a194aaa24873cda82", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/75dfe79a2aa30085b7132bb84377c24062193f33", + "reference": "75dfe79a2aa30085b7132bb84377c24062193f33", "shasum": "" }, "require": { @@ -1335,7 +1337,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.44" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.46" }, "funding": [ { @@ -1359,7 +1361,7 @@ "type": "tidelift" } ], - "time": "2025-11-13T07:17:35+00:00" + "time": "2025-12-06T08:01:15+00:00" }, { "name": "sebastian/cli-parser", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4fd25e4..364905f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,97 +1,2 @@ parameters: ignoreErrors: - - - message: '#^Variable \$aliasTo on left side of \?\?\= is never defined\.$#' - identifier: nullCoalesce.variable - count: 1 - path: src/Container/DriverInterfaceFactoryFactory.php - - - - message: '#^Parameter \#1 \$name \(string\) of method PhpDb\\Adapter\\Sqlite\\Driver\\Pdo\\Connection\:\:getLastGeneratedValue\(\) should be compatible with parameter \$name \(null\) of method PhpDb\\Adapter\\Driver\\ConnectionInterface\:\:getLastGeneratedValue\(\)$#' - identifier: method.childParameterType - count: 2 - path: src/Driver/Pdo/Connection.php - - - - message: '#^Parameter \#2 \$parameters of class PhpDb\\Adapter\\Exception\\InvalidConnectionParametersException constructor expects int, array given\.$#' - identifier: argument.type - count: 1 - path: src/Driver/Pdo/Connection.php - - - - message: '#^Parameter \#1 \$resource \(PDOStatement\) of method PhpDb\\Adapter\\Sqlite\\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 \#3 \$rowCount of method PhpDb\\Adapter\\Driver\\Pdo\\Result\:\:initialize\(\) expects int\|null, Closure\|null given\.$#' - identifier: argument.type - count: 1 - path: src/Driver/Pdo/Pdo.php - - - - message: '#^Variable \$schemas might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: src/Metadata/Source/SqliteMetadata.php - - - - message: '#^Method PhpDb\\Adapter\\Sqlite\\Sql\\Platform\\Ddl\\AlterTableDecorator\:\:processAddColumns\(\) should return array\ but returns array\\>\.$#' - identifier: return.type - count: 1 - path: src/Sql/Platform/Ddl/AlterTableDecorator.php - - - - message: '#^Method PhpDb\\Adapter\\Sqlite\\Sql\\Platform\\Ddl\\AlterTableDecorator\:\:processChangeColumns\(\) should return array\ but returns array\\>\>\.$#' - identifier: return.type - count: 1 - path: src/Sql/Platform/Ddl/AlterTableDecorator.php - - - - message: '#^Offset ''paramPrefix'' does not exist on string\.$#' - identifier: offsetAccess.notFound - count: 2 - path: src/Sql/Platform/SelectDecorator.php - - - - message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array will always evaluate to true\.$#' - identifier: staticMethod.alreadyNarrowedType - count: 3 - path: test/unit/ConfigProviderTest.php - - - - message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsCallable\(\) with callable\(\)\: mixed will always evaluate to true\.$#' - identifier: staticMethod.alreadyNarrowedType - count: 1 - path: test/unit/Container/ConnectionInterfaceFactoryFactoryTest.php - - - - message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsCallable\(\) with callable\(\)\: mixed will always evaluate to true\.$#' - identifier: staticMethod.alreadyNarrowedType - count: 1 - path: test/unit/Container/DriverInterfaceFactoryFactoryTest.php - - - - message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsCallable\(\) with callable\(\)\: mixed will always evaluate to true\.$#' - identifier: staticMethod.alreadyNarrowedType - count: 1 - path: test/unit/Container/PlatformInterfaceFactoryFactoryTest.php - - - - message: '#^PHPDoc tag @var with type PhpDb\\Adapter\\Driver\\PdoDriverAwareInterface&PhpDb\\Adapter\\Driver\\StatementInterface is not subtype of native type PHPUnit\\Framework\\MockObject\\MockObject\.$#' - identifier: varTag.nativeType - count: 1 - path: test/unit/Driver/Pdo/PdoTest.php - - - - message: '#^Parameter \#1 \$callback of function set_error_handler expects \(callable\(int, string, string, int\)\: bool\)\|null, Closure\(int, string\)\: void given\.$#' - identifier: argument.type - count: 1 - path: test/unit/Platform/SqliteTest.php - - - - message: '#^Parameter \#1 \$callback of function set_error_handler expects \(callable\(int, string, string, int\)\: bool\)\|null, Closure\(mixed, mixed\)\: void given\.$#' - identifier: argument.type - count: 1 - path: test/unit/Platform/SqliteTest.php diff --git a/src/Platform/Sqlite.php b/src/AdapterPlatform.php similarity index 85% rename from src/Platform/Sqlite.php rename to src/AdapterPlatform.php index 10e1a24..d65851d 100644 --- a/src/Platform/Sqlite.php +++ b/src/AdapterPlatform.php @@ -2,20 +2,21 @@ declare(strict_types=1); -namespace PhpDb\Adapter\Sqlite\Platform; +namespace PhpDb\Adapter\Sqlite; use Override; use PDO; use PhpDb\Adapter\Driver\PdoDriverInterface; use PhpDb\Adapter\Platform\AbstractPlatform; -use PhpDb\Adapter\Sqlite\Sql\Platform\Sqlite as SqlPlatformDecorator; +use PhpDb\Adapter\Sqlite\Sql\Platform; use PhpDb\Sql\Platform\PlatformDecoratorInterface; -class Sqlite extends AbstractPlatform +class AdapterPlatform extends AbstractPlatform { public final const PLATFORM_NAME = 'SQLite'; /** @var string[] */ - protected $quoteIdentifier = ['"', '"']; + + protected array $quoteIdentifier = ['"', '"']; /** @var PDO */ protected $resource; @@ -23,7 +24,7 @@ class Sqlite extends AbstractPlatform /** * {@inheritDoc} */ - protected $quoteIdentifierTo = '\''; + protected string $quoteIdentifierTo = '\''; public function __construct( protected readonly PdoDriverInterface|PDO $driver @@ -83,6 +84,6 @@ public function getName(): string #[Override] public function getSqlPlatformDecorator(): PlatformDecoratorInterface { - return new SqlPlatformDecorator(); + return new Platform(); } } diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index fd64fd0..743ac80 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -17,10 +17,7 @@ use PhpDb\Adapter\Platform\PlatformInterface; use PhpDb\Adapter\Profiler\Profiler; use PhpDb\Adapter\Profiler\ProfilerInterface; -use PhpDb\Container\AdapterAbstractServiceFactory; -use PhpDb\Container\ConnectionInterfaceFactoryFactoryInterface; -use PhpDb\Container\DriverInterfaceFactoryFactoryInterface; -use PhpDb\Container\PlatformInterfaceFactoryFactoryInterface; +use PhpDb\Container\AbstractAdapterInterfaceFactory; use PhpDb\Metadata\MetadataInterface; use PhpDb\ResultSet; @@ -37,48 +34,37 @@ public function getDependencies(): array { return [ 'abstract_factories' => [ - AdapterAbstractServiceFactory::class, + AbstractAdapterInterfaceFactory::class, ], 'aliases' => [ - 'SQLite' => Driver\Pdo\Pdo::class, - 'Sqlite' => Driver\Pdo\Pdo::class, - 'sqlite' => Driver\Pdo\Pdo::class, - 'pdo' => Driver\Pdo\Pdo::class, - 'pdo_sqlite' => Driver\Pdo\Pdo::class, - 'pdosqlite' => Driver\Pdo\Pdo::class, - 'pdodriver' => Driver\Pdo\Pdo::class, - ConnectionInterface::class => Driver\Pdo\Connection::class, - PdoConnectionInterface::class => Driver\Pdo\Connection::class, - DriverInterface::class => Driver\Pdo\Pdo::class, - PdoDriverInterface::class => Driver\Pdo\Pdo::class, - PlatformInterface::class => Platform\Sqlite::class, - ProfilerInterface::class => Profiler::class, - ResultInterface::class => Result::class, - ResultSet\ResultSetInterface::class => ResultSet\ResultSet::class, - StatementInterface::class => Statement::class, - ConnectionInterfaceFactoryFactoryInterface::class => Container\ConnectionInterfaceFactoryFactory::class, - DriverInterfaceFactoryFactoryInterface::class => Container\DriverInterfaceFactoryFactory::class, - PlatformInterfaceFactoryFactoryInterface::class => Container\PlatformInterfaceFactoryFactory::class, - MetadataInterface::class => Metadata\Source\SqliteMetadata::class, + 'SQLite' => Pdo\Driver::class, + 'Sqlite' => Pdo\Driver::class, + 'sqlite' => Pdo\Driver::class, + 'pdo' => Pdo\Driver::class, + 'pdo_sqlite' => Pdo\Driver::class, + 'pdosqlite' => Pdo\Driver::class, + 'pdodriver' => Pdo\Driver::class, + ConnectionInterface::class => Pdo\Connection::class, + PdoConnectionInterface::class => Pdo\Connection::class, + DriverInterface::class => Pdo\Driver::class, + PdoDriverInterface::class => Pdo\Driver::class, + PlatformInterface::class => AdapterPlatform::class, + ProfilerInterface::class => Profiler::class, + ResultInterface::class => Result::class, + ResultSet\ResultSetInterface::class => ResultSet\ResultSet::class, + StatementInterface::class => Statement::class, + MetadataInterface::class => Metadata\Source::class, ], 'factories' => [ - AdapterInterface::class => Container\AdapterFactory::class, - Driver\Pdo\Connection::class => Container\PdoConnectionFactory::class, - Driver\Pdo\Pdo::class => Container\PdoDriverFactory::class, - Result::class => Container\PdoResultFactory::class, - Statement::class => Container\PdoStatementFactory::class, - Platform\Sqlite::class => Container\PlatformInterfaceFactory::class, - Profiler::class => InvokableFactory::class, - ResultSet\ResultSet::class => InvokableFactory::class, - Metadata\Source\SqliteMetadata::class => Container\MetadataInterfaceFactory::class, - ], - 'invokables' => [ - Container\ConnectionInterfaceFactoryFactory::class - => Container\ConnectionInterfaceFactoryFactory::class, - Container\DriverInterfaceFactoryFactory::class - => Container\DriverInterfaceFactoryFactory::class, - Container\PlatformInterfaceFactoryFactory::class - => Container\PlatformInterfaceFactoryFactory::class, + AdapterInterface::class => Container\AdapterInterfaceFactory::class, + Pdo\Connection::class => Container\PdoConnectionFactory::class, + Pdo\Driver::class => Container\PdoDriverFactory::class, + Result::class => Container\PdoResultFactory::class, + Statement::class => Container\PdoStatementFactory::class, + AdapterPlatform::class => Container\PlatformInterfaceFactory::class, + Profiler::class => InvokableFactory::class, + ResultSet\ResultSet::class => InvokableFactory::class, + Metadata\Source::class => Container\MetadataInterfaceFactory::class, ], ]; } diff --git a/src/Container/AdapterFactory.php b/src/Container/AdapterInterfaceFactory.php similarity index 98% rename from src/Container/AdapterFactory.php rename to src/Container/AdapterInterfaceFactory.php index 42b022a..692f974 100644 --- a/src/Container/AdapterFactory.php +++ b/src/Container/AdapterInterfaceFactory.php @@ -17,7 +17,7 @@ use function sprintf; -final class AdapterFactory +final class AdapterInterfaceFactory { public function __invoke(ContainerInterface $container): AdapterInterface { diff --git a/src/Container/ConnectionInterfaceFactoryFactory.php b/src/Container/ConnectionInterfaceFactoryFactory.php deleted file mode 100644 index 814ba51..0000000 --- a/src/Container/ConnectionInterfaceFactoryFactory.php +++ /dev/null @@ -1,43 +0,0 @@ -get('config')['db']['adapters'] ?? []; - if (! isset($adapterConfig[$requestedName]['driver'])) { - throw new RuntimeException(sprintf( - 'Named adapter "%s" is not configured with a driver', - $requestedName - )); - } - $adapterServices = $container->get('config')['dependencies']; - $configuredDriver = $adapterConfig[$requestedName]['driver']; - if (array_key_exists($configuredDriver, $adapterServices['aliases'])) { - $aliasTo = $adapterServices['aliases'][$configuredDriver]; - } else { - $aliasTo = $configuredDriver; - } - return match ($aliasTo) { - Pdo::class => new PdoConnectionFactory(), - default => throw new RuntimeException(sprintf( - 'No connection factory found for driver "%s"', - $configuredDriver - )), - }; - } -} diff --git a/src/Container/DriverInterfaceFactoryFactory.php b/src/Container/DriverInterfaceFactoryFactory.php deleted file mode 100644 index e7219dc..0000000 --- a/src/Container/DriverInterfaceFactoryFactory.php +++ /dev/null @@ -1,33 +0,0 @@ -get('config')['db']['adapters'] ?? []; - if (! isset($adapterConfig[$requestedName]['driver'])) { - throw new RuntimeException(sprintf( - 'Named adapter "%s" is not configured with a driver', - $requestedName - )); - } - $adapterServices = $container->get('config')['dependencies']; - - $configuredDriver = $adapterConfig[$requestedName]['driver']; - $aliasTo ??= $adapterServices['aliases'][$configuredDriver] ?? $configuredDriver; - $driverFactory = $adapterServices['factories'][$aliasTo]; - return new $driverFactory(); - } -} diff --git a/src/Container/MetadataInterfaceFactory.php b/src/Container/MetadataInterfaceFactory.php index 65bcef8..25baa0b 100644 --- a/src/Container/MetadataInterfaceFactory.php +++ b/src/Container/MetadataInterfaceFactory.php @@ -5,19 +5,18 @@ namespace PhpDb\Adapter\Sqlite\Container; use PhpDb\Adapter\AdapterInterface; -use PhpDb\Adapter\SchemaAwareInterface; -use PhpDb\Adapter\Sqlite\Metadata\Source\SqliteMetadata; +use PhpDb\Adapter\Sqlite\Metadata; use PhpDb\Metadata\MetadataInterface; use Psr\Container\ContainerInterface; final class MetadataInterfaceFactory { - public function __invoke(ContainerInterface $container): MetadataInterface&SqliteMetadata + public function __invoke(ContainerInterface $container): MetadataInterface&Metadata\Source { /** @var AdapterInterface&SchemaAwareInterface $adapter */ $adapter = $container->get(AdapterInterface::class); - return new SqliteMetadata( + return new Metadata\Source( $adapter ); } diff --git a/src/Container/PdoDriverFactory.php b/src/Container/PdoDriverFactory.php index dcc8378..73d16f0 100644 --- a/src/Container/PdoDriverFactory.php +++ b/src/Container/PdoDriverFactory.php @@ -12,7 +12,7 @@ use PhpDb\Adapter\Driver\StatementInterface; use PhpDb\Adapter\Sqlite\Driver\Pdo\Connection; use PhpDb\Adapter\Sqlite\Driver\Pdo\Feature\SqliteRowCounter; -use PhpDb\Adapter\Sqlite\Driver\Pdo\Pdo as PdoDriver; +use PhpDb\Adapter\Sqlite\Pdo\Driver as PdoDriver; use Psr\Container\ContainerInterface; final class PdoDriverFactory diff --git a/src/Container/PlatformInterfaceFactory.php b/src/Container/PlatformInterfaceFactory.php index 4282633..d243525 100644 --- a/src/Container/PlatformInterfaceFactory.php +++ b/src/Container/PlatformInterfaceFactory.php @@ -7,12 +7,12 @@ use PDO; use PhpDb\Adapter\Driver\PdoDriverInterface; use PhpDb\Adapter\Platform\PlatformInterface; -use PhpDb\Adapter\Sqlite\Platform\Sqlite; +use PhpDb\Adapter\Sqlite\AdapterPlatform; use Psr\Container\ContainerInterface; final class PlatformInterfaceFactory { - public function __invoke(ContainerInterface $container): PlatformInterface&Sqlite + public function __invoke(ContainerInterface $container): PlatformInterface&AdapterPlatform { /** @var array $config */ $config = $container->get('config'); @@ -26,11 +26,11 @@ public function __invoke(ContainerInterface $container): PlatformInterface&Sqlit /** @var PdoDriverInterface|PDO $driverInstance */ $driverInstance = $container->get($driver); - return new Sqlite($driverInstance); + return new AdapterPlatform($driverInstance); } - public static function fromDriver(PdoDriverInterface $driverInstance): PlatformInterface&Sqlite + public static function fromDriver(PdoDriverInterface $driverInstance): PlatformInterface&AdapterPlatform { - return new Sqlite($driverInstance); + return new AdapterPlatform($driverInstance); } } diff --git a/src/Container/PlatformInterfaceFactoryFactory.php b/src/Container/PlatformInterfaceFactoryFactory.php deleted file mode 100644 index 15c4574..0000000 --- a/src/Container/PlatformInterfaceFactoryFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -quoteIdentifierChain([$schema, 'sqlite_master']) . ' WHERE "type" IN (\'table\',\'view\') AND "name" NOT LIKE \'sqlite_%\''; - + /** @var ResultSet $results */ $results = $this->adapter->query($sql, AdapterInterface::QUERY_MODE_EXECUTE); $tables = []; foreach ($results->toArray() as $row) { @@ -209,7 +210,7 @@ protected function loadTriggerData(string $schema): void $sql = 'SELECT "name", "tbl_name", "sql" FROM ' . $p->quoteIdentifierChain([$schema, 'sqlite_master']) . ' WHERE "type" = \'trigger\''; - + /** @var ResultSet $results */ $results = $this->adapter->query($sql, AdapterInterface::QUERY_MODE_EXECUTE); $triggers = []; foreach ($results->toArray() as $row) { @@ -255,7 +256,7 @@ protected function fetchPragma(string $name, ?string $value = null, ?string $sch if (null !== $value) { $sql .= '(' . $p->quoteTrustedValue($value) . ')'; } - + /** @var ResultSet $results */ $results = $this->adapter->query($sql, AdapterInterface::QUERY_MODE_EXECUTE); if ($results instanceof ResultSetInterface) { return $results->toArray(); diff --git a/src/Driver/Pdo/Connection.php b/src/Pdo/Connection.php similarity index 98% rename from src/Driver/Pdo/Connection.php rename to src/Pdo/Connection.php index a7340bb..306356f 100644 --- a/src/Driver/Pdo/Connection.php +++ b/src/Pdo/Connection.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDb\Adapter\Sqlite\Driver\Pdo; +namespace PhpDb\Adapter\Sqlite\Pdo; use Override; use PDO; diff --git a/src/Driver/Pdo/Pdo.php b/src/Pdo/Driver.php similarity index 86% rename from src/Driver/Pdo/Pdo.php rename to src/Pdo/Driver.php index e449816..a1b4982 100644 --- a/src/Driver/Pdo/Pdo.php +++ b/src/Pdo/Driver.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDb\Adapter\Sqlite\Driver\Pdo; +namespace PhpDb\Adapter\Sqlite\Pdo; use Override; use PDOStatement; @@ -11,9 +11,9 @@ use PhpDb\Adapter\Driver\Pdo\AbstractPdo; use PhpDb\Adapter\Driver\Pdo\Result; use PhpDb\Adapter\Driver\ResultInterface; -use PhpDb\Adapter\Sqlite\Driver\DatabasePlatformNameTrait; +use PhpDb\Adapter\Sqlite\DatabasePlatformNameTrait; -class Pdo extends AbstractPdo implements DriverFeatureProviderInterface +class Driver extends AbstractPdo implements DriverFeatureProviderInterface { use DatabasePlatformNameTrait; use DriverFeatureProviderTrait; diff --git a/src/Driver/Pdo/Feature/SqliteRowCounter.php b/src/Pdo/Feature/SqliteRowCounter.php similarity index 96% rename from src/Driver/Pdo/Feature/SqliteRowCounter.php rename to src/Pdo/Feature/SqliteRowCounter.php index 014b66b..23f2197 100644 --- a/src/Driver/Pdo/Feature/SqliteRowCounter.php +++ b/src/Pdo/Feature/SqliteRowCounter.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDb\Adapter\Sqlite\Driver\Pdo\Feature; +namespace PhpDb\Adapter\Sqlite\Pdo\Feature; use Closure; use PhpDb\Adapter\Driver\Feature\AbstractFeature; diff --git a/src/Sql/Platform/Ddl/AlterTableDecorator.php b/src/Sql/Ddl/AlterTableDecorator.php similarity index 97% rename from src/Sql/Platform/Ddl/AlterTableDecorator.php rename to src/Sql/Ddl/AlterTableDecorator.php index 0b975f7..3927d0f 100644 --- a/src/Sql/Platform/Ddl/AlterTableDecorator.php +++ b/src/Sql/Ddl/AlterTableDecorator.php @@ -2,12 +2,14 @@ declare(strict_types=1); -namespace PhpDb\Adapter\Sqlite\Sql\Platform\Ddl; +namespace PhpDb\Adapter\Sqlite\Sql\Ddl; use PhpDb\Adapter\Platform\PlatformInterface; use PhpDb\Sql\Ddl\AlterTable; use PhpDb\Sql\Ddl\Column\ColumnInterface; use PhpDb\Sql\Platform\PlatformDecoratorInterface; +use PhpDb\Sql\PreparableSqlInterface; +use PhpDb\Sql\SqlInterface; use function count; use function range; @@ -21,7 +23,7 @@ class AlterTableDecorator extends AlterTable implements PlatformDecoratorInterface { - protected AlterTable $subject; + public SqlInterface|PreparableSqlInterface|null $subject; /** @var int[] */ protected array $columnOptionSortOrder = [ diff --git a/src/Sql/Platform/Ddl/CreateTableDecorator.php b/src/Sql/Ddl/CreateTableDecorator.php similarity index 96% rename from src/Sql/Platform/Ddl/CreateTableDecorator.php rename to src/Sql/Ddl/CreateTableDecorator.php index 58819eb..2741fe0 100644 --- a/src/Sql/Platform/Ddl/CreateTableDecorator.php +++ b/src/Sql/Ddl/CreateTableDecorator.php @@ -2,11 +2,13 @@ declare(strict_types=1); -namespace PhpDb\Adapter\Sqlite\Sql\Platform\Ddl; +namespace PhpDb\Adapter\Sqlite\Sql\Ddl; use PhpDb\Adapter\Platform\PlatformInterface; use PhpDb\Sql\Ddl\CreateTable; use PhpDb\Sql\Platform\PlatformDecoratorInterface; +use PhpDb\Sql\PreparableSqlInterface; +use PhpDb\Sql\SqlInterface; use function count; use function range; @@ -21,7 +23,7 @@ final class CreateTableDecorator extends CreateTable implements PlatformDecoratorInterface { /** @psalm-suppress PossiblyUnusedProperty */ - protected CreateTable $subject; + public SqlInterface|PreparableSqlInterface|null $subject; /** @var int[] */ protected array $columnOptionSortOrder = [ diff --git a/src/Sql/Platform/Sqlite.php b/src/Sql/Platform.php similarity index 83% rename from src/Sql/Platform/Sqlite.php rename to src/Sql/Platform.php index 73d772c..c42ec8d 100644 --- a/src/Sql/Platform/Sqlite.php +++ b/src/Sql/Platform.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace PhpDb\Adapter\Sqlite\Sql\Platform; +namespace PhpDb\Adapter\Sqlite\Sql; use PhpDb\Sql\Ddl\AlterTable; use PhpDb\Sql\Ddl\CreateTable; use PhpDb\Sql\Platform\AbstractPlatform; use PhpDb\Sql\Select; -final class Sqlite extends AbstractPlatform +final class Platform extends AbstractPlatform { public function __construct() { diff --git a/src/Sql/Platform/SelectDecorator.php b/src/Sql/SelectDecorator.php similarity index 92% rename from src/Sql/Platform/SelectDecorator.php rename to src/Sql/SelectDecorator.php index ea483fa..877c24f 100644 --- a/src/Sql/Platform/SelectDecorator.php +++ b/src/Sql/SelectDecorator.php @@ -2,17 +2,19 @@ declare(strict_types=1); -namespace PhpDb\Adapter\Sqlite\Sql\Platform; +namespace PhpDb\Adapter\Sqlite\Sql; use PhpDb\Adapter\Driver\DriverInterface; use PhpDb\Adapter\ParameterContainer; use PhpDb\Adapter\Platform\PlatformInterface; use PhpDb\Sql\Platform\PlatformDecoratorInterface; +use PhpDb\Sql\PreparableSqlInterface; use PhpDb\Sql\Select; +use PhpDb\Sql\SqlInterface; final class SelectDecorator extends Select implements PlatformDecoratorInterface { - protected Select $subject; + public SqlInterface|PreparableSqlInterface|null $subject; /** * @param Select $subject diff --git a/test/integration/Platform/SqliteTest.php b/test/integration/AdapterPlatformTest.php similarity index 71% rename from test/integration/Platform/SqliteTest.php rename to test/integration/AdapterPlatformTest.php index c87ef12..51e549c 100644 --- a/test/integration/Platform/SqliteTest.php +++ b/test/integration/AdapterPlatformTest.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Sqlite\Platform; +namespace PhpDbIntegrationTest\Adapter\Sqlite; -use PhpDb\Adapter\Sqlite\Platform\Sqlite; +use PhpDb\Adapter\Sqlite\AdapterPlatform; use PhpDbIntegrationTest\Adapter\Sqlite\Container\TestAsset\SetupTrait; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; @@ -13,9 +13,9 @@ #[Group('integration')] #[Group('integration-sqlite')] -#[CoversClass(Sqlite::class)] -#[CoversMethod(Sqlite::class, 'quoteValue')] -final class SqliteTest extends TestCase +#[CoversClass(AdapterPlatform::class)] +#[CoversMethod(AdapterPlatform::class, 'quoteValue')] +final class AdapterPlatformTest extends TestCase { use SetupTrait; diff --git a/test/integration/Container/AdapterFactoryTest.php b/test/integration/Container/AdapterInterfaceFactoryTest.php similarity index 63% rename from test/integration/Container/AdapterFactoryTest.php rename to test/integration/Container/AdapterInterfaceFactoryTest.php index 272a092..660dd00 100644 --- a/test/integration/Container/AdapterFactoryTest.php +++ b/test/integration/Container/AdapterInterfaceFactoryTest.php @@ -5,20 +5,20 @@ namespace PhpDbIntegrationTest\Adapter\Sqlite\Container; use PhpDb\Adapter\AdapterInterface; -use PhpDb\Adapter\Sqlite\Container\AdapterFactory; +use PhpDb\Adapter\Sqlite\Container\AdapterInterfaceFactory; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\TestCase; -#[CoversClass(AdapterFactory::class)] -#[CoversMethod(AdapterFactory::class, '__invoke')] -final class AdapterFactoryTest extends TestCase +#[CoversClass(AdapterInterfaceFactory::class)] +#[CoversMethod(AdapterInterfaceFactory::class, '__invoke')] +final class AdapterInterfaceFactoryTest extends TestCase { use TestAsset\SetupTrait; public function testFactoryReturnsAdapterInterface(): void { - $factory = new AdapterFactory(); + $factory = new AdapterInterfaceFactory(); $adapter = $factory($this->container); self::assertInstanceOf(AdapterInterface::class, $adapter); } diff --git a/test/integration/Container/PdoConnectionFactoryTest.php b/test/integration/Container/PdoConnectionFactoryTest.php index 6095dcd..22766e6 100644 --- a/test/integration/Container/PdoConnectionFactoryTest.php +++ b/test/integration/Container/PdoConnectionFactoryTest.php @@ -7,7 +7,7 @@ use PhpDb\Adapter\Driver\ConnectionInterface; use PhpDb\Adapter\Driver\PdoConnectionInterface; use PhpDb\Adapter\Sqlite\Container\PdoConnectionFactory; -use PhpDb\Adapter\Sqlite\Driver\Pdo\Connection; +use PhpDb\Adapter\Sqlite\Pdo\Connection; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\Group; diff --git a/test/integration/Container/PdoDriverFactoryTest.php b/test/integration/Container/PdoDriverFactoryTest.php index bc16fc5..b79733a 100644 --- a/test/integration/Container/PdoDriverFactoryTest.php +++ b/test/integration/Container/PdoDriverFactoryTest.php @@ -6,7 +6,7 @@ use PhpDb\Adapter\Driver\PdoDriverInterface; use PhpDb\Adapter\Sqlite\Container\PdoDriverFactory; -use PhpDb\Adapter\Sqlite\Driver\Pdo\Pdo; +use PhpDb\Adapter\Sqlite\Pdo\Driver; 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(Driver::class, $instance); } } diff --git a/test/integration/Container/PlatformInterfaceFactoryTest.php b/test/integration/Container/PlatformInterfaceFactoryTest.php index fb3e29e..6d6ae3c 100644 --- a/test/integration/Container/PlatformInterfaceFactoryTest.php +++ b/test/integration/Container/PlatformInterfaceFactoryTest.php @@ -5,8 +5,8 @@ namespace PhpDbIntegrationTest\Adapter\Sqlite\Container; use PhpDb\Adapter\Platform\PlatformInterface; +use PhpDb\Adapter\Sqlite\AdapterPlatform; use PhpDb\Adapter\Sqlite\Container\PlatformInterfaceFactory; -use PhpDb\Adapter\Sqlite\Platform\Sqlite; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\Group; @@ -25,6 +25,6 @@ public function testInvokeReturnsPlatformInterfaceWhenDbDriverIsPdo(): void $factory = new PlatformInterfaceFactory(); $instance = $factory($this->container); self::assertInstanceOf(PlatformInterface::class, $instance); - self::assertInstanceOf(Sqlite::class, $instance); + self::assertInstanceOf(AdapterPlatform::class, $instance); } } diff --git a/test/integration/Container/SqliteMetadataFactoryTest.php b/test/integration/Container/SqliteMetadataFactoryTest.php index ac0e550..fe0ad07 100644 --- a/test/integration/Container/SqliteMetadataFactoryTest.php +++ b/test/integration/Container/SqliteMetadataFactoryTest.php @@ -5,7 +5,7 @@ namespace PhpDbIntegrationTest\Adapter\Sqlite\Container; use PhpDb\Adapter\Sqlite\Container\MetadataInterfaceFactory; -use PhpDb\Adapter\Sqlite\Metadata\Source\SqliteMetadata; +use PhpDb\Adapter\Sqlite\Metadata; use PhpDb\Metadata\MetadataInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; @@ -22,6 +22,6 @@ public function testFactoryReturnsMysqlMetadata(): void $factory = new MetadataInterfaceFactory(); $metadata = $factory($this->container); self::assertInstanceOf(MetadataInterface::class, $metadata); - self::assertInstanceOf(SqliteMetadata::class, $metadata); + self::assertInstanceOf(Metadata\Source::class, $metadata); } } diff --git a/test/integration/Container/TestAsset/SetupTrait.php b/test/integration/Container/TestAsset/SetupTrait.php index bd87ab5..d3b2a76 100644 --- a/test/integration/Container/TestAsset/SetupTrait.php +++ b/test/integration/Container/TestAsset/SetupTrait.php @@ -10,7 +10,7 @@ use PhpDb\Adapter\AdapterInterface; use PhpDb\Adapter\Driver\DriverInterface; use PhpDb\Adapter\Sqlite\ConfigProvider; -use PhpDb\Adapter\Sqlite\Driver\Pdo\Pdo; +use PhpDb\Adapter\Sqlite\Pdo\Driver; use PhpDb\ConfigProvider as LaminasDbConfigProvider; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Psr\Container\ContainerInterface; @@ -45,7 +45,7 @@ protected function getAdapter(array $config = []): AdapterInterface { $connectionConfig = [ 'db' => [ - 'driver' => $this->driver ?? Pdo::class, + 'driver' => $this->driver ?? Driver::class, 'connection' => [ 'dsn' => 'sqlite::memory:', 'charset' => 'utf8', @@ -57,7 +57,7 @@ protected function getAdapter(array $config = []): AdapterInterface ], ]; - // merge service config from both PhpDb and PhpDb\Adapter\Mysql + // merge service config from both PhpDb and PhpDb\Adapter\Sqlite $serviceManagerConfig = ArrayUtils::merge( (new LaminasDbConfigProvider())()['dependencies'], (new ConfigProvider())()['dependencies'] diff --git a/test/integration/Driver/Pdo/AbstractAdapterTestCase.php b/test/integration/Pdo/AbstractAdapterTestCase.php similarity index 97% rename from test/integration/Driver/Pdo/AbstractAdapterTestCase.php rename to test/integration/Pdo/AbstractAdapterTestCase.php index 315a294..2740434 100644 --- a/test/integration/Driver/Pdo/AbstractAdapterTestCase.php +++ b/test/integration/Pdo/AbstractAdapterTestCase.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Sqlite\Driver\Pdo; +namespace PhpDbIntegrationTest\Adapter\Sqlite\Pdo; use PhpDb\Adapter\AdapterInterface; use PhpDbIntegrationTest\Adapter\Sqlite\Container\TestAsset\SetupTrait; diff --git a/test/integration/Driver/Pdo/ConnectionIntegrationTest.php b/test/integration/Pdo/ConnectionIntegrationTest.php similarity index 97% rename from test/integration/Driver/Pdo/ConnectionIntegrationTest.php rename to test/integration/Pdo/ConnectionIntegrationTest.php index 8eae402..584a8e1 100644 --- a/test/integration/Driver/Pdo/ConnectionIntegrationTest.php +++ b/test/integration/Pdo/ConnectionIntegrationTest.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Sqlite\Driver\Pdo; +namespace PhpDbIntegrationTest\Adapter\Sqlite\Pdo; use PDO; use PhpDb\Adapter\Driver\PdoConnectionInterface; -use PhpDb\Adapter\Sqlite\Driver\Pdo\Connection; +use PhpDb\Adapter\Sqlite\Pdo\Connection; use PhpDbIntegrationTest\Adapter\Sqlite\Container\TestAsset\SetupTrait; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\Group; diff --git a/test/integration/Driver/Pdo/StatementTest.php b/test/integration/Pdo/StatementTest.php similarity index 98% rename from test/integration/Driver/Pdo/StatementTest.php rename to test/integration/Pdo/StatementTest.php index 5290b41..6cf82e1 100644 --- a/test/integration/Driver/Pdo/StatementTest.php +++ b/test/integration/Pdo/StatementTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDbIntegrationTest\Adapter\Sqlite\Driver\Pdo; +namespace PhpDbIntegrationTest\Adapter\Sqlite\Pdo; use PDO; use PDOStatement; diff --git a/test/unit/AdapterTest.php b/test/unit/AdapterInterfaceTest.php similarity index 95% rename from test/unit/AdapterTest.php rename to test/unit/AdapterInterfaceTest.php index e67c182..5187f48 100644 --- a/test/unit/AdapterTest.php +++ b/test/unit/AdapterInterfaceTest.php @@ -14,8 +14,8 @@ use PhpDb\Adapter\Driver\ResultInterface; use PhpDb\Adapter\Driver\StatementInterface; use PhpDb\Adapter\Profiler; -use PhpDb\Adapter\Sqlite\Driver\Pdo\Pdo; -use PhpDb\Adapter\Sqlite\Platform\Sqlite as SqlitePlatform; +use PhpDb\Adapter\Sqlite\AdapterPlatform as SqlitePlatform; +use PhpDb\Adapter\Sqlite\Pdo\Driver; use PhpDb\ResultSet\ResultSetInterface; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\TestDox; @@ -33,7 +33,7 @@ #[CoversMethod(Adapter::class, 'query')] #[CoversMethod(Adapter::class, 'createStatement')] #[CoversMethod(Adapter::class, '__get')] -final class AdapterTest extends TestCase +final class AdapterInterfaceTest extends TestCase { protected DriverInterface&MockObject $mockDriver; @@ -58,7 +58,7 @@ protected function setUp(): void $this->mockStatement = $this->getMockBuilder(Statement::class)->getMock(); $this->mockResultSet = $this->getMockBuilder(ResultSetInterface::class)->getMock(); $resultInterface = $this->getMockBuilder(ResultInterface::class)->getMock(); - $this->mockDriver = $this->getMockBuilder(Pdo::class) + $this->mockDriver = $this->getMockBuilder(Driver::class) ->setConstructorArgs([ $this->mockConnection, $this->mockStatement, diff --git a/test/unit/Platform/SqliteTest.php b/test/unit/AdapterPlatformTest.php similarity index 81% rename from test/unit/Platform/SqliteTest.php rename to test/unit/AdapterPlatformTest.php index 90299e9..9a12ac3 100644 --- a/test/unit/Platform/SqliteTest.php +++ b/test/unit/AdapterPlatformTest.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Sqlite\Platform; +namespace PhpDbTest\Adapter\Sqlite; use PDO; use PhpDb\Adapter\Driver\PdoDriverInterface; -use PhpDb\Adapter\Sqlite\Platform\Sqlite; -use PhpDb\Adapter\Sqlite\Sql\Platform\Sqlite as SqlPlatformDecorator; +use PhpDb\Adapter\Sqlite\AdapterPlatform; +use PhpDb\Adapter\Sqlite\Sql\Platform as SqlPlatformDecorator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; @@ -16,50 +16,50 @@ use const E_USER_NOTICE; -#[CoversClass(Sqlite::class)] -final class SqliteTest extends TestCase +#[CoversClass(AdapterPlatform::class)] +final class AdapterPlatformTest extends TestCase { - private Sqlite $platform; + private AdapterPlatform $platform; protected function setUp(): void { $pdoMock = $this->createMock(PDO::class); - $this->platform = new Sqlite($pdoMock); + $this->platform = new AdapterPlatform($pdoMock); } public function testGetNameReturnsSqlite(): void { $pdoMock = $this->createMock(PDO::class); - $platform = new Sqlite($pdoMock); + $platform = new AdapterPlatform($pdoMock); self::assertSame('SQLite', $platform->getName()); } public function testPlatformNameConstant(): void { - self::assertSame('SQLite', Sqlite::PLATFORM_NAME); + self::assertSame('SQLite', AdapterPlatform::PLATFORM_NAME); } public function testConstructWithPdo(): void { $pdoMock = $this->createMock(PDO::class); - $platform = new Sqlite($pdoMock); + $platform = new AdapterPlatform($pdoMock); - self::assertInstanceOf(Sqlite::class, $platform); + self::assertInstanceOf(AdapterPlatform::class, $platform); } public function testConstructWithPdoDriver(): void { $driverMock = $this->createMock(PdoDriverInterface::class); - $platform = new Sqlite($driverMock); + $platform = new AdapterPlatform($driverMock); - self::assertInstanceOf(Sqlite::class, $platform); + self::assertInstanceOf(AdapterPlatform::class, $platform); } public function testGetSqlPlatformDecorator(): void { $pdoMock = $this->createMock(PDO::class); - $platform = new Sqlite($pdoMock); + $platform = new AdapterPlatform($pdoMock); $decorator = $platform->getSqlPlatformDecorator(); @@ -97,16 +97,23 @@ public function testQuoteValueRaisesNoticeWithoutPlatformSupport(): void { $raisedNotice = false; - set_error_handler(function (int $errno, string $errstr) use (&$raisedNotice) { - $this->assertEquals(E_USER_NOTICE, $errno); - $this->assertEquals( - $errstr, + set_error_handler( + function ( + int $errno, + string $errstr, + ?string $errfile = null, + ?int $errline = null + ) use (&$raisedNotice) { + $this->assertEquals(E_USER_NOTICE, $errno); + $this->assertEquals( + $errstr, // phpcs:ignore Generic.Files.LineLength - 'Attempting to quote a value in PhpDb\Adapter\Sqlite\Platform\Sqlite without extension/driver support can ' + 'Attempting to quote a value in PhpDb\Adapter\Sqlite\Platform without extension/driver support can ' . 'introduce security vulnerabilities in a production environment' - ); - $raisedNotice = true; - }); + ); + $raisedNotice = true; + } + ); $this->platform->quoteValue('value'); self::assertTrue($raisedNotice); diff --git a/test/unit/ConfigProviderTest.php b/test/unit/ConfigProviderTest.php index b91adc6..0247d4b 100644 --- a/test/unit/ConfigProviderTest.php +++ b/test/unit/ConfigProviderTest.php @@ -17,16 +17,13 @@ use PhpDb\Adapter\Platform\PlatformInterface; use PhpDb\Adapter\Profiler\Profiler; use PhpDb\Adapter\Profiler\ProfilerInterface; +use PhpDb\Adapter\Sqlite\AdapterPlatform; use PhpDb\Adapter\Sqlite\ConfigProvider; use PhpDb\Adapter\Sqlite\Container; -use PhpDb\Adapter\Sqlite\Driver\Pdo\Connection; -use PhpDb\Adapter\Sqlite\Driver\Pdo\Pdo; -use PhpDb\Adapter\Sqlite\Metadata\Source\SqliteMetadata; -use PhpDb\Adapter\Sqlite\Platform\Sqlite; -use PhpDb\Container\AdapterAbstractServiceFactory; -use PhpDb\Container\ConnectionInterfaceFactoryFactoryInterface; -use PhpDb\Container\DriverInterfaceFactoryFactoryInterface; -use PhpDb\Container\PlatformInterfaceFactoryFactoryInterface; +use PhpDb\Adapter\Sqlite\Metadata; +use PhpDb\Adapter\Sqlite\Pdo\Connection; +use PhpDb\Adapter\Sqlite\Pdo\Driver; +use PhpDb\Container\AbstractAdapterInterfaceFactory; use PhpDb\Metadata\MetadataInterface; use PhpDb\ResultSet; use PHPUnit\Framework\Attributes\CoversClass; @@ -46,7 +43,6 @@ public function testInvokeReturnsExpectedStructure(): void { $config = ($this->configProvider)(); - self::assertIsArray($config); self::assertArrayHasKey('dependencies', $config); } @@ -58,7 +54,6 @@ public function testGetDependenciesReturnsCorrectStructure(): void self::assertArrayHasKey('abstract_factories', $dependencies); self::assertArrayHasKey('aliases', $dependencies); self::assertArrayHasKey('factories', $dependencies); - self::assertArrayHasKey('invokables', $dependencies); } public function testGetDependenciesContainsAbstractFactories(): void @@ -66,7 +61,7 @@ public function testGetDependenciesContainsAbstractFactories(): void $dependencies = $this->configProvider->getDependencies(); self::assertContains( - AdapterAbstractServiceFactory::class, + AbstractAdapterInterfaceFactory::class, $dependencies['abstract_factories'] ); } @@ -77,7 +72,7 @@ public function testGetDependenciesContainsMetadataAlias(): void self::assertArrayHasKey(MetadataInterface::class, $dependencies['aliases']); self::assertSame( - SqliteMetadata::class, + Metadata\Source::class, $dependencies['aliases'][MetadataInterface::class] ); } @@ -86,10 +81,10 @@ public function testGetDependenciesContainsMetadataFactory(): void { $dependencies = $this->configProvider->getDependencies(); - self::assertArrayHasKey(SqliteMetadata::class, $dependencies['factories']); + self::assertArrayHasKey(Metadata\Source::class, $dependencies['factories']); self::assertSame( Container\MetadataInterfaceFactory::class, - $dependencies['factories'][SqliteMetadata::class] + $dependencies['factories'][Metadata\Source::class] ); } @@ -97,10 +92,8 @@ public function testConfigReturnsCorrectStructure(): void { $config = $this->configProvider->getDependencies(); - self::assertIsArray($config); self::assertArrayHasKey('aliases', $config); self::assertArrayHasKey('factories', $config); - self::assertArrayHasKey('invokables', $config); } public function testGetDependenciesContainsDriverAliases(): void @@ -108,13 +101,13 @@ public function testGetDependenciesContainsDriverAliases(): void $config = $this->configProvider->getDependencies(); $expectedAliases = [ - 'SQLite' => Pdo::class, - 'Sqlite' => Pdo::class, - 'sqlite' => Pdo::class, - 'pdo' => Pdo::class, - 'pdo_sqlite' => Pdo::class, - 'pdosqlite' => Pdo::class, - 'pdodriver' => Pdo::class, + 'SQLite' => Driver::class, + 'Sqlite' => Driver::class, + 'sqlite' => Driver::class, + 'pdo' => Driver::class, + 'pdo_sqlite' => Driver::class, + 'pdosqlite' => Driver::class, + 'pdodriver' => Driver::class, ]; foreach ($expectedAliases as $alias => $target) { @@ -130,9 +123,9 @@ public function testGetDependenciesContainsInterfaceAliases(): void $expectedAliases = [ ConnectionInterface::class => Connection::class, PdoConnectionInterface::class => Connection::class, - DriverInterface::class => Pdo::class, - PdoDriverInterface::class => Pdo::class, - PlatformInterface::class => Sqlite::class, + DriverInterface::class => Driver::class, + PdoDriverInterface::class => Driver::class, + PlatformInterface::class => AdapterPlatform::class, ProfilerInterface::class => Profiler::class, ResultInterface::class => Result::class, ResultSet\ResultSetInterface::class => ResultSet\ResultSet::class, @@ -145,33 +138,17 @@ public function testGetDependenciesContainsInterfaceAliases(): void } } - public function testConfigContainsFactoryFactoryAliases(): void - { - $config = $this->configProvider->getDependencies(); - - $expectedAliases = [ - ConnectionInterfaceFactoryFactoryInterface::class => Container\ConnectionInterfaceFactoryFactory::class, - DriverInterfaceFactoryFactoryInterface::class => Container\DriverInterfaceFactoryFactory::class, - PlatformInterfaceFactoryFactoryInterface::class => Container\PlatformInterfaceFactoryFactory::class, - ]; - - foreach ($expectedAliases as $interface => $implementation) { - self::assertArrayHasKey($interface, $config['aliases']); - self::assertSame($implementation, $config['aliases'][$interface]); - } - } - public function testConfigContainsFactories(): void { $config = $this->configProvider->getDependencies(); $expectedFactories = [ - AdapterInterface::class => Container\AdapterFactory::class, + AdapterInterface::class => Container\AdapterInterfaceFactory::class, Connection::class => Container\PdoConnectionFactory::class, - Pdo::class => Container\PdoDriverFactory::class, + Driver::class => Container\PdoDriverFactory::class, Result::class => Container\PdoResultFactory::class, Statement::class => Container\PdoStatementFactory::class, - Sqlite::class => Container\PlatformInterfaceFactory::class, + AdapterPlatform::class => Container\PlatformInterfaceFactory::class, Profiler::class => InvokableFactory::class, ResultSet\ResultSet::class => InvokableFactory::class, ]; @@ -181,20 +158,4 @@ public function testConfigContainsFactories(): void self::assertSame($factory, $config['factories'][$service]); } } - - public function testConfigContainsInvokables(): void - { - $config = $this->configProvider->getDependencies(); - - $expectedInvokables = [ - Container\ConnectionInterfaceFactoryFactory::class, - Container\DriverInterfaceFactoryFactory::class, - Container\PlatformInterfaceFactoryFactory::class, - ]; - - foreach ($expectedInvokables as $invokable) { - self::assertArrayHasKey($invokable, $config['invokables']); - self::assertSame($invokable, $config['invokables'][$invokable]); - } - } } diff --git a/test/unit/Container/ConnectionInterfaceFactoryFactoryTest.php b/test/unit/Container/ConnectionInterfaceFactoryFactoryTest.php deleted file mode 100644 index a5a4783..0000000 --- a/test/unit/Container/ConnectionInterfaceFactoryFactoryTest.php +++ /dev/null @@ -1,130 +0,0 @@ -createMock(ContainerInterface::class); - $containerMock->method('get')->willReturnMap([ - [ - 'config', - [ - 'dependencies' => [ - 'aliases' => [ - 'sqlite' => Pdo::class, - ], - ], - 'db' => [ - 'adapters' => [ - 'test_adapter' => [ - 'driver' => 'sqlite', - ], - ], - ], - ], - ], - ]); - - $factoryFactory = new ConnectionInterfaceFactoryFactory(); - $result = $factoryFactory($containerMock, 'test_adapter'); - - self::assertIsCallable($result); - } - - public function testInvokeReturnsPdoConnectionFactory(): void - { - $containerMock = $this->createMock(ContainerInterface::class); - $containerMock->method('get')->willReturnMap([ - [ - 'config', - [ - 'dependencies' => [ - 'aliases' => [ - 'sqlite' => Pdo::class, - ], - ], - 'db' => [ - 'adapters' => [ - 'test_adapter' => [ - 'driver' => 'sqlite', - ], - ], - ], - ], - ], - ]); - - $factoryFactory = new ConnectionInterfaceFactoryFactory(); - $result = $factoryFactory($containerMock, 'test_adapter'); - - self::assertInstanceOf(PdoConnectionFactory::class, $result); - } - - public function testInvokeThrowsExceptionWhenDriverNotConfigured(): void - { - $containerMock = $this->createMock(ContainerInterface::class); - $containerMock->method('get')->willReturnMap([ - [ - 'config', - [ - 'db' => [ - 'adapters' => [ - 'test_adapter' => [], - ], - ], - ], - ], - ]); - - $factoryFactory = new ConnectionInterfaceFactoryFactory(); - - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('Named adapter "test_adapter" is not configured with a driver'); - - $factoryFactory($containerMock, 'test_adapter'); - } - - public function testInvokeThrowsExceptionForUnknownDriver(): void - { - $containerMock = $this->createMock(ContainerInterface::class); - $containerMock->method('get')->willReturnMap([ - [ - 'config', - [ - 'dependencies' => [ - 'aliases' => [ - 'sqlite' => Pdo::class, - ], - ], - 'db' => [ - 'adapters' => [ - 'test_adapter' => [ - 'driver' => 'unknown', - ], - ], - ], - ], - ], - ]); - - $factoryFactory = new ConnectionInterfaceFactoryFactory(); - - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('No connection factory found for driver "unknown"'); - - $factoryFactory($containerMock, 'test_adapter'); - } -} diff --git a/test/unit/Container/DriverInterfaceFactoryFactoryTest.php b/test/unit/Container/DriverInterfaceFactoryFactoryTest.php deleted file mode 100644 index 9a04f33..0000000 --- a/test/unit/Container/DriverInterfaceFactoryFactoryTest.php +++ /dev/null @@ -1,137 +0,0 @@ -createMock(ContainerInterface::class); - $containerMock->method('get')->willReturnMap([ - [ - 'config', - [ - 'dependencies' => [ - 'aliases' => [ - 'sqlite' => Pdo::class, - ], - 'factories' => [ - Pdo::class => PdoDriverFactory::class, - ], - ], - 'db' => [ - 'adapters' => [ - 'test_adapter' => [ - 'driver' => 'sqlite', - ], - ], - ], - ], - ], - ]); - - $factoryFactory = new DriverInterfaceFactoryFactory(); - $result = $factoryFactory($containerMock, 'test_adapter'); - - self::assertIsCallable($result); - } - - public function testInvokeReturnsPdoDriverFactory(): void - { - $containerMock = $this->createMock(ContainerInterface::class); - $containerMock->method('get')->willReturnMap([ - [ - 'config', - [ - 'dependencies' => [ - 'aliases' => [ - 'sqlite' => Pdo::class, - ], - 'factories' => [ - Pdo::class => PdoDriverFactory::class, - ], - ], - 'db' => [ - 'adapters' => [ - 'test_adapter' => [ - 'driver' => 'sqlite', - ], - ], - ], - ], - ], - ]); - - $factoryFactory = new DriverInterfaceFactoryFactory(); - $result = $factoryFactory($containerMock, 'test_adapter'); - - self::assertInstanceOf(PdoDriverFactory::class, $result); - } - - public function testInvokeThrowsExceptionWhenDriverNotConfigured(): void - { - $containerMock = $this->createMock(ContainerInterface::class); - $containerMock->method('get')->willReturnMap([ - [ - 'config', - [ - 'db' => [ - 'adapters' => [ - 'test_adapter' => [], - ], - ], - ], - ], - ]); - - $factoryFactory = new DriverInterfaceFactoryFactory(); - - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('Named adapter "test_adapter" is not configured with a driver'); - - $factoryFactory($containerMock, 'test_adapter'); - } - - public function testInvokeWithDriverNotInAliases(): void - { - $containerMock = $this->createMock(ContainerInterface::class); - $containerMock->method('get')->willReturnMap([ - [ - 'config', - [ - 'dependencies' => [ - 'aliases' => [ - 'sqlite' => Pdo::class, - ], - 'factories' => [ - Pdo::class => PdoDriverFactory::class, - ], - ], - 'db' => [ - 'adapters' => [ - 'test_adapter' => [ - 'driver' => Pdo::class, - ], - ], - ], - ], - ], - ]); - - $factoryFactory = new DriverInterfaceFactoryFactory(); - $result = $factoryFactory($containerMock, 'test_adapter'); - - self::assertInstanceOf(PdoDriverFactory::class, $result); - } -} diff --git a/test/unit/Container/MetadataInterfaceFactoryTest.php b/test/unit/Container/MetadataInterfaceFactoryTest.php index 525b84f..4b30c92 100644 --- a/test/unit/Container/MetadataInterfaceFactoryTest.php +++ b/test/unit/Container/MetadataInterfaceFactoryTest.php @@ -9,7 +9,7 @@ use PhpDb\Adapter\Driver\PdoDriverInterface; use PhpDb\Adapter\Platform\PlatformInterface; use PhpDb\Adapter\Sqlite\Container\MetadataInterfaceFactory; -use PhpDb\Adapter\Sqlite\Metadata\Source\SqliteMetadata; +use PhpDb\Adapter\Sqlite\Metadata; use PhpDb\ResultSet\ResultSetInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; @@ -35,6 +35,6 @@ public function testInvokeReturnsMetadata(): void $factory = new MetadataInterfaceFactory(); $metadata = $factory($containerMock); - self::assertInstanceOf(SqliteMetadata::class, $metadata); + self::assertInstanceOf(Metadata\Source::class, $metadata); } } diff --git a/test/unit/Container/PdoConnectionFactoryTest.php b/test/unit/Container/PdoConnectionFactoryTest.php index 3a5aee7..586b51f 100644 --- a/test/unit/Container/PdoConnectionFactoryTest.php +++ b/test/unit/Container/PdoConnectionFactoryTest.php @@ -5,7 +5,7 @@ namespace PhpDbTest\Adapter\Sqlite\Container; use PhpDb\Adapter\Sqlite\Container\PdoConnectionFactory; -use PhpDb\Adapter\Sqlite\Driver\Pdo\Connection; +use PhpDb\Adapter\Sqlite\Pdo\Connection; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; diff --git a/test/unit/Container/PlatformInterfaceFactoryFactoryTest.php b/test/unit/Container/PlatformInterfaceFactoryFactoryTest.php deleted file mode 100644 index ec2c0b6..0000000 --- a/test/unit/Container/PlatformInterfaceFactoryFactoryTest.php +++ /dev/null @@ -1,30 +0,0 @@ -pdo = new Pdo( + $this->pdo = new Driver( $connection, $statementPrototype, $this->createMock(ResultInterface::class), diff --git a/test/unit/Driver/Pdo/Feature/SqliteRowCounterTest.php b/test/unit/Pdo/Feature/SqliteRowCounterTest.php similarity index 80% rename from test/unit/Driver/Pdo/Feature/SqliteRowCounterTest.php rename to test/unit/Pdo/Feature/SqliteRowCounterTest.php index 97bb156..3549c3e 100644 --- a/test/unit/Driver/Pdo/Feature/SqliteRowCounterTest.php +++ b/test/unit/Pdo/Feature/SqliteRowCounterTest.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Sqlite\Driver\Pdo\Feature; +namespace PhpDbTest\Adapter\Sqlite\Pdo\Feature; -use PhpDb\Adapter\Sqlite\Driver\Pdo\Feature\SqliteRowCounter; +use PhpDb\Adapter\Sqlite\Pdo\Feature\SqliteRowCounter; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; diff --git a/test/unit/Driver/Pdo/StatementIntegrationTest.php b/test/unit/Pdo/StatementIntegrationTest.php similarity index 90% rename from test/unit/Driver/Pdo/StatementIntegrationTest.php rename to test/unit/Pdo/StatementIntegrationTest.php index b8d8d7f..8c35820 100644 --- a/test/unit/Driver/Pdo/StatementIntegrationTest.php +++ b/test/unit/Pdo/StatementIntegrationTest.php @@ -5,9 +5,10 @@ namespace PhpDbTest\Adapter\Sqlite\Driver\Pdo; use Override; +use PDO; use PDOStatement; use PhpDb\Adapter\Driver\Pdo\Statement; -use PhpDb\Adapter\Sqlite\Driver\Pdo\Pdo; +use PhpDb\Adapter\Sqlite\Pdo\Driver; use PhpDbTest\Adapter\Sqlite\Driver\Pdo\TestAsset\CtorlessPdo; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\MockObject\MockObject; @@ -25,7 +26,7 @@ public function testStatementExecuteWillConvertPhpBoolToPdoBoolWhenBinding(): vo $this->pdoStatementMock->expects($this->any())->method('bindParam')->with( $this->equalTo(':foo'), $this->equalTo(false), - $this->equalTo(\PDO::PARAM_BOOL) + $this->equalTo(PDO::PARAM_BOOL) ); $this->statement->execute(['foo' => false]); } @@ -35,7 +36,7 @@ public function testStatementExecuteWillUsePdoStrByDefaultWhenBinding(): void $this->pdoStatementMock->expects($this->any())->method('bindParam')->with( $this->equalTo(':foo'), $this->equalTo('bar'), - $this->equalTo(\PDO::PARAM_STR) + $this->equalTo(PDO::PARAM_STR) ); $this->statement->execute(['foo' => 'bar']); } @@ -45,7 +46,7 @@ public function testStatementExecuteWillUsePdoStrForStringIntegerWhenBinding(): $this->pdoStatementMock->expects($this->any())->method('bindParam')->with( $this->equalTo(':foo'), $this->equalTo('123'), - $this->equalTo(\PDO::PARAM_STR) + $this->equalTo(PDO::PARAM_STR) ); $this->statement->execute(['foo' => '123']); } @@ -55,7 +56,7 @@ public function testStatementExecuteWillUsePdoIntForIntWhenBinding(): void $this->pdoStatementMock->expects($this->any())->method('bindParam')->with( $this->equalTo(':foo'), $this->equalTo(123), - $this->equalTo(\PDO::PARAM_INT) + $this->equalTo(PDO::PARAM_INT) ); $this->statement->execute(['foo' => 123]); } @@ -67,7 +68,7 @@ public function testStatementExecuteWillUsePdoIntForIntWhenBinding(): void #[Override] protected function setUp(): void { - $driver = $this->getMockBuilder(Pdo::class) + $driver = $this->getMockBuilder(Driver::class) ->onlyMethods(['createResult']) ->disableOriginalConstructor() ->getMock(); diff --git a/test/unit/Driver/Pdo/TestAsset/CtorlessPdo.php b/test/unit/Pdo/TestAsset/CtorlessPdo.php similarity index 100% rename from test/unit/Driver/Pdo/TestAsset/CtorlessPdo.php rename to test/unit/Pdo/TestAsset/CtorlessPdo.php diff --git a/test/unit/Sql/Platform/Ddl/AlterTableDecoratorTest.php b/test/unit/Sql/Ddl/AlterTableDecoratorTest.php similarity index 98% rename from test/unit/Sql/Platform/Ddl/AlterTableDecoratorTest.php rename to test/unit/Sql/Ddl/AlterTableDecoratorTest.php index 331c66d..5cfe394 100644 --- a/test/unit/Sql/Platform/Ddl/AlterTableDecoratorTest.php +++ b/test/unit/Sql/Ddl/AlterTableDecoratorTest.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Sqlite\Sql\Platform\Ddl; +namespace PhpDbTest\Adapter\Sqlite\Sql\Ddl; -use PhpDb\Adapter\Sqlite\Sql\Platform\Ddl\AlterTableDecorator; +use PhpDb\Adapter\Sqlite\Sql\Ddl\AlterTableDecorator; use PhpDb\Sql\Ddl\AlterTable; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; diff --git a/test/unit/Sql/Platform/Ddl/CreateTableDecoratorTest.php b/test/unit/Sql/Ddl/CreateTableDecoratorTest.php similarity index 98% rename from test/unit/Sql/Platform/Ddl/CreateTableDecoratorTest.php rename to test/unit/Sql/Ddl/CreateTableDecoratorTest.php index 96a3323..1ef7fe5 100644 --- a/test/unit/Sql/Platform/Ddl/CreateTableDecoratorTest.php +++ b/test/unit/Sql/Ddl/CreateTableDecoratorTest.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Sqlite\Sql\Platform\Ddl; +namespace PhpDbTest\Adapter\Sqlite\Sql\Ddl; -use PhpDb\Adapter\Sqlite\Sql\Platform\Ddl\CreateTableDecorator; +use PhpDb\Adapter\Sqlite\Sql\Ddl\CreateTableDecorator; use PhpDb\Sql\Ddl\CreateTable; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; diff --git a/test/unit/Sql/Platform/SqliteTest.php b/test/unit/Sql/PlatformTest.php similarity index 77% rename from test/unit/Sql/Platform/SqliteTest.php rename to test/unit/Sql/PlatformTest.php index b3676ef..54b631c 100644 --- a/test/unit/Sql/Platform/SqliteTest.php +++ b/test/unit/Sql/PlatformTest.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Sqlite\Sql\Platform; +namespace PhpDbTest\Adapter\Sqlite\Sql; -use PhpDb\Adapter\Sqlite\Sql\Platform\Ddl\AlterTableDecorator; -use PhpDb\Adapter\Sqlite\Sql\Platform\Ddl\CreateTableDecorator; -use PhpDb\Adapter\Sqlite\Sql\Platform\SelectDecorator; -use PhpDb\Adapter\Sqlite\Sql\Platform\Sqlite; +use PhpDb\Adapter\Sqlite\Sql\Ddl\AlterTableDecorator; +use PhpDb\Adapter\Sqlite\Sql\Ddl\CreateTableDecorator; +use PhpDb\Adapter\Sqlite\Sql\Platform; +use PhpDb\Adapter\Sqlite\Sql\SelectDecorator; use PhpDb\Sql\Ddl\AlterTable; use PhpDb\Sql\Ddl\CreateTable; use PhpDb\Sql\Select; @@ -15,19 +15,19 @@ use PHPUnit\Framework\TestCase; use ReflectionClass; -#[CoversClass(Sqlite::class)] -final class SqliteTest extends TestCase +#[CoversClass(Platform::class)] +final class PlatformTest extends TestCase { - private Sqlite $platform; + private Platform $platform; protected function setUp(): void { - $this->platform = new Sqlite(); + $this->platform = new Platform(); } public function testConstructorSetsTypeDecorators(): void { - self::assertInstanceOf(Sqlite::class, $this->platform); + self::assertInstanceOf(Platform::class, $this->platform); } public function testSelectDecoratorIsRegistered(): void diff --git a/test/unit/Sql/Platform/SelectDecoratorTest.php b/test/unit/Sql/SelectDecoratorTest.php similarity index 98% rename from test/unit/Sql/Platform/SelectDecoratorTest.php rename to test/unit/Sql/SelectDecoratorTest.php index 309d7ce..c319d14 100644 --- a/test/unit/Sql/Platform/SelectDecoratorTest.php +++ b/test/unit/Sql/SelectDecoratorTest.php @@ -7,7 +7,7 @@ use PhpDb\Adapter\Driver\DriverInterface; use PhpDb\Adapter\ParameterContainer; use PhpDb\Adapter\Platform\PlatformInterface; -use PhpDb\Adapter\Sqlite\Sql\Platform\SelectDecorator; +use PhpDb\Adapter\Sqlite\Sql\SelectDecorator; use PhpDb\Sql\Select; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; From 6ec64794892f6e6909a24d4d83d19d2d61c822da Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Wed, 14 Jan 2026 01:14:07 -0600 Subject: [PATCH 2/2] Aligns code well enough that both adapter interface config and named adapters will load a configured adapter service. Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- composer.lock | 20 +-- src/AdapterPlatform.php | 2 +- src/ConfigProvider.php | 70 +++++------ src/Container/AdapterInterfaceFactory.php | 79 ------------ src/Container/MetadataInterfaceFactory.php | 1 + src/Container/PdoConnectionFactory.php | 13 +- src/Container/PdoDriverFactory.php | 63 ---------- src/Container/PdoDriverInterfaceFactory.php | 47 +++++++ src/Container/PlatformInterfaceFactory.php | 36 +++--- src/Metadata/Source.php | 3 + src/Pdo/Connection.php | 2 +- src/Pdo/Driver.php | 2 +- .../Container/AdapterInterfaceFactoryTest.php | 25 ---- ....php => PdoDriverInterfaceFactoryTest.php} | 17 ++- .../PlatformInterfaceFactoryTest.php | 30 ----- .../Container/TestAsset/SetupTrait.php | 6 +- test/unit/AdapterPlatformTest.php | 69 +++-------- test/unit/ConfigProviderTest.php | 117 +++++------------- .../Container/PdoConnectionFactoryTest.php | 38 ------ test/unit/Container/PdoDriverFactoryTest.php | 20 --- .../PdoDriverInterfaceFactoryTest.php | 20 +++ .../PlatformInterfaceFactoryTest.php | 24 ---- test/unit/Pdo/DriverTest.php | 3 +- test/unit/Pdo/StatementIntegrationTest.php | 2 +- test/unit/Pdo/TestAsset/CtorlessPdo.php | 2 +- 25 files changed, 195 insertions(+), 516 deletions(-) delete mode 100644 src/Container/AdapterInterfaceFactory.php delete mode 100644 src/Container/PdoDriverFactory.php create mode 100644 src/Container/PdoDriverInterfaceFactory.php delete mode 100644 test/integration/Container/AdapterInterfaceFactoryTest.php rename test/integration/Container/{PdoDriverFactoryTest.php => PdoDriverInterfaceFactoryTest.php} (55%) delete mode 100644 test/integration/Container/PlatformInterfaceFactoryTest.php delete mode 100644 test/unit/Container/PdoDriverFactoryTest.php create mode 100644 test/unit/Container/PdoDriverInterfaceFactoryTest.php delete mode 100644 test/unit/Container/PlatformInterfaceFactoryTest.php diff --git a/composer.lock b/composer.lock index 6a476f9..bcea1af 100644 --- a/composer.lock +++ b/composer.lock @@ -263,12 +263,12 @@ "source": { "type": "git", "url": "https://github.com/php-db/phpdb.git", - "reference": "358211307cf82dbc107d6f2759276c737b741117" + "reference": "e28a824dcb6e3c8acdff9a5734dcc487e6d93243" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-db/phpdb/zipball/358211307cf82dbc107d6f2759276c737b741117", - "reference": "358211307cf82dbc107d6f2759276c737b741117", + "url": "https://api.github.com/repos/php-db/phpdb/zipball/e28a824dcb6e3c8acdff9a5734dcc487e6d93243", + "reference": "e28a824dcb6e3c8acdff9a5734dcc487e6d93243", "shasum": "" }, "require": { @@ -324,7 +324,7 @@ "issues": "https://github.com/php-db/phpdb/issues", "source": "https://github.com/php-db/phpdb" }, - "time": "2026-01-06T06:52:43+00:00" + "time": "2026-01-13T22:14:01+00:00" }, { "name": "psr/container", @@ -768,16 +768,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "2.3.0", + "version": "2.3.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "1e0cd5370df5dd2e556a36b9c62f62e555870495" + "reference": "16dbf9937da8d4528ceb2145c9c7c0bd29e26374" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/1e0cd5370df5dd2e556a36b9c62f62e555870495", - "reference": "1e0cd5370df5dd2e556a36b9c62f62e555870495", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/16dbf9937da8d4528ceb2145c9c7c0bd29e26374", + "reference": "16dbf9937da8d4528ceb2145c9c7c0bd29e26374", "shasum": "" }, "require": { @@ -809,9 +809,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/2.3.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/2.3.1" }, - "time": "2025-08-30T15:50:23+00:00" + "time": "2026-01-12T11:33:04+00:00" }, { "name": "phpstan/phpstan", diff --git a/src/AdapterPlatform.php b/src/AdapterPlatform.php index d65851d..3ce8e49 100644 --- a/src/AdapterPlatform.php +++ b/src/AdapterPlatform.php @@ -27,7 +27,7 @@ class AdapterPlatform extends AbstractPlatform protected string $quoteIdentifierTo = '\''; public function __construct( - protected readonly PdoDriverInterface|PDO $driver + protected readonly PdoDriverInterface|PDO|null $driver = null ) { } diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 743ac80..a0bc81e 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -4,10 +4,7 @@ namespace PhpDb\Adapter\Sqlite; -use Laminas\ServiceManager\Factory\InvokableFactory; use PhpDb\Adapter\AdapterInterface; -use PhpDb\Adapter\Driver\ConnectionInterface; -use PhpDb\Adapter\Driver\DriverInterface; use PhpDb\Adapter\Driver\Pdo\Result; use PhpDb\Adapter\Driver\Pdo\Statement; use PhpDb\Adapter\Driver\PdoConnectionInterface; @@ -15,11 +12,7 @@ use PhpDb\Adapter\Driver\ResultInterface; use PhpDb\Adapter\Driver\StatementInterface; use PhpDb\Adapter\Platform\PlatformInterface; -use PhpDb\Adapter\Profiler\Profiler; -use PhpDb\Adapter\Profiler\ProfilerInterface; -use PhpDb\Container\AbstractAdapterInterfaceFactory; use PhpDb\Metadata\MetadataInterface; -use PhpDb\ResultSet; final class ConfigProvider { @@ -27,44 +20,45 @@ public function __invoke(): array { return [ 'dependencies' => $this->getDependencies(), + //AdapterInterface::class => $this->getConfig(), ]; } - public function getDependencies(): array + public function getConfig(): array { return [ - 'abstract_factories' => [ - AbstractAdapterInterfaceFactory::class, + 'driver' => PdoDriverInterface::class, + 'connection' => [ + 'dsn' => 'sqlite::memory:', ], - 'aliases' => [ - 'SQLite' => Pdo\Driver::class, - 'Sqlite' => Pdo\Driver::class, - 'sqlite' => Pdo\Driver::class, - 'pdo' => Pdo\Driver::class, - 'pdo_sqlite' => Pdo\Driver::class, - 'pdosqlite' => Pdo\Driver::class, - 'pdodriver' => Pdo\Driver::class, - ConnectionInterface::class => Pdo\Connection::class, - PdoConnectionInterface::class => Pdo\Connection::class, - DriverInterface::class => Pdo\Driver::class, - PdoDriverInterface::class => Pdo\Driver::class, - PlatformInterface::class => AdapterPlatform::class, - ProfilerInterface::class => Profiler::class, - ResultInterface::class => Result::class, - ResultSet\ResultSetInterface::class => ResultSet\ResultSet::class, - StatementInterface::class => Statement::class, - MetadataInterface::class => Metadata\Source::class, + ]; + } + + public function getDependencies(): array + { + return [ + 'aliases' => [ + 'SQLite' => Pdo\Driver::class, + 'Sqlite' => Pdo\Driver::class, + 'sqlite' => Pdo\Driver::class, + 'pdo' => Pdo\Driver::class, + 'pdo_sqlite' => Pdo\Driver::class, + 'pdosqlite' => Pdo\Driver::class, + 'pdodriver' => Pdo\Driver::class, + PdoConnectionInterface::class => Pdo\Connection::class, + PdoDriverInterface::class => Pdo\Driver::class, + PlatformInterface::class => AdapterPlatform::class, + ResultInterface::class => Result::class, + StatementInterface::class => Statement::class, + MetadataInterface::class => Metadata\Source::class, ], - 'factories' => [ - AdapterInterface::class => Container\AdapterInterfaceFactory::class, - Pdo\Connection::class => Container\PdoConnectionFactory::class, - Pdo\Driver::class => Container\PdoDriverFactory::class, - Result::class => Container\PdoResultFactory::class, - Statement::class => Container\PdoStatementFactory::class, - AdapterPlatform::class => Container\PlatformInterfaceFactory::class, - Profiler::class => InvokableFactory::class, - ResultSet\ResultSet::class => InvokableFactory::class, - Metadata\Source::class => Container\MetadataInterfaceFactory::class, + 'factories' => [ + Pdo\Connection::class => Container\PdoConnectionFactory::class, + Pdo\Driver::class => Container\PdoDriverInterfaceFactory::class, + Result::class => Container\PdoResultFactory::class, + Statement::class => Container\PdoStatementFactory::class, + AdapterPlatform::class => Container\PlatformInterfaceFactory::class, + Metadata\Source::class => Container\MetadataInterfaceFactory::class, ], ]; } diff --git a/src/Container/AdapterInterfaceFactory.php b/src/Container/AdapterInterfaceFactory.php deleted file mode 100644 index 692f974..0000000 --- a/src/Container/AdapterInterfaceFactory.php +++ /dev/null @@ -1,79 +0,0 @@ -get('config'); - - /** @var array $dbConfig */ - $dbConfig = $config['db'] ?? []; - - if (! isset($dbConfig['driver'])) { - throw new RuntimeException('Database driver configuration is missing.'); - } - - /** @var string $driver */ - $driver = $dbConfig['driver']; - - if (! $container->has($driver)) { - throw new ServiceNotFoundException(sprintf( - 'Database driver "%s" is not registered in the adapter manager.', - $driver - )); - } - - /** @var DriverInterface|PdoDriverInterface $driverInstance */ - $driverInstance = $container->get($driver); - - if (! $container->has(PlatformInterface::class)) { - throw new ServiceNotFoundException(sprintf( - 'Database platform "%s" is not registered in the adapter manager.', - PlatformInterface::class - )); - } - - /** @var PlatformInterface $platformInstance */ - $platformInstance = $container->get(PlatformInterface::class); - - if (! $container->has(ResultSetInterface::class)) { - throw new ServiceNotFoundException(sprintf( - 'ResultSet "%s" is not registered in the adapter manager.', - ResultSetInterface::class - )); - } - - /** @var ResultSetInterface $resultSetInstance */ - $resultSetInstance = $container->get(ResultSetInterface::class); - - /** @var ProfilerInterface|null $profilerInstanceOrNull */ - $profilerInstanceOrNull = $container->has(ProfilerInterface::class) - ? $container->get(ProfilerInterface::class) - : null; - - return new Adapter( - $driverInstance, - $platformInstance, - $resultSetInstance, - $profilerInstanceOrNull - ); - } -} diff --git a/src/Container/MetadataInterfaceFactory.php b/src/Container/MetadataInterfaceFactory.php index 25baa0b..bc68625 100644 --- a/src/Container/MetadataInterfaceFactory.php +++ b/src/Container/MetadataInterfaceFactory.php @@ -5,6 +5,7 @@ namespace PhpDb\Adapter\Sqlite\Container; use PhpDb\Adapter\AdapterInterface; +use PhpDb\Adapter\SchemaAwareInterface; use PhpDb\Adapter\Sqlite\Metadata; use PhpDb\Metadata\MetadataInterface; use Psr\Container\ContainerInterface; diff --git a/src/Container/PdoConnectionFactory.php b/src/Container/PdoConnectionFactory.php index 346e9f4..5fc0170 100644 --- a/src/Container/PdoConnectionFactory.php +++ b/src/Container/PdoConnectionFactory.php @@ -4,8 +4,9 @@ namespace PhpDb\Adapter\Sqlite\Container; +use PhpDb\Adapter\AdapterInterface; use PhpDb\Adapter\Driver\ConnectionInterface; -use PhpDb\Adapter\Sqlite\Driver\Pdo\Connection; +use PhpDb\Adapter\Sqlite\Pdo\Connection; use Psr\Container\ContainerInterface; final class PdoConnectionFactory @@ -16,19 +17,11 @@ public function __invoke(ContainerInterface $container): ConnectionInterface&Con $config = $container->get('config'); /** @var array $dbConfig */ - $dbConfig = $config['db'] ?? []; + $dbConfig = $config[AdapterInterface::class] ?? []; /** @var array $connectionConfig */ $connectionConfig = $dbConfig['connection'] ?? []; return new Connection($connectionConfig); } - - public static function createFromConfig( - ContainerInterface $container, - string $requestedName - ): ConnectionInterface&Connection { - $adapterConfig = $container->get('config')['db']['adapters'][$requestedName] ?? []; - return new Connection($adapterConfig['connection'] ?? []); - } } diff --git a/src/Container/PdoDriverFactory.php b/src/Container/PdoDriverFactory.php deleted file mode 100644 index 73d16f0..0000000 --- a/src/Container/PdoDriverFactory.php +++ /dev/null @@ -1,63 +0,0 @@ -get(Connection::class); - - /** @var StatementInterface&Statement $statementInstance */ - $statementInstance = $container->get(Statement::class); - - /** @var ResultInterface&Result $resultInstance */ - $resultInstance = $container->get(Result::class); - - return new PdoDriver( - $connectionInstance, - $statementInstance, - $resultInstance, - [new SqliteRowCounter()], - ); - } - - public static function createFromConfig( - ContainerInterface $container, - string $requestedName, - ): PdoDriverInterface&PdoDriver { - $connectionFactory = ( - $container->get(ConnectionInterfaceFactoryFactory::class) - )($container, $requestedName); - - /** @var ConnectionInterface&Connection $connectionInstance */ - $connectionInstance = $connectionFactory::createFromConfig($container, $requestedName); - - /** @var StatementInterface&Statement $statementInstance */ - $statementInstance = $container->get(Statement::class); - - /** @var ResultInterface&Result $resultInstance */ - $resultInstance = $container->get(Result::class); - - return new PdoDriver( - $connectionInstance, - $statementInstance, - $resultInstance, - [new SqliteRowCounter()], - ); - } -} diff --git a/src/Container/PdoDriverInterfaceFactory.php b/src/Container/PdoDriverInterfaceFactory.php new file mode 100644 index 0000000..67e4b20 --- /dev/null +++ b/src/Container/PdoDriverInterfaceFactory.php @@ -0,0 +1,47 @@ +has('config')) { + // throw ContainerException::forService( + // Pdo\Driver::class, + // self::class, + // 'Container is missing config service' + // ); + // } + + /** @var Pdo\Connection $connectionInstance */ + $connectionInstance = $container->build( + Pdo\Connection::class, ['connection' => $options['connection'] ?? []] + ); + + /** @var ResultInterface&Result $resultInstance */ + $resultInstance = $container->has(ResultInterface::class) + ? $container->get(ResultInterface::class) + : new Result(); + + return new Pdo\Driver( + connection:$connectionInstance, + statementPrototype: $container->build(Statement::class, $options['options'] ?? []), + resultPrototype: $resultInstance, + features: [new Pdo\Feature\SqliteRowCounter()], + ); + } +} diff --git a/src/Container/PlatformInterfaceFactory.php b/src/Container/PlatformInterfaceFactory.php index d243525..f549413 100644 --- a/src/Container/PlatformInterfaceFactory.php +++ b/src/Container/PlatformInterfaceFactory.php @@ -4,33 +4,27 @@ namespace PhpDb\Adapter\Sqlite\Container; -use PDO; -use PhpDb\Adapter\Driver\PdoDriverInterface; use PhpDb\Adapter\Platform\PlatformInterface; use PhpDb\Adapter\Sqlite\AdapterPlatform; +use PhpDb\Adapter\Sqlite\Pdo\Driver; +use PhpDb\Exception\ContainerException; use Psr\Container\ContainerInterface; final class PlatformInterfaceFactory { - public function __invoke(ContainerInterface $container): PlatformInterface&AdapterPlatform - { - /** @var array $config */ - $config = $container->get('config'); - - /** @var array $dbConfig */ - $dbConfig = $config['db'] ?? []; - - /** @var string $driver */ - $driver = $dbConfig['driver']; - - /** @var PdoDriverInterface|PDO $driverInstance */ - $driverInstance = $container->get($driver); - - return new AdapterPlatform($driverInstance); - } - - public static function fromDriver(PdoDriverInterface $driverInstance): PlatformInterface&AdapterPlatform - { + public function __invoke( + ContainerInterface $container, + string $requestedName, + ?array $options = null + ): PlatformInterface&AdapterPlatform { + $driverInstance = $options['driver'] ?? null; + if (! $driverInstance instanceof Driver) { + throw ContainerException::forService( + AdapterPlatform::class, + self::class, + 'Invalid or missing driver provided recieved: ' + ); + } return new AdapterPlatform($driverInstance); } } diff --git a/src/Metadata/Source.php b/src/Metadata/Source.php index d1a2de4..c7c452d 100644 --- a/src/Metadata/Source.php +++ b/src/Metadata/Source.php @@ -28,6 +28,9 @@ protected function loadSchemaData(): void $this->prepareDataHierarchy('schemas'); $results = $this->fetchPragma('database_list'); + // proposed phpstan fix + $schemas = $results !== [] ? [] : null; + // end proposed fix foreach ($results as $row) { $schemas[] = $row['name']; } diff --git a/src/Pdo/Connection.php b/src/Pdo/Connection.php index 306356f..4a39f14 100644 --- a/src/Pdo/Connection.php +++ b/src/Pdo/Connection.php @@ -119,7 +119,7 @@ public function connect(): ConnectionInterface * @param string $name */ #[Override] - public function getLastGeneratedValue($name = null): string|int|bool|null + public function getLastGeneratedValue($name = null): string|int|false|null { try { return $this->resource->lastInsertId($name); diff --git a/src/Pdo/Driver.php b/src/Pdo/Driver.php index a1b4982..2d7f767 100644 --- a/src/Pdo/Driver.php +++ b/src/Pdo/Driver.php @@ -19,7 +19,7 @@ class Driver extends AbstractPdo implements DriverFeatureProviderInterface use DriverFeatureProviderTrait; /** - * @param PDOStatement $resource + * @param PDOStatement|resource $resource * @param mixed $context */ #[Override] diff --git a/test/integration/Container/AdapterInterfaceFactoryTest.php b/test/integration/Container/AdapterInterfaceFactoryTest.php deleted file mode 100644 index 660dd00..0000000 --- a/test/integration/Container/AdapterInterfaceFactoryTest.php +++ /dev/null @@ -1,25 +0,0 @@ -container); - self::assertInstanceOf(AdapterInterface::class, $adapter); - } -} diff --git a/test/integration/Container/PdoDriverFactoryTest.php b/test/integration/Container/PdoDriverInterfaceFactoryTest.php similarity index 55% rename from test/integration/Container/PdoDriverFactoryTest.php rename to test/integration/Container/PdoDriverInterfaceFactoryTest.php index b79733a..c5417a9 100644 --- a/test/integration/Container/PdoDriverFactoryTest.php +++ b/test/integration/Container/PdoDriverInterfaceFactoryTest.php @@ -4,8 +4,9 @@ namespace PhpDbIntegrationTest\Adapter\Sqlite\Container; +use PhpDb\Adapter\AdapterInterface; use PhpDb\Adapter\Driver\PdoDriverInterface; -use PhpDb\Adapter\Sqlite\Container\PdoDriverFactory; +use PhpDb\Adapter\Sqlite\Container\PdoDriverInterfaceFactory; use PhpDb\Adapter\Sqlite\Pdo\Driver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversMethod; @@ -14,16 +15,20 @@ #[Group('container')] #[Group('integration')] -#[CoversClass(PdoDriverFactory::class)] -#[CoversMethod(PdoDriverFactory::class, '__invoke')] -final class PdoDriverFactoryTest extends TestCase +#[CoversClass(PdoDriverInterfaceFactory::class)] +#[CoversMethod(PdoDriverInterfaceFactory::class, '__invoke')] +final class PdoDriverInterfaceFactoryTest extends TestCase { use TestAsset\SetupTrait; public function testInvokeReturnsPdoDriver(): void { - $factory = new PdoDriverFactory(); - $instance = $factory($this->container); + $factory = new PdoDriverInterfaceFactory(); + $instance = $factory( + $this->container, + Driver::class, + $this->container->get('config')[AdapterInterface::class] + ); self::assertInstanceOf(PdoDriverInterface::class, $instance); self::assertInstanceOf(Driver::class, $instance); diff --git a/test/integration/Container/PlatformInterfaceFactoryTest.php b/test/integration/Container/PlatformInterfaceFactoryTest.php deleted file mode 100644 index 6d6ae3c..0000000 --- a/test/integration/Container/PlatformInterfaceFactoryTest.php +++ /dev/null @@ -1,30 +0,0 @@ -container); - self::assertInstanceOf(PlatformInterface::class, $instance); - self::assertInstanceOf(AdapterPlatform::class, $instance); - } -} diff --git a/test/integration/Container/TestAsset/SetupTrait.php b/test/integration/Container/TestAsset/SetupTrait.php index d3b2a76..60d84f0 100644 --- a/test/integration/Container/TestAsset/SetupTrait.php +++ b/test/integration/Container/TestAsset/SetupTrait.php @@ -26,11 +26,11 @@ #[RequiresPhpExtension('pdo_sqlite')] trait SetupTrait { - protected array $config = ['db' => []]; + protected array $config = [AdapterInterface::class => []]; protected ?AdapterInterface $adapter; - protected ContainerInterface $container; + protected ContainerInterface&ServiceManager $container; protected DriverInterface|string|null $driver; @@ -44,7 +44,7 @@ protected function setUp(): void protected function getAdapter(array $config = []): AdapterInterface { $connectionConfig = [ - 'db' => [ + AdapterInterface::class => [ 'driver' => $this->driver ?? Driver::class, 'connection' => [ 'dsn' => 'sqlite::memory:', diff --git a/test/unit/AdapterPlatformTest.php b/test/unit/AdapterPlatformTest.php index 9a12ac3..c2a1ac3 100644 --- a/test/unit/AdapterPlatformTest.php +++ b/test/unit/AdapterPlatformTest.php @@ -6,16 +6,12 @@ use PDO; use PhpDb\Adapter\Driver\PdoDriverInterface; +use PhpDb\Adapter\Exception\VunerablePlatformQuoteException; use PhpDb\Adapter\Sqlite\AdapterPlatform; use PhpDb\Adapter\Sqlite\Sql\Platform as SqlPlatformDecorator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -use function restore_error_handler; -use function set_error_handler; - -use const E_USER_NOTICE; - #[CoversClass(AdapterPlatform::class)] final class AdapterPlatformTest extends TestCase { @@ -93,32 +89,21 @@ public function testGetQuoteValueSymbol(): void self::assertEquals("'", $this->platform->getQuoteValueSymbol()); } - public function testQuoteValueRaisesNoticeWithoutPlatformSupport(): void - { - $raisedNotice = false; - - set_error_handler( - function ( - int $errno, - string $errstr, - ?string $errfile = null, - ?int $errline = null - ) use (&$raisedNotice) { - $this->assertEquals(E_USER_NOTICE, $errno); - $this->assertEquals( - $errstr, - // phpcs:ignore Generic.Files.LineLength - 'Attempting to quote a value in PhpDb\Adapter\Sqlite\Platform without extension/driver support can ' - . 'introduce security vulnerabilities in a production environment' - ); - $raisedNotice = true; - } - ); - - $this->platform->quoteValue('value'); - self::assertTrue($raisedNotice); + public function testQuoteValueThrowsExeceptionWithoutDriverSupport(): void + { + $platform = new AdapterPlatform(); + //$this->expectNotToPerformAssertions(); + $this->expectException(VunerablePlatformQuoteException::class); + $platform->quoteValue('value'); + } - restore_error_handler(); + public function testQuoteValueList(): void + { + $expected = "'Foo O\\'Bar'"; + $platform = new AdapterPlatform(); + $this->expectException(VunerablePlatformQuoteException::class); + $actual = $platform->quoteValueList("Foo O'Bar"); + self::assertEquals($expected, $actual); } public function testQuoteValue(): void @@ -151,30 +136,6 @@ public function testQuoteTrustedValue(): void ); } - public function testQuoteValueList(): void - { - $raisedNotice = false; - - /** - * @psalm-suppress InvalidArgument - */ - set_error_handler(function ($errno, $errstr) use (&$raisedNotice) { - $this->assertEquals(E_USER_NOTICE, $errno); - $this->assertEquals( - $errstr, - // phpcs:ignore Generic.Files.LineLength - 'Attempting to quote a value in PhpDb\Adapter\Sqlite\Platform\Sqlite without extension/driver support can ' - . 'introduce security vulnerabilities in a production environment' - ); - $raisedNotice = true; - }); - - self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteValueList("Foo O'Bar")); - self::assertTrue($raisedNotice); - - restore_error_handler(); - } - public function testGetIdentifierSeparator(): void { self::assertEquals('.', $this->platform->getIdentifierSeparator()); diff --git a/test/unit/ConfigProviderTest.php b/test/unit/ConfigProviderTest.php index 0247d4b..e5aa825 100644 --- a/test/unit/ConfigProviderTest.php +++ b/test/unit/ConfigProviderTest.php @@ -4,10 +4,6 @@ namespace PhpDbTest\Adapter\Sqlite; -use Laminas\ServiceManager\Factory\InvokableFactory; -use PhpDb\Adapter\AdapterInterface; -use PhpDb\Adapter\Driver\ConnectionInterface; -use PhpDb\Adapter\Driver\DriverInterface; use PhpDb\Adapter\Driver\Pdo\Result; use PhpDb\Adapter\Driver\Pdo\Statement; use PhpDb\Adapter\Driver\PdoConnectionInterface; @@ -15,23 +11,33 @@ use PhpDb\Adapter\Driver\ResultInterface; use PhpDb\Adapter\Driver\StatementInterface; use PhpDb\Adapter\Platform\PlatformInterface; -use PhpDb\Adapter\Profiler\Profiler; -use PhpDb\Adapter\Profiler\ProfilerInterface; use PhpDb\Adapter\Sqlite\AdapterPlatform; use PhpDb\Adapter\Sqlite\ConfigProvider; use PhpDb\Adapter\Sqlite\Container; use PhpDb\Adapter\Sqlite\Metadata; -use PhpDb\Adapter\Sqlite\Pdo\Connection; -use PhpDb\Adapter\Sqlite\Pdo\Driver; -use PhpDb\Container\AbstractAdapterInterfaceFactory; +use PhpDb\Adapter\Sqlite\Pdo; use PhpDb\Metadata\MetadataInterface; -use PhpDb\ResultSet; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; #[CoversClass(ConfigProvider::class)] final class ConfigProviderTest extends TestCase { + public const EXPECTED_ALIASES = [ + 'SQLite' => Pdo\Driver::class, + 'Sqlite' => Pdo\Driver::class, + 'sqlite' => Pdo\Driver::class, + 'pdo' => Pdo\Driver::class, + 'pdo_sqlite' => Pdo\Driver::class, + 'pdosqlite' => Pdo\Driver::class, + 'pdodriver' => Pdo\Driver::class, + PdoConnectionInterface::class => Pdo\Connection::class, + PdoDriverInterface::class => Pdo\Driver::class, + PlatformInterface::class => AdapterPlatform::class, + ResultInterface::class => Result::class, + StatementInterface::class => Statement::class, + MetadataInterface::class => Metadata\Source::class, + ]; private ConfigProvider $configProvider; protected function setUp(): void @@ -43,27 +49,25 @@ public function testInvokeReturnsExpectedStructure(): void { $config = ($this->configProvider)(); + self::assertNotEmpty($config); self::assertArrayHasKey('dependencies', $config); } - public function testGetDependenciesReturnsCorrectStructure(): void + public function testInvokeReturnsCorrectStructure(): void { - $dependencies = $this->configProvider->getDependencies(); - - self::assertIsArray($dependencies); - self::assertArrayHasKey('abstract_factories', $dependencies); - self::assertArrayHasKey('aliases', $dependencies); - self::assertArrayHasKey('factories', $dependencies); + $config = (new ConfigProvider())(); + self::assertArrayHasKey('dependencies', $config); + self::assertArrayHasKey('aliases', $config['dependencies']); + self::assertArrayHasKey('factories', $config['dependencies']); } - public function testGetDependenciesContainsAbstractFactories(): void + public function testGetDependenciesReturnsCorrectStructure(): void { $dependencies = $this->configProvider->getDependencies(); - self::assertContains( - AbstractAdapterInterfaceFactory::class, - $dependencies['abstract_factories'] - ); + self::assertNotEmpty($dependencies); + self::assertArrayHasKey('aliases', $dependencies); + self::assertArrayHasKey('factories', $dependencies); } public function testGetDependenciesContainsMetadataAlias(): void @@ -88,74 +92,9 @@ public function testGetDependenciesContainsMetadataFactory(): void ); } - public function testConfigReturnsCorrectStructure(): void - { - $config = $this->configProvider->getDependencies(); - - self::assertArrayHasKey('aliases', $config); - self::assertArrayHasKey('factories', $config); - } - - public function testGetDependenciesContainsDriverAliases(): void + public function testGetDependenciesContainsExpectedAliases(): void { $config = $this->configProvider->getDependencies(); - - $expectedAliases = [ - 'SQLite' => Driver::class, - 'Sqlite' => Driver::class, - 'sqlite' => Driver::class, - 'pdo' => Driver::class, - 'pdo_sqlite' => Driver::class, - 'pdosqlite' => Driver::class, - 'pdodriver' => Driver::class, - ]; - - foreach ($expectedAliases as $alias => $target) { - self::assertArrayHasKey($alias, $config['aliases']); - self::assertSame($target, $config['aliases'][$alias]); - } - } - - public function testGetDependenciesContainsInterfaceAliases(): void - { - $config = $this->configProvider->getDependencies(); - - $expectedAliases = [ - ConnectionInterface::class => Connection::class, - PdoConnectionInterface::class => Connection::class, - DriverInterface::class => Driver::class, - PdoDriverInterface::class => Driver::class, - PlatformInterface::class => AdapterPlatform::class, - ProfilerInterface::class => Profiler::class, - ResultInterface::class => Result::class, - ResultSet\ResultSetInterface::class => ResultSet\ResultSet::class, - StatementInterface::class => Statement::class, - ]; - - foreach ($expectedAliases as $interface => $implementation) { - self::assertArrayHasKey($interface, $config['aliases']); - self::assertSame($implementation, $config['aliases'][$interface]); - } - } - - public function testConfigContainsFactories(): void - { - $config = $this->configProvider->getDependencies(); - - $expectedFactories = [ - AdapterInterface::class => Container\AdapterInterfaceFactory::class, - Connection::class => Container\PdoConnectionFactory::class, - Driver::class => Container\PdoDriverFactory::class, - Result::class => Container\PdoResultFactory::class, - Statement::class => Container\PdoStatementFactory::class, - AdapterPlatform::class => Container\PlatformInterfaceFactory::class, - Profiler::class => InvokableFactory::class, - ResultSet\ResultSet::class => InvokableFactory::class, - ]; - - foreach ($expectedFactories as $service => $factory) { - self::assertArrayHasKey($service, $config['factories']); - self::assertSame($factory, $config['factories'][$service]); - } + self::assertEquals(self::EXPECTED_ALIASES, $config['aliases']); } } diff --git a/test/unit/Container/PdoConnectionFactoryTest.php b/test/unit/Container/PdoConnectionFactoryTest.php index 586b51f..e8936b8 100644 --- a/test/unit/Container/PdoConnectionFactoryTest.php +++ b/test/unit/Container/PdoConnectionFactoryTest.php @@ -59,42 +59,4 @@ public function testInvokeWithoutDbConfig(): void self::assertInstanceOf(Connection::class, $connection); } - - public function testCreateFromConfigReturnsConnection(): void - { - $containerMock = $this->createMock(ContainerInterface::class); - $containerMock->method('get') - ->with('config') - ->willReturn([ - 'db' => [ - 'adapters' => [ - 'test_adapter' => [ - 'connection' => [ - 'dsn' => 'sqlite::memory:', - ], - ], - ], - ], - ]); - - $connection = PdoConnectionFactory::createFromConfig($containerMock, 'test_adapter'); - - self::assertInstanceOf(Connection::class, $connection); - } - - public function testCreateFromConfigWithoutAdapterConfig(): void - { - $containerMock = $this->createMock(ContainerInterface::class); - $containerMock->method('get') - ->with('config') - ->willReturn([ - 'db' => [ - 'adapters' => [], - ], - ]); - - $connection = PdoConnectionFactory::createFromConfig($containerMock, 'unknown_adapter'); - - self::assertInstanceOf(Connection::class, $connection); - } } diff --git a/test/unit/Container/PdoDriverFactoryTest.php b/test/unit/Container/PdoDriverFactoryTest.php deleted file mode 100644 index f8e2826..0000000 --- a/test/unit/Container/PdoDriverFactoryTest.php +++ /dev/null @@ -1,20 +0,0 @@ -createMock(PdoDriverInterface::class); - - $platform = PlatformInterfaceFactory::fromDriver($driverMock); - - self::assertInstanceOf(AdapterPlatform::class, $platform); - } -} diff --git a/test/unit/Pdo/DriverTest.php b/test/unit/Pdo/DriverTest.php index d226de5..9a8d31e 100644 --- a/test/unit/Pdo/DriverTest.php +++ b/test/unit/Pdo/DriverTest.php @@ -14,6 +14,7 @@ use PhpDb\Exception\RuntimeException; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; #[CoversMethod(Driver::class, 'getDatabasePlatformName')] @@ -30,7 +31,7 @@ protected function setUp(): void { $connection = new Connection(['dsn' => ':memory:']); - /** @var StatementInterface&PdoDriverAwareInterface $statementPrototype */ + /** @var StatementInterface&PdoDriverAwareInterface&MockObject $statementPrototype */ $statementPrototype = $this->createMockForIntersectionOfInterfaces([ StatementInterface::class, PdoDriverAwareInterface::class, diff --git a/test/unit/Pdo/StatementIntegrationTest.php b/test/unit/Pdo/StatementIntegrationTest.php index 8c35820..89c48a7 100644 --- a/test/unit/Pdo/StatementIntegrationTest.php +++ b/test/unit/Pdo/StatementIntegrationTest.php @@ -9,7 +9,7 @@ use PDOStatement; use PhpDb\Adapter\Driver\Pdo\Statement; use PhpDb\Adapter\Sqlite\Pdo\Driver; -use PhpDbTest\Adapter\Sqlite\Driver\Pdo\TestAsset\CtorlessPdo; +use PhpDbTest\Adapter\Sqlite\Pdo\TestAsset\CtorlessPdo; use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/test/unit/Pdo/TestAsset/CtorlessPdo.php b/test/unit/Pdo/TestAsset/CtorlessPdo.php index 39a3f39..be4f2e7 100644 --- a/test/unit/Pdo/TestAsset/CtorlessPdo.php +++ b/test/unit/Pdo/TestAsset/CtorlessPdo.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhpDbTest\Adapter\Sqlite\Driver\Pdo\TestAsset; +namespace PhpDbTest\Adapter\Sqlite\Pdo\TestAsset; use Override; use PDO;