Skip to content

Commit

Permalink
Better naming classes with PDO - part 2. (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Apr 7, 2023
1 parent 85b6ab2 commit 7d8d5b0
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 33 deletions.
51 changes: 45 additions & 6 deletions .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,48 @@ name: Composer require checker

jobs:
composer-require-checker:
uses: yiisoft/actions/.github/workflows/composer-require-checker.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.0', '8.1']
name: PHP ${{ matrix.php }}

env:
COMPOSER_ROOT_VERSION: dev-master

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- 8.0
- 8.1
- 8.2

steps:
- name: Checkout.
uses: actions/checkout@v3

- name: Install PHP with extensions.
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2

- name: Update composer.
run: composer self-update

- name: Set environment variables pull request linux.
uses: yiisoft/actions/db/environment-linux@master

- name: Install db.
uses: yiisoft/actions/db/subpackage-install@master
with:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }}
CURRENT_PACKAGE: db
FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }}
WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }}

- name: Check dependencies.
run: vendor/bin/composer-require-checker
8 changes: 4 additions & 4 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

use PDOException;
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\ConvertException;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;

/**
* Implements a database command that can be executed with a PDO (PHP Data Object) database connection for MySQL,
* MariaDB.
*/
final class Command extends AbstractCommandPDO
final class Command extends AbstractPdoCommand
{
public function insertWithReturningPks(string $table, array $columns): bool|array
{
Expand Down Expand Up @@ -75,7 +75,7 @@ protected function internalExecute(string|null $rawSql): void
&& $this->db->getTransaction() === null
) {
$this->db->transaction(
fn (ConnectionPDOInterface $db) => $this->internalExecute($rawSql),
fn (PdoConnectionInterface $db) => $this->internalExecute($rawSql),
$this->isolationLevel,
);
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Exception;
use Psr\Log\LogLevel;
use Yiisoft\Db\Driver\PDO\AbstractConnectionPDO;
use Yiisoft\Db\Driver\PDO\CommandPDOInterface;
use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection;
use Yiisoft\Db\Driver\Pdo\PdoCommandInterface;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;
Expand All @@ -18,7 +18,7 @@
*
* @link https://www.php.net/manual/en/ref.pdo-mysql.php
*/
final class Connection extends AbstractConnectionPDO
final class Connection extends AbstractPdoConnection
{
public function close(): void
{
Expand All @@ -39,7 +39,7 @@ public function close(): void
}
}

public function createCommand(string $sql = null, array $params = []): CommandPDOInterface
public function createCommand(string $sql = null, array $params = []): PdoCommandInterface
{
$command = new Command($this);

Expand Down
4 changes: 2 additions & 2 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace Yiisoft\Db\Mysql;

use PDO;
use Yiisoft\Db\Driver\PDO\AbstractPDODriver;
use Yiisoft\Db\Driver\Pdo\AbstractPdoDriver;

/**
* Implements the MySQL, MariaDB driver based on the PDO (PHP Data Objects) extension.
*
* @link https://www.php.net/manual/en/ref.pdo-mysql.php
*/
final class Driver extends AbstractPDODriver
final class Driver extends AbstractPdoDriver
{
public function createConnection(): PDO
{
Expand Down
4 changes: 2 additions & 2 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Yiisoft\Db\Constraint\Constraint;
use Yiisoft\Db\Constraint\ForeignKeyConstraint;
use Yiisoft\Db\Constraint\IndexConstraint;
use Yiisoft\Db\Driver\PDO\PdoAbstractSchema;
use Yiisoft\Db\Driver\Pdo\AbstractPdoSchema;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
Expand Down Expand Up @@ -92,7 +92,7 @@
* }
* >
*/
final class Schema extends PdoAbstractSchema
final class Schema extends AbstractPdoSchema
{
/**
* @var array Mapping from physical column types (keys) to abstract column types (values).
Expand Down
4 changes: 2 additions & 2 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Yiisoft\Db\Mysql;

use Yiisoft\Db\Driver\PDO\AbstractTransactionPDO;
use Yiisoft\Db\Driver\Pdo\AbstractPdoTransaction;

/**
* Implements the MySQL, MariaDB specific transaction.
*/
final class Transaction extends AbstractTransactionPDO
final class Transaction extends AbstractPdoTransaction
{
}
2 changes: 1 addition & 1 deletion tests/CommandJSONTest.php → tests/JsonCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @psalm-suppress PropertyNotSetInConstructor
*/
final class CommandJSONTest extends TestCase
final class JsonCommandTest extends TestCase
{
use TestTrait;

Expand Down
4 changes: 2 additions & 2 deletions tests/CommandPDOTest.php → tests/PdoCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace Yiisoft\Db\Mysql\Tests;

use Yiisoft\Db\Mysql\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\Common\CommonCommandPDOTest;
use Yiisoft\Db\Tests\Common\CommonPdoCommandTest;

/**
* @group mysql
*
* @psalm-suppress PropertyNotSetInConstructor
*/
final class CommandPDOTest extends CommonCommandPDOTest
final class PdoCommandTest extends CommonPdoCommandTest
{
use TestTrait;
}
8 changes: 4 additions & 4 deletions tests/ConnectionPDOTest.php → tests/PdoConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
namespace Yiisoft\Db\Mysql\Tests;

use Throwable;
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidCallException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Mysql\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\Common\CommonConnectionPDOTest;
use Yiisoft\Db\Tests\Common\CommonPdoConnectionTest;

/**
* @group mysql
*
* @psalm-suppress PropertyNotSetInConstructor
*/
final class ConnectionPDOTest extends CommonConnectionPDOTest
final class PdoConnectionTest extends CommonPdoConnectionTest
{
use TestTrait;

Expand Down Expand Up @@ -96,7 +96,7 @@ public function testGetLastInsertID(): void
public function testTransactionAutocommit()
{
$db = $this->getConnection(true);
$db->transaction(function (ConnectionPDOInterface $db) {
$db->transaction(function (PdoConnectionInterface $db) {
$this->assertTrue($db->getTransaction()->isActive());

// create table will cause the transaction to be implicitly committed
Expand Down
4 changes: 2 additions & 2 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Yiisoft\Db\Command\CommandInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Constraint\Constraint;
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
Expand Down Expand Up @@ -407,7 +407,7 @@ public function testTableSchemaWithDbSchemes(

$commandMock = $this->createMock(CommandInterface::class);
$commandMock->method('queryAll')->willReturn([]);
$mockDb = $this->createMock(ConnectionPDOInterface::class);
$mockDb = $this->createMock(PdoConnectionInterface::class);
$mockDb->method('getQuoter')->willReturn($db->getQuoter());
$mockDb
->method('createCommand')
Expand Down
8 changes: 4 additions & 4 deletions tests/Support/TestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace Yiisoft\Db\Mysql\Tests\Support;

use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface;
use Yiisoft\Db\Mysql\Connection;
use Yiisoft\Db\Mysql\Dsn;
use Yiisoft\Db\Mysql\Driver;
use Yiisoft\Db\Mysql\Dsn;
use Yiisoft\Db\Tests\Support\DbHelper;

trait TestTrait
{
private string $dsn = '';

protected function getConnection(bool $fixture = false): ConnectionPDOInterface
protected function getConnection(bool $fixture = false): PdoConnectionInterface
{
$db = new Connection(new Driver($this->getDsn(), 'root', ''), DbHelper::getSchemaCache());

Expand All @@ -25,7 +25,7 @@ protected function getConnection(bool $fixture = false): ConnectionPDOInterface
return $db;
}

protected static function getDb(): ConnectionPDOInterface
protected static function getDb(): PdoConnectionInterface
{
$dsn = (new Dsn('mysql', '127.0.0.1', 'yiitest', '3306', ['charset' => 'utf8mb4']))->asString();

Expand Down

0 comments on commit 7d8d5b0

Please sign in to comment.