Skip to content

Commit 9f52124

Browse files
Remove src\TestSupport\TestCommandTrait::class from yiisoft/db. (#165)
* Remove src\TestSupport\TestCommandTrait::class from yiisoft/db.
1 parent a0000ee commit 9f52124

23 files changed

Lines changed: 528 additions & 442 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
/.gitignore export-ignore
2929
/.scrutinizer.yml export-ignore
3030
/phpunit.xml.dist export-ignore
31+
/tests export-ignore
3132
/docs export-ignore
3233

3334
# Avoid merge conflicts in CHANGELOG

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
run: composer self-update
7878

7979
- name: Install dependencies with composer.
80-
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
80+
run: composer config preferred-install.yiisoft/db source && composer update --no-interaction --no-progress --optimize-autoloader --ansi
8181

8282
- name: Run tests with phpunit with code coverage.
8383
run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always

.github/workflows/mutation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
run: composer self-update
6666

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

7070
- name: Run infection.
7171
run: |

.scrutinizer.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ build:
4343
ramdisks:
4444
- /var/lib/data
4545

46+
dependencies:
47+
override:
48+
- composer self-update
49+
- composer config preferred-install.yiisoft/db source
50+
- composer update --no-interaction --no-progress --optimize-autoloader --ansi
51+
4652
tests:
4753
override:
4854
- command: ./vendor/bin/phpunit --coverage-clover ./coverage.xml

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ It is used in [Yii Framework] but is supposed to be usable separately.
1919
[![Latest Stable Version](https://poser.pugx.org/yiisoft/db-pgsql/v/stable.png)](https://packagist.org/packages/yiisoft/db-pgsql)
2020
[![Total Downloads](https://poser.pugx.org/yiisoft/db-pgsql/downloads.png)](https://packagist.org/packages/yiisoft/db-pgsql)
2121
[![rector](https://github.com/yiisoft/db-pgsql/actions/workflows/rector.yml/badge.svg)](https://github.com/yiisoft/db-pgsql/actions/workflows/rector.yml)
22-
[![codecov](https://codecov.io/gh/yiisoft/db-pgsql/branch/dev/graph/badge.svg?token=3FGN91IVZA)](https://codecov.io/gh/yiisoft/db-pgsql)
22+
[![codecov](https://codecov.io/gh/yiisoft/db-pgsql/branch/master/graph/badge.svg?token=3FGN91IVZA)](https://codecov.io/gh/yiisoft/db-pgsql)
2323
[![StyleCI](https://github.styleci.io/repos/145220173/shield?branch=master)](https://github.styleci.io/repos/145220173?branch=master)
2424

2525

@@ -46,11 +46,11 @@ Di-Container:
4646

4747
```php
4848
use Yiisoft\Db\Connection\ConnectionInterface;
49-
use Yiisoft\Db\Pgsql\Connection as PgsqlConnection;
49+
use Yiisoft\Db\Pgsql\ConnectionPDO;
5050

5151
return [
5252
ConnectionInterface::class => [
53-
'class' => PgsqlConnection::class,
53+
'class' => ConnectionPDO::class,
5454
'__construct()' => [
5555
'dsn' => $params['yiisoft/db-pgsql']['dsn']
5656
],
@@ -107,6 +107,16 @@ use either newest or any specific version of PHP:
107107
./vendor/bin/rector
108108
```
109109

110+
### Composer require checker
111+
112+
This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if all dependencies are correctly defined in `composer.json`.
113+
114+
To run the checker, execute the following command:
115+
116+
```shell
117+
./vendor/bin/composer-require-checker
118+
```
119+
110120
### Support the project
111121

112122
[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective&logoColor=7eadf1&labelColor=555555)](https://opencollective.com/yiisoft)

composer.dev.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"autoload-dev": {
3+
"psr-4": {
4+
"Yiisoft\\Db\\Tests\\": "vendor/yiisoft/db/tests"
5+
}
6+
}
7+
}

composer.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"roave/infection-static-analysis-plugin": "^1.16",
3535
"spatie/phpunit-watcher": "^1.23",
3636
"vimeo/psalm": "^4.18",
37+
"wikimedia/composer-merge-plugin": "^2.0",
3738
"yiisoft/aliases": "^2.0",
3839
"yiisoft/cache": "^2.0"
3940
},
@@ -50,13 +51,20 @@
5051
"extra": {
5152
"branch-alias": {
5253
"dev-master": "3.0.x-dev"
54+
},
55+
"merge-plugin": {
56+
"include": [
57+
"composer.dev.json"
58+
],
59+
"merge-dev": true
5360
}
5461
},
5562
"config": {
5663
"sort-packages": true,
5764
"allow-plugins": {
5865
"infection/extension-installer": true,
59-
"composer/package-versions-deprecated": true
66+
"composer/package-versions-deprecated": true,
67+
"wikimedia/composer-merge-plugin": true
6068
}
6169
},
6270
"scripts": {

phpunit.xml.dist

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="vendor/autoload.php"
4-
colors="true"
5-
verbose="true"
6-
failOnRisky="true"
7-
failOnWarning="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
stopOnFailure="false"
12-
executionOrder="default"
13-
resolveDependencies="true">
3+
<phpunit
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
verbose="true"
7+
failOnRisky="true"
8+
failOnWarning="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
stopOnFailure="false"
13+
executionOrder="default"
14+
resolveDependencies="true"
15+
>
1416

1517
<coverage>
1618
<include>
17-
<directory>./</directory>
19+
<directory>./src</directory>
1820
</include>
1921
<exclude>
2022
<directory>./tests</directory>

src/CommandPDO.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
namespace Yiisoft\Db\Pgsql;
66

77
use Exception;
8+
use Throwable;
89
use Yiisoft\Db\Driver\PDO\CommandPDO as AbstractCommandPDO;
10+
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
911
use Yiisoft\Db\Exception\ConvertException;
1012
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
11-
use Yiisoft\Db\Schema\SchemaInterface;
13+
14+
use function is_array;
1215

1316
final class CommandPDO extends AbstractCommandPDO
1417
{
@@ -23,7 +26,7 @@ public function insertEx(string $table, array $columns): bool|array
2326
$this->setSql($sql)->bindValues($params);
2427
$this->prepare(false);
2528

26-
/** @var mixed */
29+
/** @var mixed $queryOne */
2730
$queryOne = $this->queryOne();
2831

2932
return is_array($queryOne) ? $queryOne : false;
@@ -34,11 +37,12 @@ public function queryBuilder(): QueryBuilderInterface
3437
return $this->db->getQueryBuilder();
3538
}
3639

37-
public function schema(): SchemaInterface
38-
{
39-
return $this->db->getSchema();
40-
}
41-
40+
/**
41+
* @psalm-suppress UnusedClosureParam
42+
*
43+
* @throws \Yiisoft\Db\Exception\Exception
44+
* @throws Throwable
45+
*/
4246
protected function internalExecute(string|null $rawSql): void
4347
{
4448
$attempt = 0;
@@ -51,7 +55,7 @@ protected function internalExecute(string|null $rawSql): void
5155
&& $this->db->getTransaction() === null
5256
) {
5357
$this->db->transaction(
54-
fn (string|null $rawSql) => $this->internalExecute($rawSql),
58+
fn (ConnectionPDOInterface $db) => $this->internalExecute($rawSql),
5559
$this->isolationLevel
5660
);
5761
} else {

src/DDLQueryBuilder.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
use Yiisoft\Db\Schema\SchemaInterface;
1616

1717
use function array_diff;
18+
use function array_unshift;
19+
use function explode;
1820
use function implode;
1921
use function preg_match;
2022
use function preg_replace;
23+
use function str_contains;
2124

2225
final class DDLQueryBuilder extends AbstractDDLQueryBuilder
2326
{
@@ -29,6 +32,14 @@ public function __construct(
2932
parent::__construct($queryBuilder, $quoter, $schema);
3033
}
3134

35+
/**
36+
* @throws NotSupportedException
37+
*/
38+
public function addDefaultValue(string $name, string $table, string $column, mixed $value): string
39+
{
40+
throw new NotSupportedException(__METHOD__ . ' is not supported by PostgreSQL.');
41+
}
42+
3243
public function alterColumn(string $table, string $column, ColumnSchemaBuilder|string $type): string
3344
{
3445
$columnName = $this->quoter->quoteColumnName($column);
@@ -85,7 +96,7 @@ public function alterColumn(string $table, string $column, ColumnSchemaBuilder|s
8596
*/
8697
public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string
8798
{
88-
/** @var Schema */
99+
/** @var Schema $schemaInstance */
89100
$schemaInstance = $this->schema;
90101
$enable = $check ? 'ENABLE' : 'DISABLE';
91102
$schema = $schema ?: $schemaInstance->getDefaultSchema();
@@ -125,6 +136,14 @@ public function createIndex(string $name, string $table, array|string $columns,
125136
. ' (' . $this->queryBuilder->buildColumns($columns) . ')';
126137
}
127138

139+
/**
140+
* @throws NotSupportedException
141+
*/
142+
public function dropDefaultValue(string $name, string $table): string
143+
{
144+
throw new NotSupportedException(__METHOD__ . ' is not supported by PostgreSQL.');
145+
}
146+
128147
public function dropIndex(string $name, string $table): string
129148
{
130149
if (str_contains($table, '.') && !str_contains($name, '.')) {

0 commit comments

Comments
 (0)