From 0d7a1eccf89d8c5d9f00bdb271d7c9b8c0958a6a Mon Sep 17 00:00:00 2001 From: Wilmer Arambula <42547589+terabytesoftw@users.noreply.github.com> Date: Wed, 5 Apr 2023 15:04:03 -0400 Subject: [PATCH] Better naming classes with `PDO` - part 1. (#278) --- src/{CommandPDO.php => Command.php} | 2 +- src/{ConnectionPDO.php => Connection.php} | 6 +++--- src/{PDODriver.php => Driver.php} | 2 +- src/{TransactionPDO.php => Transaction.php} | 2 +- tests/CommandTest.php | 6 +++--- tests/PDODriverTest.php | 10 +++++----- tests/Support/TestTrait.php | 8 ++++---- 7 files changed, 18 insertions(+), 18 deletions(-) rename src/{CommandPDO.php => Command.php} (98%) rename src/{ConnectionPDO.php => Connection.php} (94%) rename src/{PDODriver.php => Driver.php} (95%) rename src/{TransactionPDO.php => Transaction.php} (75%) diff --git a/src/CommandPDO.php b/src/Command.php similarity index 98% rename from src/CommandPDO.php rename to src/Command.php index 64e3d84d..76ab485d 100644 --- a/src/CommandPDO.php +++ b/src/Command.php @@ -15,7 +15,7 @@ * Implements a database command that can be executed with a PDO (PHP Data Object) database connection for MySQL, * MariaDB. */ -final class CommandPDO extends AbstractCommandPDO +final class Command extends AbstractCommandPDO { public function insertWithReturningPks(string $table, array $columns): bool|array { diff --git a/src/ConnectionPDO.php b/src/Connection.php similarity index 94% rename from src/ConnectionPDO.php rename to src/Connection.php index 811aad20..532b9d64 100644 --- a/src/ConnectionPDO.php +++ b/src/Connection.php @@ -18,7 +18,7 @@ * * @link https://www.php.net/manual/en/ref.pdo-mysql.php */ -final class ConnectionPDO extends AbstractConnectionPDO +final class Connection extends AbstractConnectionPDO { public function close(): void { @@ -41,7 +41,7 @@ public function close(): void public function createCommand(string $sql = null, array $params = []): CommandPDOInterface { - $command = new CommandPDO($this); + $command = new Command($this); if ($sql !== null) { $command->setSql($sql); @@ -60,7 +60,7 @@ public function createCommand(string $sql = null, array $params = []): CommandPD public function createTransaction(): TransactionInterface { - return new TransactionPDO($this); + return new Transaction($this); } public function getQueryBuilder(): QueryBuilderInterface diff --git a/src/PDODriver.php b/src/Driver.php similarity index 95% rename from src/PDODriver.php rename to src/Driver.php index 8ba6b3fa..0152c5d2 100644 --- a/src/PDODriver.php +++ b/src/Driver.php @@ -12,7 +12,7 @@ * * @link https://www.php.net/manual/en/ref.pdo-mysql.php */ -final class PDODriver extends AbstractPDODriver +final class Driver extends AbstractPDODriver { public function createConnection(): PDO { diff --git a/src/TransactionPDO.php b/src/Transaction.php similarity index 75% rename from src/TransactionPDO.php rename to src/Transaction.php index 10c398c7..5eaaf6b2 100644 --- a/src/TransactionPDO.php +++ b/src/Transaction.php @@ -9,6 +9,6 @@ /** * Implements the MySQL, MariaDB specific transaction. */ -final class TransactionPDO extends AbstractTransactionPDO +final class Transaction extends AbstractTransactionPDO { } diff --git a/tests/CommandTest.php b/tests/CommandTest.php index fb3ee0fc..54d373af 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -8,9 +8,9 @@ use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mysql\ConnectionPDO; +use Yiisoft\Db\Mysql\Connection; use Yiisoft\Db\Mysql\Dsn; -use Yiisoft\Db\Mysql\PDODriver; +use Yiisoft\Db\Mysql\Driver; use Yiisoft\Db\Mysql\Tests\Support\TestTrait; use Yiisoft\Db\Tests\Common\CommonCommandTest; use Yiisoft\Db\Tests\Support\DbHelper; @@ -141,7 +141,7 @@ public function testUpsert(array $firstData, array $secondData): void public function testShowDatabases(): void { $dsn = new Dsn('mysql', '127.0.0.1', ); - $db = new ConnectionPDO(new PDODriver($dsn->asString(), 'root', ''), DbHelper::getSchemaCache()); + $db = new Connection(new Driver($dsn->asString(), 'root', ''), DbHelper::getSchemaCache()); $command = $db->createCommand(); diff --git a/tests/PDODriverTest.php b/tests/PDODriverTest.php index d221f024..64773156 100644 --- a/tests/PDODriverTest.php +++ b/tests/PDODriverTest.php @@ -6,8 +6,8 @@ use PDO; use PHPUnit\Framework\TestCase; -use Yiisoft\Db\Mysql\ConnectionPDO; -use Yiisoft\Db\Mysql\PDODriver; +use Yiisoft\Db\Mysql\Connection; +use Yiisoft\Db\Mysql\Driver; use Yiisoft\Db\Mysql\Tests\Support\TestTrait; use Yiisoft\Db\Tests\Support\DbHelper; @@ -29,7 +29,7 @@ public function testConnectionCharset(): void $this->assertEqualsIgnoringCase('utf8mb4', array_values($charset)[1]); - $pdoDriver = new PDODriver('mysql:host=127.0.0.1;dbname=yiitest;port=3306', 'root', ''); + $pdoDriver = new Driver('mysql:host=127.0.0.1;dbname=yiitest;port=3306', 'root', ''); $newCharset = 'latin1'; $pdoDriver->charset($newCharset); $pdo = $pdoDriver->createConnection(); @@ -40,8 +40,8 @@ public function testConnectionCharset(): void public function testCharsetDefault(): void { - $db = new ConnectionPDO( - new PDODriver('mysql:host=127.0.0.1;dbname=yiitest;port=3306', 'root', ''), + $db = new Connection( + new Driver('mysql:host=127.0.0.1;dbname=yiitest;port=3306', 'root', ''), DbHelper::getSchemaCache(), ); diff --git a/tests/Support/TestTrait.php b/tests/Support/TestTrait.php index 74b8ebca..dd0eac42 100644 --- a/tests/Support/TestTrait.php +++ b/tests/Support/TestTrait.php @@ -5,9 +5,9 @@ namespace Yiisoft\Db\Mysql\Tests\Support; use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface; -use Yiisoft\Db\Mysql\ConnectionPDO; +use Yiisoft\Db\Mysql\Connection; use Yiisoft\Db\Mysql\Dsn; -use Yiisoft\Db\Mysql\PDODriver; +use Yiisoft\Db\Mysql\Driver; use Yiisoft\Db\Tests\Support\DbHelper; trait TestTrait @@ -16,7 +16,7 @@ trait TestTrait protected function getConnection(bool $fixture = false): ConnectionPDOInterface { - $db = new ConnectionPDO(new PDODriver($this->getDsn(), 'root', ''), DbHelper::getSchemaCache()); + $db = new Connection(new Driver($this->getDsn(), 'root', ''), DbHelper::getSchemaCache()); if ($fixture) { DbHelper::loadFixture($db, __DIR__ . '/Fixture/mysql.sql'); @@ -29,7 +29,7 @@ protected static function getDb(): ConnectionPDOInterface { $dsn = (new Dsn('mysql', '127.0.0.1', 'yiitest', '3306', ['charset' => 'utf8mb4']))->asString(); - return new ConnectionPDO(new PDODriver($dsn, 'root', ''), DbHelper::getSchemaCache()); + return new Connection(new Driver($dsn, 'root', ''), DbHelper::getSchemaCache()); } protected function getDsn(): string