Skip to content

Commit

Permalink
Remove src\TestSupport\TestCommandTrait::class from yiisoft/db. (y…
Browse files Browse the repository at this point in the history
…iisoft#108)

* Remove src\TestSupport\TestCommandTrait::class from yiisoft/db.
  • Loading branch information
terabytesoftw authored Nov 29, 2022
1 parent dd1ccb0 commit c10dfa3
Show file tree
Hide file tree
Showing 16 changed files with 678 additions and 763 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/docs export-ignore

# Avoid merge conflicts in CHANGELOG
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
run: composer self-update

- name: Install dependencies with composer.
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
run: composer config preferred-install.yiisoft/db source && composer update --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run tests with phpunit with code coverage.
run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
tools: composer:v2, pecl

- name: Install dependencies with composer.
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
run: composer config preferred-install.yiisoft/db source && composer update --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run infection.
run: |
Expand Down
7 changes: 7 additions & 0 deletions composer.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"autoload-dev": {
"psr-4": {
"Yiisoft\\Db\\Tests\\": "vendor/yiisoft/db/tests"
}
}
}
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18",
"wikimedia/composer-merge-plugin": "^2.0",
"yiisoft/aliases": "^2.0",
"yiisoft/cache": "^2.0"
},
Expand All @@ -46,13 +47,20 @@
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
},
"merge-plugin": {
"include": [
"composer.dev.json"
],
"merge-dev": true
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true,
"composer/package-versions-deprecated": true
"composer/package-versions-deprecated": true,
"wikimedia/composer-merge-plugin": true
}
},
"prefer-stable": true,
Expand Down
18 changes: 10 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
colors="true"
verbose="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
executionOrder="default"
resolveDependencies="true">
<phpunit
backupGlobals="false"
colors="true"
verbose="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
executionOrder="default"
resolveDependencies="true"
>

<coverage>
<include>
Expand Down
21 changes: 13 additions & 8 deletions src/CommandPDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

use PDO;
use PDOException;
use Throwable;
use Yiisoft\Db\Driver\PDO\CommandPDO as AbstractCommandPDO;
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
use Yiisoft\Db\Exception\ConvertException;
use Yiisoft\Db\QueryBuilder\QueryBuilder;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Schema;
use Yiisoft\Db\Schema\SchemaInterface;

use function array_keys;
use function count;
Expand All @@ -28,11 +29,6 @@ public function queryBuilder(): QueryBuilderInterface
return $this->db->getQueryBuilder();
}

public function schema(): SchemaInterface
{
return $this->db->getSchema();
}

public function insertEx(string $table, array $columns): bool|array
{
$params = [];
Expand All @@ -45,6 +41,7 @@ public function insertEx(string $table, array $columns): bool|array

$returnParams = [];
$returning = [];

foreach ($returnColumns as $name) {
/** @noRector \Rector\Php71\Rector\FuncCall\CountOnNullRector */
$phName = QueryBuilder::PARAM_PREFIX . (count($params) + count($returnParams));
Expand Down Expand Up @@ -82,7 +79,7 @@ public function insertEx(string $table, array $columns): bool|array
$result = [];

foreach ($returnParams as $value) {
/** @var mixed */
/** @psalm-var mixed */
$result[$value['column']] = $value['value'];
}

Expand Down Expand Up @@ -111,6 +108,11 @@ protected function bindPendingParams(): void
}
}

/**
* @psalm-suppress UnusedClosureParam
*
* @throws Throwable
*/
protected function internalExecute(?string $rawSql): void
{
$attempt = 0;
Expand All @@ -122,7 +124,10 @@ protected function internalExecute(?string $rawSql): void
&& $this->isolationLevel !== null
&& $this->db->getTransaction() === null
) {
$this->db->transaction(fn (string $rawSql) => $this->internalExecute($rawSql), $this->isolationLevel);
$this->db->transaction(
fn (ConnectionPDOInterface $db) => $this->internalExecute($rawSql),
$this->isolationLevel
);
} else {
$this->pdoStatement?->execute();
}
Expand Down
16 changes: 16 additions & 0 deletions src/DDLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ public function __construct(
parent::__construct($queryBuilder, $quoter, $schema);
}

/**
* @throws NotSupportedException
*/
public function addDefaultValue(string $name, string $table, string $column, mixed $value): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by Oracle.');
}

public function addForeignKey(
string $name,
string $table,
Expand Down Expand Up @@ -76,6 +84,14 @@ public function dropCommentFromTable(string $table): string
return 'COMMENT ON TABLE ' . $this->quoter->quoteTableName($table) . " IS ''";
}

/**
* @throws NotSupportedException
*/
public function dropDefaultValue(string $name, string $table): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by Oracle.');
}

public function dropIndex(string $name, string $table): string
{
return 'DROP INDEX ' . $this->quoter->quoteTableName($name);
Expand Down
56 changes: 43 additions & 13 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ protected function findSchemaNames(): array
}

/**
* @throws Exception|InvalidConfigException|Throwable
* @throws Exception
* @throws InvalidConfigException
* @throws Throwable
*/
protected function findTableNames(string $schema = ''): array
{
Expand Down Expand Up @@ -137,7 +139,9 @@ protected function findTableNames(string $schema = ''): array
}

/**
* @throws Exception|InvalidConfigException|Throwable
* @throws Exception
* @throws InvalidConfigException
* @throws Throwable
*/
protected function loadTableSchema(string $name): TableSchemaInterface|null
{
Expand All @@ -152,7 +156,10 @@ protected function loadTableSchema(string $name): TableSchemaInterface|null
}

/**
* @throws Exception|InvalidConfigException|NotSupportedException|Throwable
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
* @throws Throwable
*/
protected function loadTablePrimaryKey(string $tableName): Constraint|null
{
Expand All @@ -162,7 +169,10 @@ protected function loadTablePrimaryKey(string $tableName): Constraint|null
}

/**
* @throws Exception|InvalidConfigException|NotSupportedException|Throwable
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
* @throws Throwable
*/
protected function loadTableForeignKeys(string $tableName): array
{
Expand All @@ -172,7 +182,10 @@ protected function loadTableForeignKeys(string $tableName): array
}

/**
* @throws Exception|InvalidConfigException|NotSupportedException|Throwable
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
* @throws Throwable
*/
protected function loadTableIndexes(string $tableName): array
{
Expand Down Expand Up @@ -224,7 +237,10 @@ protected function loadTableIndexes(string $tableName): array
}

/**
* @throws Exception|InvalidConfigException|NotSupportedException|Throwable
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
* @throws Throwable
*/
protected function loadTableUniques(string $tableName): array
{
Expand All @@ -234,7 +250,10 @@ protected function loadTableUniques(string $tableName): array
}

/**
* @throws Exception|InvalidConfigException|NotSupportedException|Throwable
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
* @throws Throwable
*/
protected function loadTableChecks(string $tableName): array
{
Expand All @@ -248,7 +267,7 @@ protected function loadTableChecks(string $tableName): array
*/
protected function loadTableDefaultValues(string $tableName): array
{
throw new NotSupportedException('Oracle does not support default value constraints.');
throw new NotSupportedException(__METHOD__ . ' is not supported by Oracle.');
}

/**
Expand All @@ -273,7 +292,8 @@ public function createColumnSchemaBuilder(string $type, array|int|string $length
*
* @param TableSchemaInterface $table the table schema.
*
* @throws Exception|Throwable
* @throws Exception
* @throws Throwable
*
* @return bool whether the table exists.
*/
Expand Down Expand Up @@ -331,7 +351,9 @@ protected function findColumns(TableSchemaInterface $table): bool
/**
* Sequence name of table.
*
* @throws Exception|InvalidConfigException|Throwable
* @throws Exception
* @throws InvalidConfigException
* @throws Throwable
*
* @return bool|float|int|string|null whether the sequence exists.
*
Expand Down Expand Up @@ -425,7 +447,10 @@ protected function createColumn(array|string $column): ColumnSchema
/**
* Finds constraints and fills them into TableSchemaInterface object passed.
*
* @throws Exception|InvalidConfigException|Throwable
* @throws Exception
* @throws InvalidConfigException
* @throws Throwable
*
* @psalm-suppress PossiblyNullArrayOffset
*/
protected function findConstraints(TableSchemaInterface $table): void
Expand Down Expand Up @@ -525,7 +550,9 @@ protected function findConstraints(TableSchemaInterface $table): void
*
* @param TableSchemaInterface $table the table metadata.
*
* @throws Exception|InvalidConfigException|Throwable
* @throws Exception
* @throws InvalidConfigException
* @throws Throwable
*
* @return array all unique indexes for the given table.
*/
Expand Down Expand Up @@ -626,7 +653,10 @@ protected function extractColumnSize(
* - uniques
* - checks
*
* @throws Exception|InvalidConfigException|NotSupportedException|Throwable
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
* @throws Throwable
*
* @return mixed constraints.
*/
Expand Down
46 changes: 46 additions & 0 deletions tests/CommandPDOTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Oracle\Tests;

use Yiisoft\Db\Oracle\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\Common\CommonCommandPDOTest;

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

/**
* @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\CommandPDOProvider::bindParam()
*/
public function testBindParam(
string $field,
string $name,
mixed $value,
int $dataType,
int|null $length,
mixed $driverOptions,
array $expected,
): void {
parent::testBindParam($field, $name, $value, $dataType, $length, $driverOptions, $expected);
}

/**
* @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\CommandPDOProvider::bindParamsNonWhere()
*/
public function testBindParamsNonWhere(string $sql): void
{
parent::testBindParamsNonWhere($sql);
}

public function testColumnCase(): void
{
$this->markTestSkipped('It must be implemented.');
}
}
Loading

0 comments on commit c10dfa3

Please sign in to comment.