Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/docker' into docker
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev committed Dec 10, 2024
2 parents 1d5491a + b1abbc8 commit 9389803
Show file tree
Hide file tree
Showing 19 changed files with 134 additions and 68 deletions.
25 changes: 7 additions & 18 deletions .github/workflows/active-record.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,14 @@ name: active-record

jobs:
tests:
name: PHP ${{ matrix.php }}-active-record-${{ matrix.os }}
name: ActiveRecord

env:
COMPOSER_ROOT_VERSION: dev-master
EXTENSIONS: pdo, pdo_mysql, pdo_oci, pdo_pgsql, pdo_sqlite, pdo_sqlsrv-5.12
PHP_VERSION: 8.3
EXTENSIONS: pdo, pdo_mysql, pdo_oci, pdo_pgsql, pdo_sqlite, pdo_sqlsrv

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

strategy:
matrix:
os:
- ubuntu-latest

php:
- 8.1
- 8.2
- 8.3
runs-on: ubuntu-latest

services:
mysql:
Expand Down Expand Up @@ -83,19 +74,18 @@ jobs:
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
- name: Checkout.
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Create MS SQL Database.
run: docker exec -i mssql /opt/mssql-tools18/bin/sqlcmd -C -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'CREATE DATABASE yiitest'

- name: Install PHP with extensions.
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
php-version: ${{ env.PHP_VERSION }}
extensions: ${{ env.EXTENSIONS }}
ini-values: date.timezone='UTC'
coverage: pcov
tools: composer:v2, pecl

- name: Update composer.
run: composer self-update
Expand Down Expand Up @@ -170,8 +160,7 @@ jobs:
run: vendor/bin/phpunit --testsuite ActiveRecord --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations

- name: Upload coverage to Codecov.
if: matrix.php == '8.3'
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
20 changes: 5 additions & 15 deletions .github/workflows/db-migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,14 @@ name: db-migration

jobs:
tests:
name: PHP ${{ matrix.php }}-db-migration-${{ matrix.os }}
name: DbMigration

env:
COMPOSER_ROOT_VERSION: dev-master
PHP_VERSION: 8.3
EXTENSIONS: pdo, pdo_mysql, pdo_oci, pdo_pgsql, pdo_sqlite, pdo_sqlsrv

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

strategy:
matrix:
os:
- ubuntu-latest

php:
- 8.1
- 8.2
- 8.3
runs-on: ubuntu-latest

services:
mysql:
Expand Down Expand Up @@ -91,7 +82,7 @@ jobs:
- name: Install PHP with extensions.
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
php-version: ${{ env.PHP_VERSION }}
extensions: ${{ env.EXTENSIONS }}
ini-values: date.timezone='UTC'
coverage: pcov
Expand Down Expand Up @@ -166,8 +157,7 @@ jobs:
run: vendor/bin/phpunit --testsuite=DbMigration --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations

- name: Upload coverage to Codecov.
if: matrix.php == '8.3'
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
- New #899: Add `ColumnSchemaInterface::hasDefaultValue()` and `ColumnSchemaInterface::null()` methods (@Tigrov)
- New #902: Add `QueryBuilderInterface::prepareParam()` and `QueryBuilderInterface::prepareValue()` methods (@Tigrov)
- Enh #902: Refactor `Quoter::quoteValue()` method (@Tigrov)
- New #906: Add `ServerInfoInterface` and its implementation (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
3 changes: 3 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ Each table column has its own class in the `Yiisoft\Db\Schema\Column` namespace
- `QueryBuilderInterface::buildColumnDefinition()` - builds column definition for `CREATE TABLE` statement;
- `QueryBuilderInterface::prepareParam()` - converts a `ParamInterface` object to its SQL representation;
- `QueryBuilderInterface::prepareValue()` - converts a value to its SQL representation;
- `QueryBuilderInterface::getServerInfo()` - returns `ServerInfoInterface` instance which provides server information;
- `ConnectionInterface::getServerInfo()` - returns `ServerInfoInterface` instance which provides server information;

### Remove methods

Expand All @@ -123,6 +125,7 @@ Each table column has its own class in the `Yiisoft\Db\Schema\Column` namespace
- `Quoter::unquoteParts()`
- `AbstractPdoCommand::logQuery()`
- `ColumnSchemaInterface::phpType()`
- `ConnectionInterface::getServerVersion()`

### Remove deprecated parameters

Expand Down
4 changes: 2 additions & 2 deletions docs/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ services:
Adjust the `/path/to/packages` to the path where packages are installed on your host machine.

In case of ports' collisions, the mapping and enviroment variables can also be adjusted here.
In case of ports' collisions, the mapping and environment variables can also be adjusted here.

### Unit testing

#### Available commands

- `make test-all` - run all available tests.
- `make test-db` - run tests for base db package only.
- `make test-base` - run tests for base db package only.
- `make test-driver-all` - run tests for all drivers.
- `make test-driver-sqlite` - run tests for SQLite driver only.
- `make test-driver-mysql` - run tests for MySQL driver only (using MySQL database).
Expand Down
9 changes: 2 additions & 7 deletions src/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,9 @@ public function getQuoter(): QuoterInterface;
public function getSchema(): SchemaInterface;

/**
* Returns a server version as a string comparable by {@see \version_compare()}.
*
* @throws Exception
* @throws InvalidConfigException
*
* @return string The server version as a string.
* Returns {@see ServerInfoInterface} instance that provides information about the database server.
*/
public function getServerVersion(): string;
public function getServerInfo(): ServerInfoInterface;

/**
* Return table prefix for current DB connection.
Expand Down
16 changes: 16 additions & 0 deletions src/Connection/ServerInfoInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Connection;

/**
* Should be implemented by a class that provides information about the database server.
*/
interface ServerInfoInterface
{
/**
* Returns a server version as a string comparable by {@see version_compare()}.
*/
public function getVersion(): string;
}
5 changes: 3 additions & 2 deletions src/Debug/ConnectionInterfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Closure;
use Yiisoft\Db\Command\CommandInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Connection\ServerInfoInterface;
use Yiisoft\Db\Query\BatchQueryResultInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
Expand Down Expand Up @@ -82,9 +83,9 @@ public function getSchema(): SchemaInterface
return $this->connection->getSchema();
}

public function getServerVersion(): string
public function getServerInfo(): ServerInfoInterface
{
return $this->connection->getServerVersion();
return $this->connection->getServerInfo();
}

public function getTablePrefix(): string
Expand Down
13 changes: 4 additions & 9 deletions src/Driver/Pdo/AbstractPdoConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Throwable;
use Yiisoft\Db\Cache\SchemaCache;
use Yiisoft\Db\Connection\AbstractConnection;
use Yiisoft\Db\Connection\ServerInfoInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidCallException;
use Yiisoft\Db\Exception\InvalidConfigException;
Expand Down Expand Up @@ -43,7 +44,7 @@ abstract class AbstractPdoConnection extends AbstractConnection implements PdoCo
use ProfilerAwareTrait;

protected PDO|null $pdo = null;
protected string $serverVersion = '';
protected ServerInfoInterface|null $serverInfo = null;
protected bool|null $emulatePrepare = null;
protected QueryBuilderInterface|null $queryBuilder = null;
protected QuoterInterface|null $quoter = null;
Expand Down Expand Up @@ -169,15 +170,9 @@ public function getDriverName(): string
return $this->driver->getDriverName();
}

public function getServerVersion(): string
public function getServerInfo(): ServerInfoInterface
{
if ($this->serverVersion === '') {
/** @psalm-var mixed $version */
$version = $this->getActivePDO()->getAttribute(PDO::ATTR_SERVER_VERSION);
$this->serverVersion = is_string($version) ? $version : 'Version could not be determined.';
}

return $this->serverVersion;
return $this->serverInfo ??= new PdoServerInfo($this);
}

public function isActive(): bool
Expand Down
27 changes: 27 additions & 0 deletions src/Driver/Pdo/PdoServerInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Driver\Pdo;

use PDO;
use Yiisoft\Db\Connection\ServerInfoInterface;

class PdoServerInfo implements ServerInfoInterface
{
protected string|null $version = null;

public function __construct(protected PdoConnectionInterface $db)
{
}

public function getVersion(): string
{
if ($this->version === null) {
/** @var string */
$this->version = $this->db->getActivePDO()?->getAttribute(PDO::ATTR_SERVER_VERSION) ?? '';
}

return $this->version;
}
}
7 changes: 7 additions & 0 deletions src/QueryBuilder/AbstractQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Yiisoft\Db\Command\DataType;
use Yiisoft\Db\Command\ParamInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Connection\ServerInfoInterface;
use Yiisoft\Db\Constant\GettypeResult;
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Expression\Expression;
Expand Down Expand Up @@ -67,6 +68,7 @@ abstract class AbstractQueryBuilder implements QueryBuilderInterface
public function __construct(
private QuoterInterface $quoter,
private SchemaInterface $schema,
private ServerInfoInterface $serverInfo,
private AbstractDDLQueryBuilder $ddlBuilder,
private AbstractDMLQueryBuilder $dmlBuilder,
private AbstractDQLQueryBuilder $dqlBuilder,
Expand Down Expand Up @@ -386,6 +388,11 @@ public function getExpressionBuilder(ExpressionInterface $expression): object
return $this->dqlBuilder->getExpressionBuilder($expression);
}

public function getServerInfo(): ServerInfoInterface
{
return $this->serverInfo;
}

public function insert(string $table, QueryInterface|array $columns, array &$params = []): string
{
return $this->dmlBuilder->insert($table, $columns, $params);
Expand Down
6 changes: 6 additions & 0 deletions src/QueryBuilder/QueryBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Yiisoft\Db\Command\ParamInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Connection\ServerInfoInterface;
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Expression\ExpressionBuilderInterface;
use Yiisoft\Db\Expression\ExpressionInterface;
Expand Down Expand Up @@ -109,6 +110,11 @@ public function getColumnType(ColumnInterface|string $type): string;
*/
public function getExpressionBuilder(ExpressionInterface $expression): object;

/**
* Returns {@see ServerInfoInterface} instance that provides information about the database server.
*/
public function getServerInfo(): ServerInfoInterface;

/**
* @return QuoterInterface The quoter instance.
*/
Expand Down
5 changes: 3 additions & 2 deletions tests/AbstractPdoConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Yiisoft\Db\Driver\Pdo\PdoDriverInterface;
use Yiisoft\Db\Driver\Pdo\PdoServerInfo;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Tests\Support\TestTrait;
Expand All @@ -35,11 +36,11 @@ public function testGetDriver(): void
$this->assertInstanceOf(PdoDriverInterface::class, $driver);
}

public function testGetServerVersion(): void
public function testGetServerInfo(): void
{
$db = $this->getConnection();

$this->assertIsString($db->getServerVersion());
$this->assertInstanceOf(PdoServerInfo::class, $db->getServerInfo());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Common/CommonColumnSchemaBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected function checkCreateColumn(string $expected, string $type, int|null $l
$db = $this->getConnection();

if (str_contains($expected, 'UUID_TO_BIN')) {
$serverVersion = $db->getServerVersion();
$serverVersion = $db->getServerInfo()->getVersion();
if (str_contains($serverVersion, 'MariaDB')) {
$db->close();
$this->markTestSkipped('UUID_TO_BIN not supported MariaDB as defaultValue');
Expand Down
2 changes: 1 addition & 1 deletion tests/Common/CommonPdoConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function testTransactionRollbackTransactionOnLevel(): void
'getQueryBuilder',
'getQuoter',
'getSchema',
'getServerVersion',
'getServerInfo',
'isActive',
'open',
'quoteValue',
Expand Down
21 changes: 21 additions & 0 deletions tests/Db/Driver/PDO/PdoServerInfoTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Driver\PDO;

use PHPUnit\Framework\TestCase;
use Yiisoft\Db\Tests\Support\TestTrait;

class PdoServerInfoTest extends TestCase
{
use TestTrait;

public function testGetVersion(): void
{
$db = $this->getConnection();
$serverInfo = $db->getServerInfo();

$this->assertIsString($serverInfo->getVersion());
}
}
Loading

0 comments on commit 9389803

Please sign in to comment.