Skip to content

Commit

Permalink
Better naming classes with PDO - part 1. (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Apr 5, 2023
1 parent d9f47ff commit 0d7a1ec
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/CommandPDO.php → src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
6 changes: 3 additions & 3 deletions src/ConnectionPDO.php → src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/PDODriver.php → src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/TransactionPDO.php → src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
/**
* Implements the MySQL, MariaDB specific transaction.
*/
final class TransactionPDO extends AbstractTransactionPDO
final class Transaction extends AbstractTransactionPDO
{
}
6 changes: 3 additions & 3 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
10 changes: 5 additions & 5 deletions tests/PDODriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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(),
);

Expand Down
8 changes: 4 additions & 4 deletions tests/Support/TestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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
Expand Down

0 comments on commit 0d7a1ec

Please sign in to comment.