Skip to content

Commit

Permalink
Better naming classes with PDO - part 2. (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Apr 7, 2023
1 parent 7df201c commit f597e26
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 31 deletions.
51 changes: 45 additions & 6 deletions .github/workflows/composer-require-checker.yml
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
Expand Up @@ -6,8 +6,8 @@

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\Exception\Exception;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
Expand All @@ -16,7 +16,7 @@
* Implements a database command that can be executed against a PDO (PHP Data Object) database connection for MSSQL
* Server.
*/
final class Command extends AbstractCommandPDO
final class Command extends AbstractPdoCommand
{
public function showDatabases(): array
{
Expand Down Expand Up @@ -45,7 +45,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
Expand Up @@ -4,8 +4,8 @@

namespace Yiisoft\Db\Mssql;

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\Query\BatchQueryResultInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
Expand All @@ -18,14 +18,14 @@
*
* @link https://www.php.net/manual/en/ref.pdo-sqlsrv.php
*/
final class Connection extends AbstractConnectionPDO
final class Connection extends AbstractPdoConnection
{
public function createBatchQueryResult(QueryInterface $query, bool $each = false): BatchQueryResultInterface
{
return new BatchQueryResult($query, $each);
}

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
Expand Up @@ -5,14 +5,14 @@
namespace Yiisoft\Db\Mssql;

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

/**
* Implements the MSSQL Server driver based on the PDO (PHP Data Objects) extension.
*
* @link https://www.php.net/manual/en/ref.pdo-sqlsrv.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
Expand Up @@ -10,7 +10,7 @@
use Yiisoft\Db\Constraint\DefaultValueConstraint;
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\Helper\DbArrayHelper;
Expand Down Expand Up @@ -55,7 +55,7 @@
* }
* >
*/
final class Schema extends PdoAbstractSchema
final class Schema extends AbstractPdoSchema
{
/**
* @var string|null The default schema used for the current session.
Expand Down
4 changes: 2 additions & 2 deletions src/Transaction.php
Expand Up @@ -5,14 +5,14 @@
namespace Yiisoft\Db\Mssql;

use Throwable;
use Yiisoft\Db\Driver\PDO\AbstractTransactionPDO;
use Yiisoft\Db\Driver\Pdo\AbstractPdoTransaction;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;

/**
* Implements the MSSQL Server specific transaction.
*/
final class Transaction extends AbstractTransactionPDO
final class Transaction extends AbstractPdoTransaction
{
/**
* Creates a new savepoint.
Expand Down
4 changes: 2 additions & 2 deletions tests/ConnectionTest.php
Expand Up @@ -6,7 +6,7 @@

use PDO;
use Throwable;
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 @@ -59,7 +59,7 @@ public function testTransactionShortcutCustom(): void
$db = $this->getConnection();

$result = $db->transaction(
static function (ConnectionPDOInterface $db): bool {
static function (PdoConnectionInterface $db): bool {
$db->createCommand()->insert('profile', ['description' => 'test transaction shortcut'])->execute();
return true;
},
Expand Down
4 changes: 2 additions & 2 deletions tests/CommandPDOTest.php → tests/PdoCommandTest.php
Expand Up @@ -5,14 +5,14 @@
namespace Yiisoft\Db\Mssql\Tests;

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

/**
* @group mssql
*
* @psalm-suppress PropertyNotSetInConstructor
*/
final class CommandPDOTest extends CommonCommandPDOTest
final class PdoCommandTest extends CommonPdoCommandTest
{
use TestTrait;

Expand Down
4 changes: 2 additions & 2 deletions tests/ConnectionPDOTest.php → tests/PdoConnectionTest.php
Expand Up @@ -10,14 +10,14 @@
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Mssql\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\Common\CommonConnectionPDOTest;
use Yiisoft\Db\Tests\Common\CommonPdoConnectionTest;

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

Expand Down
4 changes: 2 additions & 2 deletions tests/SchemaTest.php
Expand Up @@ -7,7 +7,7 @@
use Throwable;
use Yiisoft\Db\Command\CommandInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
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 @@ -134,7 +134,7 @@ public function testTableSchemaWithDbSchemes(string $tableName, string $expected

$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
6 changes: 3 additions & 3 deletions tests/Support/TestTrait.php
Expand Up @@ -4,7 +4,7 @@

namespace Yiisoft\Db\Mssql\Tests\Support;

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\Mssql\Connection;
Expand All @@ -21,7 +21,7 @@ trait TestTrait
* @throws Exception
* @throws InvalidConfigException
*/
protected function getConnection(bool $fixture = false): ConnectionPDOInterface
protected function getConnection(bool $fixture = false): PdoConnectionInterface
{
$db = new Connection(
new Driver($this->getDsn(), 'SA', 'YourStrong!Passw0rd'),
Expand All @@ -35,7 +35,7 @@ protected function getConnection(bool $fixture = false): ConnectionPDOInterface
return $db;
}

protected static function getDb(): ConnectionPDOInterface
protected static function getDb(): PdoConnectionInterface
{
$dsn = (new Dsn('sqlsrv', 'localhost', 'yiitest'))->asString();

Expand Down

0 comments on commit f597e26

Please sign in to comment.