Skip to content

Commit

Permalink
Better naming classes with PDO - part 1. (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Apr 5, 2023
1 parent 2b2b59a commit ef22150
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/CommandPDO.php → src/Command.php
Expand Up @@ -23,7 +23,7 @@
* Implements a database command that can be executed with a PDO (PHP Data Object) database connection for SQLite
* Server.
*/
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
Expand Up @@ -19,7 +19,7 @@
*
* @link https://www.php.net/manual/en/ref.pdo-sqlite.php
*/
final class ConnectionPDO extends AbstractConnectionPDO
final class Connection extends AbstractConnectionPDO
{
/**
* Reset the connection after cloning.
Expand All @@ -36,7 +36,7 @@ public function __clone()

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 @@ -55,7 +55,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
Expand Up @@ -12,7 +12,7 @@
*
* @link https://www.php.net/manual/en/ref.pdo-sqlite.php
*/
final class PDODriver extends AbstractPDODriver
final class Driver extends AbstractPDODriver
{
public function createConnection(): PDO
{
Expand Down
4 changes: 2 additions & 2 deletions src/Dsn.php
Expand Up @@ -31,8 +31,8 @@ public function __construct(private string $driver, private string|null $databas
*
* ```php
* $dsn = new Dsn('sqlite', __DIR__ . '/data/test.sq3');
* $pdoDriver = new PDODriver($dsn->asString());
* $db = new ConnectionPDO($pdoDriver, $schemaCache);
* $driver = new Driver($dsn->asString());
* $db = new Connection($driver, $schemaCache);
* ```
*
* Will result in the DSN string `sqlite:/path/to/data/test.sq3`.
Expand Down
2 changes: 1 addition & 1 deletion src/TransactionPDO.php → src/Transaction.php
Expand Up @@ -13,7 +13,7 @@
/**
* Implements the SQLite Server specific transaction.
*/
final class TransactionPDO extends AbstractTransactionPDO
final class Transaction extends AbstractTransactionPDO
{
/**
* Sets the isolation level of the current transaction.
Expand Down
2 changes: 1 addition & 1 deletion tests/CommandPDOTest.php → tests/PdoCommandTest.php
Expand Up @@ -12,7 +12,7 @@
*
* @psalm-suppress PropertyNotSetInConstructor
*/
final class CommandPDOTest extends CommonCommandPDOTest
final class PdoCommandTest extends CommonCommandPDOTest
{
use TestTrait;
}
4 changes: 2 additions & 2 deletions tests/ConnectionPDOTest.php → tests/PdoConnectionTest.php
Expand Up @@ -18,7 +18,7 @@
*
* @psalm-suppress PropertyNotSetInConstructor
*/
final class ConnectionPDOTest extends CommonConnectionPDOTest
final class PdoConnectionTest extends CommonConnectionPDOTest
{
use TestTrait;

Expand Down Expand Up @@ -105,7 +105,7 @@ public function testTransactionIsolationException(): void

$this->expectException(NotSupportedException::class);
$this->expectExceptionMessage(
'Yiisoft\Db\Sqlite\TransactionPDO only supports transaction isolation levels READ UNCOMMITTED and SERIALIZABLE.'
'Yiisoft\Db\Sqlite\Transaction only supports transaction isolation levels READ UNCOMMITTED and SERIALIZABLE.'
);

$db->beginTransaction(TransactionInterface::READ_COMMITTED);
Expand Down
9 changes: 3 additions & 6 deletions tests/Support/TestTrait.php
Expand Up @@ -7,9 +7,9 @@
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Sqlite\ConnectionPDO;
use Yiisoft\Db\Sqlite\Connection;
use Yiisoft\Db\Sqlite\Driver;
use Yiisoft\Db\Sqlite\Dsn;
use Yiisoft\Db\Sqlite\PDODriver;
use Yiisoft\Db\Tests\Support\DbHelper;

trait TestTrait
Expand All @@ -22,10 +22,7 @@ trait TestTrait
*/
protected function getConnection(bool $fixture = false): ConnectionPDOInterface
{
$db = new ConnectionPDO(
new PDODriver($this->getDsn()),
DbHelper::getSchemaCache()
);
$db = new Connection(new Driver($this->getDsn()), DbHelper::getSchemaCache());

if ($fixture) {
DbHelper::loadFixture($db, __DIR__ . '/Fixture/sqlite.sql');
Expand Down

0 comments on commit ef22150

Please sign in to comment.