Skip to content

Commit

Permalink
Better naming classes with PDO - part 2. (#671)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Apr 7, 2023
1 parent 5b7b660 commit 4c37a2a
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 67 deletions.
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Db\Driver\PDO;
namespace Yiisoft\Db\Driver\Pdo;

use PDO;
use PDOException;
Expand All @@ -24,7 +24,7 @@
*
* It also provides methods for binding parameter values and retrieving query results.
*/
abstract class AbstractCommandPDO extends AbstractCommand implements CommandPDOInterface
abstract class AbstractPdoCommand extends AbstractCommand implements PdoCommandInterface
{
/**
* @var PDOStatement|null Represents a prepared statement and, after the statement is executed, an associated
Expand All @@ -34,7 +34,7 @@ abstract class AbstractCommandPDO extends AbstractCommand implements CommandPDOI
*/
protected PDOStatement|null $pdoStatement = null;

public function __construct(protected ConnectionPDOInterface $db)
public function __construct(protected PdoConnectionInterface $db)
{
}

Expand Down
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Db\Driver\PDO;
namespace Yiisoft\Db\Driver\Pdo;

use PDO;
use PDOException;
Expand Down Expand Up @@ -30,7 +30,7 @@
*
* It implements the ConnectionInterface, which defines the interface for interacting with a database connection.
*/
abstract class AbstractConnectionPDO extends AbstractConnection implements ConnectionPDOInterface
abstract class AbstractPdoConnection extends AbstractConnection implements PdoConnectionInterface
{
protected PDO|null $pdo = null;
protected string $serverVersion = '';
Expand All @@ -39,7 +39,7 @@ abstract class AbstractConnectionPDO extends AbstractConnection implements Conne
protected QuoterInterface|null $quoter = null;
protected SchemaInterface|null $schema = null;

public function __construct(protected PDODriverInterface $driver, protected SchemaCache $schemaCache)
public function __construct(protected PdoDriverInterface $driver, protected SchemaCache $schemaCache)
{
}

Expand Down Expand Up @@ -107,7 +107,7 @@ public function close(): void
}
}

public function getDriver(): PDODriverInterface
public function getDriver(): PdoDriverInterface
{
return $this->driver;
}
Expand Down
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Db\Driver\PDO;
namespace Yiisoft\Db\Driver\Pdo;

use PDO;

Expand All @@ -14,7 +14,7 @@
*
* @link https://www.php.net/manual/en/book.pdo.php
*/
abstract class AbstractPDODriver implements PDODriverInterface
abstract class AbstractPdoDriver implements PdoDriverInterface
{
protected string|null $charset = null;

Expand Down
Expand Up @@ -2,15 +2,15 @@

declare(strict_types=1);

namespace Yiisoft\Db\Driver\PDO;
namespace Yiisoft\Db\Driver\Pdo;

use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Schema\AbstractSchema;

/**
* Represents a schema for a PDO (PHP Data Object) connection.
*/
abstract class PdoAbstractSchema extends AbstractSchema
abstract class AbstractPdoSchema extends AbstractSchema
{
/**
* Generates the cache key for the current connection.
Expand All @@ -23,7 +23,7 @@ protected function generateCacheKey(): array
{
$cacheKey = [];

if ($this->db instanceof ConnectionPDOInterface) {
if ($this->db instanceof PdoConnectionInterface) {
$cacheKey = [$this->db->getDriver()->getDsn(), $this->db->getDriver()->getUsername()];
} else {
throw new NotSupportedException('Only PDO connections are supported.');
Expand Down
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Db\Driver\PDO;
namespace Yiisoft\Db\Driver\Pdo;

use Psr\Log\LoggerAwareTrait;
use Psr\Log\LogLevel;
Expand Down Expand Up @@ -34,7 +34,7 @@
* }
* ```
*/
abstract class AbstractTransactionPDO implements TransactionInterface
abstract class AbstractPdoTransaction implements TransactionInterface
{
use LoggerAwareTrait;

Expand All @@ -43,7 +43,7 @@ abstract class AbstractTransactionPDO implements TransactionInterface
*/
private int $level = 0;

public function __construct(protected ConnectionPDOInterface $db)
public function __construct(protected PdoConnectionInterface $db)
{
}

Expand Down
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Db\Driver\PDO;
namespace Yiisoft\Db\Driver\Pdo;

use PDOStatement;
use Yiisoft\Db\Command\CommandInterface;
Expand All @@ -12,7 +12,7 @@
*
* @see CommandInterface
*/
interface CommandPDOInterface extends CommandInterface
interface PdoCommandInterface extends CommandInterface
{
/**
* @return PDOStatement|null The PDO statement.
Expand Down
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Db\Driver\PDO;
namespace Yiisoft\Db\Driver\Pdo;

use PDO;
use Yiisoft\Db\Connection\ConnectionInterface;
Expand All @@ -13,7 +13,7 @@
* This interface defines a set of methods to implement in a class that allows to connect to a database
* with {@see PDO} (PHP Data Objects).
*/
interface ConnectionPDOInterface extends ConnectionInterface
interface PdoConnectionInterface extends ConnectionInterface
{
/**
* Returns the PDO instance for the current connection.
Expand Down Expand Up @@ -44,9 +44,9 @@ public function getPDO(): PDO|null;
/**
* Returns current DB driver.
*
* @return PDODriverInterface The driver used to create current connection.
* @return PdoDriverInterface The driver used to create current connection.
*/
public function getDriver(): PDODriverInterface;
public function getDriver(): PdoDriverInterface;

/**
* Whether to emulate prepared statements on PHP side.
Expand Down
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Db\Driver\PDO;
namespace Yiisoft\Db\Driver\Pdo;

use PDO;
use Yiisoft\Db\Driver\DriverInterface;
Expand All @@ -12,7 +12,7 @@
*
* @link https://www.php.net/manual/en/book.pdo.php
*/
interface PDODriverInterface extends DriverInterface
interface PdoDriverInterface extends DriverInterface
{
/**
* Set {@see PDO} attributes (name => value) to set when calling {@see open()} to establish a DB
Expand Down
4 changes: 2 additions & 2 deletions src/Query/Data/DataReader.php
Expand Up @@ -8,7 +8,7 @@
use Iterator;
use PDO;
use PDOStatement;
use Yiisoft\Db\Driver\PDO\CommandPDOInterface;
use Yiisoft\Db\Driver\Pdo\PdoCommandInterface;
use Yiisoft\Db\Exception\InvalidCallException;
use Yiisoft\Db\Exception\InvalidParamException;

Expand All @@ -31,7 +31,7 @@ final class DataReader implements DataReaderInterface
/**
* @throws InvalidParamException If the PDOStatement is null.
*/
public function __construct(CommandPDOInterface $command)
public function __construct(PdoCommandInterface $command)
{
$statement = $command->getPDOStatement();

Expand Down
8 changes: 4 additions & 4 deletions tests/AbstractConnectionTest.php
Expand Up @@ -7,7 +7,7 @@
use Exception;
use PHPUnit\Framework\TestCase;
use Throwable;
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Profiler\Context\ConnectionContext;
Expand All @@ -27,7 +27,7 @@ abstract class AbstractConnectionTest extends TestCase
*/
public function testConnection(): void
{
$this->assertInstanceOf(ConnectionPDOInterface::class, $this->getConnection());
$this->assertInstanceOf(PdoConnectionInterface::class, $this->getConnection());
}

public function testCreateBatchQueryResult(): void
Expand Down Expand Up @@ -77,7 +77,7 @@ public function testNestedTransactionNotSupported(): void
$this->assertFalse($db->isSavepointEnabled());

$db->transaction(
function (ConnectionPDOInterface $db) {
function (PdoConnectionInterface $db) {
$this->assertNotNull($db->getTransaction());
$this->expectException(NotSupportedException::class);

Expand Down Expand Up @@ -147,7 +147,7 @@ public function testSerialized()
$this->assertNotNull($connection->getPDO());

$unserialized = unserialize($serialized);
$this->assertInstanceOf(ConnectionPDOInterface::class, $unserialized);
$this->assertInstanceOf(PdoConnectionInterface::class, $unserialized);
$this->assertNull($unserialized->getPDO());
$this->assertEquals(123, $unserialized->createCommand('SELECT 123')->queryScalar());
$this->assertNotNull($connection->getPDO());
Expand Down
Expand Up @@ -8,12 +8,12 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Yiisoft\Db\Driver\PDO\PDODriverInterface;
use Yiisoft\Db\Driver\Pdo\PdoDriverInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Tests\Support\TestTrait;

abstract class AbstractConnectionPDOTest extends TestCase
abstract class AbstractPdoConnectionTest extends TestCase
{
use TestTrait;

Expand All @@ -32,7 +32,7 @@ public function testGetDriver(): void
{
$driver = $this->getConnection()->getDriver();

$this->assertInstanceOf(PDODriverInterface::class, $driver);
$this->assertInstanceOf(PdoDriverInterface::class, $driver);
}

public function testGetServerVersion(): void
Expand Down
10 changes: 5 additions & 5 deletions tests/Common/CommonCommandTest.php
Expand Up @@ -6,8 +6,8 @@

use ReflectionException;
use Throwable;
use Yiisoft\Db\Driver\PDO\AbstractCommandPDO;
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
use Yiisoft\Db\Driver\Pdo\AbstractPdoCommand;
use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\IntegrityException;
use Yiisoft\Db\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -1941,10 +1941,10 @@ public function testUpsert(array $firstData, array $secondData): void

public function testPrepareWithEmptySql()
{
$db = $this->createMock(ConnectionPDOInterface::class);
$db = $this->createMock(PdoConnectionInterface::class);
$db->expects(self::never())->method('getActivePDO');

$command = new class ($db) extends AbstractCommandPDO {
$command = new class ($db) extends AbstractPdoCommand {
public function showDatabases(): array
{
return $this->showDatabases();
Expand All @@ -1967,7 +1967,7 @@ protected function internalExecute(string|null $rawSql): void
* @throws InvalidConfigException
* @throws Throwable
*/
protected function performAndCompareUpsertResult(ConnectionPDOInterface $db, array $data): void
protected function performAndCompareUpsertResult(PdoConnectionInterface $db, array $data): void
{
$params = [];

Expand Down
Expand Up @@ -8,13 +8,13 @@
use PHPUnit\Framework\TestCase;
use Yiisoft\Db\Command\Param;
use Yiisoft\Db\Command\ParamInterface;
use Yiisoft\Db\Driver\PDO\AbstractCommandPDO;
use Yiisoft\Db\Driver\Pdo\AbstractPdoCommand;
use Yiisoft\Db\Exception\InvalidParamException;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Tests\Support\DbHelper;
use Yiisoft\Db\Tests\Support\TestTrait;

abstract class CommonCommandPDOTest extends TestCase
abstract class CommonPdoCommandTest extends TestCase
{
use TestTrait;

Expand Down Expand Up @@ -201,7 +201,7 @@ public function testIncorrectQueryMode(): void
{
$db = $this->getConnection(true);

$command = new class ($db) extends AbstractCommandPDO {
$command = new class ($db) extends AbstractPdoCommand {
public function testExecute(): void
{
$this->internalGetQueryResult(1024);
Expand Down
Expand Up @@ -8,16 +8,16 @@
use Psr\Log\LogLevel;
use Throwable;
use Yiisoft\Db\Connection\AbstractConnection;
use Yiisoft\Db\Driver\PDO\AbstractConnectionPDO;
use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Profiler\ProfilerInterface;
use Yiisoft\Db\Tests\AbstractConnectionPDOTest;
use Yiisoft\Db\Tests\AbstractPdoConnectionTest;
use Yiisoft\Db\Tests\Support\DbHelper;
use Yiisoft\Db\Transaction\TransactionInterface;

abstract class CommonConnectionPDOTest extends AbstractConnectionPDOTest
abstract class CommonPdoConnectionTest extends AbstractPdoConnectionTest
{
/**
* @throws Exception
Expand Down Expand Up @@ -226,7 +226,7 @@ public function testTransactionCommitSavepoint(): void
->method('log')
->with(
LogLevel::INFO,
'Transaction not committed: nested transaction not supported Yiisoft\Db\Driver\PDO\AbstractTransactionPDO::commit'
'Transaction not committed: nested transaction not supported Yiisoft\Db\Driver\Pdo\AbstractPdoTransaction::commit'
);

$db->beginTransaction();
Expand Down Expand Up @@ -264,7 +264,7 @@ public function testTransactionRollbackSavepoint(): void
->method('log')
->with(
LogLevel::INFO,
'Transaction not rolled back: nested transaction not supported Yiisoft\Db\Driver\PDO\AbstractTransactionPDO::rollBack'
'Transaction not rolled back: nested transaction not supported Yiisoft\Db\Driver\Pdo\AbstractPdoTransaction::rollBack'
);

$db->beginTransaction();
Expand Down Expand Up @@ -340,7 +340,7 @@ public function testTransactionRollbackTransactionOnLevel(): void

public function testGetActivePdo(): void
{
$db = $this->getMockBuilder(AbstractConnectionPDO::class)->onlyMethods([
$db = $this->getMockBuilder(AbstractPdoConnection::class)->onlyMethods([
'createCommand',
'createTransaction',
'getPdo',
Expand Down

0 comments on commit 4c37a2a

Please sign in to comment.