diff --git a/.gitignore b/.gitignore index 5890559..27e4c53 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ composer.lock vendor/ phpunit.xml +.phpunit.result.cache Vagrantfile puphpet/ .vagrant/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 7edd749..018eee8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ sudo: required php: - 7.1 - 7.2 + - 8.0 - nightly services: diff --git a/composer.json b/composer.json index 0c0789a..4edf40a 100644 --- a/composer.json +++ b/composer.json @@ -18,18 +18,22 @@ { "name": "Mitrofanov Nikolay", "email": "mitrofanovnk@yandex.ru" + }, + { + "name": "Sanikovich Aleksey", + "email": "asanikovich@gmail.com" } ], "require": { - "php": "^7.1", - "ext-PDO": "*", + "php": "^7.1 || ^8.0", + "ext-pdo": "*", "ext-pcre": "*", "doctrine/dbal": "^2.7", - "smi2/phpClickHouse": "^1.0" + "smi2/phpclickhouse": "^1.0" }, "require-dev": { - "doctrine/coding-standard": "^4.0", - "phpunit/phpunit": "^7.0" + "doctrine/coding-standard": "^4.0 || ^9.0", + "phpunit/phpunit": "^7.0 || ^9.0" }, "autoload": { "psr-4": { diff --git a/src/ClickHouseConnection.php b/src/ClickHouseConnection.php index 18f3c36..563437a 100644 --- a/src/ClickHouseConnection.php +++ b/src/ClickHouseConnection.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -35,11 +35,6 @@ class ClickHouseConnection implements Connection, PingableConnection, ServerInfo /** @var AbstractPlatform */ protected $platform; - /** - * Connection constructor - * - * @param mixed[] $params - */ public function __construct( array $params, string $username, @@ -60,7 +55,7 @@ public function __construct( /** * {@inheritDoc} */ - public function prepare($prepareString) + public function prepare($prepareString) : ClickHouseStatement { return new ClickHouseStatement($this->smi2CHClient, $prepareString, $this->platform); } @@ -68,7 +63,7 @@ public function prepare($prepareString) /** * {@inheritDoc} */ - public function query() + public function query() : ClickHouseStatement { $args = func_get_args(); $stmt = $this->prepare($args[0]); @@ -105,53 +100,53 @@ public function exec($statement) : int */ public function lastInsertId($name = null) { - throw new \LogicException('Unable to get last insert id in ClickHouse'); + throw ClickHouseException::notSupported('Unable to get last insert id in ClickHouse'); } /** * {@inheritDoc} */ - public function beginTransaction() + public function beginTransaction() : bool { - throw new \LogicException('Transactions are not allowed in ClickHouse'); + throw ClickHouseException::notSupported('Transactions are not allowed in ClickHouse'); } /** * {@inheritDoc} */ - public function commit() + public function commit() : bool { - throw new \LogicException('Transactions are not allowed in ClickHouse'); + throw ClickHouseException::notSupported('Transactions are not allowed in ClickHouse'); } /** * {@inheritDoc} */ - public function rollBack() + public function rollBack() : bool { - throw new \LogicException('Transactions are not allowed in ClickHouse'); + throw ClickHouseException::notSupported('Transactions are not allowed in ClickHouse'); } /** * {@inheritDoc} */ - public function errorCode() + public function errorCode() : ?string { - throw new \LogicException('You need to implement ClickHouseConnection::errorCode()'); + throw ClickHouseException::notSupported('You need to implement ClickHouseConnection::errorCode()'); } /** * {@inheritDoc} */ - public function errorInfo() + public function errorInfo() : array { - throw new \LogicException('You need to implement ClickHouseConnection::errorInfo()'); + throw ClickHouseException::notSupported('You need to implement ClickHouseConnection::errorInfo()'); } /** * {@inheritDoc} */ - public function ping() + public function ping() : bool { return $this->smi2CHClient->ping(); } @@ -159,11 +154,11 @@ public function ping() /** * {@inheritDoc} */ - public function getServerVersion() + public function getServerVersion() : string { try { return $this->smi2CHClient->getServerVersion(); - } catch (TransportException $exception) { + } catch (TransportException $e) { return ''; } } @@ -171,7 +166,7 @@ public function getServerVersion() /** * {@inheritDoc} */ - public function requiresQueryForServerVersion() + public function requiresQueryForServerVersion() : bool { return true; } diff --git a/src/ClickHouseException.php b/src/ClickHouseException.php index 1b8be8c..076f2c0 100644 --- a/src/ClickHouseException.php +++ b/src/ClickHouseException.php @@ -8,15 +8,21 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace FOD\DBALClickHouse; +use Doctrine\DBAL\Exception; + /** * Specific Exception for ClickHouse */ -class ClickHouseException extends \Exception +class ClickHouseException extends Exception { + public static function notSupported($method) : ClickHouseException + { + return new self(sprintf("Operation '%s' is not supported by platform.", $method)); + } } diff --git a/src/ClickHouseKeywords.php b/src/ClickHouseKeywords.php index 9109103..b375b7c 100644 --- a/src/ClickHouseKeywords.php +++ b/src/ClickHouseKeywords.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/ClickHousePlatform.php b/src/ClickHousePlatform.php index 7962d96..6dae699 100644 --- a/src/ClickHousePlatform.php +++ b/src/ClickHousePlatform.php @@ -8,13 +8,12 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace FOD\DBALClickHouse; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\TrimMode; @@ -113,7 +112,7 @@ public function getSmallIntTypeDeclarationSQL(array $columnDef) : string protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) : string { if (! empty($columnDef['autoincrement'])) { - throw new \Exception('Clickhouse do not support AUTO_INCREMENT fields'); + throw ClickHouseException::notSupported('Clickhouse do not support AUTO_INCREMENT fields'); } return empty($columnDef['unsigned']) ? '' : UnsignedNumericalClickHouseType::UNSIGNED_CHAR; @@ -205,7 +204,7 @@ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) : string /** * {@inheritDoc} */ - public function getVarcharTypeDeclarationSQL(array $field) + public function getVarcharTypeDeclarationSQL(array $field) : string { if (! isset($field['length'])) { $field['length'] = $this->getVarcharDefaultLength(); @@ -415,7 +414,7 @@ public function getConcatExpression() : string /** * {@inheritDoc} */ - public function getIsNullExpression($expression) + public function getIsNullExpression($expression) : string { return 'isNull(' . $expression . ')'; } @@ -423,7 +422,7 @@ public function getIsNullExpression($expression) /** * {@inheritDoc} */ - public function getIsNotNullExpression($expression) + public function getIsNotNullExpression($expression) : string { return 'isNotNull(' . $expression . ')'; } @@ -567,65 +566,65 @@ public function getBitOrComparisonExpression($value1, $value2) : string /** * {@inheritDoc} */ - public function getForUpdateSQL() + public function getForUpdateSQL() : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function appendLockHint($fromClause, $lockMode) + public function appendLockHint($fromClause, $lockMode) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getReadLockSQL() + public function getReadLockSQL() : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getWriteLockSQL() + public function getWriteLockSQL() : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getDropIndexSQL($index, $table = null) + public function getDropIndexSQL($index, $table = null) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getDropConstraintSQL($constraint, $table) + public function getDropConstraintSQL($constraint, $table) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getDropForeignKeySQL($foreignKey, $table) + public function getDropForeignKeySQL($foreignKey, $table) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getCommentOnColumnSQL($tableName, $columnName, $comment) + public function getCommentOnColumnSQL($tableName, $columnName, $comment) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** @@ -637,11 +636,11 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options $engineOptions = ''; if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) { - throw DBALException::notSupported('uniqueConstraints'); + throw ClickHouseException::notSupported('uniqueConstraints'); } if (isset($options['indexes']) && ! empty($options['indexes'])) { - throw DBALException::notSupported('uniqueConstraints'); + throw ClickHouseException::notSupported('uniqueConstraints'); } /** @@ -808,9 +807,9 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options /** * {@inheritDoc} */ - public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) + public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** @@ -821,7 +820,7 @@ public function getAlterTableSQL(TableDiff $diff) : array $columnSql = []; $queryParts = []; if ($diff->newName !== false || ! empty($diff->renamedColumns)) { - throw DBALException::notSupported('RENAME COLUMN'); + throw ClickHouseException::notSupported('RENAME COLUMN'); } foreach ($diff->addedColumns as $column) { @@ -879,38 +878,35 @@ public function getAlterTableSQL(TableDiff $diff) : array /** * {@inheritDoc} */ - protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) + protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) : array { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) + protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) : array { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) + protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) : array { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff) + protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff) : array { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } - /** - * @param mixed[] $columnDef - */ protected function prepareDeclarationSQL(string $declarationSQL, array $columnDef) : string { if (array_key_exists('notnull', $columnDef) && $columnDef['notnull'] === false) { @@ -947,66 +943,66 @@ public function getDecimalTypeDeclarationSQL(array $columnDef) : string /** * {@inheritDoc} */ - public function getCheckDeclarationSQL(array $definition) + public function getCheckDeclarationSQL(array $definition) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getUniqueConstraintDeclarationSQL($name, Index $index) + public function getUniqueConstraintDeclarationSQL($name, Index $index) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getIndexDeclarationSQL($name, Index $index) + public function getIndexDeclarationSQL($name, Index $index) : string { // Index declaration in statements like CREATE TABLE is not supported. - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey) + public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey) + public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getForeignKeyReferentialActionSQL($action) + public function getForeignKeyReferentialActionSQL($action) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey) + public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getUniqueFieldDeclarationSQL() + public function getUniqueFieldDeclarationSQL() : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** @@ -1138,9 +1134,9 @@ public function getFloatDeclarationSQL(array $fieldDeclaration) : string /** * {@inheritDoc} */ - public function getDefaultTransactionIsolationLevel() + public function getDefaultTransactionIsolationLevel() : int { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /* supports*() methods */ @@ -1207,15 +1203,15 @@ protected function doModifyLimitQuery($query, $limit, $offset) : string /** * {@inheritDoc} */ - public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName) + public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getTruncateTableSQL($tableName, $cascade = false) + public function getTruncateTableSQL($tableName, $cascade = false) : string { /** * For MergeTree* engines may be done with next workaround: @@ -1223,31 +1219,31 @@ public function getTruncateTableSQL($tableName, $cascade = false) * SELECT partition FROM system.parts WHERE table= '$tableName'; * ALTER TABLE $tableName DROP PARTITION $partitionName */ - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function createSavePoint($savepoint) + public function createSavePoint($savepoint) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function releaseSavePoint($savepoint) + public function releaseSavePoint($savepoint) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function rollbackSavePoint($savepoint) + public function rollbackSavePoint($savepoint) : string { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** diff --git a/src/ClickHouseSchemaManager.php b/src/ClickHouseSchemaManager.php index 5607c31..3cd7850 100644 --- a/src/ClickHouseSchemaManager.php +++ b/src/ClickHouseSchemaManager.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -52,9 +52,9 @@ protected function _getPortableTableDefinition($table) /** * {@inheritdoc} */ - protected function _getPortableViewDefinition($view) + protected function _getPortableViewDefinition($view) : View { - $statement = $this->_conn->fetchColumn('SHOW CREATE TABLE ' . $view['name']); + $statement = $this->_conn->fetchOne('SHOW CREATE TABLE ' . $view['name']); return new View($view['name'], $statement); } diff --git a/src/ClickHouseStatement.php b/src/ClickHouseStatement.php index 9587257..3f5e7c6 100644 --- a/src/ClickHouseStatement.php +++ b/src/ClickHouseStatement.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Connection.php b/src/Connection.php index 80f8e72..18609ce 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -8,13 +8,12 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace FOD\DBALClickHouse; -use Doctrine\DBAL\DBALException; use function strtoupper; use function substr; use function trim; @@ -39,19 +38,19 @@ public function executeUpdate($query, array $params = [], array $types = []) : i } /** - * @throws DBALException + * @throws ClickHouseException */ public function delete($tableExpression, array $identifier, array $types = []) : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function update($tableExpression, array $data, array $identifier, array $types = []) : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** @@ -59,114 +58,114 @@ public function update($tableExpression, array $data, array $identifier, array $ */ /** - * @throws DBALException + * @throws ClickHouseException */ public function setTransactionIsolation($level) : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function getTransactionIsolation() : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function getTransactionNestingLevel() : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function transactional(\Closure $func) : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function getNestTransactionsWithSavepoints() : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function beginTransaction() : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function commit() : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function rollBack() : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function createSavepoint($savepoint) : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function releaseSavepoint($savepoint) : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function rollbackSavepoint($savepoint) : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function setRollbackOnly() : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } /** - * @throws DBALException + * @throws ClickHouseException */ public function isRollbackOnly() : void { - throw DBALException::notSupported(__METHOD__); + throw ClickHouseException::notSupported(__METHOD__); } } diff --git a/src/Driver.php b/src/Driver.php index 65ac5f7..9f80080 100644 --- a/src/Driver.php +++ b/src/Driver.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -24,14 +24,14 @@ class Driver implements \Doctrine\DBAL\Driver /** * {@inheritDoc} */ - public function connect(array $params, $user = null, $password = null, array $driverOptions = []) + public function connect(array $params, $username = null, $password = null, array $driverOptions = []) : ClickHouseConnection { - if ($user === null) { + if ($username === null) { if (! isset($params['user'])) { throw new ClickHouseException('Connection parameter `user` is required'); } - $user = $params['user']; + $username = $params['user']; } if ($password === null) { @@ -54,13 +54,13 @@ public function connect(array $params, $user = null, $password = null, array $dr throw new ClickHouseException('Connection parameter `dbname` is required'); } - return new ClickHouseConnection($params, (string) $user, (string) $password, $this->getDatabasePlatform()); + return new ClickHouseConnection($params, (string) $username, (string) $password, $this->getDatabasePlatform()); } /** * {@inheritDoc} */ - public function getDatabasePlatform() + public function getDatabasePlatform() : ClickHousePlatform { return new ClickHousePlatform(); } @@ -68,7 +68,7 @@ public function getDatabasePlatform() /** * {@inheritDoc} */ - public function getSchemaManager(Connection $conn) + public function getSchemaManager(Connection $conn) : ClickHouseSchemaManager { return new ClickHouseSchemaManager($conn); } @@ -84,13 +84,10 @@ public function getName() : string /** * {@inheritDoc} */ - public function getDatabase(Connection $conn) + public function getDatabase(Connection $conn) : string { $params = $conn->getParams(); - if (isset($params['dbname'])) { - return $params['dbname']; - } - return $conn->fetchColumn('SELECT currentDatabase() as dbname'); + return $params['dbname'] ?? $conn->fetchOne('SELECT currentDatabase() as dbname'); } } diff --git a/src/Types/ArrayDateTimeType.php b/src/Types/ArrayDateTimeType.php index 76cf715..390fa91 100644 --- a/src/Types/ArrayDateTimeType.php +++ b/src/Types/ArrayDateTimeType.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -33,7 +33,7 @@ public function getBaseClickHouseType() : string /** * {@inheritDoc} */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue($value, AbstractPlatform $platform) : array { return array_map( function ($stringDatetime) use ($platform) { @@ -46,7 +46,7 @@ function ($stringDatetime) use ($platform) { /** * {@inheritDoc} */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue($value, AbstractPlatform $platform) : string { return '[' . implode( ', ', diff --git a/src/Types/ArrayDateType.php b/src/Types/ArrayDateType.php index f96829d..69ad234 100644 --- a/src/Types/ArrayDateType.php +++ b/src/Types/ArrayDateType.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -33,7 +33,7 @@ public function getBaseClickHouseType() : string /** * {@inheritDoc} */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue($value, AbstractPlatform $platform) : array { return array_map( function ($stringDatetime) use ($platform) { @@ -46,7 +46,7 @@ function ($stringDatetime) use ($platform) { /** * {@inheritDoc} */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue($value, AbstractPlatform $platform) : string { return '[' . implode( ', ', diff --git a/src/Types/ArrayFloat32Type.php b/src/Types/ArrayFloat32Type.php index fcc0b27..77eac6a 100644 --- a/src/Types/ArrayFloat32Type.php +++ b/src/Types/ArrayFloat32Type.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/ArrayFloat64Type.php b/src/Types/ArrayFloat64Type.php index 01c8790..d2924f9 100644 --- a/src/Types/ArrayFloat64Type.php +++ b/src/Types/ArrayFloat64Type.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/ArrayInt16Type.php b/src/Types/ArrayInt16Type.php index 0c78d76..7b6faf1 100644 --- a/src/Types/ArrayInt16Type.php +++ b/src/Types/ArrayInt16Type.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/ArrayInt32Type.php b/src/Types/ArrayInt32Type.php index 201278e..5df7fed 100644 --- a/src/Types/ArrayInt32Type.php +++ b/src/Types/ArrayInt32Type.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/ArrayInt64Type.php b/src/Types/ArrayInt64Type.php index 2e1860d..591708d 100644 --- a/src/Types/ArrayInt64Type.php +++ b/src/Types/ArrayInt64Type.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/ArrayInt8Type.php b/src/Types/ArrayInt8Type.php index 9f18e6f..f3db1f9 100644 --- a/src/Types/ArrayInt8Type.php +++ b/src/Types/ArrayInt8Type.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/ArrayStringType.php b/src/Types/ArrayStringType.php index 8b39e5f..b11ff28 100644 --- a/src/Types/ArrayStringType.php +++ b/src/Types/ArrayStringType.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -32,7 +32,7 @@ public function getBaseClickHouseType() : string /** * {@inheritDoc} */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue($value, AbstractPlatform $platform) : string { return '[' . implode( ', ', diff --git a/src/Types/ArrayType.php b/src/Types/ArrayType.php index 2c185fc..a7a03dc 100644 --- a/src/Types/ArrayType.php +++ b/src/Types/ArrayType.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/ArrayUInt16Type.php b/src/Types/ArrayUInt16Type.php index 3fb8d4c..89e00bf 100644 --- a/src/Types/ArrayUInt16Type.php +++ b/src/Types/ArrayUInt16Type.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/ArrayUInt32Type.php b/src/Types/ArrayUInt32Type.php index ef6794c..d2a609e 100644 --- a/src/Types/ArrayUInt32Type.php +++ b/src/Types/ArrayUInt32Type.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/ArrayUInt64Type.php b/src/Types/ArrayUInt64Type.php index a21c280..7fff264 100644 --- a/src/Types/ArrayUInt64Type.php +++ b/src/Types/ArrayUInt64Type.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/ArrayUInt8Type.php b/src/Types/ArrayUInt8Type.php index 626eafa..7692369 100644 --- a/src/Types/ArrayUInt8Type.php +++ b/src/Types/ArrayUInt8Type.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/BigIntType.php b/src/Types/BigIntType.php index ace53cf..1bdd44a 100644 --- a/src/Types/BigIntType.php +++ b/src/Types/BigIntType.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -33,7 +33,7 @@ public function getBindingType() : int /** * {@inheritdoc} */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue($value, AbstractPlatform $platform) : int { return (int) $value; } diff --git a/src/Types/BitNumericalClickHouseType.php b/src/Types/BitNumericalClickHouseType.php index ab843b8..8a1f8dc 100644 --- a/src/Types/BitNumericalClickHouseType.php +++ b/src/Types/BitNumericalClickHouseType.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/ClickHouseType.php b/src/Types/ClickHouseType.php index 9f12543..ef56712 100644 --- a/src/Types/ClickHouseType.php +++ b/src/Types/ClickHouseType.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/DatableClickHouseType.php b/src/Types/DatableClickHouseType.php index e2e7e5a..c82b069 100644 --- a/src/Types/DatableClickHouseType.php +++ b/src/Types/DatableClickHouseType.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/NumericalClickHouseType.php b/src/Types/NumericalClickHouseType.php index ebee8ed..70ce5af 100644 --- a/src/Types/NumericalClickHouseType.php +++ b/src/Types/NumericalClickHouseType.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/StringClickHouseType.php b/src/Types/StringClickHouseType.php index 524d7e9..2705923 100644 --- a/src/Types/StringClickHouseType.php +++ b/src/Types/StringClickHouseType.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/src/Types/UnsignedNumericalClickHouseType.php b/src/Types/UnsignedNumericalClickHouseType.php index f17132e..70e8291 100644 --- a/src/Types/UnsignedNumericalClickHouseType.php +++ b/src/Types/UnsignedNumericalClickHouseType.php @@ -8,7 +8,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/tests/ArraysTest.php b/tests/ArraysTest.php index dfc412d..c99d1cb 100644 --- a/tests/ArraysTest.php +++ b/tests/ArraysTest.php @@ -5,7 +5,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -25,13 +25,13 @@ class ArraysTest extends TestCase /** @var Connection */ protected $connection; - public function setUp() + public function setUp() : void { $this->connection = CreateConnectionTest::createConnection(); ArrayType::registerArrayTypes($this->connection->getDatabasePlatform()); } - public function tearDown() + public function tearDown() : void { $this->connection->exec('DROP TABLE test_array_table'); } diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 5603b10..6dd6aa9 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -5,13 +5,12 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace FOD\DBALClickHouse\Tests; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use FOD\DBALClickHouse\ClickHouseException; use FOD\DBALClickHouse\Connection; @@ -27,7 +26,7 @@ class ConnectionTest extends TestCase /** @var Connection */ protected $connection; - public function setUp() + public function setUp() : void { $this->connection = CreateConnectionTest::createConnection(); } @@ -46,98 +45,98 @@ public function testExecuteUpdateUpdate() public function testDelete() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->delete('test', ['id' => 1]); } public function testUpdate() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->update('test', ['name' => 'test'], ['id' => 1]); } public function testSetTransactionIsolation() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->setTransactionIsolation(1); } public function testGetTransactionIsolation() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->getTransactionIsolation(); } public function testGetTransactionNestingLevel() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->getTransactionNestingLevel(); } public function testTransactional() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->transactional(function () { }); } public function testSetNestTransactionsWithSavepoints() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->setNestTransactionsWithSavepoints(true); } public function testGetNestTransactionsWithSavepoints() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->getNestTransactionsWithSavepoints(); } public function testBeginTransaction() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->beginTransaction(); } public function testCommit() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->commit(); } public function testRollBack() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->rollBack(); } public function testCreateSavepoint() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->createSavepoint('1'); } public function testReleaseSavepoint() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->releaseSavepoint('1'); } public function testRollbackSavepoint() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->rollbackSavepoint('1'); } public function testSetRollbackOnly() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->setRollbackOnly(); } public function testIsRollbackOnly() { - $this->expectException(DBALException::class); + $this->expectException(ClickHouseException::class); $this->connection->isRollbackOnly(); } @@ -150,7 +149,12 @@ public function testGetServerVersion() { $conn = $this->connection->getWrappedConnection(); if ($conn instanceof ServerInfoAwareConnection) { - $this->assertRegExp('/(^[0-9]+.[0-9]+.[0-9]+(.[0-9]$|$))/mi', $conn->getServerVersion()); + $pattern = '/(^[0-9]+.[0-9]+.[0-9]+(.[0-9]$|$))/mi'; + if (method_exists($this, 'assertMatchesRegularExpression')) { + $this->assertMatchesRegularExpression($pattern, $conn->getServerVersion()); + } else { + $this->assertRegExp($pattern, $conn->getServerVersion()); + } } else { $this->fail(sprintf('`%s` does not implement the `%s` interface', \get_class($conn), ServerInfoAwareConnection::class)); diff --git a/tests/CreateConnectionTest.php b/tests/CreateConnectionTest.php index 169049f..bcc026c 100644 --- a/tests/CreateConnectionTest.php +++ b/tests/CreateConnectionTest.php @@ -5,14 +5,14 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace FOD\DBALClickHouse\Tests; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use PHPUnit\Framework\TestCase; /** @@ -29,7 +29,7 @@ public function testCreateConnectionWithRightParams() public function testCreateConnectionWithBadParams() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->assertInstanceOf(Connection::class, self::createConnection([])); } diff --git a/tests/CreateSchemaTest.php b/tests/CreateSchemaTest.php index 5abdac6..ebc358b 100644 --- a/tests/CreateSchemaTest.php +++ b/tests/CreateSchemaTest.php @@ -5,7 +5,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -29,7 +29,7 @@ class CreateSchemaTest extends TestCase /** @var Connection */ protected $connection; - public function setUp() + public function setUp() : void { $this->connection = CreateConnectionTest::createConnection(); } diff --git a/tests/DbalTypeTest.php b/tests/DbalTypeTest.php index e9c2375..17d9fee 100644 --- a/tests/DbalTypeTest.php +++ b/tests/DbalTypeTest.php @@ -5,13 +5,12 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace FOD\DBALClickHouse\Tests; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Types\Type; use FOD\DBALClickHouse\Connection; use PHPUnit\Framework\TestCase; @@ -28,7 +27,7 @@ class DbalTypeTest extends TestCase protected $schemaSQLs = []; - public function setUp() + public function setUp() : void { $this->connection = CreateConnectionTest::createConnection(); @@ -65,7 +64,7 @@ public function setUp() } } - public function tearDown() + public function tearDown() : void { $this->connection->exec('DROP TABLE test_dbal_type_table'); } diff --git a/tests/DriverTest.php b/tests/DriverTest.php index ed1e11b..521221b 100644 --- a/tests/DriverTest.php +++ b/tests/DriverTest.php @@ -5,7 +5,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -27,7 +27,7 @@ class DriverTest extends TestCase /** @var Connection */ protected $connection; - public function setUp() + public function setUp() : void { $this->connection = CreateConnectionTest::createConnection(); } diff --git a/tests/InsertTest.php b/tests/InsertTest.php index 59be336..7184e0d 100644 --- a/tests/InsertTest.php +++ b/tests/InsertTest.php @@ -5,7 +5,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -24,7 +24,7 @@ class InsertTest extends TestCase /** @var Connection */ protected $connection; - public function setUp() + public function setUp() : void { $this->connection = CreateConnectionTest::createConnection(); @@ -43,7 +43,7 @@ public function setUp() } } - public function tearDown() + public function tearDown() : void { $this->connection->exec('DROP TABLE test_insert_table'); } diff --git a/tests/SelectTest.php b/tests/SelectTest.php index 52e1dba..45c4ffb 100644 --- a/tests/SelectTest.php +++ b/tests/SelectTest.php @@ -5,7 +5,7 @@ * * (c) FriendsOfDoctrine . * - * For the full copyright and license inflormation, please view the LICENSE + * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -26,7 +26,7 @@ class SelectTest extends TestCase /** @var Connection */ protected $connection; - public function setUp() + public function setUp() : void { $this->connection = CreateConnectionTest::createConnection(); @@ -48,7 +48,7 @@ public function setUp() $this->connection->exec("INSERT INTO test_select_table(id, payload, hits) VALUES (1, 'v1', 101), (2, 'v2', 202), (3, 'v3', 303), (4, 'v4', 404), (5, 'v4', 505), (6, ' t1 ', 606), (7, 'aat2aaa', 707)"); } - public function tearDown() + public function tearDown() : void { $this->connection->exec('DROP TABLE test_select_table'); } @@ -75,9 +75,9 @@ public function testFetchAssocSelect() public function testFetchNumSelect() { - $stmt = $this->connection->query('SELECT MAX(hits) FROM test_select_table'); + $stmt = $this->connection->query('SELECT MAX(hits) as maxHits FROM test_select_table'); $result = $stmt->fetch(FetchMode::ASSOCIATIVE); - $this->assertEquals(['MAX(hits)' => 707], $result); + $this->assertEquals(['maxHits' => 707], $result); } public function testFetchObjSelect() @@ -204,16 +204,12 @@ public function testQueryBuilderSelect() public function testDynamicParametersSelect() { - $stmt = $this->connection->prepare('SELECT payload, AVG(hits) AS avg_hits FROM test_select_table WHERE id > :id GROUP BY payload'); + $stmt = $this->connection->prepare('SELECT payload, AVG(hits) AS avg_hits FROM test_select_table WHERE id > :id GROUP BY payload ORDER BY payload'); $stmt->bindValue('id', 3, 'integer'); $stmt->execute(); $this->assertEquals([ - [ - 'payload' => 'v4', - 'avg_hits' => 454.5, - ], [ 'payload' => ' t1 ', 'avg_hits' => 606, @@ -221,7 +217,11 @@ public function testDynamicParametersSelect() [ 'payload' => 'aat2aaa', 'avg_hits' => 707, - ] + ], + [ + 'payload' => 'v4', + 'avg_hits' => 454.5, + ], ], $stmt->fetchAll()); }