From 35d354e5c0b23e205b172fc965ac0fdb0890c887 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Mon, 3 Dec 2018 11:15:32 +0100 Subject: [PATCH 001/106] Clean up MySqlPlatform::getListTableIndexesSQL() fields --- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 98228fc50b3..2a7fca3115a 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -154,11 +154,10 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) $currentDatabase = $this->quoteStringLiteral($currentDatabase); $table = $this->quoteStringLiteral($table); - return 'SELECT TABLE_NAME AS `Table`, NON_UNIQUE AS Non_Unique, INDEX_NAME AS Key_name, ' . - 'SEQ_IN_INDEX AS Seq_in_index, COLUMN_NAME AS Column_Name, COLLATION AS Collation, ' . - 'CARDINALITY AS Cardinality, SUB_PART AS Sub_Part, PACKED AS Packed, ' . - 'NULLABLE AS `Null`, INDEX_TYPE AS Index_Type, COMMENT AS Comment ' . - 'FROM information_schema.STATISTICS WHERE TABLE_NAME = ' . $table . ' AND TABLE_SCHEMA = ' . $currentDatabase . + return 'SELECT NON_UNIQUE AS Non_Unique, INDEX_NAME AS Key_name, COLUMN_NAME AS Column_Name,' . + ' SUB_PART AS Sub_Part, INDEX_TYPE AS Index_Type' . + ' FROM information_schema.STATISTICS WHERE TABLE_NAME = ' . $table . + ' AND TABLE_SCHEMA = ' . $currentDatabase . ' ORDER BY SEQ_IN_INDEX ASC'; } From 6e58fbffc3c9f7cb6620344d7dc34d29c2e753dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Mon, 3 Dec 2018 15:57:33 +0100 Subject: [PATCH 002/106] fix bound parameter references on SQL Anywhere and PHP 7 --- .../DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 0ed2d454624..0bdd9a93c95 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -59,6 +59,9 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement /** @var resource The prepared SQL statement to execute. */ private $stmt; + /** @var mixed[] The references to bound parameter values. */ + private $boundValues = []; + /** * Prepares given statement for given connection. * @@ -108,6 +111,8 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l throw new SQLAnywhereException('Unknown type: ' . $type); } + $this->boundValues[$column] =& $variable; + if (! sasql_stmt_bind_param_ex($this->stmt, $column - 1, $variable, $type, $variable === null)) { throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt); } From 27023276734da75a08cfdd31995884df8030975c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 3 Dec 2018 20:49:48 -0800 Subject: [PATCH 003/106] Bump version to 2.10.0-DEV --- .doctrine-project.json | 16 +++++++++++----- README.md | 26 ++++++++++++++++++-------- lib/Doctrine/DBAL/Version.php | 2 +- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.doctrine-project.json b/.doctrine-project.json index 9fb3d836c74..7b97cb45129 100644 --- a/.doctrine-project.json +++ b/.doctrine-project.json @@ -12,21 +12,27 @@ "upcoming": true }, { - "name": "2.9", + "name": "2.10", "branchName": "master", - "slug": "2.9", + "slug": "2.10", "upcoming": true }, { - "name": "2.8", - "branchName": "2.8", - "slug": "2.8", + "name": "2.9", + "branchName": "2.9", + "slug": "2.9", "current": true, "aliases": [ "current", "stable" ] }, + { + "name": "2.8", + "branchName": "2.8", + "slug": "2.8", + "maintained": false + }, { "name": "2.7", "branchName": "2.7", diff --git a/README.md b/README.md index 8a5767338b3..2dabbf4e0b1 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Doctrine DBAL -| [Master][Master] | [2.8][2.8] | [Develop][develop] | -|:----------------:|:----------:|:------------------:| -| [![Build status][Master image]][Master] | [![Build status][2.8 image]][2.8] | [![Build status][develop image]][develop] | -| [![Build Status][ContinuousPHP image]][ContinuousPHP] | [![Build Status][ContinuousPHP 2.8 image]][ContinuousPHP] | [![Build Status][ContinuousPHP develop image]][ContinuousPHP] | -| [![Code Coverage][Coverage image]][Scrutinizer Master] | [![Code Coverage][Coverage 2.8 image]][Scrutinizer 2.8] | [![Code Coverage][Coverage develop image]][Scrutinizer develop] | -| [![Code Quality][Quality image]][Scrutinizer Master] | [![Code Quality][Quality 2.8 image]][Scrutinizer 2.8] | [![Code Quality][Quality develop image]][Scrutinizer develop] | -| [![AppVeyor][AppVeyor master image]][AppVeyor master] | [![AppVeyor][AppVeyor 2.8 image]][AppVeyor 2.8] | [![AppVeyor][AppVeyor develop image]][AppVeyor develop] | +| [Master][Master] | [2.9][2.9] | [2.8][2.8] | [Develop][develop] | +|:----------------:|:----------:|:----------:|:------------------:| +| [![Build status][Master image]][Master] | [![Build status][2.9 image]][2.9] | [![Build status][2.8 image]][2.8] | [![Build status][develop image]][develop] | +| [![Build Status][ContinuousPHP image]][ContinuousPHP] | [![Build Status][ContinuousPHP 2.9 image]][ContinuousPHP] | [![Build Status][ContinuousPHP 2.8 image]][ContinuousPHP] | [![Build Status][ContinuousPHP develop image]][ContinuousPHP] | +| [![Code Coverage][Coverage image]][Scrutinizer Master] | [![Code Coverage][Coverage 2.9 image]][Scrutinizer 2.9] | [![Code Coverage][Coverage 2.8 image]][Scrutinizer 2.8] | [![Code Coverage][Coverage develop image]][Scrutinizer develop] | +| [![Code Quality][Quality image]][Scrutinizer Master] | [![Code Quality][Quality 2.9 image]][Scrutinizer 2.9] | [![Code Quality][Quality 2.8 image]][Scrutinizer 2.8] | [![Code Quality][Quality develop image]][Scrutinizer develop] | +| [![AppVeyor][AppVeyor master image]][AppVeyor master] | [![AppVeyor][AppVeyor 2.9 image]][AppVeyor 2.9] | [![AppVeyor][AppVeyor 2.8 image]][AppVeyor 2.8] | [![AppVeyor][AppVeyor develop image]][AppVeyor develop] | Powerful database abstraction layer with many features for database schema introspection, schema management and PDO abstraction. @@ -16,7 +16,6 @@ Powerful database abstraction layer with many features for database schema intro * [Documentation](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/) * [Issue Tracker](https://github.com/doctrine/dbal/issues) - [Master image]: https://img.shields.io/travis/doctrine/dbal/master.svg?style=flat-square [Coverage image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/dbal/master.svg?style=flat-square [Quality image]: https://img.shields.io/scrutinizer/g/doctrine/dbal/master.svg?style=flat-square @@ -26,6 +25,16 @@ Powerful database abstraction layer with many features for database schema intro [AppVeyor master]: https://ci.appveyor.com/project/doctrine/dbal/branch/master [AppVeyor master image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/master?svg=true [ContinuousPHP]: https://continuousphp.com/git-hub/doctrine/dbal + + [2.9 image]: https://img.shields.io/travis/doctrine/dbal/2.9.svg?style=flat-square + [Coverage 2.9 image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/dbal/2.9.svg?style=flat-square + [Quality 2.9 image]: https://img.shields.io/scrutinizer/g/doctrine/dbal/2.9.svg?style=flat-square + [ContinuousPHP 2.9 image]: https://img.shields.io/continuousphp/git-hub/doctrine/dbal/2.9.svg?style=flat-square + [2.9]: https://github.com/doctrine/dbal/tree/2.9 + [Scrutinizer 2.9]: https://scrutinizer-ci.com/g/doctrine/dbal/?branch=2.9 + [AppVeyor 2.9]: https://ci.appveyor.com/project/doctrine/dbal/branch/2.9 + [AppVeyor 2.9 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/2.9?svg=true + [2.8 image]: https://img.shields.io/travis/doctrine/dbal/2.8.svg?style=flat-square [Coverage 2.8 image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/dbal/2.8.svg?style=flat-square [Quality 2.8 image]: https://img.shields.io/scrutinizer/g/doctrine/dbal/2.8.svg?style=flat-square @@ -34,6 +43,7 @@ Powerful database abstraction layer with many features for database schema intro [Scrutinizer 2.8]: https://scrutinizer-ci.com/g/doctrine/dbal/?branch=2.8 [AppVeyor 2.8]: https://ci.appveyor.com/project/doctrine/dbal/branch/2.8 [AppVeyor 2.8 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/2.8?svg=true + [develop]: https://github.com/doctrine/dbal/tree/develop [develop image]: https://img.shields.io/travis/doctrine/dbal/develop.svg?style=flat-square [Coverage develop image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/dbal/develop.svg?style=flat-square diff --git a/lib/Doctrine/DBAL/Version.php b/lib/Doctrine/DBAL/Version.php index 60530e69a76..93be3a1dfba 100644 --- a/lib/Doctrine/DBAL/Version.php +++ b/lib/Doctrine/DBAL/Version.php @@ -14,7 +14,7 @@ class Version /** * Current Doctrine Version. */ - public const VERSION = '2.9.0-DEV'; + public const VERSION = '2.10.0-DEV'; /** * Compares a Doctrine version with the current one. From 6304d8561bea2eb57fa291256ace4e76c833f951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Tue, 4 Dec 2018 10:04:27 +0100 Subject: [PATCH 004/106] fix query limit values "0" and "null" on SQL Anywhere --- .../DBAL/Platforms/SQLAnywherePlatform.php | 23 ++++++++----------- .../Platforms/SQLAnywherePlatformTest.php | 10 +++++++- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index a8fbfeb46e4..ec3ef933441 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -1308,25 +1308,20 @@ protected function _getTransactionIsolationLevelSQL($level) */ protected function doModifyLimitQuery($query, $limit, $offset) { - $limitOffsetClause = ''; + $limitOffsetClause = $this->getTopClauseSQL($limit, $offset); - if ($limit > 0) { - $limitOffsetClause = 'TOP ' . $limit . ' '; - } + return $limitOffsetClause === '' + ? $query + : preg_replace('/^\s*(SELECT\s+(DISTINCT\s+)?)/i', '\1' . $limitOffsetClause . ' ', $query); + } + private function getTopClauseSQL(?int $limit, ?int $offset) : string + { if ($offset > 0) { - if ($limit === 0) { - $limitOffsetClause = 'TOP ALL '; - } - - $limitOffsetClause .= 'START AT ' . ($offset + 1) . ' '; - } - - if ($limitOffsetClause) { - return preg_replace('/^\s*(SELECT\s+(DISTINCT\s+)?)/i', '\1' . $limitOffsetClause, $query); + return sprintf('TOP %s START AT %d', $limit ?? 'ALL', $offset + 1); } - return $query; + return $limit === null ? '' : 'TOP ' . $limit; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 294b9836e2e..219119c2cc1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -646,7 +646,7 @@ public function testModifiesLimitQueryWithOffset() $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 5) ); self::assertEquals( - 'SELECT TOP ALL START AT 6 * FROM user', + 'SELECT TOP 0 START AT 6 * FROM user', $this->platform->modifyLimitQuery('SELECT * FROM user', 0, 5) ); } @@ -659,6 +659,14 @@ public function testModifiesLimitQueryWithSubSelect() ); } + public function testModifiesLimitQueryWithoutLimit() + { + self::assertEquals( + 'SELECT TOP ALL START AT 11 n FROM Foo', + $this->platform->modifyLimitQuery('SELECT n FROM Foo', null, 10) + ); + } + public function testPrefersIdentityColumns() { self::assertTrue($this->platform->prefersIdentityColumns()); From 2a0f67d5809aff2be122a126ba29804d2d1579b5 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 4 Dec 2018 09:26:17 -0800 Subject: [PATCH 005/106] Reverted strict comparison back to loose because of a new regression --- lib/Doctrine/DBAL/Schema/Comparator.php | 2 +- phpcs.xml.dist | 5 +++++ .../DBAL/Functional/Schema/ComparatorTest.php | 22 ++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index 3b5a0b155d0..1d8a7275d98 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -435,7 +435,7 @@ public function diffColumn(Column $column1, Column $column2) // Null values need to be checked additionally as they tell whether to create or drop a default value. // null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation. if (($properties1['default'] === null) !== ($properties2['default'] === null) - || (string) $properties1['default'] !== (string) $properties2['default']) { + || $properties1['default'] != $properties2['default']) { $changedProperties[] = 'default'; } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index aaa6b5f04a5..c38da21aa70 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -58,4 +58,9 @@ tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php + + + + lib/Doctrine/DBAL/Schema/Comparator.php + diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php index a97eb90bbce..0feb30fa5ba 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php @@ -25,15 +25,31 @@ protected function setUp() $this->comparator = new Comparator(); } - public function testDefaultValueComparison() + /** + * @param mixed $value + * + * @dataProvider defaultValueProvider + */ + public function testDefaultValueComparison(string $type, $value) : void { $table = new Table('default_value'); - $table->addColumn('id', 'integer', ['default' => 1]); + $table->addColumn('test', $type, ['default' => $value]); - $this->schemaManager->createTable($table); + $this->schemaManager->dropAndCreateTable($table); $onlineTable = $this->schemaManager->listTableDetails('default_value'); self::assertFalse($this->comparator->diffTable($table, $onlineTable)); } + + /** + * @return mixed[][] + */ + public static function defaultValueProvider() : iterable + { + return [ + ['integer', 1], + ['boolean', false], + ]; + } } From 56abe26efeca6264a5a3b1f122459b7d6e032af7 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 4 Dec 2018 09:52:32 -0800 Subject: [PATCH 006/106] Fixed boolean column detection on Oracle --- .../DBAL/Schema/OracleSchemaManager.php | 66 +++++-------------- 1 file changed, 17 insertions(+), 49 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index e84b0a551f8..250ec2a2652 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -128,7 +128,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) } } - $unsigned = $fixed = null; + $unsigned = $fixed = $precision = $scale = $length = null; if (! isset($tableColumn['column_name'])) { $tableColumn['column_name'] = ''; @@ -146,8 +146,13 @@ protected function _getPortableTableColumnDefinition($tableColumn) $tableColumn['data_default'] = trim($tableColumn['data_default'], "'"); } - $precision = null; - $scale = null; + if ($tableColumn['data_precision'] !== null) { + $precision = (int) $tableColumn['data_precision']; + } + + if ($tableColumn['data_scale'] !== null) { + $scale = (int) $tableColumn['data_scale']; + } $type = $this->_platform->getDoctrineTypeMapping($dbType); $type = $this->extractDoctrineTypeFromComment($tableColumn['comments'], $type); @@ -155,28 +160,16 @@ protected function _getPortableTableColumnDefinition($tableColumn) switch ($dbType) { case 'number': - if ($tableColumn['data_precision'] === 20 && $tableColumn['data_scale'] === 0) { - $precision = 20; - $scale = 0; - $type = 'bigint'; - } elseif ($tableColumn['data_precision'] === 5 && $tableColumn['data_scale'] === 0) { - $type = 'smallint'; - $precision = 5; - $scale = 0; - } elseif ($tableColumn['data_precision'] === 1 && $tableColumn['data_scale'] === 0) { - $precision = 1; - $scale = 0; - $type = 'boolean'; - } elseif ($tableColumn['data_scale'] > 0) { - $precision = $tableColumn['data_precision']; - $scale = $tableColumn['data_scale']; - $type = 'decimal'; + if ($precision === 20 && $scale === 0) { + $type = 'bigint'; + } elseif ($precision === 5 && $scale === 0) { + $type = 'smallint'; + } elseif ($precision === 1 && $scale === 0) { + $type = 'boolean'; + } elseif ($scale > 0) { + $type = 'decimal'; } - $length = null; - break; - case 'pls_integer': - case 'binary_integer': - $length = null; + break; case 'varchar': case 'varchar2': @@ -189,31 +182,6 @@ protected function _getPortableTableColumnDefinition($tableColumn) $length = $tableColumn['char_length']; $fixed = true; break; - case 'date': - case 'timestamp': - $length = null; - break; - case 'float': - case 'binary_float': - case 'binary_double': - $precision = $tableColumn['data_precision']; - $scale = $tableColumn['data_scale']; - $length = null; - break; - case 'clob': - case 'nclob': - $length = null; - break; - case 'blob': - case 'raw': - case 'long raw': - case 'bfile': - $length = null; - break; - case 'rowid': - case 'urowid': - default: - $length = null; } $options = [ From 50be88c36269955ffef305ef27f4db342c5a5daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Wed, 5 Dec 2018 21:14:27 +0100 Subject: [PATCH 007/106] fix fetching empty values via fetchAll() on SQL Anywhere --- .../DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 0bdd9a93c95..6354836a478 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -253,19 +253,19 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n switch ($fetchMode) { case FetchMode::CUSTOM_OBJECT: - while ($row = $this->fetch(...func_get_args())) { + while (($row = $this->fetch(...func_get_args())) !== false) { $rows[] = $row; } break; case FetchMode::COLUMN: - while ($row = $this->fetchColumn()) { + while (($row = $this->fetchColumn()) !== false) { $rows[] = $row; } break; default: - while ($row = $this->fetch($fetchMode)) { + while (($row = $this->fetch($fetchMode)) !== false) { $rows[] = $row; } } From 2c6a85e3f26896b9d8f462c78c84b80457e02388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Wed, 5 Dec 2018 21:31:11 +0100 Subject: [PATCH 008/106] fix view schema introspection test on SQL Anywhere --- .../DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php index f48c5157256..f076a806a7a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php @@ -24,7 +24,7 @@ public function testCreateAndListViews() self::assertCount(1, $views, 'Database has to have one view.'); self::assertInstanceOf(View::class, $views[$name]); self::assertEquals($name, $views[$name]->getName()); - self::assertEquals($sql, $views[$name]->getSql()); + self::assertRegExp('/^SELECT \* from "?DBA"?\."?view_test_table"?$/', $views[$name]->getSql()); } public function testDropAndCreateAdvancedIndex() From 4f593a28eb02b345bd3c148c28dc0941bf0d4e8f Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Fri, 5 Jan 2018 03:49:59 +0100 Subject: [PATCH 009/106] Require PHP 7.2, drop <7.2 in Composer & on CI --- .scrutinizer.yml | 2 +- .travis.yml | 72 ++++-------------------------------------------- composer.json | 2 +- composer.lock | 4 +-- 4 files changed, 9 insertions(+), 71 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 68b7f344399..a3b8a5621ca 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -3,7 +3,7 @@ build: analysis: environment: php: - version: 7.1 + version: 7.2 cache: disabled: false directories: diff --git a/.travis.yml b/.travis.yml index 6be26170ae5..b87a282d332 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,73 +45,6 @@ jobs: - php: nightly include: - - stage: Test - php: 7.1 - env: DB=mysql MYSQL_VERSION=8.0 - dist: xenial - sudo: required - before_script: - - bash ./tests/travis/install-mysql-8.0.sh - - stage: Test - php: 7.1 - env: DB=mysqli MYSQL_VERSION=8.0 - dist: xenial - sudo: required - before_script: - - bash ./tests/travis/install-mysql-8.0.sh - - stage: Test - php: 7.1 - env: DB=mariadb MARIADB_VERSION=10.3 - addons: - mariadb: 10.3 - - stage: Test - php: 7.1 - env: DB=mariadb.mysqli MARIADB_VERSION=10.3 - addons: - mariadb: 10.3 - - stage: Test - php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=11.0 - sudo: required - services: - - docker - before_script: - - bash ./tests/travis/install-postgres-11.sh - - stage: Test - php: 7.1 - env: DB=sqlite - - stage: Test - php: 7.1 - env: DB=sqlsrv - sudo: required - services: - - docker - before_script: - - bash ./tests/travis/install-mssql-sqlsrv.sh - - bash ./tests/travis/install-mssql.sh - - stage: Test - php: 7.1 - env: DB=pdo_sqlsrv - sudo: required - services: - - docker - before_script: - - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - - bash ./tests/travis/install-mssql.sh - - stage: Test - php: 7.1 - env: DB=ibm_db2 - sudo: required - services: - - docker - before_script: - - bash ./tests/travis/install-db2.sh - - bash ./tests/travis/install-db2-ibm_db2.sh - - stage: Test - php: 7.1 - env: DB=sqlite DEPENDENCIES=low - install: - - travis_retry composer update --prefer-dist --prefer-lowest - stage: Test php: 7.2 env: DB=mysql COVERAGE=yes @@ -267,6 +200,11 @@ jobs: before_script: - bash ./tests/travis/install-db2.sh - bash ./tests/travis/install-db2-ibm_db2.sh + - stage: Test + php: 7.2 + env: DB=sqlite DEPENDENCIES=low + install: + - travis_retry composer update --prefer-dist --prefer-lowest - stage: Test php: 7.3 env: DB=mysql MYSQL_VERSION=5.7 diff --git a/composer.json b/composer.json index 9d5f610c2b8..bec40c7e7f2 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ {"name": "Jonathan Wage", "email": "jonwage@gmail.com"} ], "require": { - "php": "^7.1", + "php": "^7.2", "ext-pdo": "*", "doctrine/cache": "^1.0", "doctrine/event-manager": "^1.0" diff --git a/composer.lock b/composer.lock index 0c15627967d..a17fed1ffbe 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1147a9427c03f98ca063806250633645", + "content-hash": "3ebc0109174963fe21391619cdae7254", "packages": [ { "name": "doctrine/cache", @@ -2959,7 +2959,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^7.1", + "php": "^7.2", "ext-pdo": "*" }, "platform-dev": [] From 64790d4d2e5608cdaede6eb6851894ebc45bc83f Mon Sep 17 00:00:00 2001 From: Arne Groskurth Date: Thu, 6 Dec 2018 22:08:03 +0100 Subject: [PATCH 010/106] Ensuring correct ALTER TABLE statement for creation of an AUTO INCREMENT column as new PRIMARY KEY --- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 11 +++ ...imaryKeyWithNewAutoIncrementColumnTest.php | 69 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 744aa08a4bd..059535640e1 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -599,6 +599,17 @@ public function getAlterTableSQL(TableDiff $diff) $keyColumns = array_unique(array_values($diff->addedIndexes['primary']->getColumns())); $queryParts[] = 'ADD PRIMARY KEY (' . implode(', ', $keyColumns) . ')'; unset($diff->addedIndexes['primary']); + } elseif (isset($diff->changedIndexes['primary'])) { + // Necessary in case the new primary key includes a new auto_increment column + foreach ($diff->changedIndexes['primary']->getColumns() as $columnName) { + if (isset($diff->addedColumns[$columnName]) && $diff->addedColumns[$columnName]->getAutoincrement()) { + $keyColumns = array_unique(array_values($diff->changedIndexes['primary']->getColumns())); + $queryParts[] = 'DROP PRIMARY KEY'; + $queryParts[] = 'ADD PRIMARY KEY (' . implode(', ', $keyColumns) . ')'; + unset($diff->changedIndexes['primary']); + break; + } + } } $sql = []; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php b/tests/Doctrine/Tests/DBAL/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php new file mode 100644 index 00000000000..ec387638c40 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php @@ -0,0 +1,69 @@ +getPlatform()->getName(), ['mysql'])) { + return; + } + + $this->markTestSkipped('Restricted to MySQL.'); + } + + /** + * Ensures that the primary key is created within the same "alter table" statement that an auto-increment column + * is added to the table as part of the new primary key. + * + * Before the fix for this problem this resulted in a database error: (at least on mysql) + * SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto + * column and it must be defined as a key + */ + public function testAlterPrimaryKeyToAutoIncrementColumn() + { + $schemaManager = $this->connection->getSchemaManager(); + $schema = $schemaManager->createSchema(); + + $table = $schema->createTable('dbal2807'); + $table->addColumn('initial_id', 'integer'); + $table->setPrimaryKey(['initial_id']); + + $schemaManager->dropAndCreateTable($table); + + $newSchema = clone $schema; + $newTable = $newSchema->getTable($table->getName()); + $newTable->addColumn('new_id', 'integer', ['autoincrement' => true]); + $newTable->dropPrimaryKey(); + $newTable->setPrimaryKey(['new_id']); + + $diff = (new Comparator())->compare($schema, $newSchema); + + foreach ($diff->toSql($this->getPlatform()) as $sql) { + $this->connection->exec($sql); + } + + $validationSchema = $schemaManager->createSchema(); + $validationTable = $validationSchema->getTable($table->getName()); + + $this->assertTrue($validationTable->hasColumn('new_id')); + $this->assertTrue($validationTable->getColumn('new_id')->getAutoincrement()); + $this->assertTrue($validationTable->hasPrimaryKey()); + $this->assertSame(['new_id'], $validationTable->getPrimaryKeyColumns()); + } + + private function getPlatform() + { + return $this->connection->getDatabasePlatform(); + } +} From ecddeb77879646cfc5d1f835d528a6f5ff7bbd66 Mon Sep 17 00:00:00 2001 From: "roger.codina" Date: Tue, 4 Dec 2018 18:23:21 +0100 Subject: [PATCH 011/106] ResultCacheStatement lost its cache capability on fetchAll method --- lib/Doctrine/DBAL/Cache/ResultCacheStatement.php | 5 ++++- .../Doctrine/Tests/DBAL/Functional/ResultCacheTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 872f3e71fc9..721709a0dd4 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -166,7 +166,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { - return $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs); + $this->data = $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs); + $this->emptied = true; + + return $this->data; } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index ae4259da91f..2c64c280b6d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -166,6 +166,16 @@ public function testDontFinishNoCache() self::assertCount(2, $this->sqlLogger->queries); } + public function testFetchAllAndFinishSavesCache() + { + $layerCache = new ArrayCache(); + $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'testcachekey', $layerCache)); + $stmt->fetchAll(); + $stmt->closeCursor(); + + self::assertCount(1, $layerCache->fetch('testcachekey')); + } + public function assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, $fetchMode) { $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); From 2b49635d6e50c453006377d3f14f60cf2d553412 Mon Sep 17 00:00:00 2001 From: Marc-Jan Barnhoorn Date: Thu, 6 Dec 2018 17:20:46 -0800 Subject: [PATCH 012/106] Fix Fetch mode query in MasterSlaveConnection --- .../Connections/MasterSlaveConnection.php | 2 + .../Functional/MasterSlaveConnectionTest.php | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php index e9864d6df90..d2e4b2c2509 100644 --- a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php +++ b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php @@ -354,6 +354,8 @@ public function query() $statement = $this->_conn->query(...$args); + $statement->setFetchMode($this->defaultFetchMode); + if ($logger) { $logger->stopQuery(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php index 81747c3a996..b047c7da7ed 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional; use Doctrine\DBAL\Connections\MasterSlaveConnection; +use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Table; @@ -189,4 +190,54 @@ public function testMasterSlaveConnectionCloseAndReconnect() $conn->connect('master'); self::assertTrue($conn->isConnectedToMaster()); } + + public function testQueryOnMaster() + { + $conn = $this->createMasterSlaveConnection(); + + $query = 'SELECT count(*) as num FROM master_slave_table'; + + $statement = $conn->query($query); + + self::assertInstanceOf(Statement::class, $statement); + + //Query must be executed only on Master + self::assertTrue($conn->isConnectedToMaster()); + + $data = $statement->fetchAll(); + + //Default fetchmode is FetchMode::ASSOCIATIVE + self::assertArrayHasKey(0, $data); + self::assertArrayHasKey('num', $data[0]); + + //Could be set in other fetchmodes + self::assertArrayNotHasKey(0, $data[0]); + self::assertEquals(1, $data[0]['num']); + } + + public function testQueryOnSlave() + { + $conn = $this->createMasterSlaveConnection(); + $conn->connect('slave'); + + $query = 'SELECT count(*) as num FROM master_slave_table'; + + $statement = $conn->query($query); + + self::assertInstanceOf(Statement::class, $statement); + + //Query must be executed only on Master, even when we connect to the slave + self::assertTrue($conn->isConnectedToMaster()); + + $data = $statement->fetchAll(); + + //Default fetchmode is FetchMode::ASSOCIATIVE + self::assertArrayHasKey(0, $data); + self::assertArrayHasKey('num', $data[0]); + + //Could be set in other fetchmodes + self::assertArrayNotHasKey(0, $data[0]); + + self::assertEquals(1, $data[0]['num']); + } } From 6e1bb8027b8da05fee207bd58a95d4a90ed70e7e Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 6 Dec 2018 17:57:07 -0800 Subject: [PATCH 013/106] Fixed parsing MySQL create table flags (options without a value) --- .../DBAL/Schema/MySqlSchemaManager.php | 30 ++++++++++--------- .../Schema/MySqlSchemaManagerTest.php | 6 +++- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index b6332026cdd..2c058b8bf6a 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -18,7 +18,6 @@ use function strpos; use function strtok; use function strtolower; -use function trim; /** * Schema manager for the MySql RDBMS. @@ -305,25 +304,28 @@ public function listTableDetails($tableName) $table->addOption('autoincrement', $tableOptions['AUTO_INCREMENT']); } $table->addOption('comment', $tableOptions['TABLE_COMMENT']); + $table->addOption('create_options', $this->parseCreateOptions($tableOptions['CREATE_OPTIONS'])); - if ($tableOptions['CREATE_OPTIONS'] === null) { - return $table; - } + return $table; + } - $createOptionsString = trim($tableOptions['CREATE_OPTIONS']); + /** + * @return string[]|true[] + */ + private function parseCreateOptions(string $string) : array + { + $options = []; - $createOptions = []; + if ($string === '') { + return $options; + } - if ($createOptionsString !== '') { - foreach (explode(' ', $createOptionsString) as $option) { - [$createOption, $value] = explode('=', $option); + foreach (explode(' ', $string) as $pair) { + $parts = explode('=', $pair, 2); - $createOptions[$createOption] = $value; - } + $options[$parts[0]] = $parts[1] ?? true; } - $table->addOption('create_options', $createOptions); - - return $table; + return $options; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 475dcee3ee6..937d04c9058 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -502,6 +502,7 @@ public function testEnsureTableOptionsAreReflectedInMetadata() : void ROW_FORMAT COMPRESSED COMMENT 'This is a test' AUTO_INCREMENT=42 +PARTITION BY HASH (col1) SQL; $this->connection->query($sql); @@ -511,7 +512,10 @@ public function testEnsureTableOptionsAreReflectedInMetadata() : void self::assertEquals('utf8_general_ci', $onlineTable->getOption('collation')); self::assertEquals(42, $onlineTable->getOption('autoincrement')); self::assertEquals('This is a test', $onlineTable->getOption('comment')); - self::assertEquals(['row_format' => 'COMPRESSED'], $onlineTable->getOption('create_options')); + self::assertEquals([ + 'row_format' => 'COMPRESSED', + 'partitioned' => true, + ], $onlineTable->getOption('create_options')); } public function testEnsureTableWithoutOptionsAreReflectedInMetadata() : void From 7fb1421236f086e5a8aef51703576f93850a3010 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 6 Dec 2018 18:31:17 -0800 Subject: [PATCH 014/106] Grouped PHPStan and PHP_CodeSniffer for parallel execution --- .travis.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index b87a282d332..88197b8c043 100644 --- a/.travis.yml +++ b/.travis.yml @@ -320,12 +320,11 @@ jobs: - stage: Code Quality php: 7.2 - env: DB=none STATIC_ANALYSIS + env: PHPStan install: travis_retry composer install --prefer-dist script: vendor/bin/phpstan analyse - - - stage: Coding standard + - stage: Code Quality php: 7.2 + env: PHP_CodeSniffer install: travis_retry composer install --prefer-dist - script: - - ./vendor/bin/phpcs + script: vendor/bin/phpcs From 438b05251ecbe9298604ad20e32c85d79876fa22 Mon Sep 17 00:00:00 2001 From: Lukas Vitek Date: Thu, 6 Dec 2018 20:25:12 +0100 Subject: [PATCH 015/106] Fixed annotation and name of parameter $columnsNames in Table --- lib/Doctrine/DBAL/Schema/Table.php | 38 +++++++++++++----------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 5dac5bb1a34..191294d6d15 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -9,8 +9,6 @@ use function array_filter; use function array_merge; use function in_array; -use function is_numeric; -use function is_string; use function preg_match; use function strlen; use function strtolower; @@ -100,16 +98,16 @@ protected function _getMaxIdentifierLength() /** * Sets the Primary Key. * - * @param mixed[][] $columns + * @param string[] $columnNames * @param string|bool $indexName * * @return self */ - public function setPrimaryKey(array $columns, $indexName = false) + public function setPrimaryKey(array $columnNames, $indexName = false) { - $this->_addIndex($this->_createIndex($columns, $indexName ?: 'primary', true, true)); + $this->_addIndex($this->_createIndex($columnNames, $indexName ?: 'primary', true, true)); - foreach ($columns as $columnName) { + foreach ($columnNames as $columnName) { $column = $this->getColumn($columnName); $column->setNotnull(true); } @@ -118,7 +116,7 @@ public function setPrimaryKey(array $columns, $indexName = false) } /** - * @param mixed[][] $columnNames + * @param string[] $columnNames * @param string|null $indexName * @param string[] $flags * @param mixed[] $options @@ -168,7 +166,7 @@ public function dropIndex($indexName) } /** - * @param mixed[][] $columnNames + * @param string[] $columnNames * @param string|null $indexName * @param mixed[] $options * @@ -236,15 +234,15 @@ public function renameIndex($oldIndexName, $newIndexName = null) /** * Checks if an index begins in the order of the given columns. * - * @param mixed[][] $columnsNames + * @param string[] $columnNames * * @return bool */ - public function columnsAreIndexed(array $columnsNames) + public function columnsAreIndexed(array $columnNames) { foreach ($this->getIndexes() as $index) { /** @var $index Index */ - if ($index->spansColumns($columnsNames)) { + if ($index->spansColumns($columnNames)) { return true; } } @@ -253,12 +251,12 @@ public function columnsAreIndexed(array $columnsNames) } /** - * @param mixed[][] $columnNames - * @param string $indexName - * @param bool $isUnique - * @param bool $isPrimary - * @param string[] $flags - * @param mixed[] $options + * @param string[] $columnNames + * @param string $indexName + * @param bool $isUnique + * @param bool $isPrimary + * @param string[] $flags + * @param mixed[] $options * * @return Index * @@ -270,11 +268,7 @@ private function _createIndex(array $columnNames, $indexName, $isUnique, $isPrim throw SchemaException::indexNameInvalid($indexName); } - foreach ($columnNames as $columnName => $indexColOptions) { - if (is_numeric($columnName) && is_string($indexColOptions)) { - $columnName = $indexColOptions; - } - + foreach ($columnNames as $columnName) { if (! $this->hasColumn($columnName)) { throw SchemaException::columnDoesNotExist($columnName, $this->_name); } From 70b1daccd8732b751137ae96c1cb2c80d8596086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 12 Dec 2018 07:37:26 +0100 Subject: [PATCH 016/106] Link to Slack instead of Gitter Gitter has been deprecated in favor of Slack for all Doctrine purposes. --- docs/en/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/index.rst b/docs/en/index.rst index 1e8fee0c190..1bdabab85f3 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -10,7 +10,7 @@ Getting Help If this documentation is not helping to answer questions you have about the Doctrine DBAL, don't panic. You can get help from different sources: -- Gitter chat room `#doctrine/dbal `_ +- Slack chat room `#dbal `_ - On `Stack Overflow `_ - The `Doctrine Mailing List `_ - Report a bug on `GitHub `_. From ee4aa5ccaf30b255d152440047cb39ee00c1d635 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Wed, 12 Dec 2018 23:40:38 +0100 Subject: [PATCH 017/106] Travis CI: PHP 7.3 tests on MySQL 8.0 --- .travis.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 88197b8c043..ac54fcdf862 100644 --- a/.travis.yml +++ b/.travis.yml @@ -207,16 +207,18 @@ jobs: - travis_retry composer update --prefer-dist --prefer-lowest - stage: Test php: 7.3 - env: DB=mysql MYSQL_VERSION=5.7 + env: DB=mysql MYSQL_VERSION=8.0 + dist: xenial sudo: required before_script: - - bash ./tests/travis/install-mysql-5.7.sh + - bash ./tests/travis/install-mysql-8.0.sh - stage: Test php: 7.3 - env: DB=mysqli MYSQL_VERSION=5.7 + env: DB=mysqli MYSQL_VERSION=8.0 + dist: xenial sudo: required before_script: - - bash ./tests/travis/install-mysql-5.7.sh + - bash ./tests/travis/install-mysql-8.0.sh - stage: Test php: 7.3 env: DB=mariadb MARIADB_VERSION=10.3 From b9d7a36604d43a466b24d63da02982f05356dd91 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Thu, 14 Jun 2018 23:33:13 +0200 Subject: [PATCH 018/106] CI: Test against MySQL 8.0 on Travis --- .travis.yml | 30 +++++++++------- tests/travis/install-mysql-8.0.sh | 23 +++++++------ tests/travis/mysql.docker.travis.xml | 49 +++++++++++++++++++++++++++ tests/travis/mysqli.docker.travis.xml | 49 +++++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 22 deletions(-) create mode 100644 tests/travis/mysql.docker.travis.xml create mode 100644 tests/travis/mysqli.docker.travis.xml diff --git a/.travis.yml b/.travis.yml index ac54fcdf862..c863ee54ab8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,9 +56,10 @@ jobs: - bash ./tests/travis/install-mysql-5.7.sh - stage: Test php: 7.2 - env: DB=mysql MYSQL_VERSION=8.0 COVERAGE=yes - dist: xenial + env: DB=mysql.docker MYSQL_VERSION=8.0 COVERAGE=yes sudo: required + services: + - docker before_script: - bash ./tests/travis/install-mysql-8.0.sh - stage: Test @@ -72,9 +73,10 @@ jobs: - bash ./tests/travis/install-mysql-5.7.sh - stage: Test php: 7.2 - env: DB=mysqli MYSQL_VERSION=8.0 COVERAGE=yes - dist: xenial + env: DB=mysqli.docker MYSQL_VERSION=8.0 COVERAGE=yes sudo: required + services: + - docker before_script: - bash ./tests/travis/install-mysql-8.0.sh - stage: Test @@ -207,16 +209,18 @@ jobs: - travis_retry composer update --prefer-dist --prefer-lowest - stage: Test php: 7.3 - env: DB=mysql MYSQL_VERSION=8.0 - dist: xenial + env: DB=mysql.docker MYSQL_VERSION=8.0 sudo: required + services: + - docker before_script: - bash ./tests/travis/install-mysql-8.0.sh - stage: Test php: 7.3 - env: DB=mysqli MYSQL_VERSION=8.0 - dist: xenial + env: DB=mysqli.docker MYSQL_VERSION=8.0 sudo: required + services: + - docker before_script: - bash ./tests/travis/install-mysql-8.0.sh - stage: Test @@ -260,16 +264,18 @@ jobs: - bash ./tests/travis/install-mssql.sh - stage: Test php: nightly - env: DB=mysql MYSQL_VERSION=8.0 - dist: xenial + env: DB=mysql.docker MYSQL_VERSION=8.0 sudo: required + services: + - docker before_script: - bash ./tests/travis/install-mysql-8.0.sh - stage: Test php: nightly - env: DB=mysqli MYSQL_VERSION=8.0 - dist: xenial + env: DB=mysqli.docker MYSQL_VERSION=8.0 sudo: required + services: + - docker before_script: - bash ./tests/travis/install-mysql-8.0.sh - stage: Test diff --git a/tests/travis/install-mysql-8.0.sh b/tests/travis/install-mysql-8.0.sh index 1a4092e3aae..d3622777f3e 100644 --- a/tests/travis/install-mysql-8.0.sh +++ b/tests/travis/install-mysql-8.0.sh @@ -2,15 +2,18 @@ set -ex -echo "Installing MySQL 8.0..." +echo "Starting MySQL 8.0..." -echo mysql-apt-config mysql-apt-config/select-server select mysql-8.0 | sudo debconf-set-selections -wget https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb -sudo dpkg --install mysql-apt-config_0.8.10-1_all.deb -sudo apt-get update -q -sudo apt-get install -q -y --force-yes -o Dpkg::Options::=--force-confnew mysql-server -echo -e "[mysqld]\ndefault_authentication_plugin=mysql_native_password" | sudo tee --append /etc/mysql/my.cnf -sudo /etc/init.d/mysql start -sudo mysql_upgrade +echo -e "[mysqld]\ndefault_authentication_plugin=mysql_native_password" > /tmp/mysql-auth.cnf -mysql --version +sudo docker pull mysql:8.0 +sudo docker run \ + -d \ + -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ + -e MYSQL_DATABASE=doctrine_tests \ + -v /tmp/mysql-auth.cnf:/etc/mysql/conf.d/auth.cnf:ro \ + -p 33306:3306 \ + --name mysql80 \ + mysql:8.0 + +sudo docker exec -i mysql80 bash <<< 'until echo \\q | mysql doctrine_tests > /dev/null 2>&1 ; do sleep 1; done' diff --git a/tests/travis/mysql.docker.travis.xml b/tests/travis/mysql.docker.travis.xml new file mode 100644 index 00000000000..21fae6f35e9 --- /dev/null +++ b/tests/travis/mysql.docker.travis.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + ../Doctrine/Tests/DBAL + + + + + + ../../lib/Doctrine + + + + + + + + + + performance + locking_functional + + + diff --git a/tests/travis/mysqli.docker.travis.xml b/tests/travis/mysqli.docker.travis.xml new file mode 100644 index 00000000000..935815e9cf4 --- /dev/null +++ b/tests/travis/mysqli.docker.travis.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + ../Doctrine/Tests/DBAL + + + + + + ../../lib/Doctrine + + + + + + + + + + performance + locking_functional + + + From 314529f55c2659a4af2a2d2c985eff2763c72c98 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 13 Dec 2018 21:58:29 -0800 Subject: [PATCH 019/106] Fixed test failures in case of a non-standard MySQL port --- .../Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php index 8c274e1cbb2..bbd8d5ebd09 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php @@ -61,6 +61,7 @@ private function getConnection(array $driverOptions) [ 'host' => $GLOBALS['db_host'], 'dbname' => $GLOBALS['db_name'], + 'port' => $GLOBALS['db_port'], ], $GLOBALS['db_username'], $GLOBALS['db_password'], From 6c2691afbdb9ac8e805753d160ead299cde4e8e6 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 13 Dec 2018 22:35:47 -0800 Subject: [PATCH 020/106] Removed unused build files --- build.properties | 3 -- build.xml | 102 ----------------------------------------------- 2 files changed, 105 deletions(-) delete mode 100644 build.properties delete mode 100644 build.xml diff --git a/build.properties b/build.properties deleted file mode 100644 index 309e0e2105c..00000000000 --- a/build.properties +++ /dev/null @@ -1,3 +0,0 @@ -# Version class and file -project.version_class = Doctrine\\DBAL\\Version -project.version_file = lib/Doctrine/DBAL/Version.php diff --git a/build.xml b/build.xml deleted file mode 100644 index 064a6084e7e..00000000000 --- a/build.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 79e68019d51fc0891df74bdf452fbf508e215b71 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 30 Apr 2018 11:02:57 -0700 Subject: [PATCH 021/106] Introduced a smoke testing phase on Travis to run SQLite tests and static analysis first --- .travis.yml | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index ac54fcdf862..32fef1da4ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,6 +45,21 @@ jobs: - php: nightly include: + + - stage: Smoke Testing + php: 7.2 + env: DB=sqlite COVERAGE=yes + - stage: Smoke Testing + php: 7.2 + env: PHPStan + install: travis_retry composer install --prefer-dist + script: vendor/bin/phpstan analyse + - stage: Smoke Testing + php: 7.2 + env: PHP_CodeSniffer + install: travis_retry composer install --prefer-dist + script: vendor/bin/phpcs + - stage: Test php: 7.2 env: DB=mysql COVERAGE=yes @@ -170,9 +185,6 @@ jobs: - docker before_script: - bash ./tests/travis/install-postgres-11.sh - - stage: Test - php: 7.2 - env: DB=sqlite COVERAGE=yes - stage: Test php: 7.2 env: DB=sqlsrv COVERAGE=yes @@ -319,14 +331,3 @@ jobs: install: - composer config minimum-stability dev - travis_retry composer update --prefer-dist - - - stage: Code Quality - php: 7.2 - env: PHPStan - install: travis_retry composer install --prefer-dist - script: vendor/bin/phpstan analyse - - stage: Code Quality - php: 7.2 - env: PHP_CodeSniffer - install: travis_retry composer install --prefer-dist - script: vendor/bin/phpcs From 28b0190d765a0c519330ffcd247be89a8a0914ff Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 16 Dec 2018 23:25:32 -0800 Subject: [PATCH 022/106] `CREATE_OPTIONS` is nullable in MySQL --- lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php | 4 ++-- .../DBAL/Functional/Schema/MySqlSchemaManagerTest.php | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 2c058b8bf6a..7bcd5533efc 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -312,11 +312,11 @@ public function listTableDetails($tableName) /** * @return string[]|true[] */ - private function parseCreateOptions(string $string) : array + private function parseCreateOptions(?string $string) : array { $options = []; - if ($string === '') { + if ($string === null || $string === '') { return $options; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 937d04c9058..90ade2e86b8 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -531,4 +531,11 @@ public function testEnsureTableWithoutOptionsAreReflectedInMetadata() : void self::assertEquals('', $onlineTable->getOption('comment')); self::assertEquals([], $onlineTable->getOption('create_options')); } + + public function testParseNullCreateOptions() : void + { + $table = $this->schemaManager->listTableDetails('sys.processlist'); + + self::assertEquals([], $table->getOption('create_options')); + } } From ac49cb227a30fc8ccaf112562ffb7218d27cfb22 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 18 Dec 2018 20:23:57 -0800 Subject: [PATCH 023/106] Consider column lengths when comparing indices --- lib/Doctrine/DBAL/Schema/Index.php | 18 +++++++++++ .../Doctrine/Tests/DBAL/Schema/IndexTest.php | 30 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/lib/Doctrine/DBAL/Schema/Index.php b/lib/Doctrine/DBAL/Schema/Index.php index bae6d218cb6..91ffd472465 100644 --- a/lib/Doctrine/DBAL/Schema/Index.php +++ b/lib/Doctrine/DBAL/Schema/Index.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use InvalidArgumentException; +use function array_filter; use function array_keys; use function array_map; use function array_search; @@ -211,6 +212,10 @@ public function isFullfilledBy(Index $other) return false; } + if (! $this->hasSameColumnLengths($other)) { + return false; + } + if (! $this->isUnique() && ! $this->isPrimary()) { // this is a special case: If the current key is neither primary or unique, any unique or // primary key will always have the same effect for the index and there cannot be any constraint @@ -336,4 +341,17 @@ private function samePartialIndex(Index $other) return ! $this->hasOption('where') && ! $other->hasOption('where'); } + + /** + * Returns whether the index has the same column lengths as the other + */ + private function hasSameColumnLengths(self $other) : bool + { + $filter = static function (?int $length) : bool { + return $length !== null; + }; + + return array_filter($this->options['lengths'] ?? [], $filter) + === array_filter($other->options['lengths'] ?? [], $filter); + } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php b/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php index af962f95f95..ad9e2bbbdb7 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php @@ -108,6 +108,36 @@ public function testOverrulesWithPartial() self::assertTrue($another->overrules($partial)); } + /** + * @param string[] $columns + * @param int[]|null[] $lengths1 + * @param int[]|null[] $lengths2 + * + * @dataProvider indexLengthProvider + */ + public function testFulfilledWithLength(array $columns, array $lengths1, array $lengths2, bool $expected) : void + { + $index1 = new Index('index1', $columns, false, false, [], ['lengths' => $lengths1]); + $index2 = new Index('index2', $columns, false, false, [], ['lengths' => $lengths2]); + + self::assertSame($expected, $index1->isFullfilledBy($index2)); + self::assertSame($expected, $index2->isFullfilledBy($index1)); + } + + /** + * @return mixed[][] + */ + public static function indexLengthProvider() : iterable + { + return [ + 'empty' => [['column'], [], [], true], + 'same' => [['column'], [64], [64], true], + 'different' => [['column'], [32], [64], false], + 'sparse-different-positions' => [['column1', 'column2'], [0 => 32], [1 => 32], false], + 'sparse-same-positions' => [['column1', 'column2'], [null, 32], [1 => 32], true], + ]; + } + /** * @group DBAL-220 */ From 73f38e722421fed5f00ff3fba76c80cf1a7545b4 Mon Sep 17 00:00:00 2001 From: AlterTable Date: Fri, 28 Dec 2018 11:09:50 +0800 Subject: [PATCH 024/106] Add column charset for MySql --- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 8 +++ .../DBAL/Schema/MySqlSchemaManager.php | 3 ++ .../Schema/MySqlSchemaManagerTest.php | 53 +++++++++++++++++++ .../AbstractMySQLPlatformTestCase.php | 8 +++ 4 files changed, 72 insertions(+) diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 777d11216f8..289dca9e7d7 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -953,6 +953,14 @@ protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) return $this->getUnsignedDeclaration($columnDef) . $autoinc; } + /** + * {@inheritDoc} + */ + public function getColumnCharsetDeclarationSQL($charset) + { + return 'CHARACTER SET ' . $charset; + } + /** * {@inheritDoc} */ diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 7bcd5533efc..85b5b5c4734 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -192,6 +192,9 @@ protected function _getPortableTableColumnDefinition($tableColumn) $column = new Column($tableColumn['field'], Type::getType($type), $options); + if (isset($tableColumn['characterset'])) { + $column->setPlatformOption('charset', $tableColumn['characterset']); + } if (isset($tableColumn['collation'])) { $column->setPlatformOption('collation', $tableColumn['collation']); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 90ade2e86b8..ef457f0c590 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -201,6 +201,59 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() self::assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull()); } + public function testColumnCharset() + { + $table = new Table('test_column_charset'); + $table->addColumn('id', 'integer'); + $table->addColumn('no_charset', 'text'); + $table->addColumn('foo', 'text')->setPlatformOption('charset', 'ascii'); + $table->addColumn('bar', 'text')->setPlatformOption('charset', 'latin1'); + $this->schemaManager->dropAndCreateTable($table); + + $columns = $this->schemaManager->listTableColumns('test_column_charset'); + + self::assertFalse($columns['id']->hasPlatformOption('charset')); + self::assertEquals('utf8', $columns['no_charset']->getPlatformOption('charset')); + self::assertEquals('ascii', $columns['foo']->getPlatformOption('charset')); + self::assertEquals('latin1', $columns['bar']->getPlatformOption('charset')); + } + + public function testAlterColumnCharset() + { + $tableName = 'test_alter_column_charset'; + + $table = new Table($tableName); + $table->addColumn('col_text', 'text')->setPlatformOption('charset', 'utf8'); + + $this->schemaManager->dropAndCreateTable($table); + + $diffTable = clone $table; + $diffTable->getColumn('col_text')->setPlatformOption('charset', 'ascii'); + + $comparator = new Comparator(); + + $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); + + $table = $this->schemaManager->listTableDetails($tableName); + + self::assertEquals('ascii', $table->getColumn('col_text')->getPlatformOption('charset')); + } + + public function testColumnCharsetChange() + { + $table = new Table('test_column_charset_change'); + $table->addColumn('col_string', 'string')->setLength(100)->setNotnull(true)->setPlatformOption('charset', 'utf8'); + + $diffTable = clone $table; + $diffTable->getColumn('col_string')->setPlatformOption('charset', 'ascii'); + + $fromSchema = new Schema([$table]); + $toSchema = new Schema([$diffTable]); + + $diff = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform()); + self::assertContains('ALTER TABLE test_column_charset_change CHANGE col_string col_string VARCHAR(100) CHARACTER SET ascii NOT NULL', $diff); + } + public function testColumnCollation() { $table = new Table('test_collation'); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index 63148215f22..6dec263df34 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -905,6 +905,14 @@ public function testListTableForeignKeysSQLEvaluatesDatabase() self::assertNotContains('DATABASE()', $sql); } + public function testColumnCharsetDeclarationSQL() : void + { + self::assertSame( + 'CHARACTER SET ascii', + $this->platform->getColumnCharsetDeclarationSQL('ascii') + ); + } + public function testSupportsColumnCollation() : void { self::assertTrue($this->platform->supportsColumnCollation()); From 060837267e110df3902e542cfe196210949ce60b Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Wed, 2 Jan 2019 14:41:37 +0100 Subject: [PATCH 025/106] Cast the index length to int in the MySqlSchemaManager class --- lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php | 2 +- .../Functional/Schema/MySqlSchemaManagerTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 85b5b5c4734..9f50517e1d4 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -68,7 +68,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null } elseif (strpos($v['index_type'], 'SPATIAL') !== false) { $v['flags'] = ['SPATIAL']; } - $v['length'] = $v['sub_part'] ?? null; + $v['length'] = isset($v['sub_part']) ? (int) $v['sub_part'] : null; $tableIndexes[$k] = $v; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index ef457f0c590..9cb4b7e51b1 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -107,6 +107,19 @@ public function testSpatialIndex() self::assertTrue($indexes['s_index']->hasFlag('spatial')); } + public function testIndexWithLength() : void + { + $table = new Table('index_length'); + $table->addColumn('text', 'string', ['length' => 255]); + $table->addIndex(['text'], 'text_index', [], ['lengths' => [128]]); + + $this->schemaManager->dropAndCreateTable($table); + + $indexes = $this->schemaManager->listTableIndexes('index_length'); + self::assertArrayHasKey('text_index', $indexes); + self::assertSame([128], $indexes['text_index']->getOption('lengths')); + } + /** * @group DBAL-400 */ From ec22705882575e724e10c91fd7a43309ebfcddfe Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 17 Jan 2019 22:47:10 -0800 Subject: [PATCH 026/106] Updated PHPStan to v0.11 --- composer.json | 2 +- composer.lock | 226 ++++++++++++------ lib/Doctrine/DBAL/Connection.php | 14 +- .../Connections/MasterSlaveConnection.php | 4 +- .../DBAL/Driver/IBMDB2/DB2Statement.php | 2 +- .../DBAL/Driver/Mysqli/MysqliStatement.php | 30 +-- .../DBAL/Platforms/SqlitePlatform.php | 6 +- 7 files changed, 177 insertions(+), 107 deletions(-) diff --git a/composer.json b/composer.json index bec40c7e7f2..df888004dce 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "require-dev": { "doctrine/coding-standard": "^5.0", "jetbrains/phpstorm-stubs": "^2018.1.2", - "phpstan/phpstan": "^0.10.1", + "phpstan/phpstan": "^0.11.1", "phpunit/phpunit": "^7.4", "symfony/console": "^2.0.5|^3.0|^4.0", "symfony/phpunit-bridge": "^3.4.5|^4.0.5" diff --git a/composer.lock b/composer.lock index a17fed1ffbe..9d34a231f1e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3ebc0109174963fe21391619cdae7254", + "content-hash": "c0b2296029841f54d6b8438c7773e861", "packages": [ { "name": "doctrine/cache", @@ -158,16 +158,16 @@ "packages-dev": [ { "name": "composer/xdebug-handler", - "version": "1.1.0", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "c919dc6c62e221fc6406f861ea13433c0aa24f08" + "reference": "dc523135366eb68f22268d069ea7749486458562" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/c919dc6c62e221fc6406f861ea13433c0aa24f08", - "reference": "c919dc6c62e221fc6406f861ea13433c0aa24f08", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/dc523135366eb68f22268d069ea7749486458562", + "reference": "dc523135366eb68f22268d069ea7749486458562", "shasum": "" }, "require": { @@ -198,7 +198,7 @@ "Xdebug", "performance" ], - "time": "2018-04-11T15:42:36+00:00" + "time": "2018-11-29T10:59:02+00:00" }, { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -598,16 +598,16 @@ }, { "name": "nette/di", - "version": "v2.4.13", + "version": "v2.4.14", "source": { "type": "git", "url": "https://github.com/nette/di.git", - "reference": "3f8f212b02d5c17feb97a7e0a39ab306f40c06ca" + "reference": "923da3e2c0aa53162ef455472c0ac7787b096c5a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/di/zipball/3f8f212b02d5c17feb97a7e0a39ab306f40c06ca", - "reference": "3f8f212b02d5c17feb97a7e0a39ab306f40c06ca", + "url": "https://api.github.com/repos/nette/di/zipball/923da3e2c0aa53162ef455472c0ac7787b096c5a", + "reference": "923da3e2c0aa53162ef455472c0ac7787b096c5a", "shasum": "" }, "require": { @@ -663,7 +663,7 @@ "nette", "static" ], - "time": "2018-06-11T08:46:01+00:00" + "time": "2018-09-17T15:47:40+00:00" }, { "name": "nette/finder", @@ -790,16 +790,16 @@ }, { "name": "nette/php-generator", - "version": "v3.0.4", + "version": "v3.0.5", "source": { "type": "git", "url": "https://github.com/nette/php-generator.git", - "reference": "b381ecacbf5a0b5f99cc0b303d5b0578d409f446" + "reference": "ea90209c2e8a7cd087b2742ca553c047a8df5eff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/php-generator/zipball/b381ecacbf5a0b5f99cc0b303d5b0578d409f446", - "reference": "b381ecacbf5a0b5f99cc0b303d5b0578d409f446", + "url": "https://api.github.com/repos/nette/php-generator/zipball/ea90209c2e8a7cd087b2742ca553c047a8df5eff", + "reference": "ea90209c2e8a7cd087b2742ca553c047a8df5eff", "shasum": "" }, "require": { @@ -848,20 +848,20 @@ "php", "scaffolding" ], - "time": "2018-04-26T16:48:20+00:00" + "time": "2018-08-09T14:32:27+00:00" }, { "name": "nette/robot-loader", - "version": "v3.0.4", + "version": "v3.1.0", "source": { "type": "git", "url": "https://github.com/nette/robot-loader.git", - "reference": "3cf88781a05e0bf4618ae605361afcbaa4d5b392" + "reference": "fc76c70e740b10f091e502b2e393d0be912f38d4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/robot-loader/zipball/3cf88781a05e0bf4618ae605361afcbaa4d5b392", - "reference": "3cf88781a05e0bf4618ae605361afcbaa4d5b392", + "url": "https://api.github.com/repos/nette/robot-loader/zipball/fc76c70e740b10f091e502b2e393d0be912f38d4", + "reference": "fc76c70e740b10f091e502b2e393d0be912f38d4", "shasum": "" }, "require": { @@ -880,7 +880,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -913,20 +913,20 @@ "nette", "trait" ], - "time": "2018-06-22T09:34:04+00:00" + "time": "2018-08-13T14:19:06+00:00" }, { "name": "nette/utils", - "version": "v2.5.2", + "version": "v2.5.3", "source": { "type": "git", "url": "https://github.com/nette/utils.git", - "reference": "183069866dc477fcfbac393ed486aaa6d93d19a5" + "reference": "17b9f76f2abd0c943adfb556e56f2165460b15ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/utils/zipball/183069866dc477fcfbac393ed486aaa6d93d19a5", - "reference": "183069866dc477fcfbac393ed486aaa6d93d19a5", + "url": "https://api.github.com/repos/nette/utils/zipball/17b9f76f2abd0c943adfb556e56f2165460b15ce", + "reference": "17b9f76f2abd0c943adfb556e56f2165460b15ce", "shasum": "" }, "require": { @@ -995,20 +995,20 @@ "utility", "validation" ], - "time": "2018-05-02T17:16:08+00:00" + "time": "2018-09-18T10:22:16+00:00" }, { "name": "nikic/php-parser", - "version": "v4.0.2", + "version": "v4.2.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "35b8caf75e791ba1b2d24fec1552168d72692b12" + "reference": "594bcae1fc0bccd3993d2f0d61a018e26ac2865a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/35b8caf75e791ba1b2d24fec1552168d72692b12", - "reference": "35b8caf75e791ba1b2d24fec1552168d72692b12", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/594bcae1fc0bccd3993d2f0d61a018e26ac2865a", + "reference": "594bcae1fc0bccd3993d2f0d61a018e26ac2865a", "shasum": "" }, "require": { @@ -1024,7 +1024,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -1046,7 +1046,7 @@ "parser", "php" ], - "time": "2018-06-03T11:33:10+00:00" + "time": "2019-01-12T16:31:37+00:00" }, { "name": "ocramius/package-versions", @@ -1416,16 +1416,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "0.3", + "version": "0.3.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "ed3223362174b8067729930439e139794e9e514a" + "reference": "2cc49f47c69b023eaf05b48e6529389893b13d74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/ed3223362174b8067729930439e139794e9e514a", - "reference": "ed3223362174b8067729930439e139794e9e514a", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/2cc49f47c69b023eaf05b48e6529389893b13d74", + "reference": "2cc49f47c69b023eaf05b48e6529389893b13d74", "shasum": "" }, "require": { @@ -1435,7 +1435,7 @@ "consistence/coding-standard": "^2.0.0", "jakub-onderka/php-parallel-lint": "^0.9.2", "phing/phing": "^2.16.0", - "phpstan/phpstan": "^0.10@dev", + "phpstan/phpstan": "^0.10", "phpunit/phpunit": "^6.3", "slevomat/coding-standard": "^3.3.0", "symfony/process": "^3.4 || ^4.0" @@ -1458,24 +1458,24 @@ "MIT" ], "description": "PHPDoc parser with support for nullable, intersection and generic types", - "time": "2018-06-20T17:48:01+00:00" + "time": "2019-01-14T12:26:23+00:00" }, { "name": "phpstan/phpstan", - "version": "0.10.1", + "version": "0.11.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "3179cf27542e9e47acb548150e7ca21ca5ab92d6" + "reference": "a138b8a2731b2c19f1dffa2f1411984a638fe977" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/3179cf27542e9e47acb548150e7ca21ca5ab92d6", - "reference": "3179cf27542e9e47acb548150e7ca21ca5ab92d6", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/a138b8a2731b2c19f1dffa2f1411984a638fe977", + "reference": "a138b8a2731b2c19f1dffa2f1411984a638fe977", "shasum": "" }, "require": { - "composer/xdebug-handler": "^1.0", + "composer/xdebug-handler": "^1.3.0", "jean85/pretty-package-versions": "^1.0.3", "nette/bootstrap": "^2.4 || ^3.0", "nette/di": "^2.4.7 || ^3.0", @@ -1487,22 +1487,27 @@ "symfony/console": "~3.2 || ~4.0", "symfony/finder": "~3.2 || ~4.0" }, + "conflict": { + "symfony/console": "3.4.16 || 4.1.5" + }, "require-dev": { "brianium/paratest": "^2.0", - "consistence/coding-standard": "^3.3", + "consistence/coding-standard": "^3.5", "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", - "ext-gd": "*", "ext-intl": "*", "ext-mysqli": "*", + "ext-soap": "*", "ext-zip": "*", "jakub-onderka/php-parallel-lint": "^1.0", + "localheinz/composer-normalize": "^1.1.0", "phing/phing": "^2.16.0", - "phpstan/phpstan-deprecation-rules": "^0.10.2", - "phpstan/phpstan-php-parser": "^0.10", - "phpstan/phpstan-phpunit": "^0.10", - "phpstan/phpstan-strict-rules": "^0.10", + "phpstan/phpstan-deprecation-rules": "^0.11", + "phpstan/phpstan-php-parser": "^0.11", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-strict-rules": "^0.11", "phpunit/phpunit": "^7.0", - "slevomat/coding-standard": "^4.6.2" + "slevomat/coding-standard": "^4.7.2", + "squizlabs/php_codesniffer": "^3.3.2" }, "bin": [ "bin/phpstan" @@ -1510,7 +1515,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "0.10-dev" + "dev-master": "0.11-dev" } }, "autoload": { @@ -1526,7 +1531,7 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", - "time": "2018-07-01T18:22:12+00:00" + "time": "2019-01-19T20:23:08+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1866,16 +1871,16 @@ }, { "name": "psr/log", - "version": "1.0.2", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", "shasum": "" }, "require": { @@ -1909,7 +1914,7 @@ "psr", "psr-3" ], - "time": "2016-10-10T12:19:37+00:00" + "time": "2018-11-20T15:27:04+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -2566,20 +2571,21 @@ }, { "name": "symfony/console", - "version": "v4.1.1", + "version": "v4.2.2", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "70591cda56b4b47c55776ac78e157c4bb6c8b43f" + "reference": "b0a03c1bb0fcbe288629956cf2f1dd3f1dc97522" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/70591cda56b4b47c55776ac78e157c4bb6c8b43f", - "reference": "70591cda56b4b47c55776ac78e157c4bb6c8b43f", + "url": "https://api.github.com/repos/symfony/console/zipball/b0a03c1bb0fcbe288629956cf2f1dd3f1dc97522", + "reference": "b0a03c1bb0fcbe288629956cf2f1dd3f1dc97522", "shasum": "" }, "require": { "php": "^7.1.3", + "symfony/contracts": "^1.0", "symfony/polyfill-mbstring": "~1.0" }, "conflict": { @@ -2603,7 +2609,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -2630,7 +2636,75 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2018-05-31T10:17:53+00:00" + "time": "2019-01-04T15:13:53+00:00" + }, + { + "name": "symfony/contracts", + "version": "v1.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/contracts.git", + "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/contracts/zipball/1aa7ab2429c3d594dd70689604b5cf7421254cdf", + "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "require-dev": { + "psr/cache": "^1.0", + "psr/container": "^1.0" + }, + "suggest": { + "psr/cache": "When using the Cache contracts", + "psr/container": "When using the Service contracts", + "symfony/cache-contracts-implementation": "", + "symfony/service-contracts-implementation": "", + "symfony/translation-contracts-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\": "" + }, + "exclude-from-classmap": [ + "**/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A set of abstractions extracted out of the Symfony components", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "time": "2018-12-05T08:06:11+00:00" }, { "name": "symfony/debug", @@ -2690,16 +2764,16 @@ }, { "name": "symfony/finder", - "version": "v4.1.1", + "version": "v4.2.2", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "84714b8417d19e4ba02ea78a41a975b3efaafddb" + "reference": "9094d69e8c6ee3fe186a0ec5a4f1401e506071ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/84714b8417d19e4ba02ea78a41a975b3efaafddb", - "reference": "84714b8417d19e4ba02ea78a41a975b3efaafddb", + "url": "https://api.github.com/repos/symfony/finder/zipball/9094d69e8c6ee3fe186a0ec5a4f1401e506071ce", + "reference": "9094d69e8c6ee3fe186a0ec5a4f1401e506071ce", "shasum": "" }, "require": { @@ -2708,7 +2782,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -2735,7 +2809,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2018-06-19T21:38:16+00:00" + "time": "2019-01-03T09:07:35+00:00" }, { "name": "symfony/phpunit-bridge", @@ -2805,16 +2879,16 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.7.0", + "version": "v1.10.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b" + "reference": "c79c051f5b3a46be09205c73b80b346e4153e494" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/78be803ce01e55d3491c1397cf1c64beb9c1b63b", - "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/c79c051f5b3a46be09205c73b80b346e4153e494", + "reference": "c79c051f5b3a46be09205c73b80b346e4153e494", "shasum": "" }, "require": { @@ -2826,7 +2900,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7-dev" + "dev-master": "1.9-dev" } }, "autoload": { @@ -2860,7 +2934,7 @@ "portable", "shim" ], - "time": "2018-01-30T19:27:44+00:00" + "time": "2018-09-21T13:07:52+00:00" }, { "name": "theseer/tokenizer", diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 85761fcca9b..62023534c87 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1227,9 +1227,7 @@ protected function _getNestedTransactionSavePointName() } /** - * Starts a transaction by suspending auto-commit mode. - * - * @return void + * {@inheritDoc} */ public function beginTransaction() { @@ -1256,12 +1254,12 @@ public function beginTransaction() $logger->stopQuery(); } } + + return true; } /** - * Commits the current transaction. - * - * @return void + * {@inheritDoc} * * @throws ConnectionException If the commit failed due to no active transaction or * because the transaction was marked for rollback only. @@ -1300,10 +1298,12 @@ public function commit() --$this->transactionNestingLevel; if ($this->autoCommit !== false || $this->transactionNestingLevel !== 0) { - return; + return true; } $this->beginTransaction(); + + return true; } /** diff --git a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php index d2e4b2c2509..17dac54d4a2 100644 --- a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php +++ b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php @@ -232,7 +232,7 @@ public function beginTransaction() { $this->connect('master'); - parent::beginTransaction(); + return parent::beginTransaction(); } /** @@ -242,7 +242,7 @@ public function commit() { $this->connect('master'); - parent::commit(); + return parent::commit(); } /** diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 9c87d46319b..0743c2b9817 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -167,7 +167,7 @@ public function closeCursor() public function columnCount() { if (! $this->stmt) { - return false; + return 0; } return db2_num_fields($this->stmt); diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 2bbe0ca8b20..895e5fa501d 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -11,13 +11,14 @@ use mysqli; use mysqli_stmt; use PDO; -use stdClass; use function array_combine; use function array_fill; +use function assert; use function count; use function feof; use function fread; use function get_resource_type; +use function is_array; use function is_resource; use function sprintf; use function str_repeat; @@ -327,28 +328,23 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); } - switch ($fetchMode) { - case FetchMode::NUMERIC: - return $values; + if ($fetchMode === FetchMode::NUMERIC) { + return $values; + } + assert(is_array($this->_columnNames)); + $assoc = array_combine($this->_columnNames, $values); + assert(is_array($assoc)); + + switch ($fetchMode) { case FetchMode::ASSOCIATIVE: - return array_combine($this->_columnNames, $values); + return $assoc; case FetchMode::MIXED: - $ret = array_combine($this->_columnNames, $values); - $ret += $values; - - return $ret; + return $assoc + $values; case FetchMode::STANDARD_OBJECT: - $assoc = array_combine($this->_columnNames, $values); - $ret = new stdClass(); - - foreach ($assoc as $column => $value) { - $ret->$column = $value; - } - - return $ret; + return (object) $assoc; default: throw new MysqliException(sprintf("Unknown fetch type '%s'", $fetchMode)); diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 819421d3469..6eff6b88d79 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -356,8 +356,8 @@ protected function _getCreateTableSQL($name, array $columns, array $options = [] /** * Generate a PRIMARY KEY definition if no autoincrement value is used * - * @param string[] $columns - * @param mixed[] $options + * @param mixed[][] $columns + * @param mixed[] $options */ private function getNonAutoincrementPrimaryKeyDefinition(array $columns, array $options) : string { @@ -368,7 +368,7 @@ private function getNonAutoincrementPrimaryKeyDefinition(array $columns, array $ $keyColumns = array_unique(array_values($options['primary'])); foreach ($keyColumns as $keyColumn) { - if (isset($columns[$keyColumn]['autoincrement']) && ! empty($columns[$keyColumn]['autoincrement'])) { + if (! empty($columns[$keyColumn]['autoincrement'])) { return ''; } } From 3e83d36eb4e77c4858d3b4cdbed32dea8bc77d72 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 21 Jan 2019 22:30:49 -0800 Subject: [PATCH 027/106] PHPStan Level 4 --- lib/Doctrine/DBAL/Connection.php | 4 +-- .../Connections/MasterSlaveConnection.php | 4 +-- .../DBAL/Driver/IBMDB2/DB2Statement.php | 14 +--------- .../DBAL/Driver/Mysqli/MysqliStatement.php | 26 +++++++------------ .../DBAL/Platforms/AbstractPlatform.php | 17 ++++++------ .../DBAL/Platforms/PostgreSqlPlatform.php | 3 ++- lib/Doctrine/DBAL/Query/QueryBuilder.php | 2 +- .../DBAL/Schema/AbstractSchemaManager.php | 18 +++---------- lib/Doctrine/DBAL/Schema/ColumnDiff.php | 2 +- lib/Doctrine/DBAL/Schema/Sequence.php | 5 ++-- .../DBAL/Schema/SqliteSchemaManager.php | 11 ++++---- lib/Doctrine/DBAL/Schema/TableDiff.php | 12 ++++++--- .../SQLAzure/SQLAzureShardManager.php | 6 ----- phpstan.neon.dist | 2 +- .../SQLAzure/SQLAzureShardManagerTest.php | 12 --------- 15 files changed, 47 insertions(+), 91 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 62023534c87..06ebae21944 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -149,7 +149,7 @@ class Connection implements DriverConnection /** * The schema manager. * - * @var AbstractSchemaManager + * @var AbstractSchemaManager|null */ protected $_schemaManager; @@ -1446,7 +1446,7 @@ public function getWrappedConnection() */ public function getSchemaManager() { - if (! $this->_schemaManager) { + if ($this->_schemaManager === null) { $this->_schemaManager = $this->_driver->getSchemaManager($this); } diff --git a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php index 17dac54d4a2..1365e4039fb 100644 --- a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php +++ b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php @@ -133,7 +133,7 @@ public function connect($connectionName = null) // If we have a connection open, and this is not an explicit connection // change request, then abort right here, because we are already done. // This prevents writes to the slave in case of "keepSlave" option enabled. - if (isset($this->_conn) && $this->_conn && ! $requestedConnectionChange) { + if ($this->_conn !== null && ! $requestedConnectionChange) { return false; } @@ -144,7 +144,7 @@ public function connect($connectionName = null) $forceMasterAsSlave = true; } - if (isset($this->connections[$connectionName]) && $this->connections[$connectionName]) { + if (isset($this->connections[$connectionName])) { $this->_conn = $this->connections[$connectionName]; if ($forceMasterAsSlave && ! $this->keepSlave) { diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 0743c2b9817..4244b256414 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -146,10 +146,6 @@ private function bind($parameter, &$variable, int $parameterType, int $dataType) */ public function closeCursor() { - if (! $this->stmt) { - return false; - } - $this->bindParam = []; if (! db2_free_result($this->stmt)) { @@ -166,11 +162,7 @@ public function closeCursor() */ public function columnCount() { - if (! $this->stmt) { - return 0; - } - - return db2_num_fields($this->stmt); + return db2_num_fields($this->stmt) ?: 0; } /** @@ -197,10 +189,6 @@ public function errorInfo() */ public function execute($params = null) { - if (! $this->stmt) { - return false; - } - if ($params === null) { ksort($this->bindParam); diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 895e5fa501d..e7600d92296 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -97,16 +97,12 @@ public function __construct(mysqli $conn, $prepareString) */ public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { - if ($type === null) { - $type = 's'; - } else { - if (! isset(self::$_paramTypeMap[$type])) { - throw new MysqliException(sprintf("Unknown type: '%s'", $type)); - } - - $type = self::$_paramTypeMap[$type]; + if (! isset(self::$_paramTypeMap[$type])) { + throw new MysqliException(sprintf("Unknown type: '%s'", $type)); } + $type = self::$_paramTypeMap[$type]; + $this->_bindedValues[$column] =& $variable; $this->types[$column - 1] = $type; @@ -118,16 +114,12 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l */ public function bindValue($param, $value, $type = ParameterType::STRING) { - if ($type === null) { - $type = 's'; - } else { - if (! isset(self::$_paramTypeMap[$type])) { - throw new MysqliException(sprintf("Unknown type: '%s'", $type)); - } - - $type = self::$_paramTypeMap[$type]; + if (! isset(self::$_paramTypeMap[$type])) { + throw new MysqliException(sprintf("Unknown type: '%s'", $type)); } + $type = self::$_paramTypeMap[$type]; + $this->_values[$param] = $value; $this->_bindedValues[$param] =& $this->_values[$param]; $this->types[$param - 1] = $type; @@ -284,7 +276,7 @@ private function _bindValues($values) } /** - * @return mixed[]|false + * @return mixed[]|false|null */ private function _fetch() { diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 5e4537391ed..68994846864 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -144,7 +144,7 @@ abstract class AbstractPlatform /** * Holds the KeywordList instance for the current platform. * - * @var KeywordList + * @var KeywordList|null */ protected $_keywords; @@ -518,7 +518,7 @@ public function getDoctrineTypeComment(Type $doctrineType) /** * Gets the comment of a passed column modified by potential doctrine type comment hints. * - * @return string + * @return string|null */ protected function getColumnComment(Column $column) { @@ -1610,9 +1610,9 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE } /** - * @param string $tableName - * @param string $columnName - * @param string $comment + * @param string $tableName + * @param string $columnName + * @param string|null $comment * * @return string */ @@ -1620,13 +1620,12 @@ public function getCommentOnColumnSQL($tableName, $columnName, $comment) { $tableName = new Identifier($tableName); $columnName = new Identifier($columnName); - $comment = $this->quoteStringLiteral($comment); return sprintf( 'COMMENT ON COLUMN %s.%s IS %s', $tableName->getQuotedName($this), $columnName->getQuotedName($this), - $comment + $this->quoteStringLiteral((string) $comment) ); } @@ -2300,7 +2299,7 @@ public function getDefaultValueDeclarationSQL($field) * Obtains DBMS specific SQL code portion needed to set a CHECK constraint * declaration to be used in statements like CREATE TABLE. * - * @param mixed[][] $definition The check definition. + * @param string[]|mixed[][] $definition The check definition. * * @return string DBMS specific SQL code portion needed to set a CHECK constraint. */ @@ -3154,7 +3153,7 @@ public function supportsForeignKeyConstraints() */ public function supportsForeignKeyOnUpdate() { - return $this->supportsForeignKeyConstraints() && true; + return $this->supportsForeignKeyConstraints(); } /** diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index cb4603f5199..3c9984f95e6 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -1215,7 +1215,8 @@ public function getDefaultValueDeclarationSQL($field) */ private function isSerialField(array $field) : bool { - return $field['autoincrement'] ?? false === true && isset($field['type']) + return isset($field['type'], $field['autoincrement']) + && $field['autoincrement'] === true && $this->isNumericType($field['type']); } diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 12584d960ab..773afa23d87 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -403,7 +403,7 @@ public function getMaxResults() * 'groupBy', 'having' and 'orderBy'. * * @param string $sqlPartName - * @param string $sqlPart + * @param mixed $sqlPart * @param bool $append * * @return $this This QueryBuilder instance. diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 9b917427fd8..52b807f8042 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -747,14 +747,9 @@ protected function _getPortableTriggerDefinition($trigger) protected function _getPortableSequencesList($sequences) { $list = []; - foreach ($sequences as $value) { - $value = $this->_getPortableSequenceDefinition($value); - if (! $value) { - continue; - } - - $list[] = $value; + foreach ($sequences as $value) { + $list[] = $this->_getPortableSequenceDefinition($value); } return $list; @@ -996,14 +991,9 @@ protected function _getPortableViewDefinition($view) protected function _getPortableTableForeignKeysList($tableForeignKeys) { $list = []; - foreach ($tableForeignKeys as $value) { - $value = $this->_getPortableTableForeignKeyDefinition($value); - if (! $value) { - continue; - } - - $list[] = $value; + foreach ($tableForeignKeys as $value) { + $list[] = $this->_getPortableTableForeignKeyDefinition($value); } return $list; diff --git a/lib/Doctrine/DBAL/Schema/ColumnDiff.php b/lib/Doctrine/DBAL/Schema/ColumnDiff.php index cb64592109b..1589f98d4a9 100644 --- a/lib/Doctrine/DBAL/Schema/ColumnDiff.php +++ b/lib/Doctrine/DBAL/Schema/ColumnDiff.php @@ -18,7 +18,7 @@ class ColumnDiff /** @var string[] */ public $changedProperties = []; - /** @var Column */ + /** @var Column|null */ public $fromColumn; /** diff --git a/lib/Doctrine/DBAL/Schema/Sequence.php b/lib/Doctrine/DBAL/Schema/Sequence.php index 24cf4aae0b4..269961fb232 100644 --- a/lib/Doctrine/DBAL/Schema/Sequence.php +++ b/lib/Doctrine/DBAL/Schema/Sequence.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Schema\Visitor\Visitor; use function count; -use function is_numeric; use function sprintf; /** @@ -66,7 +65,7 @@ public function getCache() */ public function setAllocationSize($allocationSize) { - $this->allocationSize = is_numeric($allocationSize) ? (int) $allocationSize : 1; + $this->allocationSize = (int) $allocationSize ?: 1; return $this; } @@ -78,7 +77,7 @@ public function setAllocationSize($allocationSize) */ public function setInitialValue($initialValue) { - $this->initialValue = is_numeric($initialValue) ? (int) $initialValue : 1; + $this->initialValue = (int) $initialValue ?: 1; return $this; } diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 744acedabb5..431206a0733 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -77,7 +77,7 @@ public function renameTable($name, $newName) */ public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) { - $tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table); + $tableDiff = $this->getTableDiffForAlterForeignKey($table); $tableDiff->addedForeignKeys[] = $foreignKey; $this->alterTable($tableDiff); @@ -88,7 +88,7 @@ public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) */ public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) { - $tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table); + $tableDiff = $this->getTableDiffForAlterForeignKey($table); $tableDiff->changedForeignKeys[] = $foreignKey; $this->alterTable($tableDiff); @@ -99,7 +99,7 @@ public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table */ public function dropForeignKey($foreignKey, $table) { - $tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table); + $tableDiff = $this->getTableDiffForAlterForeignKey($table); $tableDiff->removedForeignKeys[] = $foreignKey; $this->alterTable($tableDiff); @@ -436,11 +436,12 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) * * @throws DBALException */ - private function getTableDiffForAlterForeignKey(ForeignKeyConstraint $foreignKey, $table) + private function getTableDiffForAlterForeignKey($table) { if (! $table instanceof Table) { $tableDetails = $this->tryMethod('listTableDetails', $table); - if ($table === false) { + + if ($tableDetails === false) { throw new DBALException(sprintf('Sqlite schema manager requires to modify foreign keys table definition "%s".', $table)); } diff --git a/lib/Doctrine/DBAL/Schema/TableDiff.php b/lib/Doctrine/DBAL/Schema/TableDiff.php index 457e1b6a963..1ff2c0ad105 100644 --- a/lib/Doctrine/DBAL/Schema/TableDiff.php +++ b/lib/Doctrine/DBAL/Schema/TableDiff.php @@ -12,7 +12,7 @@ class TableDiff /** @var string */ public $name = null; - /** @var string|bool */ + /** @var string|false */ public $newName = false; /** @@ -92,7 +92,7 @@ class TableDiff */ public $removedForeignKeys = []; - /** @var Table */ + /** @var Table|null */ public $fromTable; /** @@ -139,10 +139,14 @@ public function getName(AbstractPlatform $platform) } /** - * @return Identifier|string|bool + * @return Identifier|false */ public function getNewName() { - return $this->newName ? new Identifier($this->newName) : $this->newName; + if ($this->newName === false) { + return false; + } + + return new Identifier($this->newName); } } diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php index 7c5dfe5c4be..d8178ee07db 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php @@ -7,8 +7,6 @@ use Doctrine\DBAL\Sharding\ShardManager; use Doctrine\DBAL\Types\Type; use RuntimeException; -use function is_bool; -use function is_scalar; use function sprintf; /** @@ -125,10 +123,6 @@ public function selectShard($distributionValue) throw ShardingException::activeTransaction(); } - if ($distributionValue === null || is_bool($distributionValue) || ! is_scalar($distributionValue)) { - throw ShardingException::noShardDistributionValue(); - } - $platform = $this->conn->getDatabasePlatform(); $sql = sprintf( 'USE FEDERATION %s (%s = %s) WITH RESET, FILTERING = %s;', diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 406cc2a530e..13b6ef6a393 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 3 + level: 4 paths: - %currentWorkingDirectory%/lib autoload_files: diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php index edc88d376c9..b96a9eaa173 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php @@ -79,18 +79,6 @@ public function testSelectShard() self::assertEquals(1234, $sm->getCurrentDistributionValue()); } - public function testSelectShardNoDistributionValue() - { - $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); - $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false)); - - $this->expectException(ShardingException::class); - $this->expectExceptionMessage('You have to specify a string or integer as shard distribution value.'); - - $sm = new SQLAzureShardManager($conn); - $sm->selectShard(null); - } - /** * @param mixed[] $params */ From 5600b8672829ccc403f61eec5c4cfe33199dd11f Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 22 Jan 2019 23:29:45 -0800 Subject: [PATCH 028/106] PHPStan Level 5 --- .../DBAL/Cache/ResultCacheStatement.php | 7 +++++-- lib/Doctrine/DBAL/DBALException.php | 15 +++++---------- .../DBAL/Driver/OCI8/OCI8Statement.php | 2 +- .../DBAL/Event/SchemaCreateTableEventArgs.php | 9 ++++----- lib/Doctrine/DBAL/Portability/Statement.php | 18 ++++++++++++++++-- .../Query/Expression/ExpressionBuilder.php | 4 ++-- lib/Doctrine/DBAL/SQLParserUtils.php | 6 +++--- .../DBAL/Schema/AbstractSchemaManager.php | 2 +- .../DBAL/Schema/SQLServerSchemaManager.php | 2 +- .../DBAL/Schema/SqliteSchemaManager.php | 4 ++-- lib/Doctrine/DBAL/Schema/Table.php | 2 +- .../Schema/Visitor/DropSchemaSqlCollector.php | 3 +++ lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php | 4 +--- .../DBAL/Sharding/PoolingShardConnection.php | 2 +- phpstan.neon.dist | 5 ++++- 15 files changed, 50 insertions(+), 35 deletions(-) diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 721709a0dd4..8fbae62de29 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -12,6 +12,7 @@ use PDO; use function array_merge; use function array_values; +use function assert; use function reset; /** @@ -41,7 +42,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement /** @var int */ private $lifetime; - /** @var Statement */ + /** @var ResultStatement */ private $statement; /** @@ -62,7 +63,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement * @param string $realKey * @param int $lifetime */ - public function __construct(Statement $stmt, Cache $resultCache, $cacheKey, $realKey, $lifetime) + public function __construct(ResultStatement $stmt, Cache $resultCache, $cacheKey, $realKey, $lifetime) { $this->statement = $stmt; $this->resultCache = $resultCache; @@ -196,6 +197,8 @@ public function fetchColumn($columnIndex = 0) */ public function rowCount() { + assert($this->statement instanceof Statement); + return $this->statement->rowCount(); } } diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index 15bac7f0f66..5b7465f99fe 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -128,11 +128,10 @@ public static function unknownDriver($unknownDriverName, array $knownDrivers) } /** - * @param Exception $driverEx - * @param string $sql - * @param mixed[] $params + * @param string $sql + * @param mixed[] $params * - * @return \Doctrine\DBAL\DBALException + * @return self */ public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = []) { @@ -146,9 +145,7 @@ public static function driverExceptionDuringQuery(Driver $driver, Throwable $dri } /** - * @param Exception $driverEx - * - * @return \Doctrine\DBAL\DBALException + * @return self */ public static function driverException(Driver $driver, Throwable $driverEx) { @@ -156,9 +153,7 @@ public static function driverException(Driver $driver, Throwable $driverEx) } /** - * @param Exception $driverEx - * - * @return \Doctrine\DBAL\DBALException + * @return self */ private static function wrapException(Driver $driver, Throwable $driverEx, $msg) { diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index 8db54c86aa7..568f3713b5a 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -240,7 +240,7 @@ private static function findClosingQuote( * where the token was found. * * @param string $statement The SQL statement to parse - * @param string $offset The offset to start searching from + * @param int $offset The offset to start searching from * @param string $regex The regex containing token pattern * * @return string|null Token or NULL if not found diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php index 538617cc328..954f77aa55a 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php @@ -3,7 +3,6 @@ namespace Doctrine\DBAL\Event; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table; use function array_merge; use function is_array; @@ -16,7 +15,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs /** @var Table */ private $table; - /** @var Column[] */ + /** @var mixed[][] */ private $columns; /** @var mixed[] */ @@ -29,8 +28,8 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs private $sql = []; /** - * @param Column[] $columns - * @param mixed[] $options + * @param mixed[][] $columns + * @param mixed[] $options */ public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform) { @@ -49,7 +48,7 @@ public function getTable() } /** - * @return Column[] + * @return mixed[][] */ public function getColumns() { diff --git a/lib/Doctrine/DBAL/Portability/Statement.php b/lib/Doctrine/DBAL/Portability/Statement.php index 1499ff1bf48..514b3be2d74 100644 --- a/lib/Doctrine/DBAL/Portability/Statement.php +++ b/lib/Doctrine/DBAL/Portability/Statement.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Portability; +use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; @@ -9,6 +10,7 @@ use IteratorAggregate; use PDO; use function array_change_key_case; +use function assert; use function is_string; use function rtrim; @@ -20,7 +22,7 @@ class Statement implements IteratorAggregate, DriverStatement /** @var int */ private $portability; - /** @var DriverStatement */ + /** @var DriverStatement|ResultStatement */ private $stmt; /** @var int */ @@ -32,7 +34,7 @@ class Statement implements IteratorAggregate, DriverStatement /** * Wraps Statement and applies portability measures. * - * @param DriverStatement $stmt + * @param DriverStatement|ResultStatement $stmt */ public function __construct($stmt, Connection $conn) { @@ -46,6 +48,8 @@ public function __construct($stmt, Connection $conn) */ public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { + assert($this->stmt instanceof DriverStatement); + return $this->stmt->bindParam($column, $variable, $type, $length); } @@ -54,6 +58,8 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l */ public function bindValue($param, $value, $type = ParameterType::STRING) { + assert($this->stmt instanceof DriverStatement); + return $this->stmt->bindValue($param, $value, $type); } @@ -78,6 +84,8 @@ public function columnCount() */ public function errorCode() { + assert($this->stmt instanceof DriverStatement); + return $this->stmt->errorCode(); } @@ -86,6 +94,8 @@ public function errorCode() */ public function errorInfo() { + assert($this->stmt instanceof DriverStatement); + return $this->stmt->errorInfo(); } @@ -94,6 +104,8 @@ public function errorInfo() */ public function execute($params = null) { + assert($this->stmt instanceof DriverStatement); + return $this->stmt->execute($params); } @@ -228,6 +240,8 @@ public function fetchColumn($columnIndex = 0) */ public function rowCount() { + assert($this->stmt instanceof DriverStatement); + return $this->stmt->rowCount(); } } diff --git a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php index 91f370aecb6..dfcc31ec709 100644 --- a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php +++ b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php @@ -286,8 +286,8 @@ public function notIn($x, $y) /** * Quotes a given input parameter. * - * @param mixed $input The parameter to be quoted. - * @param string|null $type The type of the parameter. + * @param mixed $input The parameter to be quoted. + * @param int|null $type The type of the parameter. * * @return string */ diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 537cd9e4884..7dc63884a51 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -36,13 +36,13 @@ class SQLParserUtils /** * Gets an array of the placeholders in an sql statements as keys and their positions in the query string. * - * Returns an integer => integer pair (indexed from zero) for a positional statement - * and a string => int[] pair for a named statement. + * For a statement with positional parameters, returns a zero-indexed list of placeholder position. + * For a statement with named parameters, returns a map of placeholder positions to their parameter names. * * @param string $statement * @param bool $isPositional * - * @return int[] + * @return int[]|string[] */ public static function getPlaceholderPositions($statement, $isPositional = true) { diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 52b807f8042..bf278e6e78a 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -268,7 +268,7 @@ public function listTableDetails($tableName) } $indexes = $this->listTableIndexes($tableName); - return new Table($tableName, $columns, $indexes, $foreignKeys, false, []); + return new Table($tableName, $columns, $indexes, $foreignKeys); } /** diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index 6cd82b2ffaf..763074e7d27 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -216,7 +216,7 @@ protected function getPortableNamespaceDefinition(array $namespace) protected function _getPortableViewDefinition($view) { // @todo - return new View($view['name'], null); + return new View($view['name'], ''); } /** diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 431206a0733..9d03552b667 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -283,9 +283,9 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) continue; } - $type = $this->extractDoctrineTypeFromComment($comment, null); + $type = $this->extractDoctrineTypeFromComment($comment, ''); - if ($type !== null) { + if ($type !== '') { $column->setType(Type::getType($type)); $comment = $this->removeDoctrineTypeFromComment($comment, $type); diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 191294d6d15..09ae27f0590 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -425,7 +425,7 @@ public function addNamedForeignKeyConstraint($name, $foreignTable, array $localC /** * @param string $name - * @param string $value + * @param mixed $value * * @return self */ diff --git a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php index 44f5ea80af5..81e2023128b 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php @@ -78,15 +78,18 @@ public function getQueries() { $sql = []; + /** @var ForeignKeyConstraint $fkConstraint */ foreach ($this->constraints as $fkConstraint) { $localTable = $this->constraints[$fkConstraint]; $sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable); } + /** @var Sequence $sequence */ foreach ($this->sequences as $sequence) { $sql[] = $this->platform->getDropSequenceSQL($sequence); } + /** @var Table $table */ foreach ($this->tables as $table) { $sql[] = $this->platform->getDropTableSQL($table); } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php b/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php index 889f9611254..7efb39e2863 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php @@ -8,8 +8,6 @@ use function current; use function file_put_contents; use function in_array; -use function mt_rand; -use function sha1; use function strtolower; /** @@ -41,7 +39,7 @@ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkCons */ public function acceptSchema(Schema $schema) { - $this->output = 'digraph "' . sha1(mt_rand()) . '" {' . "\n"; + $this->output = 'digraph "' . $schema->getName() . '" {' . "\n"; $this->output .= 'splines = true;' . "\n"; $this->output .= 'overlap = false;' . "\n"; $this->output .= 'outputorder=edgesfirst;' . "\n"; diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php index abb5b4004e2..0adea2894c5 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php @@ -205,7 +205,7 @@ public function connect($shardId = null) /** * Connects to a specific connection. * - * @param string $shardId + * @param string|int $shardId * * @return \Doctrine\DBAL\Driver\Connection */ diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 13b6ef6a393..4bedf0cd776 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 4 + level: 5 paths: - %currentWorkingDirectory%/lib autoload_files: @@ -26,6 +26,9 @@ parameters: # http://php.net/manual/en/pdo.sqlitecreatefunction.php - '~^Call to an undefined method Doctrine\\DBAL\\Driver\\PDOConnection::sqliteCreateFunction\(\)\.\z~' + # https://github.com/JetBrains/phpstorm-stubs/pull/488 + - '~^Parameter #1 \$byteCount of function SQLSRV_SQLTYPE_VARBINARY expects int, string given\.\z~' + # legacy variadic-like signature - '~^Method Doctrine\\DBAL\\Driver\\Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~' From 000cd9dd08f65b885fc895f862387df9837d6589 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 24 Jan 2019 13:17:04 -0800 Subject: [PATCH 029/106] PHPStan Level 6 --- lib/Doctrine/DBAL/Connection.php | 51 +++++++------- .../DBAL/Driver/IBMDB2/DB2Connection.php | 9 ++- .../DBAL/Driver/IBMDB2/DB2Statement.php | 10 +-- .../DBAL/Driver/Mysqli/MysqliStatement.php | 52 ++++++++------ .../DBAL/Driver/OCI8/OCI8Connection.php | 26 +++++-- .../DBAL/Driver/OCI8/OCI8Exception.php | 6 +- .../DBAL/Driver/OCI8/OCI8Statement.php | 43 ++++++++---- lib/Doctrine/DBAL/Driver/PDOConnection.php | 20 ++---- lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php | 37 +++------- lib/Doctrine/DBAL/Driver/PDOStatement.php | 27 +++---- .../SQLAnywhere/SQLAnywhereStatement.php | 10 +-- .../DBAL/Driver/SQLSrv/SQLSrvConnection.php | 15 +++- .../DBAL/Driver/SQLSrv/SQLSrvStatement.php | 21 ++++-- lib/Doctrine/DBAL/DriverManager.php | 5 ++ .../DBAL/Platforms/AbstractPlatform.php | 21 ++++-- lib/Doctrine/DBAL/Platforms/DB2Platform.php | 10 ++- .../DBAL/Platforms/DrizzlePlatform.php | 6 +- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 18 +++-- .../DBAL/Platforms/OraclePlatform.php | 10 ++- .../DBAL/Platforms/PostgreSqlPlatform.php | 10 ++- .../DBAL/Platforms/SQLAnywherePlatform.php | 6 +- .../DBAL/Platforms/SQLServerPlatform.php | 23 ++++-- .../DBAL/Platforms/SqlitePlatform.php | 25 +++++-- lib/Doctrine/DBAL/SQLParserUtils.php | 70 +++++++++++++++---- .../DBAL/Schema/AbstractSchemaManager.php | 7 +- lib/Doctrine/DBAL/Schema/Comparator.php | 3 + .../DBAL/Schema/ForeignKeyConstraint.php | 42 +++++++---- .../DBAL/Schema/MySqlSchemaManager.php | 4 ++ .../DBAL/Schema/SQLAnywhereSchemaManager.php | 9 +-- .../DBAL/Schema/SQLServerSchemaManager.php | 31 +++++--- lib/Doctrine/DBAL/Schema/Table.php | 7 +- .../Tools/Console/Command/ImportCommand.php | 9 ++- .../Tools/Console/Command/RunSqlCommand.php | 4 ++ lib/Doctrine/DBAL/Tools/Dumper.php | 9 ++- lib/Doctrine/DBAL/Types/BinaryType.php | 2 + lib/Doctrine/DBAL/Types/BlobType.php | 2 + lib/Doctrine/DBAL/Types/Type.php | 13 ++-- phpstan.neon.dist | 6 +- 38 files changed, 447 insertions(+), 232 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 06ebae21944..4d79fb739b6 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -22,7 +22,6 @@ use Exception; use Throwable; use function array_key_exists; -use function array_merge; use function assert; use function func_get_args; use function implode; @@ -599,24 +598,26 @@ public function isTransactionActive() } /** - * Gathers conditions for an update or delete call. + * Adds identifier condition to the query components * - * @param mixed[] $identifiers Input array of columns to values + * @param mixed[] $identifier Map of key columns to their values + * @param string[] $columns Column names + * @param mixed[] $values Column values + * @param string[] $conditions Key conditions * - * @return string[][] a triplet with: - * - the first key being the columns - * - the second key being the values - * - the third key being the conditions + * @throws DBALException */ - private function gatherConditions(array $identifiers) - { - $columns = []; - $values = []; - $conditions = []; + private function addIdentifierCondition( + array $identifier, + array &$columns, + array &$values, + array &$conditions + ) : void { + $platform = $this->getDatabasePlatform(); - foreach ($identifiers as $columnName => $value) { + foreach ($identifier as $columnName => $value) { if ($value === null) { - $conditions[] = $this->getDatabasePlatform()->getIsNullExpression($columnName); + $conditions[] = $platform->getIsNullExpression($columnName); continue; } @@ -624,8 +625,6 @@ private function gatherConditions(array $identifiers) $values[] = $value; $conditions[] = $columnName . ' = ?'; } - - return [$columns, $values, $conditions]; } /** @@ -648,7 +647,9 @@ public function delete($tableExpression, array $identifier, array $types = []) throw InvalidArgumentException::fromEmptyCriteria(); } - [$columns, $values, $conditions] = $this->gatherConditions($identifier); + $columns = $values = $conditions = []; + + $this->addIdentifierCondition($identifier, $columns, $values, $conditions); return $this->executeUpdate( 'DELETE FROM ' . $tableExpression . ' WHERE ' . implode(' AND ', $conditions), @@ -713,19 +714,15 @@ public function getTransactionIsolation() */ public function update($tableExpression, array $data, array $identifier, array $types = []) { - $setColumns = []; - $setValues = []; - $set = []; + $columns = $values = $conditions = $set = []; foreach ($data as $columnName => $value) { - $setColumns[] = $columnName; - $setValues[] = $value; - $set[] = $columnName . ' = ?'; + $columns[] = $columnName; + $values[] = $value; + $set[] = $columnName . ' = ?'; } - [$conditionColumns, $conditionValues, $conditions] = $this->gatherConditions($identifier); - $columns = array_merge($setColumns, $conditionColumns); - $values = array_merge($setValues, $conditionValues); + $this->addIdentifierCondition($identifier, $columns, $values, $conditions); if (is_string(key($types))) { $types = $this->extractTypeValues($columns, $types); @@ -777,7 +774,7 @@ public function insert($tableExpression, array $data, array $types = []) /** * Extract ordered type list from an ordered column list and type map. * - * @param string[] $columnList + * @param int[]|string[] $columnList * @param int[]|string[] $types * * @return int[]|string[] diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index bd80e6e49a7..cb1e6018f3e 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -42,13 +42,16 @@ public function __construct(array $params, $username, $password, $driverOptions $isPersistent = (isset($params['persistent']) && $params['persistent'] === true); if ($isPersistent) { - $this->conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions); + $conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions); } else { - $this->conn = db2_connect($params['dbname'], $username, $password, $driverOptions); + $conn = db2_connect($params['dbname'], $username, $password, $driverOptions); } - if (! $this->conn) { + + if ($conn === false) { throw new DB2Exception(db2_conn_errormsg()); } + + $this->conn = $conn; } /** diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 4244b256414..af6e852bc43 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -127,16 +127,16 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l } /** - * @param int|string $parameter Parameter position or name - * @param mixed $variable + * @param int $position Parameter position + * @param mixed $variable * * @throws DB2Exception */ - private function bind($parameter, &$variable, int $parameterType, int $dataType) : void + private function bind($position, &$variable, int $parameterType, int $dataType) : void { - $this->bindParam[$parameter] =& $variable; + $this->bindParam[$position] =& $variable; - if (! db2_bind_param($this->stmt, $parameter, 'variable', $parameterType, $dataType)) { + if (! db2_bind_param($this->stmt, $position, 'variable', $parameterType, $dataType)) { throw new DB2Exception(db2_stmt_errormsg()); } } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index e7600d92296..85a88f33401 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -19,6 +19,7 @@ use function fread; use function get_resource_type; use function is_array; +use function is_int; use function is_resource; use function sprintf; use function str_repeat; @@ -41,7 +42,7 @@ class MysqliStatement implements IteratorAggregate, Statement /** @var mysqli_stmt */ protected $_stmt; - /** @var string[]|bool|null */ + /** @var string[]|false|null */ protected $_columnNames; /** @var mixed[]|null */ @@ -78,11 +79,15 @@ class MysqliStatement implements IteratorAggregate, Statement public function __construct(mysqli $conn, $prepareString) { $this->_conn = $conn; - $this->_stmt = $conn->prepare($prepareString); - if ($this->_stmt === false) { + + $stmt = $conn->prepare($prepareString); + + if ($stmt === false) { throw new MysqliException($this->_conn->error, $this->_conn->sqlstate, $this->_conn->errno); } + $this->_stmt = $stmt; + $paramCount = $this->_stmt->param_count; if (0 >= $paramCount) { return; @@ -97,14 +102,14 @@ public function __construct(mysqli $conn, $prepareString) */ public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { + assert(is_int($column)); + if (! isset(self::$_paramTypeMap[$type])) { throw new MysqliException(sprintf("Unknown type: '%s'", $type)); } - $type = self::$_paramTypeMap[$type]; - $this->_bindedValues[$column] =& $variable; - $this->types[$column - 1] = $type; + $this->types[$column - 1] = self::$_paramTypeMap[$type]; return true; } @@ -114,15 +119,15 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l */ public function bindValue($param, $value, $type = ParameterType::STRING) { + assert(is_int($param)); + if (! isset(self::$_paramTypeMap[$type])) { throw new MysqliException(sprintf("Unknown type: '%s'", $type)); } - $type = self::$_paramTypeMap[$type]; - $this->_values[$param] = $value; $this->_bindedValues[$param] =& $this->_values[$param]; - $this->types[$param - 1] = $type; + $this->types[$param - 1] = self::$_paramTypeMap[$type]; return true; } @@ -134,15 +139,11 @@ public function execute($params = null) { if ($this->_bindedValues !== null) { if ($params !== null) { - if (! $this->_bindValues($params)) { + if (! $this->bindUntypedValues($params)) { throw new MysqliException($this->_stmt->error, $this->_stmt->errno); } } else { - [$types, $values, $streams] = $this->separateBoundValues(); - if (! $this->_stmt->bind_param($types, ...$values)) { - throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); - } - $this->sendLongData($streams); + $this->bindTypedParameters(); } } @@ -153,10 +154,14 @@ public function execute($params = null) if ($this->_columnNames === null) { $meta = $this->_stmt->result_metadata(); if ($meta !== false) { + $fields = $meta->fetch_fields(); + assert(is_array($fields)); + $columnNames = []; - foreach ($meta->fetch_fields() as $col) { + foreach ($fields as $col) { $columnNames[] = $col->name; } + $meta->free(); $this->_columnNames = $columnNames; @@ -200,12 +205,9 @@ public function execute($params = null) } /** - * Split $this->_bindedValues into those values that need to be sent using mysqli::send_long_data() - * and those that can be bound the usual way. - * - * @return array|string> + * Binds parameters with known types previously bound to the statement */ - private function separateBoundValues() + private function bindTypedParameters() { $streams = $values = []; $types = $this->types; @@ -231,7 +233,11 @@ private function separateBoundValues() $values[$parameter] = $value; } - return [$types, $values, $streams]; + if (! $this->_stmt->bind_param($types, ...$values)) { + throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); + } + + $this->sendLongData($streams); } /** @@ -263,7 +269,7 @@ private function sendLongData($streams) * * @return bool */ - private function _bindValues($values) + private function bindUntypedValues(array $values) { $params = []; $types = str_repeat('s', count($values)); diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php index 5ebc877a898..35333e8d2d7 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php @@ -54,13 +54,15 @@ public function __construct($username, $password, $db, $charset = null, $session define('OCI_NO_AUTO_COMMIT', 0); } - $this->dbh = $persistent + $dbh = $persistent ? @oci_pconnect($username, $password, $db, $charset, $sessionMode) : @oci_connect($username, $password, $db, $charset, $sessionMode); - if (! $this->dbh) { + if ($dbh === false) { throw OCI8Exception::fromErrorInfo(oci_error()); } + + $this->dbh = $dbh; } /** @@ -71,17 +73,23 @@ public function __construct($username, $password, $db, $charset = null, $session */ public function getServerVersion() { - if (! preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', oci_server_version($this->dbh), $version)) { + $version = oci_server_version($this->dbh); + + if ($version === false) { + throw OCI8Exception::fromErrorInfo(oci_error($this->dbh)); + } + + if (! preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', $version, $matches)) { throw new UnexpectedValueException( sprintf( 'Unexpected database version string "%s". Cannot parse an appropriate version number from it. ' . 'Please report this database version string to the Doctrine team.', - oci_server_version($this->dbh) + $version ) ); } - return $version[1]; + return $matches[1]; } /** @@ -222,6 +230,12 @@ public function errorCode() */ public function errorInfo() { - return oci_error($this->dbh); + $error = oci_error($this->dbh); + + if ($error === false) { + return []; + } + + return $error; } } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php index 9d61ad42d08..af3a9d1a7a9 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php @@ -7,12 +7,16 @@ class OCI8Exception extends AbstractDriverException { /** - * @param mixed[] $error + * @param mixed[]|false $error * * @return \Doctrine\DBAL\Driver\OCI8\OCI8Exception */ public static function fromErrorInfo($error) { + if ($error === false) { + return new self('Database error occurred but no error information was retrieved from the driver.'); + } + return new self($error['message'], null, $error['code']); } } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index 568f3713b5a..32feaef93e3 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -23,9 +23,11 @@ use const PREG_OFFSET_CAPTURE; use const SQLT_CHR; use function array_key_exists; +use function assert; use function count; use function implode; -use function is_numeric; +use function is_int; +use function is_resource; use function oci_bind_by_name; use function oci_cancel; use function oci_error; @@ -92,16 +94,20 @@ class OCI8Statement implements IteratorAggregate, Statement /** * Creates a new OCI8Statement that uses the given connection handle and SQL statement. * - * @param resource $dbh The connection handle. - * @param string $statement The SQL statement. + * @param resource $dbh The connection handle. + * @param string $query The SQL query. */ - public function __construct($dbh, $statement, OCI8Connection $conn) + public function __construct($dbh, $query, OCI8Connection $conn) { - [$statement, $paramMap] = self::convertPositionalToNamedPlaceholders($statement); - $this->_sth = oci_parse($dbh, $statement); - $this->_dbh = $dbh; - $this->_paramMap = $paramMap; - $this->_conn = $conn; + [$query, $paramMap] = self::convertPositionalToNamedPlaceholders($query); + + $stmt = oci_parse($dbh, $query); + assert(is_resource($stmt)); + + $this->_sth = $stmt; + $this->_dbh = $dbh; + $this->_paramMap = $paramMap; + $this->_conn = $conn; } /** @@ -272,6 +278,10 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l if ($type === ParameterType::LARGE_OBJECT) { $lob = oci_new_descriptor($this->_dbh, OCI_D_LOB); + + $class = 'OCI-Lob'; + assert($lob instanceof $class); + $lob->writeTemporary($variable, OCI_TEMP_BLOB); $variable =& $lob; @@ -327,7 +337,7 @@ public function closeCursor() */ public function columnCount() { - return oci_num_fields($this->_sth); + return oci_num_fields($this->_sth) ?: 0; } /** @@ -348,7 +358,13 @@ public function errorCode() */ public function errorInfo() { - return oci_error($this->_sth); + $error = oci_error($this->_sth); + + if ($error === false) { + return []; + } + + return $error; } /** @@ -358,8 +374,9 @@ public function execute($params = null) { if ($params) { $hasZeroIndex = array_key_exists(0, $params); + foreach ($params as $key => $val) { - if ($hasZeroIndex && is_numeric($key)) { + if ($hasZeroIndex && is_int($key)) { $this->bindValue($key + 1, $val); } else { $this->bindValue($key, $val); @@ -505,6 +522,6 @@ public function fetchColumn($columnIndex = 0) */ public function rowCount() { - return oci_num_rows($this->_sth); + return oci_num_rows($this->_sth) ?: 0; } } diff --git a/lib/Doctrine/DBAL/Driver/PDOConnection.php b/lib/Doctrine/DBAL/Driver/PDOConnection.php index 2155140b2a8..11f5febc87b 100644 --- a/lib/Doctrine/DBAL/Driver/PDOConnection.php +++ b/lib/Doctrine/DBAL/Driver/PDOConnection.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\ParameterType; use PDO; -use function count; +use function assert; use function func_get_args; /** @@ -69,23 +69,13 @@ public function prepare($prepareString, $driverOptions = []) */ public function query() { - $args = func_get_args(); - $argsCount = count($args); + $args = func_get_args(); try { - if ($argsCount === 4) { - return parent::query($args[0], $args[1], $args[2], $args[3]); - } + $stmt = parent::query(...$args); + assert($stmt instanceof \PDOStatement); - if ($argsCount === 3) { - return parent::query($args[0], $args[1], $args[2]); - } - - if ($argsCount === 2) { - return parent::query($args[0], $args[1]); - } - - return parent::query($args[0]); + return $stmt; } catch (\PDOException $exception) { throw new PDOException($exception); } diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php index 6543e32392e..8bc8671620f 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php @@ -16,13 +16,21 @@ class Driver extends AbstractSQLServerDriver */ public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { - [$driverOptions, $connectionOptions] = $this->splitOptions($driverOptions); + $pdoOptions = $dsnOptions = []; + + foreach ($driverOptions as $option => $value) { + if (is_int($option)) { + $pdoOptions[$option] = $value; + } else { + $dsnOptions[$option] = $value; + } + } return new Connection( - $this->_constructPdoDsn($params, $connectionOptions), + $this->_constructPdoDsn($params, $dsnOptions), $username, $password, - $driverOptions + $pdoOptions ); } @@ -57,29 +65,6 @@ private function _constructPdoDsn(array $params, array $connectionOptions) return $dsn . $this->getConnectionOptionsDsn($connectionOptions); } - /** - * Separates a connection options from a driver options - * - * @param int[]|string[] $options - * - * @return int[][]|string[][] - */ - private function splitOptions(array $options) : array - { - $driverOptions = []; - $connectionOptions = []; - - foreach ($options as $optionKey => $optionValue) { - if (is_int($optionKey)) { - $driverOptions[$optionKey] = $optionValue; - } else { - $connectionOptions[$optionKey] = $optionValue; - } - } - - return [$driverOptions, $connectionOptions]; - } - /** * Converts a connection options array to the DSN * diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index 2aed89fbf07..f734659c2b7 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -6,6 +6,8 @@ use Doctrine\DBAL\ParameterType; use PDO; use const E_USER_DEPRECATED; +use function assert; +use function is_array; use function sprintf; use function trigger_error; @@ -153,20 +155,21 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n { $fetchMode = $this->convertFetchMode($fetchMode); - try { - if ($fetchMode === null && $fetchArgument === null && $ctorArgs === null) { - return parent::fetchAll(); - } - - if ($fetchArgument === null && $ctorArgs === null) { - return parent::fetchAll($fetchMode); - } + if ($fetchMode === null && $fetchArgument === null && $ctorArgs === null) { + $args = []; + } elseif ($fetchArgument === null && $ctorArgs === null) { + $args = [$fetchMode]; + } elseif ($ctorArgs === null) { + $args = [$fetchMode, $fetchArgument]; + } else { + $args = [$fetchMode, $fetchArgument, $ctorArgs]; + } - if ($ctorArgs === null) { - return parent::fetchAll($fetchMode, $fetchArgument); - } + try { + $data = parent::fetchAll(...$args); + assert(is_array($data)); - return parent::fetchAll($fetchMode, $fetchArgument, $ctorArgs); + return $data; } catch (\PDOException $exception) { throw new PDOException($exception); } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 6354836a478..886bb245873 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -17,7 +17,7 @@ use function func_num_args; use function gettype; use function is_array; -use function is_numeric; +use function is_int; use function is_object; use function is_resource; use function is_string; @@ -177,9 +177,11 @@ public function execute($params = null) $hasZeroIndex = array_key_exists(0, $params); foreach ($params as $key => $val) { - $key = $hasZeroIndex && is_numeric($key) ? $key + 1 : $key; - - $this->bindValue($key, $val); + if ($hasZeroIndex && is_int($key)) { + $this->bindValue($key + 1, $val); + } else { + $this->bindValue($key, $val); + } } } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index f1f9ddd1d79..dbda962006a 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -44,10 +44,13 @@ public function __construct($serverName, $connectionOptions) throw SQLSrvException::fromSqlSrvErrors(); } - $this->conn = sqlsrv_connect($serverName, $connectionOptions); - if (! $this->conn) { + $conn = sqlsrv_connect($serverName, $connectionOptions); + + if ($conn === false) { throw SQLSrvException::fromSqlSrvErrors(); } + + $this->conn = $conn; $this->lastInsertId = new LastInsertId(); } @@ -115,7 +118,13 @@ public function exec($statement) throw SQLSrvException::fromSqlSrvErrors(); } - return sqlsrv_rows_affected($stmt); + $rowsAffected = sqlsrv_rows_affected($stmt); + + if ($rowsAffected === false) { + throw SQLSrvException::fromSqlSrvErrors(); + } + + return $rowsAffected; } /** diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index 147ef76e1a0..49ca2567845 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -18,6 +18,7 @@ use function count; use function func_get_args; use function in_array; +use function is_int; use function is_numeric; use function sqlsrv_errors; use function sqlsrv_execute; @@ -200,7 +201,11 @@ public function closeCursor() */ public function columnCount() { - return sqlsrv_num_fields($this->stmt); + if ($this->stmt === null) { + return 0; + } + + return sqlsrv_num_fields($this->stmt) ?: 0; } /** @@ -231,9 +236,13 @@ public function execute($params = null) { if ($params) { $hasZeroIndex = array_key_exists(0, $params); + foreach ($params as $key => $val) { - $key = $hasZeroIndex && is_numeric($key) ? $key + 1 : $key; - $this->bindValue($key, $val); + if ($hasZeroIndex && is_int($key)) { + $this->bindValue($key + 1, $val); + } else { + $this->bindValue($key, $val); + } } } @@ -406,6 +415,10 @@ public function fetchColumn($columnIndex = 0) */ public function rowCount() { - return sqlsrv_rows_affected($this->stmt); + if ($this->stmt === null) { + return 0; + } + + return sqlsrv_rows_affected($this->stmt) ?: 0; } } diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 658123199c0..cb9db2c0221 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -18,8 +18,10 @@ use function array_keys; use function array_map; use function array_merge; +use function assert; use function class_implements; use function in_array; +use function is_string; use function is_subclass_of; use function parse_str; use function parse_url; @@ -263,6 +265,8 @@ private static function parseDatabaseUrl(array $params) : array // (pdo_)?sqlite3?:///... => (pdo_)?sqlite3?://localhost/... or else the URL will be invalid $url = preg_replace('#^((?:pdo_)?sqlite3?):///#', '$1://localhost/', $params['url']); + assert(is_string($url)); + $url = parse_url($url); if ($url === false) { @@ -414,6 +418,7 @@ private static function parseDatabaseUrlScheme(array $url, array $params) : arra // URL schemes must not contain underscores, but dashes are ok $driver = str_replace('-', '_', $url['scheme']); + assert(is_string($driver)); // The requested driver from the URL scheme takes precedence over the // default driver from the connection parameters. If the driver is diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 68994846864..439f6f541d2 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -864,9 +864,9 @@ public function getLowerExpression($str) /** * Returns the SQL snippet to get the position of the first occurrence of substring $substr in string $str. * - * @param string $str Literal string. - * @param string $substr Literal string to find. - * @param int|bool $startPos Position to start at, beginning of string by default. + * @param string $str Literal string. + * @param string $substr Literal string to find. + * @param int|false $startPos Position to start at, beginning of string by default. * * @return string * @@ -1832,6 +1832,10 @@ protected function getCreateIndexSQLFlags(Index $index) */ public function getCreatePrimaryKeySQL(Index $index, $table) { + if ($table instanceof Table) { + $table = $table->getQuotedName($this); + } + return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index) . ')'; } @@ -2066,11 +2070,14 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) */ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) { - $tableName = $diff->newName !== false - ? $diff->getNewName()->getQuotedName($this) - : $diff->getName($this)->getQuotedName($this); + $sql = []; + $newName = $diff->getNewName(); - $sql = []; + if ($newName !== false) { + $tableName = $newName->getQuotedName($this); + } else { + $tableName = $diff->getName($this)->getQuotedName($this); + } if ($this->supportsForeignKeyConstraints()) { foreach ($diff->addedForeignKeys as $foreignKey) { diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index 605122115d4..bfe2790e30c 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -599,8 +599,14 @@ public function getAlterTableSQL(TableDiff $diff) $sql = array_merge($sql, $commentsSQL); - if ($diff->newName !== false) { - $sql[] = 'RENAME TABLE ' . $diff->getName($this)->getQuotedName($this) . ' TO ' . $diff->getNewName()->getQuotedName($this); + $newName = $diff->getNewName(); + + if ($newName !== false) { + $sql[] = sprintf( + 'RENAME TABLE %s TO %s', + $diff->getName($this)->getQuotedName($this), + $newName->getQuotedName($this) + ); } $sql = array_merge( diff --git a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php index 27aacf42286..bb5b5cad36d 100644 --- a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php @@ -480,8 +480,10 @@ public function getAlterTableSQL(TableDiff $diff) $columnSql = []; $queryParts = []; - if ($diff->newName !== false) { - $queryParts[] = 'RENAME TO ' . $diff->getNewName()->getQuotedName($this); + $newName = $diff->getNewName(); + + if ($newName !== false) { + $queryParts[] = 'RENAME TO ' . $newName->getQuotedName($this); } foreach ($diff->addedColumns as $column) { diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 289dca9e7d7..9679a8447e7 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -553,8 +553,10 @@ public function getAlterTableSQL(TableDiff $diff) { $columnSql = []; $queryParts = []; - if ($diff->newName !== false) { - $queryParts[] = 'RENAME TO ' . $diff->getNewName()->getQuotedName($this); + $newName = $diff->getNewName(); + + if ($newName !== false) { + $queryParts[] = 'RENAME TO ' . $newName->getQuotedName($this); } foreach ($diff->addedColumns as $column) { @@ -855,10 +857,14 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) */ protected function getPostAlterTableRenameIndexForeignKeySQL(TableDiff $diff) { - $sql = []; - $tableName = $diff->newName !== false - ? $diff->getNewName()->getQuotedName($this) - : $diff->getName($this)->getQuotedName($this); + $sql = []; + $newName = $diff->getNewName(); + + if ($newName !== false) { + $tableName = $newName->getQuotedName($this); + } else { + $tableName = $diff->getName($this)->getQuotedName($this); + } foreach ($this->getRemainingForeignKeyConstraintsRequiringRenamedIndexes($diff) as $foreignKey) { if (in_array($foreignKey, $diff->changedForeignKeys, true)) { diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 537a566bada..711fbccbd53 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -869,8 +869,14 @@ public function getAlterTableSQL(TableDiff $diff) if (! $this->onSchemaAlterTable($diff, $tableSql)) { $sql = array_merge($sql, $commentsSQL); - if ($diff->newName !== false) { - $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' RENAME TO ' . $diff->getNewName()->getQuotedName($this); + $newName = $diff->getNewName(); + + if ($newName !== false) { + $sql[] = sprintf( + 'ALTER TABLE %s RENAME TO %s', + $diff->getName($this)->getQuotedName($this), + $newName->getQuotedName($this) + ); } $sql = array_merge( diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 3c9984f95e6..806d59e6c97 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -614,8 +614,14 @@ public function getAlterTableSQL(TableDiff $diff) if (! $this->onSchemaAlterTable($diff, $tableSql)) { $sql = array_merge($sql, $commentsSQL); - if ($diff->newName !== false) { - $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' RENAME TO ' . $diff->getNewName()->getQuotedName($this); + $newName = $diff->getNewName(); + + if ($newName !== false) { + $sql[] = sprintf( + 'ALTER TABLE %s RENAME TO %s', + $diff->getName($this)->getQuotedName($this), + $newName->getQuotedName($this) + ); } $sql = array_merge( diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index ec3ef933441..0f097de601b 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -184,9 +184,11 @@ public function getAlterTableSQL(TableDiff $diff) $sql = array_merge($sql, $commentsSQL); - if ($diff->newName !== false) { + $newName = $diff->getNewName(); + + if ($newName !== false) { $sql[] = $this->getAlterTableClause($diff->getName($this)) . ' ' . - $this->getAlterTableRenameTableClause($diff->getNewName()); + $this->getAlterTableRenameTableClause($newName); } $sql = array_merge( diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index dc8775e61ab..5ce17aae36b 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -315,12 +315,19 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options */ public function getCreatePrimaryKeySQL(Index $index, $table) { - $flags = ''; + if ($table instanceof Table) { + $identifier = $table->getQuotedName($this); + } else { + $identifier = $table; + } + + $sql = 'ALTER TABLE ' . $identifier . ' ADD PRIMARY KEY'; + if ($index->hasFlag('nonclustered')) { - $flags = ' NONCLUSTERED'; + $sql .= ' NONCLUSTERED'; } - return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY' . $flags . ' (' . $this->getIndexFieldDeclarationListSQL($index) . ')'; + return $sql . ' (' . $this->getIndexFieldDeclarationListSQL($index) . ')'; } /** @@ -584,8 +591,10 @@ public function getAlterTableSQL(TableDiff $diff) $sql = array_merge($sql, $commentsSql); - if ($diff->newName !== false) { - $sql[] = "sp_RENAME '" . $diff->getName($this)->getQuotedName($this) . "', '" . $diff->getNewName()->getName() . "'"; + $newName = $diff->getNewName(); + + if ($newName !== false) { + $sql[] = "sp_RENAME '" . $diff->getName($this)->getQuotedName($this) . "', '" . $newName->getName() . "'"; /** * Rename table's default constraints names @@ -598,10 +607,10 @@ public function getAlterTableSQL(TableDiff $diff) $sql[] = "DECLARE @sql NVARCHAR(MAX) = N''; " . "SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', N''' " . "+ REPLACE(dc.name, '" . $this->generateIdentifierName($diff->name) . "', " . - "'" . $this->generateIdentifierName($diff->newName) . "') + ''', ''OBJECT'';' " . + "'" . $this->generateIdentifierName($newName->getName()) . "') + ''', ''OBJECT'';' " . 'FROM sys.default_constraints dc ' . 'JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id ' . - "WHERE tbl.name = '" . $diff->getNewName()->getName() . "';" . + "WHERE tbl.name = '" . $newName->getName() . "';" . 'EXEC sp_executesql @sql'; } diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 6eff6b88d79..009a8f23df4 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -685,7 +685,12 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) } $sql = []; - $tableName = $diff->newName ? $diff->getNewName(): $diff->getName($this); + $tableName = $diff->getNewName(); + + if ($tableName === false) { + $tableName = $diff->getName($this); + } + foreach ($this->getIndexesInAlteredTable($diff) as $index) { if ($index->isPrimary()) { continue; @@ -908,9 +913,14 @@ public function getAlterTableSQL(TableDiff $diff) $sql[] = sprintf('INSERT INTO %s (%s) SELECT %s FROM %s', $newTable->getQuotedName($this), implode(', ', $newColumnNames), implode(', ', $oldColumnNames), $dataTable->getQuotedName($this)); $sql[] = $this->getDropTableSQL($dataTable); - if ($diff->newName && $diff->newName !== $diff->name) { - $renamedTable = $diff->getNewName(); - $sql[] = 'ALTER TABLE ' . $newTable->getQuotedName($this) . ' RENAME TO ' . $renamedTable->getQuotedName($this); + $newName = $diff->getNewName(); + + if ($newName !== false) { + $sql[] = sprintf( + 'ALTER TABLE %s RENAME TO %s', + $newTable->getQuotedName($this), + $newName->getQuotedName($this) + ); } $sql = array_merge($sql, $this->getPostAlterTableIndexForeignKeySQL($diff)); @@ -1028,7 +1038,8 @@ private function getColumnNamesInAlteredTable(TableDiff $diff) $columns[strtolower($columnName)] = $columnName; } - foreach ($diff->addedColumns as $columnName => $column) { + foreach ($diff->addedColumns as $column) { + $columnName = $column->getName(); $columns[strtolower($columnName)] = $columnName; } @@ -1127,6 +1138,10 @@ private function getForeignKeysInAlteredTable(TableDiff $diff) } foreach ($diff->removedForeignKeys as $constraint) { + if (! $constraint instanceof ForeignKeyConstraint) { + $constraint = new Identifier($constraint); + } + $constraintName = strtolower($constraint->getName()); if (! strlen($constraintName) || ! isset($foreignKeys[$constraintName])) { continue; diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 7dc63884a51..0ff0456a00e 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -24,8 +24,13 @@ */ class SQLParserUtils { + /**#@+ + * + * @deprecated Will be removed as internal implementation details. + */ public const POSITIONAL_TOKEN = '\?'; public const NAMED_TOKEN = '(? $needlePos) { if (! isset($arrayPositions[$needle])) { continue; @@ -156,6 +200,8 @@ public static function expandListParameters($query, $params, $types) $typesOrd = []; $paramsOrd = []; + $paramPos = self::getNamedPlaceholderPositions($query); + foreach ($paramPos as $pos => $paramName) { $paramLen = strlen($paramName) + 1; $value = static::extractParam($paramName, $params, true); diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index bf278e6e78a..d1db70c4c25 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -14,10 +14,12 @@ use function array_intersect; use function array_map; use function array_values; +use function assert; use function call_user_func_array; use function count; use function func_get_args; use function is_array; +use function is_callable; use function preg_match; use function str_replace; use function strtolower; @@ -80,8 +82,11 @@ public function tryMethod() unset($args[0]); $args = array_values($args); + $callback = [$this, $method]; + assert(is_callable($callback)); + try { - return call_user_func_array([$this, $method], $args); + return call_user_func_array($callback, $args); } catch (Throwable $e) { return false; } diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index 1d8a7275d98..585732d7dff 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -10,6 +10,7 @@ use function array_merge; use function array_shift; use function array_unique; +use function assert; use function count; use function strtolower; @@ -108,6 +109,8 @@ public function compare(Schema $fromSchema, Schema $toSchema) } foreach ($diff->changedTables[$localTableName]->removedForeignKeys as $key => $removedForeignKey) { + assert($removedForeignKey instanceof ForeignKeyConstraint); + // We check if the key is from the removed table if not we skip. if ($tableName !== strtolower($removedForeignKey->getForeignTableName())) { continue; diff --git a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php index 31850d7f23e..0a0977a4027 100644 --- a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php +++ b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php @@ -3,14 +3,13 @@ namespace Doctrine\DBAL\Schema; use Doctrine\DBAL\Platforms\AbstractPlatform; -use function array_combine; use function array_keys; use function array_map; -use function end; -use function explode; use function in_array; +use function strrpos; use function strtolower; use function strtoupper; +use function substr; /** * An abstraction class for a foreign key constraint. @@ -66,12 +65,8 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint public function __construct(array $localColumnNames, $foreignTableName, array $foreignColumnNames, $name = null, array $options = []) { $this->_setName($name); - $identifierConstructorCallback = static function ($column) { - return new Identifier($column); - }; - $this->_localColumnNames = $localColumnNames - ? array_combine($localColumnNames, array_map($identifierConstructorCallback, $localColumnNames)) - : []; + + $this->_localColumnNames = $this->createIdentifierMap($localColumnNames); if ($foreignTableName instanceof Table) { $this->_foreignTableName = $foreignTableName; @@ -79,12 +74,26 @@ public function __construct(array $localColumnNames, $foreignTableName, array $f $this->_foreignTableName = new Identifier($foreignTableName); } - $this->_foreignColumnNames = $foreignColumnNames - ? array_combine($foreignColumnNames, array_map($identifierConstructorCallback, $foreignColumnNames)) - : []; + $this->_foreignColumnNames = $this->createIdentifierMap($foreignColumnNames); $this->_options = $options; } + /** + * @param string[] $names + * + * @return Identifier[] + */ + private function createIdentifierMap(array $names) : array + { + $identifiers = []; + + foreach ($names as $name) { + $identifiers[$name] = new Identifier($name); + } + + return $identifiers; + } + /** * Returns the name of the referencing table * the foreign key constraint is associated with. @@ -218,9 +227,14 @@ public function getForeignTableName() */ public function getUnqualifiedForeignTableName() { - $parts = explode('.', $this->_foreignTableName->getName()); + $name = $this->_foreignTableName->getName(); + $position = strrpos($name, '.'); + + if ($position !== false) { + $name = substr($name, $position); + } - return strtolower(end($parts)); + return strtolower($name); } /** diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 9f50517e1d4..f442f54d116 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -9,8 +9,10 @@ use function array_change_key_case; use function array_shift; use function array_values; +use function assert; use function end; use function explode; +use function is_string; use function preg_match; use function preg_replace; use function str_replace; @@ -101,6 +103,8 @@ protected function _getPortableTableColumnDefinition($tableColumn) $dbType = strtolower($tableColumn['type']); $dbType = strtok($dbType, '(), '); + assert(is_string($dbType)); + $length = $tableColumn['length'] ?? strtok('(), '); $fixed = null; diff --git a/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php index 62d5fa88e89..c169a6e0708 100644 --- a/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Platforms\SQLAnywherePlatform; use Doctrine\DBAL\Types\Type; use function assert; +use function is_string; use function preg_replace; /** @@ -222,9 +223,9 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName = nu */ protected function _getPortableViewDefinition($view) { - return new View( - $view['table_name'], - preg_replace('/^.*\s+as\s+SELECT(.*)/i', 'SELECT$1', $view['view_def']) - ); + $definition = preg_replace('/^.*\s+as\s+SELECT(.*)/i', 'SELECT$1', $view['view_def']); + assert(is_string($definition)); + + return new View($view['table_name'], $definition); } } diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index 763074e7d27..ce3e403ae77 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -6,9 +6,11 @@ use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Types\Type; use PDOException; +use function assert; use function count; use function in_array; -use function preg_replace; +use function is_string; +use function preg_match; use function sprintf; use function str_replace; use function strpos; @@ -61,7 +63,9 @@ protected function _getPortableSequenceDefinition($sequence) */ protected function _getPortableTableColumnDefinition($tableColumn) { - $dbType = strtok($tableColumn['type'], '(), '); + $dbType = strtok($tableColumn['type'], '(), '); + assert(is_string($dbType)); + $fixed = null; $length = (int) $tableColumn['length']; $default = $tableColumn['default']; @@ -71,15 +75,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) } if ($default !== null) { - while ($default !== ($default2 = preg_replace('/^\((.*)\)$/', '$1', $default))) { - $default = trim($default2, "'"); - - if ($default !== 'getdate()') { - continue; - } - - $default = $this->_platform->getCurrentTimestampSQL(); - } + $default = $this->parseDefaultExpression($default); } switch ($dbType) { @@ -126,6 +122,19 @@ protected function _getPortableTableColumnDefinition($tableColumn) return $column; } + private function parseDefaultExpression(string $value) : string + { + while (preg_match('/^\((.*)\)$/', $value, $matches)) { + $value = trim($matches[1], "'"); + } + + if ($value === 'getdate()') { + return $this->_platform->getCurrentTimestampSQL(); + } + + return $value; + } + /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 09ae27f0590..5659e578636 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -18,9 +18,6 @@ */ class Table extends AbstractAsset { - /** @var string */ - protected $_name = null; - /** @var Column[] */ protected $_columns = []; @@ -98,8 +95,8 @@ protected function _getMaxIdentifierLength() /** * Sets the Primary Key. * - * @param string[] $columnNames - * @param string|bool $indexName + * @param string[] $columnNames + * @param string|false $indexName * * @return self */ diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index 0e815663786..22bce134061 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -13,6 +13,7 @@ use Symfony\Component\Console\Output\OutputInterface; use const PHP_EOL; use function assert; +use function error_get_last; use function file_exists; use function file_get_contents; use function is_readable; @@ -79,7 +80,13 @@ protected function execute(InputInterface $input, OutputInterface $output) } $output->write(sprintf("Processing file '%s'... ", $filePath)); - $sql = file_get_contents($filePath); + $sql = @file_get_contents($filePath); + + if ($sql === false) { + throw new RuntimeException( + sprintf("Unable to read SQL file '%s': %s", $filePath, error_get_last()['message']) + ); + } if ($conn instanceof PDOConnection) { // PDO Drivers diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php index 8361219ad08..8aeb0ea2fba 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php @@ -10,7 +10,9 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use function assert; use function is_numeric; +use function is_string; use function stripos; /** @@ -51,6 +53,8 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new RuntimeException("Argument 'SQL' is required in order to execute this command correctly."); } + assert(is_string($sql)); + $depth = $input->getOption('depth'); if (! is_numeric($depth)) { diff --git a/lib/Doctrine/DBAL/Tools/Dumper.php b/lib/Doctrine/DBAL/Tools/Dumper.php index d5086adee81..6174b7ad865 100644 --- a/lib/Doctrine/DBAL/Tools/Dumper.php +++ b/lib/Doctrine/DBAL/Tools/Dumper.php @@ -9,6 +9,7 @@ use Doctrine\Common\Persistence\Proxy; use stdClass; use function array_keys; +use function assert; use function class_exists; use function count; use function end; @@ -20,9 +21,11 @@ use function ini_set; use function is_array; use function is_object; +use function is_string; use function ob_get_clean; use function ob_start; use function strip_tags; +use function strlen; use function strrpos; use function substr; use function var_dump; @@ -68,7 +71,9 @@ public static function dump($var, int $maxDepth = 2) : string var_dump($var); try { - return strip_tags(html_entity_decode(ob_get_clean())); + $output = ob_get_clean(); + assert(is_string($output)); + return strip_tags(html_entity_decode($output)); } finally { ini_set('html_errors', $html); } @@ -171,6 +176,6 @@ private static function getClass($object) : string return $class; } - return substr($class, $pos + Proxy::MARKER_LENGTH + 2); + return substr($class, $pos + strlen(Proxy::MARKER) + 2); } } diff --git a/lib/Doctrine/DBAL/Types/BinaryType.php b/lib/Doctrine/DBAL/Types/BinaryType.php index 14362e840ae..2894f8c864d 100644 --- a/lib/Doctrine/DBAL/Types/BinaryType.php +++ b/lib/Doctrine/DBAL/Types/BinaryType.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; +use function assert; use function fopen; use function fseek; use function fwrite; @@ -34,6 +35,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) if (is_string($value)) { $fp = fopen('php://temp', 'rb+'); + assert(is_resource($fp)); fwrite($fp, $value); fseek($fp, 0); $value = $fp; diff --git a/lib/Doctrine/DBAL/Types/BlobType.php b/lib/Doctrine/DBAL/Types/BlobType.php index c309f0f0637..c9c8d88ec1c 100644 --- a/lib/Doctrine/DBAL/Types/BlobType.php +++ b/lib/Doctrine/DBAL/Types/BlobType.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; +use function assert; use function fopen; use function fseek; use function fwrite; @@ -34,6 +35,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) if (is_string($value)) { $fp = fopen('php://temp', 'rb+'); + assert(is_resource($fp)); fwrite($fp, $value); fseek($fp, 0); $value = $fp; diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index ec1ab681356..025eb14cbda 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -5,9 +5,9 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; -use function end; -use function explode; use function str_replace; +use function strrpos; +use function substr; /** * The base class for so-called Doctrine mapping types. @@ -255,9 +255,14 @@ public static function getTypesMap() */ public function __toString() { - $e = explode('\\', static::class); + $type = static::class; + $position = strrpos($type, '\\'); - return str_replace('Type', '', end($e)); + if ($position !== false) { + $type = substr($type, $position); + } + + return str_replace('Type', '', $type); } /** diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 4bedf0cd776..22f53630b64 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 5 + level: 6 paths: - %currentWorkingDirectory%/lib autoload_files: @@ -29,6 +29,10 @@ parameters: # https://github.com/JetBrains/phpstorm-stubs/pull/488 - '~^Parameter #1 \$byteCount of function SQLSRV_SQLTYPE_VARBINARY expects int, string given\.\z~' + # https://github.com/phpstan/phpstan/issues/1847 + - '~^Parameter #2 \$registeredAliases of static method Doctrine\\DBAL\\Query\\QueryException::unknownAlias\(\) expects array, array given\.\z~' + - '~^Parameter #2 \$registeredAliases of static method Doctrine\\DBAL\\Query\\QueryException::nonUniqueAlias\(\) expects array, array given\.\z~' + # legacy variadic-like signature - '~^Method Doctrine\\DBAL\\Driver\\Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~' From 0a165b465ddbc4312be469e8a6b762877a61c87a Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 3 Feb 2019 09:12:37 -0800 Subject: [PATCH 030/106] Replaced custom docker image for PostgreSQL with the official one See https://travis-ci.org/doctrine/dbal/jobs/488051004 for the dependency issue. --- tests/travis/Dockerfile-postgres11 | 15 --------------- tests/travis/install-postgres-11.sh | 6 ++---- 2 files changed, 2 insertions(+), 19 deletions(-) delete mode 100644 tests/travis/Dockerfile-postgres11 diff --git a/tests/travis/Dockerfile-postgres11 b/tests/travis/Dockerfile-postgres11 deleted file mode 100644 index 039a84a6cfd..00000000000 --- a/tests/travis/Dockerfile-postgres11 +++ /dev/null @@ -1,15 +0,0 @@ -FROM debian:experimental-20180426 - -RUN apt-get update && \ - apt-get install -y -t experimental --no-install-recommends \ - postgresql-11 \ - postgresql-client-11 \ - && \ - rm -rf /var/lib/apt/lists/* - -RUN echo "host all all all trust" >> /etc/postgresql/11/main/pg_hba.conf -RUN echo "listen_addresses='*'" >> /etc/postgresql/11/main/conf.d/listen.conf - -EXPOSE 5432 - -CMD ["sleep", "inf"] diff --git a/tests/travis/install-postgres-11.sh b/tests/travis/install-postgres-11.sh index 9137a55001b..2ef1aabc4f0 100644 --- a/tests/travis/install-postgres-11.sh +++ b/tests/travis/install-postgres-11.sh @@ -6,9 +6,7 @@ echo "Preparing Postgres 11" sudo service postgresql stop || true -sudo docker build -t postgres11 - < tests/travis/Dockerfile-postgres11 -sudo docker run -d --name postgres11 -p 5432:5432 postgres11 -sudo docker exec postgres11 service postgresql start -sudo docker exec -i postgres11 su -c psql postgres <<<"create database doctrine_tests" +sudo docker run -d --name postgres11 -p 5432:5432 postgres:11.1 +sudo docker exec -i postgres11 bash <<< 'until pg_isready -U postgres > /dev/null 2>&1 ; do sleep 1; done' echo "Postgres 11 ready" From 53912cc066906c481f93957c4c2ea0239f28fea4 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 1 Feb 2019 11:53:26 -0800 Subject: [PATCH 031/106] Upgraded PHPUnit to 8.0 --- .gitignore | 1 + composer.json | 2 +- composer.lock | 169 +++++++++----- .../DBAL/Cache/QueryCacheProfileTest.php | 4 +- .../Doctrine/Tests/DBAL/ConfigurationTest.php | 2 +- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 25 +- .../Doctrine/Tests/DBAL/DBALExceptionTest.php | 4 +- .../Tests/DBAL/Driver/AbstractDriverTest.php | 14 +- .../DBAL/Driver/IBMDB2/DB2ConnectionTest.php | 6 +- .../Driver/Mysqli/MysqliConnectionTest.php | 6 +- .../DBAL/Driver/OCI8/OCI8ConnectionTest.php | 6 +- .../DBAL/Driver/OCI8/OCI8StatementTest.php | 4 +- .../Tests/DBAL/Driver/PDOExceptionTest.php | 6 +- .../SQLAnywhere/SQLAnywhereConnectionTest.php | 6 +- .../Driver/SQLSrv/SQLSrvConnectionTest.php | 6 +- .../Doctrine/Tests/DBAL/DriverManagerTest.php | 12 +- .../Tests/DBAL/Functional/BlobTest.php | 4 +- .../Tests/DBAL/Functional/ConnectionTest.php | 4 +- .../Tests/DBAL/Functional/DataAccessTest.php | 29 +-- .../Functional/Driver/AbstractDriverTest.php | 2 +- .../Driver/IBMDB2/DB2DriverTest.php | 2 +- .../Driver/IBMDB2/DB2StatementTest.php | 2 +- .../Driver/Mysqli/ConnectionTest.php | 10 +- .../Functional/Driver/Mysqli/DriverTest.php | 2 +- .../Functional/Driver/OCI8/DriverTest.php | 2 +- .../Driver/OCI8/OCI8ConnectionTest.php | 2 +- .../Functional/Driver/OCI8/StatementTest.php | 2 +- .../Functional/Driver/PDOConnectionTest.php | 23 +- .../Functional/Driver/PDOMySql/DriverTest.php | 2 +- .../Driver/PDOOracle/DriverTest.php | 2 +- .../Functional/Driver/PDOPgSql/DriverTest.php | 2 +- .../Driver/PDOPgsqlConnectionTest.php | 2 +- .../Driver/PDOSqlite/DriverTest.php | 2 +- .../Driver/PDOSqlsrv/DriverTest.php | 2 +- .../Driver/SQLAnywhere/ConnectionTest.php | 2 +- .../Driver/SQLAnywhere/DriverTest.php | 4 +- .../Driver/SQLAnywhere/StatementTest.php | 2 +- .../Functional/Driver/SQLSrv/DriverTest.php | 2 +- .../Driver/SQLSrv/StatementTest.php | 2 +- .../Tests/DBAL/Functional/ExceptionTest.php | 2 +- .../Functional/MasterSlaveConnectionTest.php | 2 +- .../DBAL/Functional/ModifyLimitQueryTest.php | 2 +- .../DBAL/Functional/NamedParametersTest.php | 2 +- .../DBAL/Functional/PDOStatementTest.php | 2 +- ...imaryKeyWithNewAutoIncrementColumnTest.php | 2 +- .../Tests/DBAL/Functional/PortabilityTest.php | 2 +- .../Tests/DBAL/Functional/ResultCacheTest.php | 4 +- .../DBAL/Functional/Schema/ComparatorTest.php | 2 +- .../Schema/MySqlSchemaManagerTest.php | 2 +- .../Schema/OracleSchemaManagerTest.php | 2 +- .../Schema/PostgreSqlSchemaManagerTest.php | 4 +- .../Schema/SQLAnywhereSchemaManagerTest.php | 2 +- .../SchemaManagerFunctionalTestCase.php | 28 +-- .../Schema/SqliteSchemaManagerTest.php | 5 +- .../Tests/DBAL/Functional/StatementTest.php | 6 +- .../DBAL/Functional/TableGeneratorTest.php | 2 +- .../DBAL/Functional/TemporaryTableTest.php | 4 +- .../DBAL/Functional/Ticket/DBAL202Test.php | 2 +- .../DBAL/Functional/Ticket/DBAL421Test.php | 2 +- .../DBAL/Functional/Ticket/DBAL510Test.php | 2 +- .../DBAL/Functional/Ticket/DBAL630Test.php | 4 +- .../DBAL/Functional/Ticket/DBAL752Test.php | 2 +- .../DBAL/Functional/TypeConversionTest.php | 217 ++++++++++++++---- .../DBAL/Functional/Types/BinaryTest.php | 2 +- .../Tests/DBAL/Functional/WriteTest.php | 2 +- .../Tests/DBAL/Logging/DebugStackTest.php | 4 +- .../AbstractMySQLPlatformTestCase.php | 45 +++- .../Platforms/AbstractPlatformTestCase.php | 25 +- .../AbstractPostgreSqlPlatformTestCase.php | 58 ++--- .../AbstractSQLServerPlatformTestCase.php | 38 +-- .../Tests/DBAL/Platforms/DB2PlatformTest.php | 15 +- .../DBAL/Platforms/OraclePlatformTest.php | 42 ++-- .../ReservedKeywordsValidatorTest.php | 2 +- .../Platforms/SQLAnywherePlatformTest.php | 36 ++- .../DBAL/Platforms/SQLAzurePlatformTest.php | 2 +- .../DBAL/Platforms/SqlitePlatformTest.php | 30 ++- .../Tests/DBAL/Portability/StatementTest.php | 20 +- .../Expression/ExpressionBuilderTest.php | 2 +- .../Tests/DBAL/Query/QueryBuilderTest.php | 2 +- .../DBAL/Schema/DB2SchemaManagerTest.php | 8 +- .../DBAL/Schema/MySqlSchemaManagerTest.php | 2 +- .../DBAL/Schema/Platforms/MySQLSchemaTest.php | 2 +- .../Doctrine/Tests/DBAL/Schema/SchemaTest.php | 11 +- .../SingleDatabaseSynchronizerTest.php | 2 +- .../Doctrine/Tests/DBAL/Schema/TableTest.php | 6 +- .../Visitor/CreateSchemaSqlCollectorTest.php | 12 +- .../Sharding/SQLAzure/AbstractTestCase.php | 2 +- tests/Doctrine/Tests/DBAL/StatementTest.php | 9 +- .../DBAL/Tools/Console/RunSqlCommandTest.php | 6 +- tests/Doctrine/Tests/DBAL/Types/ArrayTest.php | 12 +- .../Tests/DBAL/Types/BaseDateTypeTestCase.php | 11 +- .../Doctrine/Tests/DBAL/Types/BinaryTest.php | 8 +- tests/Doctrine/Tests/DBAL/Types/BlobTest.php | 4 +- .../Doctrine/Tests/DBAL/Types/BooleanTest.php | 6 +- .../DBAL/Types/DateImmutableTypeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 2 +- .../DBAL/Types/DateTimeImmutableTypeTest.php | 2 +- .../Tests/DBAL/Types/DateTimeTest.php | 2 +- .../Types/DateTimeTzImmutableTypeTest.php | 2 +- .../Tests/DBAL/Types/DateTimeTzTest.php | 2 +- .../Doctrine/Tests/DBAL/Types/DecimalTest.php | 4 +- tests/Doctrine/Tests/DBAL/Types/FloatTest.php | 6 +- .../Tests/DBAL/Types/GuidTypeTest.php | 6 +- .../Doctrine/Tests/DBAL/Types/IntegerTest.php | 6 +- .../Tests/DBAL/Types/JsonArrayTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/JsonTest.php | 2 +- .../Doctrine/Tests/DBAL/Types/ObjectTest.php | 6 +- .../Tests/DBAL/Types/SmallIntTest.php | 6 +- .../Doctrine/Tests/DBAL/Types/StringTest.php | 6 +- .../DBAL/Types/TimeImmutableTypeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 2 +- .../Types/VarDateTimeImmutableTypeTest.php | 2 +- .../Tests/DBAL/Types/VarDateTimeTest.php | 2 +- .../Doctrine/Tests/DbalFunctionalTestCase.php | 6 +- .../Tests/DbalPerformanceTestCase.php | 2 +- 115 files changed, 722 insertions(+), 461 deletions(-) diff --git a/.gitignore b/.gitignore index 8b9a3da4a22..aa1b09adbc1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.phpunit.result.cache build/ logs/ reports/ diff --git a/composer.json b/composer.json index df888004dce..4e5631af098 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "doctrine/coding-standard": "^5.0", "jetbrains/phpstorm-stubs": "^2018.1.2", "phpstan/phpstan": "^0.11.1", - "phpunit/phpunit": "^7.4", + "phpunit/phpunit": "^8.0", "symfony/console": "^2.0.5|^3.0|^4.0", "symfony/phpunit-bridge": "^3.4.5|^4.0.5" }, diff --git a/composer.lock b/composer.lock index 9d34a231f1e..6cbca943384 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c0b2296029841f54d6b8438c7773e861", + "content-hash": "3bc5aa75b3af3332def5f89114986259", "packages": [ { "name": "doctrine/cache", @@ -1535,40 +1535,40 @@ }, { "name": "phpunit/php-code-coverage", - "version": "6.0.8", + "version": "7.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "848f78b3309780fef7ec8c4666b7ab4e6b09b22f" + "reference": "4832739a02c418397e404da6c3e4fe680b7a4de7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/848f78b3309780fef7ec8c4666b7ab4e6b09b22f", - "reference": "848f78b3309780fef7ec8c4666b7ab4e6b09b22f", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/4832739a02c418397e404da6c3e4fe680b7a4de7", + "reference": "4832739a02c418397e404da6c3e4fe680b7a4de7", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", - "php": "^7.1", - "phpunit/php-file-iterator": "^2.0", + "php": "^7.2", + "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.0", + "phpunit/php-token-stream": "^3.0.1", "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^3.1", + "sebastian/environment": "^4.1", "sebastian/version": "^2.0.1", "theseer/tokenizer": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^8.0" }, "suggest": { - "ext-xdebug": "^2.6.0" + "ext-xdebug": "^2.6.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "6.0-dev" + "dev-master": "7.0-dev" } }, "autoload": { @@ -1594,7 +1594,7 @@ "testing", "xunit" ], - "time": "2018-10-04T03:41:23+00:00" + "time": "2019-02-01T07:29:14+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1738,16 +1738,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "3.0.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "21ad88bbba7c3d93530d93994e0a33cd45f02ace" + "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/21ad88bbba7c3d93530d93994e0a33cd45f02ace", - "reference": "21ad88bbba7c3d93530d93994e0a33cd45f02ace", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c99e3be9d3e85f60646f152f9002d46ed7770d18", + "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18", "shasum": "" }, "require": { @@ -1783,20 +1783,20 @@ "keywords": [ "tokenizer" ], - "time": "2018-02-01T13:16:43+00:00" + "time": "2018-10-30T05:52:18+00:00" }, { "name": "phpunit/phpunit", - "version": "7.4.0", + "version": "8.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "f3837fa1e07758057ae06e8ddec6d06ba183f126" + "reference": "130104cf796a88dd1547dc5beb8bd555c2deb55e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f3837fa1e07758057ae06e8ddec6d06ba183f126", - "reference": "f3837fa1e07758057ae06e8ddec6d06ba183f126", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/130104cf796a88dd1547dc5beb8bd555c2deb55e", + "reference": "130104cf796a88dd1547dc5beb8bd555c2deb55e", "shasum": "" }, "require": { @@ -1806,27 +1806,25 @@ "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", + "ext-xmlwriter": "*", "myclabs/deep-copy": "^1.7", "phar-io/manifest": "^1.0.2", "phar-io/version": "^2.0", - "php": "^7.1", + "php": "^7.2", "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^6.0.7", + "phpunit/php-code-coverage": "^7.0", "phpunit/php-file-iterator": "^2.0.1", "phpunit/php-text-template": "^1.2.1", "phpunit/php-timer": "^2.0", "sebastian/comparator": "^3.0", "sebastian/diff": "^3.0", - "sebastian/environment": "^3.1", + "sebastian/environment": "^4.1", "sebastian/exporter": "^3.1", - "sebastian/global-state": "^2.0", + "sebastian/global-state": "^3.0", "sebastian/object-enumerator": "^3.0.3", "sebastian/resource-operations": "^2.0", "sebastian/version": "^2.0.1" }, - "conflict": { - "phpunit/phpunit-mock-objects": "*" - }, "require-dev": { "ext-pdo": "*" }, @@ -1841,7 +1839,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "7.4-dev" + "dev-master": "8.0-dev" } }, "autoload": { @@ -1867,7 +1865,7 @@ "testing", "xunit" ], - "time": "2018-10-05T04:05:24+00:00" + "time": "2019-02-01T05:41:59+00:00" }, { "name": "psr/log", @@ -2083,28 +2081,31 @@ }, { "name": "sebastian/environment", - "version": "3.1.0", + "version": "4.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5" + "reference": "6fda8ce1974b62b14935adc02a9ed38252eca656" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/cd0871b3975fb7fc44d11314fd1ee20925fce4f5", - "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6fda8ce1974b62b14935adc02a9ed38252eca656", + "reference": "6fda8ce1974b62b14935adc02a9ed38252eca656", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^6.1" + "phpunit/phpunit": "^7.5" + }, + "suggest": { + "ext-posix": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1.x-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -2129,7 +2130,7 @@ "environment", "hhvm" ], - "time": "2017-07-01T08:51:00+00:00" + "time": "2019-02-01T05:27:49+00:00" }, { "name": "sebastian/exporter", @@ -2200,23 +2201,26 @@ }, { "name": "sebastian/global-state", - "version": "2.0.0", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" + "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", - "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", + "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.2", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "ext-dom": "*", + "phpunit/phpunit": "^8.0" }, "suggest": { "ext-uopz": "*" @@ -2224,7 +2228,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -2247,7 +2251,7 @@ "keywords": [ "global state" ], - "time": "2017-04-27T15:39:26+00:00" + "time": "2019-02-01T05:30:01+00:00" }, { "name": "sebastian/object-enumerator", @@ -2877,6 +2881,64 @@ "homepage": "https://symfony.com", "time": "2018-02-19T16:50:22+00:00" }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.10.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "backendtea@gmail.com" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2018-08-06T14:22:27+00:00" + }, { "name": "symfony/polyfill-mbstring", "version": "v1.10.0", @@ -2978,20 +3040,21 @@ }, { "name": "webmozart/assert", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a" + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a", + "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" }, "require-dev": { "phpunit/phpunit": "^4.6", @@ -3024,7 +3087,7 @@ "check", "validate" ], - "time": "2018-01-29T19:49:41+00:00" + "time": "2018-12-25T11:19:39+00:00" } ], "aliases": [], diff --git a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php index 1d500046260..2a8fe528c9d 100644 --- a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php +++ b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php @@ -33,7 +33,7 @@ class QueryCacheProfileTest extends DbalTestCase 'driver' => 'database_driver', ]; - protected function setUp() + protected function setUp() : void { $this->queryCacheProfile = new QueryCacheProfile(self::LIFETIME, self::CACHE_KEY); } @@ -110,7 +110,7 @@ public function testConnectionParamsShouldBeHashed() self::assertArrayHasKey('connectionParams', $params); foreach ($this->connectionParams as $param) { - self::assertNotContains($param, $params['connectionParams']); + self::assertStringNotContainsString($param, $params['connectionParams']); } } diff --git a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php index 8310ea15c66..87189bec852 100644 --- a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php +++ b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php @@ -20,7 +20,7 @@ class ConfigurationTest extends DbalTestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp() : void { $this->config = new Configuration(); } diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 52e95cfc528..3b085ea54c1 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -27,7 +27,7 @@ use Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock; use Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock; use Exception; -use PHPUnit_Framework_MockObject_MockObject; +use PHPUnit\Framework\MockObject\MockObject; use ReflectionObject; use stdClass; use function call_user_func_array; @@ -49,7 +49,7 @@ class ConnectionTest extends DbalTestCase 'port' => '1234', ]; - protected function setUp() + protected function setUp() : void { $this->connection = DriverManager::getConnection($this->params); } @@ -170,7 +170,6 @@ public function testEventManagerPassedToPlatform() /** * @requires extension pdo_sqlite - * @expectedException \Doctrine\DBAL\DBALException * @dataProvider getQueryMethods */ public function testDriverExceptionIsWrapped($method) @@ -519,7 +518,7 @@ public function testFetchAssoc() ->with(FetchMode::ASSOCIATIVE) ->will($this->returnValue($result)); - /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ + /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeQuery']) ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) @@ -555,7 +554,7 @@ public function testFetchArray() ->with(FetchMode::NUMERIC) ->will($this->returnValue($result)); - /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ + /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeQuery']) ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) @@ -592,7 +591,7 @@ public function testFetchColumn() ->with($column) ->will($this->returnValue($result)); - /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ + /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeQuery']) ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) @@ -650,7 +649,7 @@ public function testFetchAll() ->method('fetchAll') ->will($this->returnValue($result)); - /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ + /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeQuery']) ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) @@ -742,13 +741,13 @@ public function testCallConnectOnce($method, $params) */ public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() { - /** @var VersionAwarePlatformDriverMock|PHPUnit_Framework_MockObject_MockObject $driverMock */ + /** @var VersionAwarePlatformDriverMock|MockObject $driverMock */ $driverMock = $this->createMock(VersionAwarePlatformDriverMock::class); - /** @var ServerInfoAwareConnectionMock|PHPUnit_Framework_MockObject_MockObject $driverConnectionMock */ + /** @var ServerInfoAwareConnectionMock|MockObject $driverConnectionMock */ $driverConnectionMock = $this->createMock(ServerInfoAwareConnectionMock::class); - /** @var AbstractPlatform|PHPUnit_Framework_MockObject_MockObject $platformMock */ + /** @var AbstractPlatform|MockObject $platformMock */ $platformMock = $this->getMockForAbstractClass(AbstractPlatform::class); $connection = new Connection([], $driverMock); @@ -787,7 +786,7 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach $params = [666]; $types = [ParameterType::INTEGER]; - /** @var QueryCacheProfile|PHPUnit_Framework_MockObject_MockObject $queryCacheProfileMock */ + /** @var QueryCacheProfile|MockObject $queryCacheProfileMock */ $queryCacheProfileMock = $this->createMock(QueryCacheProfile::class); $queryCacheProfileMock @@ -824,7 +823,7 @@ public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecute ->with('cacheKey') ->will($this->returnValue(['realKey' => []])); - /** @var QueryCacheProfile|PHPUnit_Framework_MockObject_MockObject $queryCacheProfileMock */ + /** @var QueryCacheProfile|MockObject $queryCacheProfileMock */ $queryCacheProfileMock = $this->createMock(QueryCacheProfile::class); $queryCacheProfileMock @@ -871,7 +870,7 @@ public function testThrowsExceptionWhenInValidPlatformSpecified() : void */ public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnectingToNonExistentDatabase() { - /** @var VersionAwarePlatformDriverMock|PHPUnit_Framework_MockObject_MockObject $driverMock */ + /** @var VersionAwarePlatformDriverMock|MockObject $driverMock */ $driverMock = $this->createMock(VersionAwarePlatformDriverMock::class); $connection = new Connection(['dbname' => 'foo'], $driverMock); diff --git a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php index 9c0cc18c0be..ccd1becfac9 100644 --- a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php @@ -20,7 +20,7 @@ public function testDriverExceptionDuringQueryAcceptsBinaryData() /** @var Driver $driver */ $driver = $this->createMock(Driver::class); $e = DBALException::driverExceptionDuringQuery($driver, new Exception(), '', ['ABC', chr(128)]); - self::assertContains('with params ["ABC", "\x80"]', $e->getMessage()); + self::assertStringContainsString('with params ["ABC", "\x80"]', $e->getMessage()); } public function testDriverExceptionDuringQueryAcceptsResource() @@ -28,7 +28,7 @@ public function testDriverExceptionDuringQueryAcceptsResource() /** @var Driver $driver */ $driver = $this->createMock(Driver::class); $e = DBALException::driverExceptionDuringQuery($driver, new Exception(), 'INSERT INTO file (`content`) VALUES (?)', [1 => fopen(__FILE__, 'r')]); - self::assertContains('Resource', $e->getMessage()); + self::assertStringContainsString('Resource', $e->getMessage()); } public function testAvoidOverWrappingOnDriverException() diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index 0475ea11b89..6a16dd65a91 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DriverException as DriverExceptionInterface; use Doctrine\DBAL\Driver\ExceptionConverterDriver; @@ -28,6 +29,7 @@ use Doctrine\DBAL\VersionAwarePlatformDriver; use Doctrine\Tests\DbalTestCase; use Exception; +use ReflectionProperty; use function get_class; use function sprintf; @@ -58,7 +60,7 @@ abstract class AbstractDriverTest extends DbalTestCase */ protected $driver; - protected function setUp() + protected function setUp() : void { parent::setUp(); @@ -158,15 +160,13 @@ public function testCreatesDatabasePlatformForVersion() } } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion() { if (! $this->driver instanceof VersionAwarePlatformDriver) { $this->markTestSkipped('This test is only intended for version aware platform drivers.'); } + $this->expectException(DBALException::class); $this->driver->createDatabasePlatformForVersion('foo'); } @@ -198,7 +198,11 @@ public function testReturnsSchemaManager() $schemaManager = $this->driver->getSchemaManager($connection); self::assertEquals($this->createSchemaManager($connection), $schemaManager); - self::assertAttributeSame($connection, '_conn', $schemaManager); + + $re = new ReflectionProperty($schemaManager, '_conn'); + $re->setAccessible(true); + + self::assertSame($connection, $re->getValue($schemaManager)); } /** diff --git a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php index a60772295a6..b6b32751262 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Driver\IBMDB2\DB2Connection; use Doctrine\Tests\DbalTestCase; -use PHPUnit_Framework_MockObject_MockObject; +use PHPUnit\Framework\MockObject\MockObject; use function extension_loaded; class DB2ConnectionTest extends DbalTestCase @@ -12,11 +12,11 @@ class DB2ConnectionTest extends DbalTestCase /** * The ibm_db2 driver connection mock under test. * - * @var DB2Connection|PHPUnit_Framework_MockObject_MockObject + * @var DB2Connection|MockObject */ private $connectionMock; - protected function setUp() + protected function setUp() : void { if (! extension_loaded('ibm_db2')) { $this->markTestSkipped('ibm_db2 is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php index 9bd3172dd1d..a192edf6f52 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php @@ -6,7 +6,7 @@ use Doctrine\DBAL\Driver\Mysqli\MysqliException; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\Tests\DbalFunctionalTestCase; -use PHPUnit_Framework_MockObject_MockObject; +use PHPUnit\Framework\MockObject\MockObject; use function extension_loaded; use function restore_error_handler; use function set_error_handler; @@ -16,11 +16,11 @@ class MysqliConnectionTest extends DbalFunctionalTestCase /** * The mysqli driver connection mock under test. * - * @var MysqliConnection|PHPUnit_Framework_MockObject_MockObject + * @var MysqliConnection|MockObject */ private $connectionMock; - protected function setUp() + protected function setUp() : void { if (! extension_loaded('mysqli')) { $this->markTestSkipped('mysqli is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php index 0628738400e..81466a3a72e 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Driver\OCI8\OCI8Connection; use Doctrine\Tests\DbalTestCase; -use PHPUnit_Framework_MockObject_MockObject; +use PHPUnit\Framework\MockObject\MockObject; use function extension_loaded; class OCI8ConnectionTest extends DbalTestCase @@ -12,11 +12,11 @@ class OCI8ConnectionTest extends DbalTestCase /** * The oci8 driver connection mock under test. * - * @var OCI8Connection|PHPUnit_Framework_MockObject_MockObject + * @var OCI8Connection|MockObject */ private $connectionMock; - protected function setUp() + protected function setUp() : void { if (! extension_loaded('oci8')) { $this->markTestSkipped('oci8 is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php index b51f3bf2f5b..86d57105cbb 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php @@ -11,7 +11,7 @@ class OCI8StatementTest extends DbalTestCase { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('oci8')) { $this->markTestSkipped('oci8 is not installed.'); @@ -32,7 +32,6 @@ protected function setUp() * @param mixed[] $params * * @dataProvider executeDataProvider - * @expectedException \Doctrine\DBAL\Driver\OCI8\OCI8Exception */ public function testExecute(array $params) { @@ -73,6 +72,7 @@ public function testExecute(array $params) $reflProperty->setAccessible(true); $reflProperty->setValue($statement, $conn); + $this->expectException(OCI8Exception::class); $statement->execute($params); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php index 593f04d203c..c7564470252 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Driver\PDOException; use Doctrine\Tests\DbalTestCase; -use PHPUnit_Framework_MockObject_MockObject; +use PHPUnit\Framework\MockObject\MockObject; use function extension_loaded; class PDOExceptionTest extends DbalTestCase @@ -25,11 +25,11 @@ class PDOExceptionTest extends DbalTestCase /** * The wrapped PDO exception mock. * - * @var \PDOException|PHPUnit_Framework_MockObject_MockObject + * @var \PDOException|MockObject */ private $wrappedException; - protected function setUp() + protected function setUp() : void { if (! extension_loaded('PDO')) { $this->markTestSkipped('PDO is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php index d70d36396ba..ccf6e3358f2 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Driver\SQLAnywhere\SQLAnywhereConnection; use Doctrine\Tests\DbalTestCase; -use PHPUnit_Framework_MockObject_MockObject; +use PHPUnit\Framework\MockObject\MockObject; use function extension_loaded; class SQLAnywhereConnectionTest extends DbalTestCase @@ -12,11 +12,11 @@ class SQLAnywhereConnectionTest extends DbalTestCase /** * The sqlanywhere driver connection mock under test. * - * @var SQLAnywhereConnection|PHPUnit_Framework_MockObject_MockObject + * @var SQLAnywhereConnection|MockObject */ private $connectionMock; - protected function setUp() + protected function setUp() : void { if (! extension_loaded('sqlanywhere')) { $this->markTestSkipped('sqlanywhere is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php index b0e32708428..13ce72a942f 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Driver\SQLSrv\SQLSrvConnection; use Doctrine\Tests\DbalTestCase; -use PHPUnit_Framework_MockObject_MockObject; +use PHPUnit\Framework\MockObject\MockObject; use function extension_loaded; class SQLSrvConnectionTest extends DbalTestCase @@ -12,11 +12,11 @@ class SQLSrvConnectionTest extends DbalTestCase /** * The sqlsrv driver connection mock under test. * - * @var SQLSrvConnection|PHPUnit_Framework_MockObject_MockObject + * @var SQLSrvConnection|MockObject */ private $connectionMock; - protected function setUp() + protected function setUp() : void { if (! extension_loaded('sqlsrv')) { $this->markTestSkipped('sqlsrv is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index e5520afcf1e..828e4fc1a3a 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -25,10 +25,10 @@ class DriverManagerTest extends DbalTestCase { /** * @requires extension pdo_sqlite - * @expectedException \Doctrine\DBAL\DBALException */ public function testInvalidPdoInstance() { + $this->expectException(DBALException::class); DriverManager::getConnection(['pdo' => 'test']); } @@ -58,19 +58,17 @@ public function testPdoInstanceSetErrorMode() self::assertEquals(PDO::ERRMODE_EXCEPTION, $pdo->getAttribute(PDO::ATTR_ERRMODE)); } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testCheckParams() { + $this->expectException(DBALException::class); + DriverManager::getConnection([]); } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testInvalidDriver() { + $this->expectException(DBALException::class); + DriverManager::getConnection(['driver' => 'invalid_driver']); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php index 7c6de8e3795..69094c97838 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php @@ -18,7 +18,7 @@ */ class BlobTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { parent::setUp(); @@ -164,7 +164,7 @@ private function assertBlobContains($text) $blobValue = Type::getType('blob')->convertToPHPValue($rows[0], $this->connection->getDatabasePlatform()); - self::assertInternalType('resource', $blobValue); + self::assertIsResource($blobValue); self::assertEquals($text, stream_get_contents($blobValue)); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index b9d03d5e66c..2c75b946500 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -18,13 +18,13 @@ class ConnectionTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { $this->resetSharedConn(); parent::setUp(); } - protected function tearDown() + protected function tearDown() : void { parent::tearDown(); $this->resetSharedConn(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index f6ad3cb6b22..fdb0ace7078 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -4,6 +4,7 @@ use DateTime; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Mysqli\Driver as MySQLiDriver; use Doctrine\DBAL\Driver\OCI8\Driver as Oci8Driver; use Doctrine\DBAL\Driver\PDOConnection; @@ -37,7 +38,7 @@ class DataAccessTest extends DbalFunctionalTestCase /** @var bool */ static private $generated = false; - protected function setUp() + protected function setUp() : void { parent::setUp(); @@ -238,7 +239,6 @@ public function testFetchAllWithTypes() /** * @group DBAL-209 - * @expectedException \Doctrine\DBAL\DBALException */ public function testFetchAllWithMissingTypes() { @@ -250,6 +250,9 @@ public function testFetchAllWithMissingTypes() $datetimeString = '2010-01-01 10:10:10'; $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; + + $this->expectException(DBALException::class); + $this->connection->fetchAll($sql, [1, $datetime]); } @@ -304,9 +307,6 @@ public function testFetchAssocWithTypes() self::assertStringStartsWith($datetimeString, $row['test_datetime']); } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testFetchAssocWithMissingTypes() { if ($this->connection->getDriver() instanceof MySQLiDriver || @@ -317,6 +317,9 @@ public function testFetchAssocWithMissingTypes() $datetimeString = '2010-01-01 10:10:10'; $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; + + $this->expectException(DBALException::class); + $this->connection->fetchAssoc($sql, [1, $datetime]); } @@ -345,9 +348,6 @@ public function testFetchArrayWithTypes() self::assertStringStartsWith($datetimeString, $row[1]); } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testFetchArrayWithMissingTypes() { if ($this->connection->getDriver() instanceof MySQLiDriver || @@ -358,7 +358,10 @@ public function testFetchArrayWithMissingTypes() $datetimeString = '2010-01-01 10:10:10'; $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; - $row = $this->connection->fetchArray($sql, [1, $datetime]); + + $this->expectException(DBALException::class); + + $this->connection->fetchArray($sql, [1, $datetime]); } public function testFetchColumn() @@ -387,9 +390,6 @@ public function testFetchColumnWithTypes() self::assertStringStartsWith($datetimeString, $column); } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testFetchColumnWithMissingTypes() { if ($this->connection->getDriver() instanceof MySQLiDriver || @@ -400,7 +400,10 @@ public function testFetchColumnWithMissingTypes() $datetimeString = '2010-01-01 10:10:10'; $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; - $column = $this->connection->fetchColumn($sql, [1, $datetime], 1); + + $this->expectException(DBALException::class); + + $this->connection->fetchColumn($sql, [1, $datetime], 1); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php index 738c259d5c0..8a0418d2f0a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php @@ -16,7 +16,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase */ protected $driver; - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php index 82da6090b7e..144365e0d4d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php @@ -8,7 +8,7 @@ class DB2DriverTest extends AbstractDriverTest { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('ibm_db2')) { $this->markTestSkipped('ibm_db2 is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php index 6c2ec6a9ca6..536c1093073 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php @@ -11,7 +11,7 @@ class DB2StatementTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('ibm_db2')) { $this->markTestSkipped('ibm_db2 is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php index bbd8d5ebd09..d2ced1912c4 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php @@ -4,13 +4,14 @@ use Doctrine\DBAL\Driver\Mysqli\Driver; use Doctrine\DBAL\Driver\Mysqli\MysqliConnection; +use Doctrine\DBAL\Driver\Mysqli\MysqliException; use Doctrine\Tests\DbalFunctionalTestCase; use const MYSQLI_OPT_CONNECT_TIMEOUT; use function extension_loaded; class ConnectionTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('mysqli')) { $this->markTestSkipped('mysqli is not installed.'); @@ -25,7 +26,7 @@ protected function setUp() $this->markTestSkipped('MySQLi only test.'); } - protected function tearDown() + protected function tearDown() : void { parent::tearDown(); } @@ -38,11 +39,10 @@ public function testDriverOptions() self::assertInstanceOf(MysqliConnection::class, $connection); } - /** - * @expectedException \Doctrine\DBAL\Driver\Mysqli\MysqliException - */ public function testUnsupportedDriverOption() { + $this->expectException(MysqliException::class); + $this->getConnection(['hello' => 'world']); // use local infile } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php index d7f02a40306..a7b7338beed 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php @@ -8,7 +8,7 @@ class DriverTest extends AbstractDriverTest { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('mysqli')) { $this->markTestSkipped('mysqli is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php index a781b31007d..b617b2bb0d3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php @@ -8,7 +8,7 @@ class DriverTest extends AbstractDriverTest { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('oci8')) { $this->markTestSkipped('oci8 is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php index 1c3226852d6..4e23a2a059a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php @@ -13,7 +13,7 @@ class OCI8ConnectionTest extends DbalFunctionalTestCase /** @var OCI8Connection */ protected $driverConnection; - protected function setUp() + protected function setUp() : void { if (! extension_loaded('oci8')) { $this->markTestSkipped('oci8 is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php index db6a4d552ca..fce2820bde8 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php @@ -8,7 +8,7 @@ class StatementTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('oci8')) { $this->markTestSkipped('oci8 is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php index 214f90700c1..9a12cb8f714 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver; use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Driver\PDOException; use Doctrine\Tests\DbalFunctionalTestCase; use PDO; use function extension_loaded; @@ -17,7 +18,7 @@ class PDOConnectionTest extends DbalFunctionalTestCase */ protected $driverConnection; - protected function setUp() + protected function setUp() : void { if (! extension_loaded('PDO')) { $this->markTestSkipped('PDO is not installed.'); @@ -34,7 +35,7 @@ protected function setUp() $this->markTestSkipped('PDO connection only test.'); } - protected function tearDown() + protected function tearDown() : void { $this->resetSharedConn(); @@ -46,26 +47,23 @@ public function testDoesNotRequireQueryForServerVersion() self::assertFalse($this->driverConnection->requiresQueryForServerVersion()); } - /** - * @expectedException \Doctrine\DBAL\Driver\PDOException - */ public function testThrowsWrappedExceptionOnConstruct() { + $this->expectException(PDOException::class); + new PDOConnection('foo'); } /** * @group DBAL-1022 - * @expectedException \Doctrine\DBAL\Driver\PDOException */ public function testThrowsWrappedExceptionOnExec() { + $this->expectException(PDOException::class); + $this->driverConnection->exec('foo'); } - /** - * @expectedException \Doctrine\DBAL\Driver\PDOException - */ public function testThrowsWrappedExceptionOnPrepare() { if ($this->connection->getDriver()->getName() === 'pdo_sqlsrv') { @@ -76,6 +74,8 @@ public function testThrowsWrappedExceptionOnPrepare() // so that PDO actually communicates with the database server to check the query. $this->driverConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); + $this->expectException(PDOException::class); + $this->driverConnection->prepare('foo'); // Some PDO adapters like PostgreSQL do not check the query server-side @@ -91,11 +91,10 @@ public function testThrowsWrappedExceptionOnPrepare() ); } - /** - * @expectedException \Doctrine\DBAL\Driver\PDOException - */ public function testThrowsWrappedExceptionOnQuery() { + $this->expectException(PDOException::class); + $this->driverConnection->query('foo'); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php index cb0f9633201..9fe297278f6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php @@ -8,7 +8,7 @@ class DriverTest extends AbstractDriverTest { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('pdo_mysql')) { $this->markTestSkipped('pdo_mysql is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php index 604fbc8b123..3a5b44c22fa 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php @@ -8,7 +8,7 @@ class DriverTest extends AbstractDriverTest { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('PDO_OCI')) { $this->markTestSkipped('PDO_OCI is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php index 289621c5eba..2ea657cfa99 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php @@ -13,7 +13,7 @@ class DriverTest extends AbstractDriverTest { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('pdo_pgsql')) { $this->markTestSkipped('pdo_pgsql is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php index 0893bed2e70..7bfde54a6f3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php @@ -10,7 +10,7 @@ class PDOPgsqlConnectionTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('pdo_pgsql')) { $this->markTestSkipped('pdo_pgsql is not loaded.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php index 36978d4b4fd..3df6d7a6540 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php @@ -8,7 +8,7 @@ class DriverTest extends AbstractDriverTest { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('pdo_sqlite')) { $this->markTestSkipped('pdo_sqlite is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php index f125eab3515..a20bf838a89 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php @@ -10,7 +10,7 @@ class DriverTest extends AbstractDriverTest { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('pdo_sqlsrv')) { $this->markTestSkipped('pdo_sqlsrv is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php index 63253a84408..e1df07bbac2 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php @@ -9,7 +9,7 @@ class ConnectionTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('sqlanywhere')) { $this->markTestSkipped('sqlanywhere is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php index 07d0189a88d..4e42e863a46 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php @@ -9,7 +9,7 @@ class DriverTest extends AbstractDriverTest { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('sqlanywhere')) { $this->markTestSkipped('sqlanywhere is not installed.'); @@ -38,7 +38,7 @@ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() // SQL Anywhere has no "default" database. The name of the default database // is defined on server startup and therefore can be arbitrary. - self::assertInternalType('string', $this->driver->getDatabase($connection)); + self::assertIsString($this->driver->getDatabase($connection)); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php index 3cf5c282ea0..b67c8e571b4 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php @@ -9,7 +9,7 @@ class StatementTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('sqlanywhere')) { $this->markTestSkipped('sqlanywhere is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php index b09d7339fc9..0677878063d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php @@ -8,7 +8,7 @@ class DriverTest extends AbstractDriverTest { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('sqlsrv')) { $this->markTestSkipped('sqlsrv is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php index 38df9cb5181..2d52b5c0cd3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php @@ -9,7 +9,7 @@ class StatementTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('sqlsrv')) { self::markTestSkipped('sqlsrv is not installed.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php index e420000ba58..54b4bc1d90a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php @@ -20,7 +20,7 @@ class ExceptionTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php index 00dc7e876eb..d927285e2a3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php @@ -20,7 +20,7 @@ */ class MasterSlaveConnectionTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php index 94fb02da547..88c28661634 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php @@ -13,7 +13,7 @@ class ModifyLimitQueryTest extends DbalFunctionalTestCase /** @var bool */ private static $tableCreated = false; - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php index fec2e5944d6..4dec0809fb4 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php @@ -147,7 +147,7 @@ public function ticketProvider() ]; } - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php index f1e5c5a229a..1ba37b61394 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php @@ -10,7 +10,7 @@ class PDOStatementTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { if (! extension_loaded('pdo')) { $this->markTestSkipped('PDO is not installed'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php b/tests/Doctrine/Tests/DBAL/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php index ec387638c40..64efb1aad6a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php @@ -11,7 +11,7 @@ final class NewPrimaryKeyWithNewAutoIncrementColumnTest extends DbalFunctionalTe /** * {@inheritDoc} */ - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php index 33894dc55b8..6f4e0642db1 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php @@ -21,7 +21,7 @@ class PortabilityTest extends DbalFunctionalTestCase /** @var Connection */ private $portableConnection; - protected function tearDown() + protected function tearDown() : void { if ($this->portableConnection) { $this->portableConnection->close(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index 2c64c280b6d..82f9e6541ed 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -26,7 +26,7 @@ class ResultCacheTest extends DbalFunctionalTestCase /** @var DebugStack */ private $sqlLogger; - protected function setUp() + protected function setUp() : void { parent::setUp(); @@ -49,7 +49,7 @@ protected function setUp() $config->setResultCacheImpl($cache); } - protected function tearDown() + protected function tearDown() : void { $this->connection->getSchemaManager()->dropTable('caching'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php index 0feb30fa5ba..13503e3187b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php @@ -17,7 +17,7 @@ class ComparatorTest extends DbalFunctionalTestCase /** @var Comparator */ private $comparator; - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 9cb4b7e51b1..92e0f497a6d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -15,7 +15,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase { - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index b366cc9c002..14e082c07dc 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -14,7 +14,7 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase /** @var bool */ private static $privilegesGranted = false; - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index 864820b595c..b30c861f704 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -19,7 +19,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase { - protected function tearDown() + protected function tearDown() : void { parent::tearDown(); @@ -48,7 +48,7 @@ public function testGetSchemaNames() { $names = $this->schemaManager->getSchemaNames(); - self::assertInternalType('array', $names); + self::assertIsArray($names); self::assertNotEmpty($names); self::assertContains('public', $names, 'The public schema should be found.'); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php index f076a806a7a..73eb07ea178 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php @@ -37,7 +37,7 @@ public function testDropAndCreateAdvancedIndex() ); $tableIndexes = $this->schemaManager->listTableIndexes('test_create_advanced_index'); - self::assertInternalType('array', $tableIndexes); + self::assertIsArray($tableIndexes); self::assertEquals('test', $tableIndexes['test']->getName()); self::assertEquals(['test'], $tableIndexes['test']->getColumns()); self::assertTrue($tableIndexes['test']->isUnique()); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 1c0afc93e66..6c2679baebb 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -59,7 +59,7 @@ protected function getPlatformName() return strtolower(str_replace('SchemaManagerTest', null, $testClass)); } - protected function setUp() + protected function setUp() : void { parent::setUp(); @@ -73,7 +73,7 @@ protected function setUp() } - protected function tearDown() + protected function tearDown() : void { parent::tearDown(); @@ -168,7 +168,7 @@ public function testListSequences() $sequences = $this->schemaManager->listSequences(); - self::assertInternalType('array', $sequences, 'listSequences() should return an array.'); + self::assertIsArray($sequences, 'listSequences() should return an array.'); $foundSequence = null; foreach ($sequences as $sequence) { @@ -227,7 +227,7 @@ public function testListTables() $this->createTestTable('list_tables_test'); $tables = $this->schemaManager->listTables(); - self::assertInternalType('array', $tables); + self::assertIsArray($tables); self::assertTrue(count($tables) > 0, "List Tables has to find at least one table named 'list_tables_test'."); $foundTable = false; @@ -278,7 +278,7 @@ public function testListTableColumns() self::assertEquals(false, $columns['id']->getunsigned()); self::assertEquals(true, $columns['id']->getnotnull()); self::assertEquals(null, $columns['id']->getdefault()); - self::assertInternalType('array', $columns['id']->getPlatformOptions()); + self::assertIsArray($columns['id']->getPlatformOptions()); self::assertArrayHasKey('test', $columns); self::assertEquals(1, array_search('test', $columnsKeys)); @@ -288,7 +288,7 @@ public function testListTableColumns() self::assertEquals(false, $columns['test']->getfixed()); self::assertEquals(false, $columns['test']->getnotnull()); self::assertEquals('expected default', $columns['test']->getdefault()); - self::assertInternalType('array', $columns['test']->getPlatformOptions()); + self::assertIsArray($columns['test']->getPlatformOptions()); self::assertEquals('foo', strtolower($columns['foo']->getname())); self::assertEquals(2, array_search('foo', $columnsKeys)); @@ -297,7 +297,7 @@ public function testListTableColumns() self::assertEquals(false, $columns['foo']->getfixed()); self::assertEquals(true, $columns['foo']->getnotnull()); self::assertEquals(null, $columns['foo']->getdefault()); - self::assertInternalType('array', $columns['foo']->getPlatformOptions()); + self::assertIsArray($columns['foo']->getPlatformOptions()); self::assertEquals('bar', strtolower($columns['bar']->getname())); self::assertEquals(3, array_search('bar', $columnsKeys)); @@ -309,28 +309,28 @@ public function testListTableColumns() self::assertEquals(false, $columns['bar']->getfixed()); self::assertEquals(false, $columns['bar']->getnotnull()); self::assertEquals(null, $columns['bar']->getdefault()); - self::assertInternalType('array', $columns['bar']->getPlatformOptions()); + self::assertIsArray($columns['bar']->getPlatformOptions()); self::assertEquals('baz1', strtolower($columns['baz1']->getname())); self::assertEquals(4, array_search('baz1', $columnsKeys)); self::assertInstanceOf(DateTimeType::class, $columns['baz1']->gettype()); self::assertEquals(true, $columns['baz1']->getnotnull()); self::assertEquals(null, $columns['baz1']->getdefault()); - self::assertInternalType('array', $columns['baz1']->getPlatformOptions()); + self::assertIsArray($columns['baz1']->getPlatformOptions()); self::assertEquals('baz2', strtolower($columns['baz2']->getname())); self::assertEquals(5, array_search('baz2', $columnsKeys)); self::assertContains($columns['baz2']->gettype()->getName(), ['time', 'date', 'datetime']); self::assertEquals(true, $columns['baz2']->getnotnull()); self::assertEquals(null, $columns['baz2']->getdefault()); - self::assertInternalType('array', $columns['baz2']->getPlatformOptions()); + self::assertIsArray($columns['baz2']->getPlatformOptions()); self::assertEquals('baz3', strtolower($columns['baz3']->getname())); self::assertEquals(6, array_search('baz3', $columnsKeys)); self::assertContains($columns['baz3']->gettype()->getName(), ['time', 'date', 'datetime']); self::assertEquals(true, $columns['baz3']->getnotnull()); self::assertEquals(null, $columns['baz3']->getdefault()); - self::assertInternalType('array', $columns['baz3']->getPlatformOptions()); + self::assertIsArray($columns['baz3']->getPlatformOptions()); } /** @@ -459,7 +459,7 @@ public function testDropAndCreateIndex() $this->schemaManager->dropAndCreateIndex($table->getIndex('test'), $table); $tableIndexes = $this->schemaManager->listTableIndexes('test_create_index'); - self::assertInternalType('array', $tableIndexes); + self::assertIsArray($tableIndexes); self::assertEquals('test', strtolower($tableIndexes['test']->getName())); self::assertEquals(['test'], array_map('strtolower', $tableIndexes['test']->getColumns())); @@ -1188,8 +1188,8 @@ public function testCommentNotDuplicated() $table->addColumn('id', 'integer', ['columnDefinition' => $columnDefinition, 'comment' => 'unexpected_column_comment']); $sql = $this->connection->getDatabasePlatform()->getCreateTableSQL($table); - self::assertContains('expected+column+comment', $sql[0]); - self::assertNotContains('unexpected_column_comment', $sql[0]); + self::assertStringContainsString('expected+column+comment', $sql[0]); + self::assertStringNotContainsString('unexpected_column_comment', $sql[0]); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index 659e6d8dff2..a9f0ccdcfec 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Table; @@ -17,11 +18,11 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase { /** * SQLITE does not support databases. - * - * @expectedException \Doctrine\DBAL\DBALException */ public function testListDatabases() { + $this->expectException(DBALException::class); + $this->schemaManager->listDatabases(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php index 7bd7009c788..66b4a93a207 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php @@ -14,7 +14,7 @@ class StatementTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { parent::setUp(); @@ -69,7 +69,7 @@ public function testReuseStatementWithLongerResults() $stmt = $this->connection->prepare('SELECT param, val FROM stmt_longer_results ORDER BY param'); $stmt->execute(); - self::assertArraySubset([ + self::assertEquals([ ['param1', 'X'], ], $stmt->fetchAll(FetchMode::NUMERIC)); @@ -80,7 +80,7 @@ public function testReuseStatementWithLongerResults() $this->connection->insert('stmt_longer_results', $row2); $stmt->execute(); - self::assertArraySubset([ + self::assertEquals([ ['param1', 'X'], ['param2', 'A bit longer value'], ], $stmt->fetchAll(FetchMode::NUMERIC)); diff --git a/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php b/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php index f62b992015c..a6721b88f8d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php @@ -16,7 +16,7 @@ class TableGeneratorTest extends DbalFunctionalTestCase /** @var TableGenerator */ private $generator; - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php b/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php index 87a776c7e06..8dae876dc0c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php @@ -9,7 +9,7 @@ class TemporaryTableTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { parent::setUp(); try { @@ -18,7 +18,7 @@ protected function setUp() } } - protected function tearDown() + protected function tearDown() : void { if ($this->connection) { try { diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php index 1adf993250f..eeb9b7e24ed 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php @@ -10,7 +10,7 @@ */ class DBAL202Test extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php index af41670690a..6b77db02f0a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php @@ -11,7 +11,7 @@ */ class DBAL421Test extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php index fa98ecb3eca..620b0a66249 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php @@ -11,7 +11,7 @@ */ class DBAL510Test extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php index 827a9124277..21c6e492622 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php @@ -16,7 +16,7 @@ class DBAL630Test extends DbalFunctionalTestCase /** @var bool */ private $running = false; - protected function setUp() + protected function setUp() : void { parent::setUp(); @@ -34,7 +34,7 @@ protected function setUp() $this->running = true; } - protected function tearDown() + protected function tearDown() : void { if ($this->running) { $this->connection->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php index ee0bce44e08..3e087b21b36 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php @@ -10,7 +10,7 @@ */ class DBAL752Test extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php index 0e086b598e4..768b65275f7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php @@ -8,7 +8,6 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalFunctionalTestCase; use stdClass; -use Throwable; use function str_repeat; class TypeConversionTest extends DbalFunctionalTestCase @@ -16,7 +15,7 @@ class TypeConversionTest extends DbalFunctionalTestCase /** @var int */ static private $typeCounter = 0; - protected function setUp() + protected function setUp() : void { parent::setUp(); @@ -38,45 +37,79 @@ protected function setUp() $table->addColumn('test_decimal', 'decimal', ['notnull' => false, 'scale' => 2, 'precision' => 10]); $table->setPrimaryKey(['id']); - try { - $this->connection->getSchemaManager()->createTable($table); - } catch (Throwable $e) { - } + $this->connection + ->getSchemaManager() + ->dropAndCreateTable($table); } - public static function dataIdempotentDataConversion() + /** + * @dataProvider booleanProvider + */ + public function testIdempotentConversionToBoolean(string $type, $originalValue) : void { - $obj = new stdClass(); - $obj->foo = 'bar'; - $obj->bar = 'baz'; + $dbValue = $this->processValue($type, $originalValue); + + self::assertIsBool($dbValue); + self::assertEquals($originalValue, $dbValue); + } + + /** + * @return mixed[][] + */ + public static function booleanProvider() : iterable + { + return [ + 'true' => ['boolean', true], + 'false' => ['boolean', false], + ]; + } + /** + * @dataProvider integerProvider + */ + public function testIdempotentConversionToInteger(string $type, $originalValue) : void + { + $dbValue = $this->processValue($type, $originalValue); + + self::assertIsInt($dbValue); + self::assertEquals($originalValue, $dbValue); + } + + /** + * @return mixed[][] + */ + public static function integerProvider() : iterable + { return [ - ['string', 'ABCDEFGaaaBBB', 'string'], - ['boolean', true, 'bool'], - ['boolean', false, 'bool'], - ['bigint', 12345678, 'string'], - ['smallint', 123, 'int'], - ['datetime', new DateTime('2010-04-05 10:10:10'), 'DateTime'], - ['datetimetz', new DateTime('2010-04-05 10:10:10'), 'DateTime'], - ['date', new DateTime('2010-04-05'), 'DateTime'], - ['time', new DateTime('1970-01-01 10:10:10'), 'DateTime'], - ['text', str_repeat('foo ', 1000), 'string'], - ['array', ['foo' => 'bar'], 'array'], - ['json_array', ['foo' => 'bar'], 'array'], - ['object', $obj, 'object'], - ['float', 1.5, 'float'], - ['decimal', 1.55, 'string'], + 'smallint' => ['smallint', 123], ]; } /** - * @param string $type - * @param mixed $originalValue - * @param string $expectedPhpType - * - * @dataProvider dataIdempotentDataConversion + * @dataProvider floatProvider */ - public function testIdempotentDataConversion($type, $originalValue, $expectedPhpType) + public function testIdempotentConversionToFloat(string $type, $originalValue) : void + { + $dbValue = $this->processValue($type, $originalValue); + + self::assertIsFloat($dbValue); + self::assertEquals($originalValue, $dbValue); + } + + /** + * @return mixed[][] + */ + public static function floatProvider() : iterable + { + return [ + 'float' => ['float', 1.5], + ]; + } + + /** + * @dataProvider toStringProvider + */ + public function testIdempotentConversionToString(string $type, $originalValue) : void { if ($type === 'text' && $this->connection->getDriver() instanceof PDOOracleDriver) { // inserting BLOBs as streams on Oracle requires Oracle-specific SQL syntax which is currently not supported @@ -84,31 +117,121 @@ public function testIdempotentDataConversion($type, $originalValue, $expectedPhp $this->markTestSkipped('DBAL doesn\'t support storing LOBs represented as streams using PDO_OCI'); } - $columnName = 'test_' . $type; - $typeInstance = Type::getType($type); - $insertionValue = $typeInstance->convertToDatabaseValue($originalValue, $this->connection->getDatabasePlatform()); + $dbValue = $this->processValue($type, $originalValue); - $this->connection->insert('type_conversion', ['id' => ++self::$typeCounter, $columnName => $insertionValue]); + self::assertIsString($dbValue); + self::assertEquals($originalValue, $dbValue); + } - $sql = 'SELECT ' . $columnName . ' FROM type_conversion WHERE id = ' . self::$typeCounter; - $actualDbValue = $typeInstance->convertToPHPValue($this->connection->fetchColumn($sql), $this->connection->getDatabasePlatform()); + /** + * @return mixed[][] + */ + public static function toStringProvider() : iterable + { + return [ + 'string' => ['string', 'ABCDEFGabcdefg'], + 'bigint' => ['bigint', 12345678], + 'text' => ['text', str_repeat('foo ', 1000)], + 'decimal' => ['decimal', 1.55], + ]; + } - if ($originalValue instanceof DateTime) { - self::assertInstanceOf($expectedPhpType, $actualDbValue, 'The expected type from the conversion to and back from the database should be ' . $expectedPhpType); - } else { - self::assertInternalType($expectedPhpType, $actualDbValue, 'The expected type from the conversion to and back from the database should be ' . $expectedPhpType); - } + /** + * @dataProvider toArrayProvider + */ + public function testIdempotentConversionToArray(string $type, $originalValue) : void + { + $dbValue = $this->processValue($type, $originalValue); + + self::assertIsArray($dbValue); + self::assertEquals($originalValue, $dbValue); + } + + /** + * @return mixed[][] + */ + public static function toArrayProvider() : iterable + { + return [ + 'array' => ['array', ['foo' => 'bar']], + 'json_array' => ['json_array', ['foo' => 'bar']], + ]; + } + + /** + * @dataProvider toObjectProvider + */ + public function testIdempotentConversionToObject(string $type, $originalValue) : void + { + $dbValue = $this->processValue($type, $originalValue); + + self::assertIsObject($dbValue); + self::assertEquals($originalValue, $dbValue); + } + + /** + * @return mixed[][] + */ + public static function toObjectProvider() : iterable + { + $obj = new stdClass(); + $obj->foo = 'bar'; + $obj->bar = 'baz'; + + return [ + 'object' => ['object', $obj], + ]; + } + + /** + * @dataProvider toDateTimeProvider + */ + public function testIdempotentConversionToDateTime(string $type, DateTime $originalValue) : void + { + $dbValue = $this->processValue($type, $originalValue); + + self::assertInstanceOf(DateTime::class, $dbValue); if ($type === 'datetimetz') { return; } - self::assertEquals($originalValue, $actualDbValue, 'Conversion between values should produce the same out as in value, but doesnt!'); + self::assertEquals($originalValue, $dbValue); + self::assertEquals( + $originalValue->getTimezone(), + $dbValue->getTimezone() + ); + } - if (! ($originalValue instanceof DateTime)) { - return; - } + /** + * @return mixed[][] + */ + public static function toDateTimeProvider() : iterable + { + return [ + 'datetime' => ['datetime', new DateTime('2010-04-05 10:10:10')], + 'datetimetz' => ['datetimetz', new DateTime('2010-04-05 10:10:10')], + 'date' => ['date', new DateTime('2010-04-05')], + 'time' => ['time', new DateTime('1970-01-01 10:10:10')], + ]; + } + + /** + * @param mixed $originalValue + */ + private function processValue(string $type, $originalValue) + { + $columnName = 'test_' . $type; + $typeInstance = Type::getType($type); + $insertionValue = $typeInstance->convertToDatabaseValue($originalValue, $this->connection->getDatabasePlatform()); + + $this->connection->insert('type_conversion', ['id' => ++self::$typeCounter, $columnName => $insertionValue]); + + $sql = 'SELECT ' . $columnName . ' FROM type_conversion WHERE id = ' . self::$typeCounter; - self::assertEquals($originalValue->getTimezone()->getName(), $actualDbValue->getTimezone()->getName(), 'Timezones should be the same.'); + return $typeInstance->convertToPHPValue( + $this->connection->fetchColumn($sql), + $this->connection->getDatabasePlatform() + ); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php index 55b49156f87..d212b969997 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php @@ -16,7 +16,7 @@ class BinaryTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php index e25de428aff..52cef4d9fc2 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php @@ -15,7 +15,7 @@ class WriteTest extends DbalFunctionalTestCase { - protected function setUp() + protected function setUp() : void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php b/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php index 914351c75dc..c2239639f26 100644 --- a/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php +++ b/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php @@ -10,12 +10,12 @@ class DebugStackTest extends DbalTestCase /** @var DebugStack */ private $logger; - protected function setUp() + protected function setUp() : void { $this->logger = new DebugStack(); } - protected function tearDown() + protected function tearDown() : void { unset($this->logger); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index 6dec263df34..79dbc0040b1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Index; @@ -13,6 +14,9 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase { + /** @var MySqlPlatform */ + protected $platform; + public function testModifyLimitQueryWitoutLimit() { $sql = $this->platform->modifyLimitQuery('SELECT n FROM Foo', null, 10); @@ -842,7 +846,10 @@ public function getGeneratesFloatDeclarationSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\", 'foo_db'), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\\\'", + $this->platform->getListTableIndexesSQL("Foo'Bar\\", 'foo_db') + ); } /** @@ -850,7 +857,10 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesDatabaseNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL('foo_table', "Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\\\'", + $this->platform->getListTableIndexesSQL('foo_table', "Foo'Bar\\") + ); } /** @@ -858,7 +868,10 @@ public function testQuotesDatabaseNameInListTableIndexesSQL() */ public function testQuotesDatabaseNameInListViewsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListViewsSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\\\'", + $this->platform->getListViewsSQL("Foo'Bar\\") + ); } /** @@ -866,7 +879,10 @@ public function testQuotesDatabaseNameInListViewsSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\\\'", + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\") + ); } /** @@ -874,7 +890,10 @@ public function testQuotesTableNameInListTableForeignKeysSQL() */ public function testQuotesDatabaseNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL('foo_table', "Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\\\'", + $this->platform->getListTableForeignKeysSQL('foo_table', "Foo'Bar\\") + ); } /** @@ -882,7 +901,10 @@ public function testQuotesDatabaseNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\\\'", + $this->platform->getListTableColumnsSQL("Foo'Bar\\") + ); } /** @@ -890,19 +912,22 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesDatabaseNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\\\'", + $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\") + ); } public function testListTableForeignKeysSQLEvaluatesDatabase() { $sql = $this->platform->getListTableForeignKeysSQL('foo'); - self::assertContains('DATABASE()', $sql); + self::assertStringContainsString('DATABASE()', $sql); $sql = $this->platform->getListTableForeignKeysSQL('foo', 'bar'); - self::assertContains('bar', $sql); - self::assertNotContains('DATABASE()', $sql); + self::assertStringContainsString('bar', $sql); + self::assertStringNotContainsString('DATABASE()', $sql); } public function testColumnCharsetDeclarationSQL() : void diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 8fee20fede2..5feba5f96f6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -29,7 +29,7 @@ abstract class AbstractPlatformTestCase extends DbalTestCase abstract public function createPlatform(); - protected function setUp() + protected function setUp() : void { $this->platform = $this->createPlatform(); } @@ -266,10 +266,7 @@ public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys() $fk = new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk'); if ($this->platform->supportsForeignKeyConstraints()) { - self::assertInternalType( - 'string', - $this->platform->getCreateForeignKeySQL($fk, 'test') - ); + self::assertIsString($this->platform->getCreateForeignKeySQL($fk, 'test')); } else { $this->expectException(DBALException::class); $this->platform->getCreateForeignKeySQL($fk, 'test'); @@ -773,11 +770,10 @@ protected function supportsCommentOnStatement() return false; } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testGetCreateSchemaSQL() { + $this->expectException(DBALException::class); + $this->platform->getCreateSchemaSQL('schema'); } @@ -797,7 +793,7 @@ public function testAlterTableChangeQuotedColumn() ['type'] ); - self::assertContains( + self::assertStringContainsString( $this->platform->quoteIdentifier('select'), implode(';', $this->platform->getAlterTableSQL($tableDiff)) ); @@ -813,10 +809,11 @@ public function testUsesSequenceEmulatedIdentityColumns() /** * @group DBAL-563 - * @expectedException \Doctrine\DBAL\DBALException */ public function testReturnsIdentitySequenceName() { + $this->expectException(DBALException::class); + $this->platform->getIdentitySequenceName('mytable', 'mycolumn'); } @@ -840,11 +837,10 @@ protected function getBinaryMaxLength() return 4000; } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testReturnsBinaryTypeDeclarationSQL() { + $this->expectException(DBALException::class); + $this->platform->getBinaryTypeDeclarationSQL([]); } @@ -1301,10 +1297,11 @@ public function testQuoteStringLiteral() /** * @group DBAL-423 - * @expectedException \Doctrine\DBAL\DBALException */ public function testReturnsGuidTypeDeclarationSQL() { + $this->expectException(DBALException::class); + $this->platform->getGuidTypeDeclarationSQL([]); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 2624de8f71c..81d760e30b6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\Type; +use UnexpectedValueException; use function sprintf; abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCase @@ -477,13 +478,14 @@ public function testConvertFromBoolean($databaseValue, $prepareStatementValue, $ self::assertSame($booleanValue, $platform->convertFromBoolean($databaseValue)); } - /** - * @expectedException UnexpectedValueException - * @expectedExceptionMessage Unrecognized boolean literal 'my-bool' - */ public function testThrowsExceptionWithInvalidBooleanLiteral() { - $platform = $this->createPlatform()->convertBooleansToDatabaseValue('my-bool'); + $platform = $this->createPlatform(); + + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage("Unrecognized boolean literal 'my-bool'"); + + $platform->convertBooleansToDatabaseValue('my-bool'); } public function testGetCreateSchemaSQL() @@ -602,7 +604,7 @@ public function testReturnsIdentitySequenceName() public function testCreateSequenceWithCache($cacheSize, $expectedSql) { $sequence = new Sequence('foo', 1, 1, $cacheSize); - self::assertContains($expectedSql, $this->platform->getCreateSequenceSQL($sequence)); + self::assertStringContainsString($expectedSql, $this->platform->getCreateSequenceSQL($sequence)); } public function dataCreateSequenceWithCache() @@ -952,7 +954,10 @@ public function testReturnsCloseActiveDatabaseConnectionsSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\") + ); } /** @@ -960,11 +965,9 @@ public function testQuotesTableNameInListTableForeignKeysSQL() */ public function testQuotesSchemaNameInListTableForeignKeysSQL() { - self::assertContains( + self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", - $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"), - '', - true + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table") ); } @@ -973,7 +976,10 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableConstraintsSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableConstraintsSQL("Foo'Bar\\") + ); } /** @@ -981,7 +987,10 @@ public function testQuotesTableNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableIndexesSQL("Foo'Bar\\") + ); } /** @@ -989,11 +998,9 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesSchemaNameInListTableIndexesSQL() { - self::assertContains( + self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", - $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"), - '', - true + $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table") ); } @@ -1002,7 +1009,10 @@ public function testQuotesSchemaNameInListTableIndexesSQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableColumnsSQL("Foo'Bar\\") + ); } /** @@ -1010,11 +1020,9 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesSchemaNameInListTableColumnsSQL() { - self::assertContains( + self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", - $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"), - '', - true + $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table") ); } @@ -1023,11 +1031,9 @@ public function testQuotesSchemaNameInListTableColumnsSQL() */ public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() { - self::assertContains( + self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", - $this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\"), - '', - true + $this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\") ); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 1341c9e8819..b43facd2406 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -47,11 +47,10 @@ public function getGenerateAlterTableSql() ]; } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testDoesNotSupportRegexp() { + $this->expectException(DBALException::class); + $this->platform->getRegexpExpression(); } @@ -1423,7 +1422,10 @@ public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableColumnsSQL("Foo'Bar\\") + ); } /** @@ -1431,11 +1433,9 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesSchemaNameInListTableColumnsSQL() { - self::assertContains( + self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", - $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"), - '', - true + $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table") ); } @@ -1444,7 +1444,10 @@ public function testQuotesSchemaNameInListTableColumnsSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\") + ); } /** @@ -1452,11 +1455,9 @@ public function testQuotesTableNameInListTableForeignKeysSQL() */ public function testQuotesSchemaNameInListTableForeignKeysSQL() { - self::assertContains( + self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", - $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"), - '', - true + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table") ); } @@ -1465,7 +1466,10 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableIndexesSQL("Foo'Bar\\") + ); } /** @@ -1473,11 +1477,9 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesSchemaNameInListTableIndexesSQL() { - self::assertContains( + self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", - $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"), - '', - true + $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table") ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php index ce2b7df42a8..5969e9d0355 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php @@ -686,7 +686,10 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableColumnsSQL("Foo'Bar\\") + ); } /** @@ -694,7 +697,10 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableIndexesSQL("Foo'Bar\\") + ); } /** @@ -702,6 +708,9 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\") + ); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index e8f8f0cdd7f..439c413d1a0 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -97,11 +97,10 @@ public function getGenerateAlterTableSql() ]; } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testRLike() { + $this->expectException(DBALException::class); + self::assertEquals('RLIKE', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct'); } @@ -131,11 +130,10 @@ public function testGeneratesTransactionsCommands() ); } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testCreateDatabaseThrowsException() { + $this->expectException(DBALException::class); + self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); } @@ -539,7 +537,7 @@ public function testReturnsIdentitySequenceName() public function testCreateSequenceWithCache($cacheSize, $expectedSql) { $sequence = new Sequence('foo', 1, 1, $cacheSize); - self::assertContains($expectedSql, $this->platform->getCreateSequenceSQL($sequence)); + self::assertStringContainsString($expectedSql, $this->platform->getCreateSequenceSQL($sequence)); } public function dataCreateSequenceWithCache() @@ -875,7 +873,10 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function testQuotesDatabaseNameInListSequencesSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListSequencesSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListSequencesSQL("Foo'Bar\\") + ); } /** @@ -883,7 +884,10 @@ public function testQuotesDatabaseNameInListSequencesSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableIndexesSQL("Foo'Bar\\") + ); } /** @@ -891,7 +895,10 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\") + ); } /** @@ -899,7 +906,10 @@ public function testQuotesTableNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableConstraintsSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableConstraintsSQL("Foo'Bar\\") + ); } /** @@ -907,7 +917,10 @@ public function testQuotesTableNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableColumnsSQL("Foo'Bar\\") + ); } /** @@ -915,6 +928,9 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesDatabaseNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\") + ); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php b/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php index 22ab967fd7e..b0c49ae6bb9 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php @@ -12,7 +12,7 @@ class ReservedKeywordsValidatorTest extends DbalTestCase /** @var ReservedKeywordsValidator */ private $validator; - protected function setUp() + protected function setUp() : void { $this->validator = new ReservedKeywordsValidator([new MySQLKeywords()]); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 219119c2cc1..767fb268408 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -995,11 +995,9 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function testQuotesSchemaNameInListTableColumnsSQL() { - self::assertContains( + self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", - $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"), - '', - true + $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table") ); } @@ -1008,7 +1006,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL() */ public function testQuotesTableNameInListTableConstraintsSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); } /** @@ -1016,11 +1014,9 @@ public function testQuotesTableNameInListTableConstraintsSQL() */ public function testQuotesSchemaNameInListTableConstraintsSQL() { - self::assertContains( + self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", - $this->platform->getListTableConstraintsSQL("Foo'Bar\\.baz_table"), - '', - true + $this->platform->getListTableConstraintsSQL("Foo'Bar\\.baz_table") ); } @@ -1029,7 +1025,10 @@ public function testQuotesSchemaNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\") + ); } /** @@ -1037,11 +1036,9 @@ public function testQuotesTableNameInListTableForeignKeysSQL() */ public function testQuotesSchemaNameInListTableForeignKeysSQL() { - self::assertContains( + self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", - $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"), - '', - true + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table") ); } @@ -1050,7 +1047,10 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableIndexesSQL("Foo'Bar\\") + ); } /** @@ -1058,11 +1058,9 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesSchemaNameInListTableIndexesSQL() { - self::assertContains( + self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", - $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"), - '', - true + $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table") ); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php index e42aaeb8eaf..8aa6bc0cda3 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php @@ -14,7 +14,7 @@ class SQLAzurePlatformTest extends DbalTestCase /** @var SQLAzurePlatform */ private $platform; - protected function setUp() + protected function setUp() : void { $this->platform = new SQLAzurePlatform(); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index f2e12ae7b22..26cc4d304eb 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -262,19 +262,17 @@ public function getGenerateUniqueIndexSql() return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testGeneratesForeignKeyCreationSql() { + $this->expectException(DBALException::class); + parent::testGeneratesForeignKeyCreationSql(); } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testGeneratesConstraintCreationSql() { + $this->expectException(DBALException::class); + parent::testGeneratesConstraintCreationSql(); } @@ -727,7 +725,10 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function testQuotesTableNameInListTableConstraintsSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableConstraintsSQL("Foo'Bar\\") + ); } /** @@ -735,7 +736,10 @@ public function testQuotesTableNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableColumnsSQL("Foo'Bar\\") + ); } /** @@ -743,7 +747,10 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableIndexesSQL("Foo'Bar\\") + ); } /** @@ -751,7 +758,10 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertStringContainsStringIgnoringCase( + "'Foo''Bar\\'", + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\") + ); } public function testDateAddStaticNumberOfDays() diff --git a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php index b4d5168d497..74ace7cc042 100644 --- a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php @@ -9,24 +9,25 @@ use Doctrine\DBAL\Portability\Statement; use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\Mocks\DriverStatementMock; -use PHPUnit_Framework_MockObject_MockObject; +use PHPUnit\Framework\MockObject\MockObject; +use ReflectionProperty; use function iterator_to_array; class StatementTest extends DbalTestCase { - /** @var Connection|PHPUnit_Framework_MockObject_MockObject */ + /** @var Connection|MockObject */ protected $conn; /** @var Statement */ protected $stmt; - /** @var DriverStatement|PHPUnit_Framework_MockObject_MockObject */ + /** @var DriverStatement|MockObject */ protected $wrappedStmt; /** * {@inheritdoc} */ - protected function setUp() + protected function setUp() : void { $this->wrappedStmt = $this->createWrappedStatement(); $this->conn = $this->createConnection(); @@ -133,9 +134,12 @@ public function testSetFetchMode() ->with($fetchMode, $arg1, $arg2) ->will($this->returnValue(true)); - self::assertAttributeSame(FetchMode::MIXED, 'defaultFetchMode', $this->stmt); + $re = new ReflectionProperty($this->stmt, 'defaultFetchMode'); + $re->setAccessible(true); + + self::assertSame(FetchMode::MIXED, $re->getValue($this->stmt)); self::assertTrue($this->stmt->setFetchMode($fetchMode, $arg1, $arg2)); - self::assertAttributeSame($fetchMode, 'defaultFetchMode', $this->stmt); + self::assertSame($fetchMode, $re->getValue($this->stmt)); } public function testGetIterator() @@ -159,7 +163,7 @@ public function testRowCount() } /** - * @return Connection|PHPUnit_Framework_MockObject_MockObject + * @return Connection|MockObject */ protected function createConnection() { @@ -177,7 +181,7 @@ protected function createStatement(DriverStatement $wrappedStatement, Connection } /** - * @return DriverStatement|PHPUnit_Framework_MockObject_MockObject + * @return DriverStatement|MockObject */ protected function createWrappedStatement() { diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php index efa173829c3..d419f8d5fd4 100644 --- a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php @@ -15,7 +15,7 @@ class ExpressionBuilderTest extends DbalTestCase /** @var ExpressionBuilder */ protected $expr; - protected function setUp() + protected function setUp() : void { $conn = $this->createMock(Connection::class); diff --git a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php index fdd28d87847..b6d4d090374 100644 --- a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php @@ -17,7 +17,7 @@ class QueryBuilderTest extends DbalTestCase /** @var Connection */ protected $conn; - protected function setUp() + protected function setUp() : void { $this->conn = $this->createMock(Connection::class); diff --git a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php index bdde3d4fbcb..b3f91149b32 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php @@ -8,8 +8,8 @@ use Doctrine\DBAL\Driver; use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Schema\DB2SchemaManager; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_MockObject; use function in_array; /** @@ -17,13 +17,13 @@ */ final class DB2SchemaManagerTest extends TestCase { - /** @var Connection|PHPUnit_Framework_MockObject_MockObject */ + /** @var Connection|MockObject */ private $conn; /** @var DB2SchemaManager */ private $manager; - protected function setUp() + protected function setUp() : void { $eventManager = new EventManager(); $driverMock = $this->createMock(Driver::class); @@ -87,7 +87,7 @@ public function testAssetFilteringSetsACallable() ); $callable = $this->conn->getConfiguration()->getSchemaAssetsFilter(); - $this->assertInternalType('callable', $callable); + self::assertIsCallable($callable); // BC check: Test that regexp expression is still preserved & accessible. $this->assertEquals($filterExpression, $this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); diff --git a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php index 737a8223812..4646700e0e7 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php @@ -21,7 +21,7 @@ class MySqlSchemaManagerTest extends TestCase /** @var Connection */ private $conn; - protected function setUp() + protected function setUp() : void { $eventManager = new EventManager(); $driverMock = $this->createMock(Driver::class); diff --git a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php index 0d45a5ef5e5..568a4bfa79a 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php @@ -16,7 +16,7 @@ class MySQLSchemaTest extends TestCase /** @var AbstractPlatform */ private $platform; - protected function setUp() + protected function setUp() : void { $this->comparator = new Comparator(); $this->platform = new MySqlPlatform(); diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php index f7254c97cb7..5618feeefdb 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php @@ -10,6 +10,7 @@ use Doctrine\DBAL\Schema\Visitor\AbstractVisitor; use Doctrine\DBAL\Schema\Visitor\Visitor; use PHPUnit\Framework\TestCase; +use ReflectionProperty; use function current; use function strlen; @@ -211,7 +212,11 @@ public function testDeepClone() $fk = $schemaNew->getTable('bar')->getForeignKeys(); $fk = current($fk); - self::assertSame($schemaNew->getTable('bar'), $this->readAttribute($fk, '_localTable')); + + $re = new ReflectionProperty($fk, '_localTable'); + $re->setAccessible(true); + + self::assertSame($schemaNew->getTable('bar'), $re->getValue($fk)); } /** @@ -279,13 +284,15 @@ public function testCreatesNamespace() /** * @group DBAL-669 - * @expectedException \Doctrine\DBAL\Schema\SchemaException */ public function testThrowsExceptionOnCreatingNamespaceTwice() { $schema = new Schema(); $schema->createNamespace('foo'); + + $this->expectException(SchemaException::class); + $schema->createNamespace('foo'); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php index cedc3583137..80d43e0e1b4 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php @@ -19,7 +19,7 @@ class SingleDatabaseSynchronizerTest extends TestCase /** @var SingleDatabaseSynchronizer */ private $synchronizer; - protected function setUp() + protected function setUp() : void { $this->conn = DriverManager::getConnection([ 'driver' => 'pdo_sqlite', diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index ac5fead5bcf..154a29ad7b0 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -783,7 +783,6 @@ public function testKeepsIndexOptionsOnRenamingUniqueIndex() /** * @group DBAL-234 - * @expectedException \Doctrine\DBAL\Schema\SchemaException */ public function testThrowsExceptionOnRenamingNonExistingIndex() { @@ -791,12 +790,13 @@ public function testThrowsExceptionOnRenamingNonExistingIndex() $table->addColumn('id', 'integer'); $table->addIndex(['id'], 'idx'); + $this->expectException(SchemaException::class); + $table->renameIndex('foo', 'bar'); } /** * @group DBAL-234 - * @expectedException \Doctrine\DBAL\Schema\SchemaException */ public function testThrowsExceptionOnRenamingToAlreadyExistingIndex() { @@ -806,6 +806,8 @@ public function testThrowsExceptionOnRenamingToAlreadyExistingIndex() $table->addIndex(['id'], 'idx_id'); $table->addIndex(['foo'], 'idx_foo'); + $this->expectException(SchemaException::class); + $table->renameIndex('idx_id', 'idx_foo'); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php index e64b4c523f3..790ba66db7b 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -7,12 +7,12 @@ use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_MockObject; class CreateSchemaSqlCollectorTest extends TestCase { - /** @var AbstractPlatform|PHPUnit_Framework_MockObject_MockObject */ + /** @var AbstractPlatform|MockObject */ private $platformMock; /** @var CreateSchemaSqlCollector */ @@ -21,7 +21,7 @@ class CreateSchemaSqlCollectorTest extends TestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp() : void { parent::setUp(); @@ -130,7 +130,7 @@ public function testResetsQueries() } /** - * @return ForeignKeyConstraint|PHPUnit_Framework_MockObject_MockObject + * @return ForeignKeyConstraint|MockObject */ private function createForeignKeyConstraintMock() { @@ -140,7 +140,7 @@ private function createForeignKeyConstraintMock() } /** - * @return Sequence|PHPUnit_Framework_MockObject_MockObject + * @return Sequence|MockObject */ private function createSequenceMock() { @@ -150,7 +150,7 @@ private function createSequenceMock() } /** - * @return Table|PHPUnit_Framework_MockObject_MockObject + * @return Table|MockObject */ private function createTableMock() { diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php index 2e67d0a023f..5424c7bb676 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php @@ -17,7 +17,7 @@ abstract class AbstractTestCase extends TestCase /** @var SQLAzureShardManager */ protected $sm; - protected function setUp() + protected function setUp() : void { if (! isset($GLOBALS['db_type']) || strpos($GLOBALS['db_type'], 'sqlsrv') === false) { $this->markTestSkipped('No driver or sqlserver driver specified.'); diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index 7f18b20936a..f7ff02d2ac6 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Logging\SQLLogger; @@ -25,7 +26,7 @@ class StatementTest extends DbalTestCase /** @var PDOStatement */ private $pdoStatement; - protected function setUp() + protected function setUp() : void { $this->pdoStatement = $this->getMockBuilder(PDOStatement::class) ->setMethods(['execute', 'bindParam', 'bindValue']) @@ -124,9 +125,6 @@ public function testExecuteCallsStartQueryWithTheParametersBoundViaBindParam() $statement->execute(); } - /** - * @expectedException \Doctrine\DBAL\DBALException - */ public function testExecuteCallsLoggerStopQueryOnException() { $logger = $this->createMock(SQLLogger::class); @@ -151,6 +149,9 @@ public function testExecuteCallsLoggerStopQueryOnException() ->will($this->throwException(new Exception('Mock test exception'))); $statement = new Statement('', $this->conn); + + $this->expectException(DBALException::class); + $statement->execute(); } } diff --git a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php index a85efd0a88c..eb06ddc350b 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php @@ -21,7 +21,7 @@ class RunSqlCommandTest extends TestCase /** @var Connection */ private $connectionMock; - protected function setUp() + protected function setUp() : void { $application = new Application(); $application->add(new RunSqlCommand()); @@ -48,7 +48,7 @@ public function testMissingSqlArgument() ]); $this->fail('Expected a runtime exception when omitting sql argument'); } catch (RuntimeException $e) { - self::assertContains("Argument 'SQL", $e->getMessage()); + self::assertStringContainsString("Argument 'SQL", $e->getMessage()); } } @@ -62,7 +62,7 @@ public function testIncorrectDepthOption() ]); $this->fail('Expected a logic exception when executing with a stringy depth'); } catch (LogicException $e) { - self::assertContains("Option 'depth'", $e->getMessage()); + self::assertStringContainsString("Option 'depth'", $e->getMessage()); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php index ecb4155f74f..66181f7e0c8 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php @@ -17,7 +17,7 @@ class ArrayTest extends DbalTestCase /** @var Type */ private $type; - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('array'); @@ -25,18 +25,12 @@ protected function setUp() public function testArrayConvertsToDatabaseValue() { - self::assertInternalType( - 'string', - $this->type->convertToDatabaseValue([], $this->platform) - ); + self::assertIsString($this->type->convertToDatabaseValue([], $this->platform)); } public function testArrayConvertsToPHPValue() { - self::assertInternalType( - 'array', - $this->type->convertToPHPValue(serialize([]), $this->platform) - ); + self::assertIsArray($this->type->convertToPHPValue(serialize([]), $this->platform)); } public function testConversionFailure() diff --git a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php index 8140cf6d109..2b447d95cfd 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php @@ -26,7 +26,7 @@ abstract class BaseDateTypeTestCase extends TestCase /** * {@inheritDoc} */ - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->currentTimezone = date_default_timezone_get(); @@ -37,14 +37,14 @@ protected function setUp() /** * {@inheritDoc} */ - protected function tearDown() + protected function tearDown() : void { date_default_timezone_set($this->currentTimezone); } public function testDateConvertsToDatabaseValue() { - self::assertInternalType('string', $this->type->convertToDatabaseValue(new DateTime(), $this->platform)); + self::assertIsString($this->type->convertToDatabaseValue(new DateTime(), $this->platform)); } /** @@ -94,10 +94,7 @@ public function testConvertDateTimeImmutableToPHPValue() */ public function testDateTimeImmutableConvertsToDatabaseValue() { - self::assertInternalType( - 'string', - $this->type->convertToDatabaseValue(new DateTimeImmutable(), $this->platform) - ); + self::assertIsString($this->type->convertToDatabaseValue(new DateTimeImmutable(), $this->platform)); } /** diff --git a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php index fbcf5fb9357..e5bd3c201dc 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\BinaryType; +use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; @@ -22,7 +23,7 @@ class BinaryTest extends DbalTestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('binary'); @@ -53,7 +54,7 @@ public function testBinaryStringConvertsToPHPValue() $databaseValue = 'binary string'; $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); - self::assertInternalType('resource', $phpValue); + self::assertIsResource($phpValue); self::assertEquals($databaseValue, stream_get_contents($phpValue)); } @@ -67,10 +68,11 @@ public function testBinaryResourceConvertsToPHPValue() /** * @dataProvider getInvalidDatabaseValues - * @expectedException \Doctrine\DBAL\Types\ConversionException */ public function testThrowsConversionExceptionOnInvalidDatabaseValue($value) { + $this->expectException(ConversionException::class); + $this->type->convertToPHPValue($value, $this->platform); } diff --git a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php index 5500836cfdb..57f26004140 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php @@ -22,7 +22,7 @@ class BlobTest extends DbalTestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('blob'); @@ -38,7 +38,7 @@ public function testBinaryStringConvertsToPHPValue() $databaseValue = $this->getBinaryString(); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); - self::assertInternalType('resource', $phpValue); + self::assertIsResource($phpValue); self::assertSame($databaseValue, stream_get_contents($phpValue)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php index a7e3377107a..ad9dcc673bf 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php @@ -14,7 +14,7 @@ class BooleanTest extends DbalTestCase /** @var Type */ private $type; - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('boolean'); @@ -22,12 +22,12 @@ protected function setUp() public function testBooleanConvertsToDatabaseValue() { - self::assertInternalType('integer', $this->type->convertToDatabaseValue(1, $this->platform)); + self::assertIsInt($this->type->convertToDatabaseValue(1, $this->platform)); } public function testBooleanConvertsToPHPValue() { - self::assertInternalType('bool', $this->type->convertToPHPValue(0, $this->platform)); + self::assertIsBool($this->type->convertToPHPValue(0, $this->platform)); } public function testBooleanNullConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php index 5fd15d812d3..38cf0a98a33 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php @@ -21,7 +21,7 @@ class DateImmutableTypeTest extends TestCase /** @var DateImmutableType */ private $type; - protected function setUp() + protected function setUp() : void { $this->type = Type::getType('date_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index a8c7327b337..e7c76ba77ff 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -12,7 +12,7 @@ class DateTest extends BaseDateTypeTestCase /** * {@inheritDoc} */ - protected function setUp() + protected function setUp() : void { $this->type = Type::getType('date'); diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php index dfedcca32b1..4c2ed8e104e 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php @@ -21,7 +21,7 @@ class DateTimeImmutableTypeTest extends TestCase /** @var DateTimeImmutableType */ private $type; - protected function setUp() + protected function setUp() : void { $this->type = Type::getType('datetime_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index 7d571f80eb2..615c14d584d 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -11,7 +11,7 @@ class DateTimeTest extends BaseDateTypeTestCase /** * {@inheritDoc} */ - protected function setUp() + protected function setUp() : void { $this->type = Type::getType('datetime'); diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php index df47f7b3991..aa602b629c2 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php @@ -21,7 +21,7 @@ class DateTimeTzImmutableTypeTest extends TestCase /** @var DateTimeTzImmutableType */ private $type; - protected function setUp() + protected function setUp() : void { $this->type = Type::getType('datetimetz_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index 4b6c8fb208f..419974c6b09 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -11,7 +11,7 @@ class DateTimeTzTest extends BaseDateTypeTestCase /** * {@inheritDoc} */ - protected function setUp() + protected function setUp() : void { $this->type = Type::getType('datetimetz'); diff --git a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php index 3d1164afbfb..e702f7718ff 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php @@ -14,7 +14,7 @@ class DecimalTest extends DbalTestCase /** @var Type */ private $type; - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('decimal'); @@ -22,7 +22,7 @@ protected function setUp() public function testDecimalConvertsToPHPValue() { - self::assertInternalType('string', $this->type->convertToPHPValue('5.5', $this->platform)); + self::assertIsString($this->type->convertToPHPValue('5.5', $this->platform)); } public function testDecimalNullConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php index e68bf0bc46f..b3da2257c72 100644 --- a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php @@ -14,7 +14,7 @@ class FloatTest extends DbalTestCase /** @var Type */ private $type; - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('float'); @@ -22,7 +22,7 @@ protected function setUp() public function testFloatConvertsToPHPValue() { - self::assertInternalType('float', $this->type->convertToPHPValue('5.5', $this->platform)); + self::assertIsFloat($this->type->convertToPHPValue('5.5', $this->platform)); } public function testFloatNullConvertsToPHPValue() @@ -32,7 +32,7 @@ public function testFloatNullConvertsToPHPValue() public function testFloatConvertToDatabaseValue() { - self::assertInternalType('float', $this->type->convertToDatabaseValue(5.5, $this->platform)); + self::assertIsFloat($this->type->convertToDatabaseValue(5.5, $this->platform)); } public function testFloatNullConvertToDatabaseValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php index 978cfd50fb7..b35670405d4 100644 --- a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php @@ -15,7 +15,7 @@ class GuidTypeTest extends DbalTestCase /** @var Type */ private $type; - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('guid'); @@ -23,8 +23,8 @@ protected function setUp() public function testConvertToPHPValue() { - self::assertInternalType('string', $this->type->convertToPHPValue('foo', $this->platform)); - self::assertInternalType('string', $this->type->convertToPHPValue('', $this->platform)); + self::assertIsString($this->type->convertToPHPValue('foo', $this->platform)); + self::assertIsString($this->type->convertToPHPValue('', $this->platform)); } public function testNullConversion() diff --git a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php index 848ff05dfc8..11e0f91c5fe 100644 --- a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php @@ -14,7 +14,7 @@ class IntegerTest extends DbalTestCase /** @var Type */ private $type; - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('integer'); @@ -22,8 +22,8 @@ protected function setUp() public function testIntegerConvertsToPHPValue() { - self::assertInternalType('integer', $this->type->convertToPHPValue('1', $this->platform)); - self::assertInternalType('integer', $this->type->convertToPHPValue('0', $this->platform)); + self::assertIsInt($this->type->convertToPHPValue('1', $this->platform)); + self::assertIsInt($this->type->convertToPHPValue('0', $this->platform)); } public function testIntegerNullConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index 564371a30b3..8bc0ed1d8f8 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -22,7 +22,7 @@ class JsonArrayTest extends DbalTestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('json_array'); diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index 4f204a8baec..e36c84a33d4 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -23,7 +23,7 @@ class JsonTest extends DbalTestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('json'); diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index 858004b73f4..0176f35a295 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -17,7 +17,7 @@ class ObjectTest extends DbalTestCase /** @var Type */ private $type; - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('object'); @@ -25,12 +25,12 @@ protected function setUp() public function testObjectConvertsToDatabaseValue() { - self::assertInternalType('string', $this->type->convertToDatabaseValue(new stdClass(), $this->platform)); + self::assertIsString($this->type->convertToDatabaseValue(new stdClass(), $this->platform)); } public function testObjectConvertsToPHPValue() { - self::assertInternalType('object', $this->type->convertToPHPValue(serialize(new stdClass()), $this->platform)); + self::assertIsObject($this->type->convertToPHPValue(serialize(new stdClass()), $this->platform)); } public function testConversionFailure() diff --git a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php index 4a453421b36..d7c98caad4a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php @@ -14,7 +14,7 @@ class SmallIntTest extends DbalTestCase /** @var Type */ private $type; - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('smallint'); @@ -22,8 +22,8 @@ protected function setUp() public function testSmallIntConvertsToPHPValue() { - self::assertInternalType('integer', $this->type->convertToPHPValue('1', $this->platform)); - self::assertInternalType('integer', $this->type->convertToPHPValue('0', $this->platform)); + self::assertIsInt($this->type->convertToPHPValue('1', $this->platform)); + self::assertIsInt($this->type->convertToPHPValue('0', $this->platform)); } public function testSmallIntNullConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/StringTest.php b/tests/Doctrine/Tests/DBAL/Types/StringTest.php index 74716e4f23c..651058811f2 100644 --- a/tests/Doctrine/Tests/DBAL/Types/StringTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/StringTest.php @@ -14,7 +14,7 @@ class StringTest extends DbalTestCase /** @var Type */ private $type; - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); $this->type = Type::getType('string'); @@ -32,8 +32,8 @@ public function testReturnsDefaultLengthFromPlatformVarchar() public function testConvertToPHPValue() { - self::assertInternalType('string', $this->type->convertToPHPValue('foo', $this->platform)); - self::assertInternalType('string', $this->type->convertToPHPValue('', $this->platform)); + self::assertIsString($this->type->convertToPHPValue('foo', $this->platform)); + self::assertIsString($this->type->convertToPHPValue('', $this->platform)); } public function testNullConversion() diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php index 0f7427df3ed..a374cf1015f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php @@ -21,7 +21,7 @@ class TimeImmutableTypeTest extends TestCase /** @var TimeImmutableType */ private $type; - protected function setUp() + protected function setUp() : void { $this->type = Type::getType('time_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index c2cd766b1c3..1b254730092 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -10,7 +10,7 @@ class TimeTest extends BaseDateTypeTestCase /** * {@inheritDoc} */ - protected function setUp() + protected function setUp() : void { $this->type = Type::getType('time'); diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php index 870bb23cc98..b948f22af77 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php @@ -20,7 +20,7 @@ class VarDateTimeImmutableTypeTest extends TestCase /** @var VarDateTimeImmutableType */ private $type; - protected function setUp() + protected function setUp() : void { if (! Type::hasType('vardatetime_immutable')) { Type::addType('vardatetime_immutable', VarDateTimeImmutableType::class); diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index 2322aa474fe..516f42836b4 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -17,7 +17,7 @@ class VarDateTimeTest extends DbalTestCase /** @var Type */ private $type; - protected function setUp() + protected function setUp() : void { $this->platform = new MockPlatform(); if (! Type::hasType('vardatetime')) { diff --git a/tests/Doctrine/Tests/DbalFunctionalTestCase.php b/tests/Doctrine/Tests/DbalFunctionalTestCase.php index 77cfd8d6900..149db8bf998 100644 --- a/tests/Doctrine/Tests/DbalFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DbalFunctionalTestCase.php @@ -43,7 +43,7 @@ protected function resetSharedConn() self::$sharedConnection = null; } - protected function setUp() + protected function setUp() : void { if (! isset(self::$sharedConnection)) { self::$sharedConnection = TestUtil::getConnection(); @@ -54,14 +54,14 @@ protected function setUp() $this->connection->getConfiguration()->setSQLLogger($this->sqlLoggerStack); } - protected function tearDown() + protected function tearDown() : void { while ($this->connection->isTransactionActive()) { $this->connection->rollBack(); } } - protected function onNotSuccessfulTest(Throwable $t) + protected function onNotSuccessfulTest(Throwable $t) : void { if ($t instanceof AssertionFailedError) { throw $t; diff --git a/tests/Doctrine/Tests/DbalPerformanceTestCase.php b/tests/Doctrine/Tests/DbalPerformanceTestCase.php index bfc60201bef..0001431454a 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestCase.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestCase.php @@ -30,7 +30,7 @@ class DbalPerformanceTestCase extends DbalFunctionalTestCase /** * {@inheritdoc} */ - protected function assertPostConditions() + protected function assertPostConditions() : void { // If a perf test doesn't start or stop, it fails. self::assertNotNull($this->startTime, 'Test timing was started'); From 7bafa27cf7467031f35bfefc8eea8b0805f479bb Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 7 Jan 2019 23:46:54 -0800 Subject: [PATCH 032/106] PHPStan Level 7 --- lib/Doctrine/DBAL/Connection.php | 92 +++++++++---------- .../Connections/MasterSlaveConnection.php | 2 + lib/Doctrine/DBAL/DBALException.php | 4 +- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php | 2 +- lib/Doctrine/DBAL/Driver/Mysqli/Driver.php | 2 +- .../DBAL/Driver/Mysqli/MysqliStatement.php | 5 +- lib/Doctrine/DBAL/Driver/OCI8/Driver.php | 6 +- .../DBAL/Driver/OCI8/OCI8Connection.php | 28 +++--- .../DBAL/Driver/OCI8/OCI8Statement.php | 9 +- lib/Doctrine/DBAL/Driver/PDOConnection.php | 6 +- lib/Doctrine/DBAL/Driver/PDOStatement.php | 38 ++++---- .../DBAL/Driver/SQLSrv/SQLSrvConnection.php | 2 +- .../DBAL/Driver/SQLSrv/SQLSrvException.php | 4 +- .../DBAL/Driver/SQLSrv/SQLSrvStatement.php | 6 +- lib/Doctrine/DBAL/Driver/Statement.php | 2 +- .../DBAL/Platforms/AbstractPlatform.php | 14 ++- lib/Doctrine/DBAL/Platforms/DB2Platform.php | 7 +- .../DBAL/Platforms/DrizzlePlatform.php | 4 +- .../DBAL/Platforms/SQLAnywherePlatform.php | 14 ++- .../DBAL/Platforms/SQLServerPlatform.php | 43 ++++----- lib/Doctrine/DBAL/Portability/Connection.php | 4 +- lib/Doctrine/DBAL/Schema/AbstractAsset.php | 2 +- .../DBAL/Schema/AbstractSchemaManager.php | 20 ++-- lib/Doctrine/DBAL/Schema/Column.php | 2 +- lib/Doctrine/DBAL/Schema/Comparator.php | 1 + lib/Doctrine/DBAL/Schema/DB2SchemaManager.php | 3 +- .../DBAL/Schema/ForeignKeyConstraint.php | 4 +- .../DBAL/Schema/MySqlSchemaManager.php | 22 +---- .../DBAL/Schema/OracleSchemaManager.php | 2 + .../DBAL/Schema/PostgreSqlSchemaManager.php | 4 +- .../DBAL/Schema/SQLServerSchemaManager.php | 2 + lib/Doctrine/DBAL/Schema/Schema.php | 8 +- lib/Doctrine/DBAL/Schema/SchemaDiff.php | 2 +- lib/Doctrine/DBAL/Schema/Sequence.php | 6 +- .../SingleDatabaseSynchronizer.php | 7 +- lib/Doctrine/DBAL/Schema/Table.php | 21 +++-- .../Visitor/CreateSchemaSqlCollector.php | 2 +- lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php | 5 +- .../DBAL/Sharding/PoolingShardConnection.php | 16 ++-- phpstan.neon.dist | 10 +- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 24 ----- .../Tests/DBAL/Functional/PortabilityTest.php | 24 ----- .../Visitor/CreateSchemaSqlCollectorTest.php | 10 +- 43 files changed, 241 insertions(+), 250 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 4d79fb739b6..8016b7da6a1 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -459,11 +459,11 @@ private function getDatabasePlatformVersion() */ private function getServerVersion() { + $connection = $this->getWrappedConnection(); + // Automatic platform version detection. - if ($this->_conn instanceof ServerInfoAwareConnection && - ! $this->_conn->requiresQueryForServerVersion() - ) { - return $this->_conn->getServerVersion(); + if ($connection instanceof ServerInfoAwareConnection && ! $connection->requiresQueryForServerVersion()) { + return $connection->getServerVersion(); } // Unable to detect platform version. @@ -810,20 +810,15 @@ public function quoteIdentifier($str) } /** - * Quotes a given input parameter. - * - * @param mixed $input The parameter to be quoted. - * @param int|null $type The type of the parameter. - * - * @return string The quoted parameter. + * {@inheritDoc} */ public function quote($input, $type = null) { - $this->connect(); + $connection = $this->getWrappedConnection(); [$value, $bindingType] = $this->getBindingInfo($input, $type); - return $this->_conn->quote($value, $bindingType); + return $connection->quote($value, $bindingType); } /** @@ -883,7 +878,7 @@ public function executeQuery($query, array $params = [], $types = [], ?QueryCach return $this->executeCacheQuery($query, $params, $types, $qcp); } - $this->connect(); + $connection = $this->getWrappedConnection(); $logger = $this->_config->getSQLLogger(); if ($logger) { @@ -894,7 +889,7 @@ public function executeQuery($query, array $params = [], $types = [], ?QueryCach if ($params) { [$query, $params, $types] = SQLParserUtils::expandListParameters($query, $params, $types); - $stmt = $this->_conn->prepare($query); + $stmt = $connection->prepare($query); if ($types) { $this->_bindTypedValues($stmt, $params, $types); $stmt->execute(); @@ -902,7 +897,7 @@ public function executeQuery($query, array $params = [], $types = [], ?QueryCach $stmt->execute($params); } } else { - $stmt = $this->_conn->query($query); + $stmt = $connection->query($query); } } catch (Throwable $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types)); @@ -931,8 +926,9 @@ public function executeQuery($query, array $params = [], $types = [], ?QueryCach */ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qcp) { - $resultCache = $qcp->getResultCacheDriver() ?: $this->_config->getResultCacheImpl(); - if (! $resultCache) { + $resultCache = $qcp->getResultCacheDriver() ?? $this->_config->getResultCacheImpl(); + + if ($resultCache === null) { throw CacheException::noResultDriverConfigured(); } @@ -994,7 +990,7 @@ public function project($query, array $params, Closure $function) */ public function query() { - $this->connect(); + $connection = $this->getWrappedConnection(); $args = func_get_args(); @@ -1004,7 +1000,7 @@ public function query() } try { - $statement = $this->_conn->query(...$args); + $statement = $connection->query(...$args); } catch (Throwable $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $args[0]); } @@ -1034,7 +1030,7 @@ public function query() */ public function executeUpdate($query, array $params = [], array $types = []) { - $this->connect(); + $connection = $this->getWrappedConnection(); $logger = $this->_config->getSQLLogger(); if ($logger) { @@ -1045,7 +1041,8 @@ public function executeUpdate($query, array $params = [], array $types = []) if ($params) { [$query, $params, $types] = SQLParserUtils::expandListParameters($query, $params, $types); - $stmt = $this->_conn->prepare($query); + $stmt = $connection->prepare($query); + if ($types) { $this->_bindTypedValues($stmt, $params, $types); $stmt->execute(); @@ -1054,7 +1051,7 @@ public function executeUpdate($query, array $params = [], array $types = []) } $result = $stmt->rowCount(); } else { - $result = $this->_conn->exec($query); + $result = $connection->exec($query); } } catch (Throwable $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types)); @@ -1078,7 +1075,7 @@ public function executeUpdate($query, array $params = [], array $types = []) */ public function exec($statement) { - $this->connect(); + $connection = $this->getWrappedConnection(); $logger = $this->_config->getSQLLogger(); if ($logger) { @@ -1086,7 +1083,7 @@ public function exec($statement) } try { - $result = $this->_conn->exec($statement); + $result = $connection->exec($statement); } catch (Throwable $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement); } @@ -1115,9 +1112,7 @@ public function getTransactionNestingLevel() */ public function errorCode() { - $this->connect(); - - return $this->_conn->errorCode(); + return $this->getWrappedConnection()->errorCode(); } /** @@ -1125,9 +1120,7 @@ public function errorCode() */ public function errorInfo() { - $this->connect(); - - return $this->_conn->errorInfo(); + return $this->getWrappedConnection()->errorInfo(); } /** @@ -1144,9 +1137,7 @@ public function errorInfo() */ public function lastInsertId($seqName = null) { - $this->connect(); - - return $this->_conn->lastInsertId($seqName); + return $this->getWrappedConnection()->lastInsertId($seqName); } /** @@ -1228,7 +1219,7 @@ protected function _getNestedTransactionSavePointName() */ public function beginTransaction() { - $this->connect(); + $connection = $this->getWrappedConnection(); ++$this->transactionNestingLevel; @@ -1238,7 +1229,9 @@ public function beginTransaction() if ($logger) { $logger->startQuery('"START TRANSACTION"'); } - $this->_conn->beginTransaction(); + + $connection->beginTransaction(); + if ($logger) { $logger->stopQuery(); } @@ -1270,7 +1263,7 @@ public function commit() throw ConnectionException::commitFailedRollbackOnly(); } - $this->connect(); + $connection = $this->getWrappedConnection(); $logger = $this->_config->getSQLLogger(); @@ -1278,7 +1271,9 @@ public function commit() if ($logger) { $logger->startQuery('"COMMIT"'); } - $this->_conn->commit(); + + $connection->commit(); + if ($logger) { $logger->stopQuery(); } @@ -1332,7 +1327,7 @@ public function rollBack() throw ConnectionException::noActiveTransaction(); } - $this->connect(); + $connection = $this->getWrappedConnection(); $logger = $this->_config->getSQLLogger(); @@ -1341,7 +1336,7 @@ public function rollBack() $logger->startQuery('"ROLLBACK"'); } $this->transactionNestingLevel = 0; - $this->_conn->rollBack(); + $connection->rollBack(); $this->isRollbackOnly = false; if ($logger) { $logger->stopQuery(); @@ -1380,7 +1375,7 @@ public function createSavepoint($savepoint) throw ConnectionException::savepointsNotSupported(); } - $this->_conn->exec($this->platform->createSavePoint($savepoint)); + $this->getWrappedConnection()->exec($this->platform->createSavePoint($savepoint)); } /** @@ -1402,7 +1397,7 @@ public function releaseSavepoint($savepoint) return; } - $this->_conn->exec($this->platform->releaseSavePoint($savepoint)); + $this->getWrappedConnection()->exec($this->platform->releaseSavePoint($savepoint)); } /** @@ -1420,17 +1415,18 @@ public function rollbackSavepoint($savepoint) throw ConnectionException::savepointsNotSupported(); } - $this->_conn->exec($this->platform->rollbackSavePoint($savepoint)); + $this->getWrappedConnection()->exec($this->platform->rollbackSavePoint($savepoint)); } /** * Gets the wrapped driver connection. * - * @return \Doctrine\DBAL\Driver\Connection + * @return DriverConnection */ public function getWrappedConnection() { $this->connect(); + assert($this->_conn instanceof DriverConnection); return $this->_conn; } @@ -1558,8 +1554,8 @@ private function _bindTypedValues($stmt, array $params, array $types) /** * Gets the binding type of a given type. The given type can be a PDO or DBAL mapping type. * - * @param mixed $value The value to bind. - * @param int|string $type The type to bind (PDO or DBAL). + * @param mixed $value The value to bind. + * @param int|string|null $type The type to bind (PDO or DBAL). * * @return mixed[] [0] => the (escaped) value, [1] => the binding type. */ @@ -1658,10 +1654,10 @@ public function createQueryBuilder() */ public function ping() { - $this->connect(); + $connection = $this->getWrappedConnection(); - if ($this->_conn instanceof PingableConnection) { - return $this->_conn->ping(); + if ($connection instanceof PingableConnection) { + return $connection->ping(); } try { diff --git a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php index 1365e4039fb..ff310d9196b 100644 --- a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php +++ b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Events; use InvalidArgumentException; use function array_rand; +use function assert; use function count; use function func_get_args; @@ -344,6 +345,7 @@ public function rollbackSavepoint($savepoint) public function query() { $this->connect('master'); + assert($this->_conn instanceof DriverConnection); $args = func_get_args(); diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index 5b7465f99fe..02cad00cc43 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -17,8 +17,8 @@ use function is_resource; use function is_string; use function json_encode; +use function preg_replace; use function sprintf; -use function str_split; class DBALException extends Exception { @@ -186,7 +186,7 @@ private static function formatParameters(array $params) if (! is_string($json) || $json === 'null' && is_string($param)) { // JSON encoding failed, this is not a UTF-8 string. - return '"\x' . implode('\x', str_split(bin2hex($param), 2)) . '"'; + return sprintf('"%s"', preg_replace('/.{2}/', '\\x$0', bin2hex($param))); } return $json; diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php index 712cbe419f3..43497fd6026 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php @@ -34,7 +34,7 @@ public function connect(array $params, $username = null, $password = null, array $password = null; } - return new DB2Connection($params, $username, $password, $driverOptions); + return new DB2Connection($params, (string) $username, (string) $password, $driverOptions); } /** diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php b/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php index aaf4f2bd9fd..1166e8d4c2e 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php @@ -13,7 +13,7 @@ class Driver extends AbstractMySQLDriver public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { try { - return new MysqliConnection($params, $username, $password, $driverOptions); + return new MysqliConnection($params, (string) $username, (string) $password, $driverOptions); } catch (MysqliException $e) { throw DBALException::driverException($this, $e); } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 85a88f33401..893b3be4688 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -45,8 +45,8 @@ class MysqliStatement implements IteratorAggregate, Statement /** @var string[]|false|null */ protected $_columnNames; - /** @var mixed[]|null */ - protected $_rowBindedValues; + /** @var mixed[] */ + protected $_rowBindedValues = []; /** @var mixed[] */ protected $_bindedValues; @@ -318,6 +318,7 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX } $values = $this->_fetch(); + if ($values === null) { return false; } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php index 872582d80b7..48195f1517e 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php @@ -18,10 +18,10 @@ public function connect(array $params, $username = null, $password = null, array { try { return new OCI8Connection( - $username, - $password, + (string) $username, + (string) $password, $this->_constructDsn($params), - $params['charset'] ?? null, + $params['charset'] ?? '', $params['sessionMode'] ?? OCI_DEFAULT, $params['persistent'] ?? false ); diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php index 35333e8d2d7..c1857936f5a 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php @@ -10,8 +10,6 @@ use const OCI_DEFAULT; use const OCI_NO_AUTO_COMMIT; use function addcslashes; -use function define; -use function defined; use function func_get_args; use function is_float; use function is_int; @@ -39,21 +37,23 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection /** * Creates a Connection to an Oracle Database using oci8 extension. * - * @param string $username - * @param string $password - * @param string $db - * @param string|null $charset - * @param int $sessionMode - * @param bool $persistent + * @param string $username + * @param string $password + * @param string $db + * @param string $charset + * @param int $sessionMode + * @param bool $persistent * * @throws OCI8Exception */ - public function __construct($username, $password, $db, $charset = null, $sessionMode = OCI_DEFAULT, $persistent = false) - { - if (! defined('OCI_NO_AUTO_COMMIT')) { - define('OCI_NO_AUTO_COMMIT', 0); - } - + public function __construct( + $username, + $password, + $db, + $charset = '', + $sessionMode = OCI_DEFAULT, + $persistent = false + ) { $dbh = $persistent ? @oci_pconnect($username, $password, $db, $charset, $sessionMode) : @oci_connect($username, $password, $db, $charset, $sessionMode); diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index 32feaef93e3..f5a141c1732 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -213,10 +213,9 @@ private static function findPlaceholderOrOpeningQuote( /** * Finds closing quote * - * @param string $statement The SQL statement to parse - * @param string $tokenOffset The offset to start searching from - * @param string|null $currentLiteralDelimiter The delimiter of the current string literal - * or NULL if not currently in a literal + * @param string $statement The SQL statement to parse + * @param string $tokenOffset The offset to start searching from + * @param string $currentLiteralDelimiter The delimiter of the current string literal * * @return bool Whether the token was found */ @@ -274,7 +273,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING) */ public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { - $column = $this->_paramMap[$column] ?? $column; + $column = $this->_paramMap[$column]; if ($type === ParameterType::LARGE_OBJECT) { $lob = oci_new_descriptor($this->_dbh, OCI_D_LOB); diff --git a/lib/Doctrine/DBAL/Driver/PDOConnection.php b/lib/Doctrine/DBAL/Driver/PDOConnection.php index 11f5febc87b..336542ea50a 100644 --- a/lib/Doctrine/DBAL/Driver/PDOConnection.php +++ b/lib/Doctrine/DBAL/Driver/PDOConnection.php @@ -24,7 +24,7 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection public function __construct($dsn, $user = null, $password = null, ?array $options = null) { try { - parent::__construct($dsn, $user, $password, $options); + parent::__construct($dsn, (string) $user, (string) $password, (array) $options); $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (\PDOException $exception) { @@ -95,6 +95,10 @@ public function quote($input, $type = ParameterType::STRING) public function lastInsertId($name = null) { try { + if ($name === null) { + return parent::lastInsertId(); + } + return parent::lastInsertId($name); } catch (\PDOException $exception) { throw new PDOException($exception); diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index f734659c2b7..5be4f2c046d 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -6,7 +6,9 @@ use Doctrine\DBAL\ParameterType; use PDO; use const E_USER_DEPRECATED; +use function array_slice; use function assert; +use function func_get_args; use function is_array; use function sprintf; use function trigger_error; @@ -90,7 +92,7 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l $type = $this->convertParamType($type); try { - return parent::bindParam($column, $variable, $type, $length, $driverOptions); + return parent::bindParam($column, $variable, $type, ...array_slice(func_get_args(), 3)); } catch (\PDOException $exception) { throw new PDOException($exception); } @@ -127,22 +129,14 @@ public function execute($params = null) */ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { - $fetchMode = $this->convertFetchMode($fetchMode); - - try { - if ($fetchMode === null && $cursorOrientation === PDO::FETCH_ORI_NEXT && $cursorOffset === 0) { - return parent::fetch(); - } + $args = func_get_args(); - if ($cursorOrientation === PDO::FETCH_ORI_NEXT && $cursorOffset === 0) { - return parent::fetch($fetchMode); - } - - if ($cursorOffset === 0) { - return parent::fetch($fetchMode, $cursorOrientation); - } + if (isset($args[0])) { + $args[0] = $this->convertFetchMode($args[0]); + } - return parent::fetch($fetchMode, $cursorOrientation, $cursorOffset); + try { + return parent::fetch(...$args); } catch (\PDOException $exception) { throw new PDOException($exception); } @@ -153,7 +147,11 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { - $fetchMode = $this->convertFetchMode($fetchMode); + $args = func_get_args(); + + if (isset($args[0])) { + $args[0] = $this->convertFetchMode($args[0]); + } if ($fetchMode === null && $fetchArgument === null && $ctorArgs === null) { $args = []; @@ -210,14 +208,10 @@ private function convertParamType(int $type) : int /** * Converts DBAL fetch mode to PDO fetch mode * - * @param int|null $fetchMode Fetch mode + * @param int $fetchMode Fetch mode */ - private function convertFetchMode(?int $fetchMode) : ?int + private function convertFetchMode(int $fetchMode) : int { - if ($fetchMode === null) { - return null; - } - if (! isset(self::FETCH_MODE_MAP[$fetchMode])) { // TODO: next major: throw an exception @trigger_error(sprintf( diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index dbda962006a..e36bc9051cf 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -190,6 +190,6 @@ public function errorCode() */ public function errorInfo() { - return sqlsrv_errors(SQLSRV_ERR_ERRORS); + return (array) sqlsrv_errors(SQLSRV_ERR_ERRORS); } } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php index 796f5d129d4..1c1e8c472d7 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php @@ -16,12 +16,11 @@ class SQLSrvException extends AbstractDriverException */ public static function fromSqlSrvErrors() { - $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); $message = ''; $sqlState = null; $errorCode = null; - foreach ($errors as $error) { + foreach ((array) sqlsrv_errors(SQLSRV_ERR_ERRORS) as $error) { $message .= 'SQLSTATE [' . $error['SQLSTATE'] . ', ' . $error['code'] . ']: ' . $error['message'] . "\n"; if ($sqlState === null) { @@ -34,6 +33,7 @@ public static function fromSqlSrvErrors() $errorCode = $error['code']; } + if (! $message) { $message = 'SQL Server error occurred but no error message was retrieved from driver.'; } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index 49ca2567845..453bc8b3f3f 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -180,7 +180,7 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l public function closeCursor() { // not having the result means there's nothing to close - if (! $this->result) { + if ($this->stmt === null || ! $this->result) { return true; } @@ -226,7 +226,7 @@ public function errorCode() */ public function errorInfo() { - return sqlsrv_errors(SQLSRV_ERR_ERRORS); + return (array) sqlsrv_errors(SQLSRV_ERR_ERRORS); } /** @@ -337,7 +337,7 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX { // do not try fetching from the statement if it's not expected to contain result // in order to prevent exceptional situation - if (! $this->result) { + if ($this->stmt === null || ! $this->result) { return false; } diff --git a/lib/Doctrine/DBAL/Driver/Statement.php b/lib/Doctrine/DBAL/Driver/Statement.php index a3ea74a4df5..388983e46a6 100644 --- a/lib/Doctrine/DBAL/Driver/Statement.php +++ b/lib/Doctrine/DBAL/Driver/Statement.php @@ -48,7 +48,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING); * this will be a parameter name of the form :name. For a prepared statement using * question mark placeholders, this will be the 1-indexed position of the parameter. * @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter. - * @param int|null $type Explicit data type for the parameter using the {@link \Doctrine\DBAL\ParameterType} + * @param int $type Explicit data type for the parameter using the {@link \Doctrine\DBAL\ParameterType} * constants. To return an INOUT parameter from a stored procedure, use the bitwise * OR operator to set the PDO::PARAM_INPUT_OUTPUT bits for the data_type parameter. * @param int|null $length You must specify maxlength when using an OUT bind diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 439f6f541d2..6a6c65a4092 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -27,12 +27,14 @@ use Doctrine\DBAL\Types; use Doctrine\DBAL\Types\Type; use InvalidArgumentException; +use UnexpectedValueException; use const E_USER_DEPRECATED; use function addcslashes; use function array_map; use function array_merge; use function array_unique; use function array_values; +use function assert; use function count; use function explode; use function func_get_arg; @@ -486,6 +488,8 @@ public function isCommentedDoctrineType(Type $doctrineType) $this->initializeCommentedDoctrineTypes(); } + assert(is_array($this->doctrineTypeComments)); + return in_array($doctrineType->getName(), $this->doctrineTypeComments); } @@ -502,6 +506,8 @@ public function markDoctrineTypeCommented($doctrineType) $this->initializeCommentedDoctrineTypes(); } + assert(is_array($this->doctrineTypeComments)); + $this->doctrineTypeComments[] = $doctrineType instanceof Type ? $doctrineType->getName() : $doctrineType; } @@ -1419,7 +1425,13 @@ public function getDropTableSQL($table) $this->_eventManager->dispatchEvent(Events::onSchemaDropTable, $eventArgs); if ($eventArgs->isDefaultPrevented()) { - return $eventArgs->getSql(); + $sql = $eventArgs->getSql(); + + if ($sql === null) { + throw new UnexpectedValueException('Default implementation of DROP TABLE was overridden with NULL'); + } + + return $sql; } } diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index bfe2790e30c..88c9b187f9d 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Index; -use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Type; use function array_merge; @@ -571,7 +570,7 @@ public function getAlterTableSQL(TableDiff $diff) } } - $this->gatherAlterColumnSQL($diff->fromTable, $columnDiff, $sql, $queryParts); + $this->gatherAlterColumnSQL($diff->getName($this), $columnDiff, $sql, $queryParts); } foreach ($diff->renamedColumns as $oldColumnName => $column) { @@ -622,12 +621,12 @@ public function getAlterTableSQL(TableDiff $diff) /** * Gathers the table alteration SQL for a given column diff. * - * @param Table $table The table to gather the SQL for. + * @param Identifier $table The table to gather the SQL for. * @param ColumnDiff $columnDiff The column diff to evaluate. * @param string[] $sql The sequence of table alteration statements to fill. * @param mixed[] $queryParts The sequence of column alteration clauses to fill. */ - private function gatherAlterColumnSQL(Table $table, ColumnDiff $columnDiff, array &$sql, array &$queryParts) + private function gatherAlterColumnSQL(Identifier $table, ColumnDiff $columnDiff, array &$sql, array &$queryParts) { $alterColumnClauses = $this->getAlterColumnClausesSQL($columnDiff); diff --git a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php index bb5b5cad36d..ae25e28ee30 100644 --- a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php @@ -47,9 +47,7 @@ public function getIdentifierQuoteCharacter() */ public function getConcatExpression() { - $args = func_get_args(); - - return 'CONCAT(' . implode(', ', (array) $args) . ')'; + return 'CONCAT(' . implode(', ', func_get_args()) . ')'; } /** diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index 0f097de601b..510c153e65f 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -23,7 +23,7 @@ use function get_class; use function implode; use function is_string; -use function preg_replace; +use function preg_match; use function sprintf; use function strlen; use function strpos; @@ -1312,9 +1312,15 @@ protected function doModifyLimitQuery($query, $limit, $offset) { $limitOffsetClause = $this->getTopClauseSQL($limit, $offset); - return $limitOffsetClause === '' - ? $query - : preg_replace('/^\s*(SELECT\s+(DISTINCT\s+)?)/i', '\1' . $limitOffsetClause . ' ', $query); + if ($limitOffsetClause === '') { + return $query; + } + + if (! preg_match('/^\s*(SELECT\s+(DISTINCT\s+)?)(.*)/i', $query, $matches)) { + return $query; + } + + return $matches[1] . $limitOffsetClause . ' ' . $matches[3]; } private function getTopClauseSQL(?int $limit, ?int $offset) : string diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 5ce17aae36b..12419ee6cd4 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -26,7 +26,6 @@ use function is_numeric; use function is_string; use function preg_match; -use function preg_replace; use function sprintf; use function str_replace; use function stripos; @@ -341,9 +340,9 @@ public function getCreatePrimaryKeySQL(Index $index, $table) * as column comments are stored in the same property there when * specifying a column's "Description" attribute. * - * @param string $tableName The quoted table name to which the column belongs. - * @param string $columnName The quoted column name to create the comment for. - * @param string $comment The column's comment. + * @param string $tableName The quoted table name to which the column belongs. + * @param string $columnName The quoted column name to create the comment for. + * @param string|null $comment The column's comment. * * @return string */ @@ -700,9 +699,9 @@ private function alterColumnRequiresDropDefaultConstraint(ColumnDiff $columnDiff * as column comments are stored in the same property there when * specifying a column's "Description" attribute. * - * @param string $tableName The quoted table name to which the column belongs. - * @param string $columnName The quoted column name to alter the comment for. - * @param string $comment The column's comment. + * @param string $tableName The quoted table name to which the column belongs. + * @param string $columnName The quoted column name to alter the comment for. + * @param string|null $comment The column's comment. * * @return string */ @@ -808,10 +807,10 @@ public function getAddExtendedPropertySQL( $level2Name = null ) { return 'EXEC sp_addextendedproperty ' . - 'N' . $this->quoteStringLiteral($name) . ', N' . $this->quoteStringLiteral($value) . ', ' . - 'N' . $this->quoteStringLiteral($level0Type) . ', ' . $level0Name . ', ' . - 'N' . $this->quoteStringLiteral($level1Type) . ', ' . $level1Name . ', ' . - 'N' . $this->quoteStringLiteral($level2Type) . ', ' . $level2Name; + 'N' . $this->quoteStringLiteral($name) . ', N' . $this->quoteStringLiteral((string) $value) . ', ' . + 'N' . $this->quoteStringLiteral((string) $level0Type) . ', ' . $level0Name . ', ' . + 'N' . $this->quoteStringLiteral((string) $level1Type) . ', ' . $level1Name . ', ' . + 'N' . $this->quoteStringLiteral((string) $level2Type) . ', ' . $level2Name; } /** @@ -840,9 +839,9 @@ public function getDropExtendedPropertySQL( ) { return 'EXEC sp_dropextendedproperty ' . 'N' . $this->quoteStringLiteral($name) . ', ' . - 'N' . $this->quoteStringLiteral($level0Type) . ', ' . $level0Name . ', ' . - 'N' . $this->quoteStringLiteral($level1Type) . ', ' . $level1Name . ', ' . - 'N' . $this->quoteStringLiteral($level2Type) . ', ' . $level2Name; + 'N' . $this->quoteStringLiteral((string) $level0Type) . ', ' . $level0Name . ', ' . + 'N' . $this->quoteStringLiteral((string) $level1Type) . ', ' . $level1Name . ', ' . + 'N' . $this->quoteStringLiteral((string) $level2Type) . ', ' . $level2Name; } /** @@ -872,10 +871,10 @@ public function getUpdateExtendedPropertySQL( $level2Name = null ) { return 'EXEC sp_updateextendedproperty ' . - 'N' . $this->quoteStringLiteral($name) . ', N' . $this->quoteStringLiteral($value) . ', ' . - 'N' . $this->quoteStringLiteral($level0Type) . ', ' . $level0Name . ', ' . - 'N' . $this->quoteStringLiteral($level1Type) . ', ' . $level1Name . ', ' . - 'N' . $this->quoteStringLiteral($level2Type) . ', ' . $level2Name; + 'N' . $this->quoteStringLiteral($name) . ', N' . $this->quoteStringLiteral((string) $value) . ', ' . + 'N' . $this->quoteStringLiteral((string) $level0Type) . ', ' . $level0Name . ', ' . + 'N' . $this->quoteStringLiteral((string) $level1Type) . ', ' . $level1Name . ', ' . + 'N' . $this->quoteStringLiteral((string) $level2Type) . ', ' . $level2Name; } /** @@ -1279,9 +1278,11 @@ protected function doModifyLimitQuery($query, $limit, $offset = null) // Even if the TOP n is very large, the use of a CTE will // allow the SQL Server query planner to optimize it so it doesn't // actually scan the entire range covered by the TOP clause. - $selectPattern = '/^(\s*SELECT\s+(?:DISTINCT\s+)?)(.*)$/im'; - $replacePattern = sprintf('$1%s $2', $top); - $query = preg_replace($selectPattern, $replacePattern, $query); + if (! preg_match('/^(\s*SELECT\s+(?:DISTINCT\s+)?)(.*)$/im', $query, $matches)) { + return $query; + } + + $query = $matches[1] . $top . ' ' . $matches[2]; if (stristr($query, 'ORDER BY')) { // Inner order by is not valid in SQL Server for our purposes diff --git a/lib/Doctrine/DBAL/Portability/Connection.php b/lib/Doctrine/DBAL/Portability/Connection.php index 32186dcb0ec..7b4af8a8799 100644 --- a/lib/Doctrine/DBAL/Portability/Connection.php +++ b/lib/Doctrine/DBAL/Portability/Connection.php @@ -121,9 +121,9 @@ public function prepare($statement) */ public function query() { - $this->connect(); + $connection = $this->getWrappedConnection(); - $stmt = $this->_conn->query(...func_get_args()); + $stmt = $connection->query(...func_get_args()); $stmt = new Statement($stmt, $this); $stmt->setFetchMode($this->defaultFetchMode); diff --git a/lib/Doctrine/DBAL/Schema/AbstractAsset.php b/lib/Doctrine/DBAL/Schema/AbstractAsset.php index eb7262e32a6..45af02f5cc9 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractAsset.php +++ b/lib/Doctrine/DBAL/Schema/AbstractAsset.php @@ -84,7 +84,7 @@ public function getNamespaceName() * The shortest name is stripped of the default namespace. All other * namespaced elements are returned as full-qualified names. * - * @param string $defaultNamespaceName + * @param string|null $defaultNamespaceName * * @return string */ diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index d1db70c4c25..eea98c09be4 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -188,7 +188,7 @@ public function listTableIndexes($table) /** * Returns true if all the given tables exist. * - * @param string[] $tableNames + * @param string|string[] $tableNames * * @return bool */ @@ -1098,28 +1098,32 @@ public function getSchemaSearchPaths() * Given a table comment this method tries to extract a typehint for Doctrine Type, or returns * the type given as default. * - * @param string $comment - * @param string $currentType + * @param string|null $comment + * @param string $currentType * * @return string */ public function extractDoctrineTypeFromComment($comment, $currentType) { - if (preg_match('(\(DC2Type:(((?!\)).)+)\))', $comment, $match)) { - $currentType = $match[1]; + if ($comment !== null && preg_match('(\(DC2Type:(((?!\)).)+)\))', $comment, $match)) { + return $match[1]; } return $currentType; } /** - * @param string $comment - * @param string $type + * @param string|null $comment + * @param string|null $type * - * @return string + * @return string|null */ public function removeDoctrineTypeFromComment($comment, $type) { + if ($comment === null) { + return null; + } + return str_replace('(DC2Type:' . $type . ')', '', $comment); } } diff --git a/lib/Doctrine/DBAL/Schema/Column.php b/lib/Doctrine/DBAL/Schema/Column.php index aef471e06fe..56c39c14994 100644 --- a/lib/Doctrine/DBAL/Schema/Column.php +++ b/lib/Doctrine/DBAL/Schema/Column.php @@ -356,7 +356,7 @@ public function setAutoincrement($flag) } /** - * @param string $comment + * @param string|null $comment * * @return Column */ diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index 585732d7dff..84d7808abef 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -253,6 +253,7 @@ public function diffTable(Table $table1, Table $table2) // See if index has changed in table 2. $table2Index = $index->isPrimary() ? $table2->getPrimaryKey() : $table2->getIndex($indexName); + assert($table2Index instanceof Index); if (! $this->diffIndex($index, $table2Index)) { continue; diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index f5e225512ab..0307a0d537d 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -41,7 +41,6 @@ protected function _getPortableTableColumnDefinition($tableColumn) $length = null; $fixed = null; - $unsigned = false; $scale = false; $precision = false; @@ -80,7 +79,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) $options = [ 'length' => $length, - 'unsigned' => (bool) $unsigned, + 'unsigned' => false, 'fixed' => (bool) $fixed, 'default' => $default, 'autoincrement' => (bool) $tableColumn['autoincrement'], diff --git a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php index 0a0977a4027..3c6585e4600 100644 --- a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php +++ b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php @@ -64,7 +64,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint */ public function __construct(array $localColumnNames, $foreignTableName, array $foreignColumnNames, $name = null, array $options = []) { - $this->_setName($name); + if ($name !== null) { + $this->_setName($name); + } $this->_localColumnNames = $this->createIdentifierMap($localColumnNames); diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index f442f54d116..4cc31a9258a 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -10,11 +10,9 @@ use function array_shift; use function array_values; use function assert; -use function end; use function explode; use function is_string; use function preg_match; -use function preg_replace; use function str_replace; use function stripslashes; use function strpos; @@ -78,14 +76,6 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null return parent::_getPortableTableIndexesList($tableIndexes, $tableName); } - /** - * {@inheritdoc} - */ - protected function _getPortableSequenceDefinition($sequence) - { - return end($sequence); - } - /** * {@inheritdoc} */ @@ -227,15 +217,11 @@ private function getMariaDb1027ColumnDefault(MariaDb1027Platform $platform, ?str if ($columnDefault === 'NULL' || $columnDefault === null) { return null; } - if ($columnDefault[0] === "'") { - return stripslashes( - str_replace( - "''", - "'", - preg_replace('/^\'(.*)\'$/', '$1', $columnDefault) - ) - ); + + if (preg_match('/^\'(.*)\'$/', $columnDefault, $matches)) { + return stripslashes(str_replace("''", "'", $matches[1])); } + switch ($columnDefault) { case 'current_timestamp()': return $platform->getCurrentTimestampSQL(); diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index 250ec2a2652..0a3e76b1c51 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Types\Type; +use Throwable; use const CASE_LOWER; use function array_change_key_case; use function array_values; @@ -31,6 +32,7 @@ public function dropDatabase($database) parent::dropDatabase($database); } catch (DBALException $exception) { $exception = $exception->getPrevious(); + assert($exception instanceof Throwable); if (! $exception instanceof DriverException) { throw $exception; diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 168e74ea87f..d0f50562785 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -134,8 +134,8 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) { $onUpdate = null; $onDelete = null; - $localColumns = null; - $foreignColumns = null; + $localColumns = []; + $foreignColumns = []; $foreignTable = null; if (preg_match('(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) { diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index ce3e403ae77..bd6b02cb9a0 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Types\Type; use PDOException; +use Throwable; use function assert; use function count; use function in_array; @@ -31,6 +32,7 @@ public function dropDatabase($database) parent::dropDatabase($database); } catch (DBALException $exception) { $exception = $exception->getPrevious(); + assert($exception instanceof Throwable); if (! $exception instanceof DriverException) { throw $exception; diff --git a/lib/Doctrine/DBAL/Schema/Schema.php b/lib/Doctrine/DBAL/Schema/Schema.php index 7b75f4fb743..5d746654a40 100644 --- a/lib/Doctrine/DBAL/Schema/Schema.php +++ b/lib/Doctrine/DBAL/Schema/Schema.php @@ -105,7 +105,9 @@ protected function _addTable(Table $table) throw SchemaException::tableAlreadyExists($tableName); } - if (! $table->isInDefaultNamespace($this->getName()) && ! $this->hasNamespace($namespaceName)) { + if ($namespaceName !== null + && ! $table->isInDefaultNamespace($this->getName()) + && ! $this->hasNamespace($namespaceName)) { $this->createNamespace($namespaceName); } @@ -127,7 +129,9 @@ protected function _addSequence(Sequence $sequence) throw SchemaException::sequenceAlreadyExists($seqName); } - if (! $sequence->isInDefaultNamespace($this->getName()) && ! $this->hasNamespace($namespaceName)) { + if ($namespaceName !== null + && ! $sequence->isInDefaultNamespace($this->getName()) + && ! $this->hasNamespace($namespaceName)) { $this->createNamespace($namespaceName); } diff --git a/lib/Doctrine/DBAL/Schema/SchemaDiff.php b/lib/Doctrine/DBAL/Schema/SchemaDiff.php index 0f2e25fb32b..69bf125a844 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaDiff.php +++ b/lib/Doctrine/DBAL/Schema/SchemaDiff.php @@ -10,7 +10,7 @@ */ class SchemaDiff { - /** @var Schema */ + /** @var Schema|null */ public $fromSchema; /** diff --git a/lib/Doctrine/DBAL/Schema/Sequence.php b/lib/Doctrine/DBAL/Schema/Sequence.php index 269961fb232..88891019bfd 100644 --- a/lib/Doctrine/DBAL/Schema/Sequence.php +++ b/lib/Doctrine/DBAL/Schema/Sequence.php @@ -104,11 +104,13 @@ public function setCache($cache) */ public function isAutoIncrementsFor(Table $table) { - if (! $table->hasPrimaryKey()) { + $primaryKey = $table->getPrimaryKey(); + + if ($primaryKey === null) { return false; } - $pkColumns = $table->getPrimaryKey()->getColumns(); + $pkColumns = $primaryKey->getColumns(); if (count($pkColumns) !== 1) { return false; diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php index e51b27f3726..0925b7743c8 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php @@ -87,11 +87,14 @@ public function getDropSchema(Schema $dropSchema) } foreach ($dropSchema->getTables() as $table) { - if (! $table->hasPrimaryKey()) { + $primaryKey = $table->getPrimaryKey(); + + if ($primaryKey === null) { continue; } - $columns = $table->getPrimaryKey()->getColumns(); + $columns = $primaryKey->getColumns(); + if (count($columns) > 1) { continue; } diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 5659e578636..6030f25cffa 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -216,7 +216,7 @@ public function renameIndex($oldIndexName, $newIndexName = null) if ($oldIndex->isPrimary()) { $this->dropPrimaryKey(); - return $this->setPrimaryKey($oldIndex->getColumns(), $newIndexName); + return $this->setPrimaryKey($oldIndex->getColumns(), $newIndexName ?? false); } unset($this->_indexes[$oldIndexName]); @@ -589,9 +589,11 @@ public function removeForeignKey($constraintName) */ public function getColumns() { + $primaryKey = $this->getPrimaryKey(); $primaryKeyColumns = []; - if ($this->hasPrimaryKey()) { - $primaryKeyColumns = $this->filterColumns($this->getPrimaryKey()->getColumns()); + + if ($primaryKey !== null) { + $primaryKeyColumns = $this->filterColumns($primaryKey->getColumns()); } return array_merge($primaryKeyColumns, $this->getForeignKeyColumns(), $this->_columns); @@ -681,10 +683,13 @@ public function getPrimaryKey() */ public function getPrimaryKeyColumns() { - if (! $this->hasPrimaryKey()) { + $primaryKey = $this->getPrimaryKey(); + + if ($primaryKey === null) { throw new DBALException('Table ' . $this->getName() . ' has no primary key.'); } - return $this->getPrimaryKey()->getColumns(); + + return $primaryKey->getColumns(); } /** @@ -820,12 +825,16 @@ public function __clone() * * Trims quotes and lowercases the given identifier. * - * @param string $identifier The identifier to normalize. + * @param string|null $identifier The identifier to normalize. * * @return string The normalized identifier. */ private function normalizeIdentifier($identifier) { + if ($identifier === null) { + return ''; + } + return $this->trimQuotes(strtolower($identifier)); } } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php index 318c8b26222..cc15bc0f655 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php @@ -47,7 +47,7 @@ public function acceptNamespace($namespaceName) */ public function acceptTable(Table $table) { - $this->createTableQueries = array_merge($this->createTableQueries, (array) $this->platform->getCreateTableSQL($table)); + $this->createTableQueries = array_merge($this->createTableQueries, $this->platform->getCreateTableSQL($table)); } /** diff --git a/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php b/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php index 7efb39e2863..d5e94cf6ea3 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php @@ -81,7 +81,10 @@ private function createTableLabel(Table $table) $label .= '' . $columnLabel . ''; $label .= '' . strtolower($column->getType()) . ''; $label .= ''; - if ($table->hasPrimaryKey() && in_array($column->getName(), $table->getPrimaryKey()->getColumns())) { + + $primaryKey = $table->getPrimaryKey(); + + if ($primaryKey !== null && in_array($column->getName(), $primaryKey->getColumns())) { $label .= "\xe2\x9c\xb7"; } $label .= ''; diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php index 0adea2894c5..ad345598235 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php @@ -53,7 +53,7 @@ class PoolingShardConnection extends Connection /** @var DriverConnection[] */ private $activeConnections = []; - /** @var int|null */ + /** @var string|int|null */ private $activeShardId; /** @var mixed[] */ @@ -106,7 +106,7 @@ public function __construct(array $params, Driver $driver, ?Configuration $confi /** * Get active shard id. * - * @return int + * @return string|int|null */ public function getActiveShardId() { @@ -164,7 +164,7 @@ public function getPassword() /** * Connects to a given shard. * - * @param mixed $shardId + * @param string|int|null $shardId * * @return bool * @@ -184,15 +184,15 @@ public function connect($shardId = null) throw new ShardingException('Cannot switch shard when transaction is active.'); } - $this->activeShardId = (int) $shardId; + $activeShardId = $this->activeShardId = (int) $shardId; - if (isset($this->activeConnections[$this->activeShardId])) { - $this->_conn = $this->activeConnections[$this->activeShardId]; + if (isset($this->activeConnections[$activeShardId])) { + $this->_conn = $this->activeConnections[$activeShardId]; return false; } - $this->_conn = $this->activeConnections[$this->activeShardId] = $this->connectTo($this->activeShardId); + $this->_conn = $this->activeConnections[$activeShardId] = $this->connectTo($activeShardId); if ($this->_eventManager->hasListeners(Events::postConnect)) { $eventArgs = new ConnectionEventArgs($this); @@ -224,7 +224,7 @@ protected function connectTo($shardId) } /** - * @param string|null $shardId + * @param string|int|null $shardId * * @return bool */ diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 22f53630b64..7aca228c393 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 6 + level: 7 paths: - %currentWorkingDirectory%/lib autoload_files: @@ -12,7 +12,12 @@ parameters: # removing it would be BC break - '~^Constructor of class Doctrine\\DBAL\\Schema\\Table has an unused parameter \$idGeneratorType\.\z~' + # declaring $tableName in AbstractSchemaManager::_getPortableTableIndexesList() non-optional will be a BC break + - '~^Parameter #2 \$table of class Doctrine\\DBAL\\Event\\SchemaIndexDefinitionEventArgs constructor expects string, string\|null given\.\z~' + # changing these would be a BC break, to be done in next major + - "~^Casting to bool something that's already bool.~" + - "~^Casting to int something that's already int.~" - '~^Method Doctrine\\DBAL\\Driver\\IBMDB2\\DB2Connection::exec\(\) should return int but returns bool\.\z~' - '~^Method Doctrine\\DBAL\\Query\\QueryBuilder::execute\(\) should return Doctrine\\DBAL\\Driver\\Statement\|int but returns Doctrine\\DBAL\\Driver\\ResultStatement\.\z~' - '~^Property Doctrine\\DBAL\\Schema\\Table::\$_primaryKeyName \(string\) does not accept (default value of type )?false\.\z~' @@ -33,6 +38,9 @@ parameters: - '~^Parameter #2 \$registeredAliases of static method Doctrine\\DBAL\\Query\\QueryException::unknownAlias\(\) expects array, array given\.\z~' - '~^Parameter #2 \$registeredAliases of static method Doctrine\\DBAL\\Query\\QueryException::nonUniqueAlias\(\) expects array, array given\.\z~' + # PHPStan is too strict about preg_replace(): https://phpstan.org/r/993dc99f-0d43-4b51-868b-d01f982c1463 + - '~^Method Doctrine\\DBAL\\Platforms\\AbstractPlatform::escapeStringForLike\(\) should return string but returns string|null\.\z~' + # legacy variadic-like signature - '~^Method Doctrine\\DBAL\\Driver\\Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~' diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 3b085ea54c1..a2a72bdf207 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -28,7 +28,6 @@ use Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock; use Exception; use PHPUnit\Framework\MockObject\MockObject; -use ReflectionObject; use stdClass; use function call_user_func_array; @@ -605,29 +604,6 @@ public function testFetchColumn() self::assertSame($result, $conn->fetchColumn($statement, $params, $column, $types)); } - public function testConnectionIsClosedButNotUnset() - { - // mock Connection, and make connect() purposefully do nothing - $connection = $this->getMockBuilder(Connection::class) - ->disableOriginalConstructor() - ->setMethods(['connect']) - ->getMock(); - - // artificially set the wrapped connection to non-null - $reflection = new ReflectionObject($connection); - $connProperty = $reflection->getProperty('_conn'); - $connProperty->setAccessible(true); - $connProperty->setValue($connection, new stdClass()); - - // close the connection (should nullify the wrapped connection) - $connection->close(); - - // the wrapped connection should be null - // (and since connect() does nothing, this will not reconnect) - // this will also fail if this _conn property was unset instead of set to null - self::assertNull($connection->getWrappedConnection()); - } - public function testFetchAll() { $statement = 'SELECT * FROM foo WHERE bar = ?'; diff --git a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php index 6f4e0642db1..73308f8e7b3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\ColumnCase; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\PDOSqlsrv\Driver; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Portability\Connection as ConnectionPortability; @@ -136,29 +135,6 @@ public function assertFetchResultRow($row) self::assertArrayNotHasKey(0, $row, 'The row should not contain numerical keys.'); } - /** - * @requires extension pdo - */ - public function testPortabilityPdoSqlServer() - { - $portability = ConnectionPortability::PORTABILITY_SQLSRV; - $params = ['portability' => $portability]; - - $driverMock = $this->getMockBuilder(Driver::class) - ->setMethods(['connect']) - ->getMock(); - - $driverMock->expects($this->once()) - ->method('connect') - ->will($this->returnValue(null)); - - $connection = new ConnectionPortability($params, $driverMock); - - $connection->connect($params); - - self::assertEquals($portability, $connection->getPortability()); - } - /** * @param string $field * @param mixed[] $expected diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php index 790ba66db7b..e35583182a1 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -39,11 +39,13 @@ protected function setUp() : void ->getMockForAbstractClass(); $this->visitor = new CreateSchemaSqlCollector($this->platformMock); - foreach (['getCreateSchemaSQL', 'getCreateTableSQL', 'getCreateForeignKeySQL', 'getCreateSequenceSQL'] as $method) { - $this->platformMock->expects($this->any()) - ->method($method) - ->will($this->returnValue('foo')); + foreach (['getCreateSchemaSQL', 'getCreateForeignKeySQL', 'getCreateSequenceSQL'] as $method) { + $this->platformMock->method($method) + ->willReturn('foo'); } + + $this->platformMock->method('getCreateTableSQL') + ->willReturn(['foo']); } public function testAcceptsNamespace() From b43f582536779794ee8e5d95e43fa2855d02fda4 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 7 Feb 2019 20:29:20 -0800 Subject: [PATCH 033/106] Fixed mistakenly passing builds on AppVeyor PowerShell doesn't automatically handle exit codes of the invoked commands automatically, and $ErrorActionPreference = "Stop" doesn't seem working. Additionally, the ocular command is moved out of the "test_script" section to "after_test" since it's not part of the actual test. --- .appveyor.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 636c269d846..cfdc76aeb08 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -131,17 +131,25 @@ before_test: } test_script: - - cd C:\projects\dbal - ps: >- if ($env:db_version) { $env:phpunit_config = "tests\appveyor\$($env:db).$($env:db_version).$($env:driver).appveyor.xml" } else { $env:phpunit_config = "tests\appveyor\$($env:db).$($env:driver).appveyor.xml" } - - ps: >- + if ($env:coverage -eq "yes") { vendor\bin\phpunit -c $($env:phpunit_config) --coverage-clover clover.xml - appveyor-retry ocular code-coverage:upload --format=php-clover clover.xml } else { vendor\bin\phpunit -c $($env:phpunit_config) } + + if ($LastExitCode -ne 0) { + $host.SetShouldExit($LastExitCode) + } + +after_test: + - ps: >- + if ($env:coverage -eq "yes") { + appveyor-retry ocular code-coverage:upload --format=php-clover clover.xml + } From ccc6a0afab3be41dc985968cb6c0108f5c7508c4 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 8 Feb 2019 15:31:19 -0800 Subject: [PATCH 034/106] Fixed regression on SQL Server introduced by a recent rework --- lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 12419ee6cd4..616faf6664a 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1278,7 +1278,7 @@ protected function doModifyLimitQuery($query, $limit, $offset = null) // Even if the TOP n is very large, the use of a CTE will // allow the SQL Server query planner to optimize it so it doesn't // actually scan the entire range covered by the TOP clause. - if (! preg_match('/^(\s*SELECT\s+(?:DISTINCT\s+)?)(.*)$/im', $query, $matches)) { + if (! preg_match('/^(\s*SELECT\s+(?:DISTINCT\s+)?)(.*)$/is', $query, $matches)) { return $query; } From 6896a75aa30001dd50e8255f61bfc2042755563f Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sat, 9 Feb 2019 17:51:01 +0100 Subject: [PATCH 035/106] CI: Test against PHP 7.4snapshot instead of nightly (8.0) --- .travis.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index ab3ae2525a2..5a6a69914d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ after_script: jobs: allow_failures: - - php: nightly + - php: 7.4snapshot include: @@ -275,7 +275,7 @@ jobs: - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test - php: nightly + php: 7.4snapshot env: DB=mysql.docker MYSQL_VERSION=8.0 sudo: required services: @@ -283,7 +283,7 @@ jobs: before_script: - bash ./tests/travis/install-mysql-8.0.sh - stage: Test - php: nightly + php: 7.4snapshot env: DB=mysqli.docker MYSQL_VERSION=8.0 sudo: required services: @@ -291,17 +291,17 @@ jobs: before_script: - bash ./tests/travis/install-mysql-8.0.sh - stage: Test - php: nightly + php: 7.4snapshot env: DB=mariadb MARIADB_VERSION=10.3 addons: mariadb: 10.3 - stage: Test - php: nightly + php: 7.4snapshot env: DB=mariadb.mysqli MARIADB_VERSION=10.3 addons: mariadb: 10.3 - stage: Test - php: nightly + php: 7.4snapshot env: DB=pgsql POSTGRESQL_VERSION=11.0 sudo: required services: @@ -309,10 +309,10 @@ jobs: before_script: - bash ./tests/travis/install-postgres-11.sh - stage: Test - php: nightly + php: 7.4snapshot env: DB=sqlite - stage: Test - php: nightly + php: 7.4snapshot env: DB=sqlsrv sudo: required services: @@ -321,7 +321,7 @@ jobs: - bash ./tests/travis/install-mssql-sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test - php: nightly + php: 7.4snapshot env: DB=pdo_sqlsrv sudo: required services: From c7450d2b4489681199ed0290e5d54363afada5c9 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 20 Feb 2019 10:16:53 -0800 Subject: [PATCH 036/106] Replaced MySQL 5.7 installed from a PPA with an official Docker image See https://travis-ci.org/doctrine/dbal/jobs/495144274 for the PPA issue. --- .travis.yml | 4 ++-- tests/travis/install-mysql-5.7.sh | 25 +++++++++---------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5a6a69914d4..62e1a3d5c0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,7 +65,7 @@ jobs: env: DB=mysql COVERAGE=yes - stage: Test php: 7.2 - env: DB=mysql MYSQL_VERSION=5.7 COVERAGE=yes + env: DB=mysql.docker MYSQL_VERSION=5.7 COVERAGE=yes sudo: required before_script: - bash ./tests/travis/install-mysql-5.7.sh @@ -82,7 +82,7 @@ jobs: env: DB=mysqli COVERAGE=yes - stage: Test php: 7.2 - env: DB=mysqli MYSQL_VERSION=5.7 COVERAGE=yes + env: DB=mysqli.docker MYSQL_VERSION=5.7 COVERAGE=yes sudo: required before_script: - bash ./tests/travis/install-mysql-5.7.sh diff --git a/tests/travis/install-mysql-5.7.sh b/tests/travis/install-mysql-5.7.sh index 686fa34c991..25459382c6f 100644 --- a/tests/travis/install-mysql-5.7.sh +++ b/tests/travis/install-mysql-5.7.sh @@ -2,21 +2,14 @@ set -ex -echo "Installing MySQL 5.7..." +echo "Starting MySQL 5.7..." -sudo service mysql stop -sudo apt-get remove "^mysql.*" -sudo apt-get autoremove -sudo apt-get autoclean -echo mysql-apt-config mysql-apt-config/select-server select mysql-5.7 | sudo debconf-set-selections -wget http://dev.mysql.com/get/mysql-apt-config_0.8.9-1_all.deb -sudo DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.8.9-1_all.deb -sudo rm -rf /var/lib/apt/lists/* -sudo apt-get clean -sudo apt-get update -q -sudo apt-get install -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" mysql-server libmysqlclient-dev -sudo mysql_upgrade - -echo "Restart mysql..." -sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;" +sudo docker run \ + -d \ + -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ + -e MYSQL_DATABASE=doctrine_tests \ + -p 33306:3306 \ + --name mysql57 \ + mysql:5.7 +sudo docker exec -i mysql57 bash <<< 'until echo \\q | mysql doctrine_tests > /dev/null 2>&1 ; do sleep 1; done' From b0ed680fc3dd7be4f98c3956e2c382615841b652 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 22 Feb 2019 16:23:50 -0800 Subject: [PATCH 037/106] Marked some test classes abstract 1. SchemaManagerFunctionalTestCase can be run only via an extending class. Otherwise, it skips all tests. If the test case is represented as an abstract class, PhpStorm will offer a choise of concrete classes which is very handy when debugging test failures. 2. DbalFunctionalTestCase and DbalPerformanceTestCase are meant to be used as base classes and don't contain any tests. --- .../DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php | 2 +- tests/Doctrine/Tests/DbalFunctionalTestCase.php | 2 +- tests/Doctrine/Tests/DbalPerformanceTestCase.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 6c2679baebb..c9826f14243 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -46,7 +46,7 @@ use function strtolower; use function substr; -class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase +abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase { /** @var AbstractSchemaManager */ protected $schemaManager; diff --git a/tests/Doctrine/Tests/DbalFunctionalTestCase.php b/tests/Doctrine/Tests/DbalFunctionalTestCase.php index 149db8bf998..1e37c3060e8 100644 --- a/tests/Doctrine/Tests/DbalFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DbalFunctionalTestCase.php @@ -18,7 +18,7 @@ use function strpos; use function var_export; -class DbalFunctionalTestCase extends DbalTestCase +abstract class DbalFunctionalTestCase extends DbalTestCase { /** * Shared connection when a TestCase is run alone (outside of it's functional suite) diff --git a/tests/Doctrine/Tests/DbalPerformanceTestCase.php b/tests/Doctrine/Tests/DbalPerformanceTestCase.php index 0001431454a..f9bb40df38c 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestCase.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestCase.php @@ -11,7 +11,7 @@ * and stopTiming at the end of all tests. Tests that do not start or stop * timing will fail. */ -class DbalPerformanceTestCase extends DbalFunctionalTestCase +abstract class DbalPerformanceTestCase extends DbalFunctionalTestCase { /** * time the test started From e96c01736552977061d3620f0e9b358a4269d98c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 22 Feb 2019 17:23:00 -0800 Subject: [PATCH 038/106] Replaced Xdebug with PCOV for code coverage --- .travis.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 62e1a3d5c0a..9620b0c3c14 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,18 +8,14 @@ cache: - $HOME/.composer/cache before_install: + - phpenv config-rm xdebug.ini || true - | - if [ "x$COVERAGE" != "xyes" ]; then - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || true + if [ "x$COVERAGE" == "xyes" ]; then + pecl install pcov-1.0.0 fi before_script: - if [[ "$DB" == "mysql" || "$DB" == "mysqli" || "$DB" == *"mariadb"* ]]; then mysql < tests/travis/create-mysql-schema.sql; fi; - - | - if [ "x$COVERAGE" == "xyes" ] && [[ ! $(php -m | grep -si xdebug) ]]; then - echo "xdebug is required for coverage" - exit 1 - fi install: - rm composer.lock From c61c0b91579bbbdd1032e7b106e108209eaa0ae9 Mon Sep 17 00:00:00 2001 From: adapik Date: Tue, 19 Feb 2019 10:34:11 +0300 Subject: [PATCH 039/106] fixed a typo in PoolingShardConnection phpdoc --- lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php index ad345598235..8d8134127d7 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php @@ -26,7 +26,7 @@ * - By default, the global shard is selected. If no global shard is configured * an exception is thrown on access. * - Selecting a shard by distribution value delegates the mapping - * "distributionValue" => "client" to the ShardChooser interface. + * "distributionValue" => "client" to the ShardChoser interface. * - An exception is thrown if trying to switch shards during an open * transaction. * From d4be62fb518507efe0881cafa1a61bf86a58d2e5 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 24 Feb 2019 00:32:01 -0800 Subject: [PATCH 040/106] Replaced MockPlatform with the ones generated by PHPUnit --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 32 +++--- .../Doctrine/Tests/DBAL/DriverManagerTest.php | 10 +- .../Tests/DBAL/Mocks/MockPlatform.php | 100 ------------------ .../Tests/DBAL/Schema/SchemaDiffTest.php | 12 ++- .../Tests/DBAL/Schema/TableDiffTest.php | 20 ++-- tests/Doctrine/Tests/DBAL/StatementTest.php | 16 ++- tests/Doctrine/Tests/DBAL/Types/ArrayTest.php | 9 +- .../Tests/DBAL/Types/BaseDateTypeTestCase.php | 7 +- .../Doctrine/Tests/DBAL/Types/BinaryTest.php | 13 ++- tests/Doctrine/Tests/DBAL/Types/BlobTest.php | 7 +- .../Doctrine/Tests/DBAL/Types/BooleanTest.php | 10 +- .../Tests/DBAL/Types/DateIntervalTest.php | 7 +- .../Doctrine/Tests/DBAL/Types/DecimalTest.php | 10 +- tests/Doctrine/Tests/DBAL/Types/FloatTest.php | 10 +- .../Tests/DBAL/Types/GuidTypeTest.php | 16 +-- .../Doctrine/Tests/DBAL/Types/IntegerTest.php | 10 +- .../Tests/DBAL/Types/JsonArrayTest.php | 13 ++- tests/Doctrine/Tests/DBAL/Types/JsonTest.php | 13 ++- .../Doctrine/Tests/DBAL/Types/ObjectTest.php | 10 +- .../Tests/DBAL/Types/SmallIntTest.php | 10 +- .../Doctrine/Tests/DBAL/Types/StringTest.php | 20 +++- .../Tests/DBAL/Types/VarDateTimeTest.php | 9 +- 22 files changed, 160 insertions(+), 204 deletions(-) delete mode 100644 tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index a2a72bdf207..3eed3a72650 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -53,7 +53,10 @@ protected function setUp() : void $this->connection = DriverManager::getConnection($this->params); } - public function getExecuteUpdateMockConnection() + /** + * @return Connection|MockObject + */ + private function getExecuteUpdateMockConnection() { $driverMock = $this->createMock(Driver::class); @@ -63,9 +66,11 @@ public function getExecuteUpdateMockConnection() $this->createMock(DriverConnection::class) )); + $platform = $this->getMockForAbstractClass(AbstractPlatform::class); + return $this->getMockBuilder(Connection::class) ->setMethods(['executeUpdate']) - ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) + ->setConstructorArgs([['platform' => $platform], $driverMock]) ->getMock(); } @@ -153,9 +158,8 @@ public function testConnectDispatchEvent() $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->at(0)) ->method('connect'); - $platform = new Mocks\MockPlatform(); - $conn = new Connection(['platform' => $platform], $driverMock, new Configuration(), $eventManager); + $conn = new Connection([], $driverMock, new Configuration(), $eventManager); $conn->connect(); } @@ -249,7 +253,7 @@ public function testConnectStartsTransactionInNoAutoCommitMode() ->will($this->returnValue( $this->createMock(DriverConnection::class) )); - $conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); + $conn = new Connection([], $driverMock); $conn->setAutoCommit(false); @@ -271,7 +275,7 @@ public function testCommitStartsTransactionInNoAutoCommitMode() ->will($this->returnValue( $this->createMock(DriverConnection::class) )); - $conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); + $conn = new Connection([], $driverMock); $conn->setAutoCommit(false); $conn->connect(); @@ -291,7 +295,7 @@ public function testRollBackStartsTransactionInNoAutoCommitMode() ->will($this->returnValue( $this->createMock(DriverConnection::class) )); - $conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); + $conn = new Connection([], $driverMock); $conn->setAutoCommit(false); $conn->connect(); @@ -311,7 +315,7 @@ public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() ->will($this->returnValue( $this->createMock(DriverConnection::class) )); - $conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); + $conn = new Connection([], $driverMock); $conn->connect(); $conn->beginTransaction(); @@ -520,7 +524,7 @@ public function testFetchAssoc() /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeQuery']) - ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) + ->setConstructorArgs([[], $driverMock]) ->getMock(); $conn->expects($this->once()) @@ -556,7 +560,7 @@ public function testFetchArray() /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeQuery']) - ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) + ->setConstructorArgs([[], $driverMock]) ->getMock(); $conn->expects($this->once()) @@ -593,7 +597,7 @@ public function testFetchColumn() /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeQuery']) - ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) + ->setConstructorArgs([[], $driverMock]) ->getMock(); $conn->expects($this->once()) @@ -628,7 +632,7 @@ public function testFetchAll() /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeQuery']) - ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) + ->setConstructorArgs([[], $driverMock]) ->getMock(); $conn->expects($this->once()) @@ -694,8 +698,8 @@ public function dataCallConnectOnce() public function testCallConnectOnce($method, $params) { $driverMock = $this->createMock(Driver::class); - $pdoMock = $this->createMock(\Doctrine\DBAL\Driver\Connection::class); - $platformMock = new Mocks\MockPlatform(); + $pdoMock = $this->createMock(Connection::class); + $platformMock = $this->createMock(AbstractPlatform::class); $stmtMock = $this->createMock(Statement::class); $pdoMock->expects($this->any()) diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index 828e4fc1a3a..0fe228aa45a 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -9,9 +9,9 @@ use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSqliteDriver; use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Sharding\PoolingShardConnection; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; @@ -77,14 +77,14 @@ public function testInvalidDriver() */ public function testCustomPlatform() { - $mockPlatform = new MockPlatform(); - $options = [ + $platform = $this->createMock(AbstractPlatform::class); + $options = [ 'pdo' => new PDO('sqlite::memory:'), - 'platform' => $mockPlatform, + 'platform' => $platform, ]; $conn = DriverManager::getConnection($options); - self::assertSame($mockPlatform, $conn->getDatabasePlatform()); + self::assertSame($platform, $conn->getDatabasePlatform()); } /** diff --git a/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php b/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php deleted file mode 100644 index 6a3f3d8e376..00000000000 --- a/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php +++ /dev/null @@ -1,100 +0,0 @@ -createMock(MockPlatform::class); + /** @var AbstractPlatform|MockObject $platform */ + $platform = $this->createMock(AbstractPlatform::class); $platform->expects($this->exactly(1)) ->method('getCreateSchemaSQL') ->with('foo_ns') @@ -93,6 +98,7 @@ public function createPlatform($unsafe = false) $platform->expects($this->exactly(2)) ->method('supportsForeignKeyConstraints') ->will($this->returnValue(true)); + return $platform; } diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php index 80b9ef7b2c2..ae1682739c6 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php @@ -2,14 +2,23 @@ namespace Doctrine\Tests\DBAL\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class TableDiffTest extends TestCase { + /** @var AbstractPlatform|MockObject */ + private $platform; + + public function setUp() : void + { + $this->platform = $this->createMock(AbstractPlatform::class); + } + /** * @group DBAL-1013 */ @@ -17,7 +26,7 @@ public function testReturnsName() { $tableDiff = new TableDiff('foo'); - self::assertEquals(new Identifier('foo'), $tableDiff->getName(new MockPlatform())); + self::assertEquals(new Identifier('foo'), $tableDiff->getName($this->platform)); } /** @@ -25,8 +34,7 @@ public function testReturnsName() */ public function testPrefersNameFromTableObject() { - $platformMock = new MockPlatform(); - $tableMock = $this->getMockBuilder(Table::class) + $tableMock = $this->getMockBuilder(Table::class) ->disableOriginalConstructor() ->getMock(); @@ -35,10 +43,10 @@ public function testPrefersNameFromTableObject() $tableMock->expects($this->once()) ->method('getQuotedName') - ->with($platformMock) + ->with($this->platform) ->will($this->returnValue('foo')); - self::assertEquals(new Identifier('foo'), $tableDiff->getName($platformMock)); + self::assertEquals(new Identifier('foo'), $tableDiff->getName($this->platform)); } /** diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index f7ff02d2ac6..1dae44d253d 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -10,7 +10,6 @@ use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Statement; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; use Exception; use PDOStatement; @@ -31,19 +30,16 @@ protected function setUp() : void $this->pdoStatement = $this->getMockBuilder(PDOStatement::class) ->setMethods(['execute', 'bindParam', 'bindValue']) ->getMock(); - $platform = new MockPlatform(); - $driverConnection = $this->createMock(DriverConnection::class); + + $driverConnection = $this->createMock(DriverConnection::class); $driverConnection->expects($this->any()) ->method('prepare') ->will($this->returnValue($this->pdoStatement)); - $driver = $this->createMock(Driver::class); - $constructorArgs = [ - ['platform' => $platform], - $driver, - ]; - $this->conn = $this->getMockBuilder(Connection::class) - ->setConstructorArgs($constructorArgs) + $driver = $this->createMock(Driver::class); + + $this->conn = $this->getMockBuilder(Connection::class) + ->setConstructorArgs([[], $driver]) ->getMock(); $this->conn->expects($this->atLeastOnce()) ->method('getWrappedConnection') diff --git a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php index 66181f7e0c8..6f09cbf2bc0 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php @@ -3,23 +3,24 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\ArrayType; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; use function serialize; class ArrayTest extends DbalTestCase { - /** @var AbstractPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var Type */ + /** @var ArrayType */ private $type; protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('array'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php index 2b447d95cfd..3e73c96e7c9 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php @@ -4,9 +4,10 @@ use DateTime; use DateTimeImmutable; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use stdClass; use function date_default_timezone_get; @@ -14,7 +15,7 @@ abstract class BaseDateTypeTestCase extends TestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ protected $platform; /** @var Type */ @@ -28,7 +29,7 @@ abstract class BaseDateTypeTestCase extends TestCase */ protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); $this->currentTimezone = date_default_timezone_get(); self::assertInstanceOf(Type::class, $this->type); diff --git a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php index e5bd3c201dc..b26a35cab42 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php @@ -3,18 +3,19 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; use function base64_encode; use function fopen; use function stream_get_contents; class BinaryTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ protected $platform; /** @var BinaryType */ @@ -25,7 +26,7 @@ class BinaryTest extends DbalTestCase */ protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('binary'); } @@ -41,7 +42,11 @@ public function testReturnsName() public function testReturnsSQLDeclaration() { - self::assertSame('DUMMYBINARY', $this->type->getSQLDeclaration([], $this->platform)); + $this->platform->expects($this->once()) + ->method('getBinaryTypeDeclarationSQL') + ->willReturn('TEST_BINARY'); + + self::assertSame('TEST_BINARY', $this->type->getSQLDeclaration([], $this->platform)); } public function testBinaryNullConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php index 57f26004140..70bbcf55967 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php @@ -2,10 +2,11 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; use function base64_encode; use function chr; use function fopen; @@ -13,7 +14,7 @@ class BlobTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ protected $platform; /** @var BlobType */ @@ -24,7 +25,7 @@ class BlobTest extends DbalTestCase */ protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('blob'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php index ad9dcc673bf..af84fbf00d2 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php @@ -2,21 +2,23 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\BooleanType; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; class BooleanTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var Type */ + /** @var BooleanType */ private $type; protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); $this->type = Type::getType('boolean'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php index 27d83ae7df7..710474257af 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php @@ -4,16 +4,17 @@ use DateInterval; use DateTime; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateIntervalType; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; use stdClass; final class DateIntervalTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; /** @var DateIntervalType */ @@ -24,7 +25,7 @@ final class DateIntervalTest extends DbalTestCase */ protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('dateinterval'); self::assertInstanceOf(DateIntervalType::class, $this->type); diff --git a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php index e702f7718ff..7087d2a6a49 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php @@ -2,21 +2,23 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\DecimalType; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; class DecimalTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var Type */ + /** @var DecimalType */ private $type; protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('decimal'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php index b3da2257c72..6daffd7d29b 100644 --- a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php @@ -2,21 +2,23 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\FloatType; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; class FloatTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var Type */ + /** @var FloatType */ private $type; protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('float'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php index b35670405d4..bbd309bea6d 100644 --- a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php @@ -2,22 +2,23 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\GuidType; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; -use function get_class; +use PHPUnit\Framework\MockObject\MockObject; class GuidTypeTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var Type */ + /** @var GuidType */ private $type; protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('guid'); } @@ -36,11 +37,10 @@ public function testNativeGuidSupport() { self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); - $mock = $this->createMock(get_class($this->platform)); - $mock->expects($this->any()) + $this->platform->expects($this->any()) ->method('hasNativeGuidType') ->will($this->returnValue(true)); - self::assertFalse($this->type->requiresSQLCommentHint($mock)); + self::assertFalse($this->type->requiresSQLCommentHint($this->platform)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php index 11e0f91c5fe..789de21e208 100644 --- a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php @@ -2,21 +2,23 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\IntegerType; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; class IntegerTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var Type */ + /** @var IntegerType */ private $type; protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('integer'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index 8bc0ed1d8f8..730234dc85f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -3,17 +3,18 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\JsonArrayType; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; use function base64_encode; use function fopen; use function json_encode; class JsonArrayTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ protected $platform; /** @var JsonArrayType */ @@ -24,7 +25,7 @@ class JsonArrayTest extends DbalTestCase */ protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('json_array'); } @@ -40,7 +41,11 @@ public function testReturnsName() public function testReturnsSQLDeclaration() { - self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration([], $this->platform)); + $this->platform->expects($this->once()) + ->method('getJsonTypeDeclarationSQL') + ->willReturn('TEST_JSON'); + + self::assertSame('TEST_JSON', $this->type->getSQLDeclaration([], $this->platform)); } public function testJsonNullConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index e36c84a33d4..123291f53b6 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -3,18 +3,19 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\JsonType; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; use function base64_encode; use function fopen; use function json_encode; class JsonTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ protected $platform; /** @var JsonType */ @@ -25,7 +26,7 @@ class JsonTest extends DbalTestCase */ protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('json'); } @@ -41,7 +42,11 @@ public function testReturnsName() public function testReturnsSQLDeclaration() { - self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration([], $this->platform)); + $this->platform->expects($this->once()) + ->method('getJsonTypeDeclarationSQL') + ->willReturn('TEST_JSON'); + + self::assertSame('TEST_JSON', $this->type->getSQLDeclaration([], $this->platform)); } public function testJsonNullConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index 0176f35a295..f8852ff1640 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -2,24 +2,26 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\ObjectType; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; use stdClass; use function serialize; class ObjectTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var Type */ + /** @var ObjectType */ private $type; protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('object'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php index d7c98caad4a..8aecc6649fa 100644 --- a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php @@ -2,21 +2,23 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\SmallIntType; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; class SmallIntTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var Type */ + /** @var SmallIntType */ private $type; protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('smallint'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/StringTest.php b/tests/Doctrine/Tests/DBAL/Types/StringTest.php index 651058811f2..4ffb9af7d96 100644 --- a/tests/Doctrine/Tests/DBAL/Types/StringTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/StringTest.php @@ -2,31 +2,41 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\StringType; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; class StringTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var Type */ + /** @var StringType */ private $type; protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); $this->type = Type::getType('string'); } public function testReturnsSqlDeclarationFromPlatformVarchar() { - self::assertEquals('DUMMYVARCHAR()', $this->type->getSqlDeclaration([], $this->platform)); + $this->platform->expects($this->once()) + ->method('getVarcharTypeDeclarationSQL') + ->willReturn('TEST_VARCHAR'); + + self::assertEquals('TEST_VARCHAR', $this->type->getSqlDeclaration([], $this->platform)); } public function testReturnsDefaultLengthFromPlatformVarchar() { + $this->platform->expects($this->once()) + ->method('getVarcharDefaultLength') + ->willReturn(255); + self::assertEquals(255, $this->type->getDefaultLength($this->platform)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index 516f42836b4..0807b25f022 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -3,23 +3,24 @@ namespace Doctrine\Tests\DBAL\Types; use DateTime; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\VarDateTimeType; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; class VarDateTimeTest extends DbalTestCase { - /** @var MockPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var Type */ + /** @var VarDateTimeType */ private $type; protected function setUp() : void { - $this->platform = new MockPlatform(); + $this->platform = $this->createMock(AbstractPlatform::class); if (! Type::hasType('vardatetime')) { Type::addType('vardatetime', VarDateTimeType::class); } From 8a1b0a2dac7cb15f874a78cbe77a0dadc201db44 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 26 Feb 2019 07:45:13 -0800 Subject: [PATCH 041/106] Avoid database connection from PHPUnit data providers --- .../Functional/Driver/AbstractDriverTest.php | 7 +--- .../Functional/Driver/PDOPgSql/DriverTest.php | 11 ++++-- .../Driver/PDOSqlsrv/DriverTest.php | 2 +- .../Functional/Driver/SQLSrv/DriverTest.php | 2 +- tests/Doctrine/Tests/TestUtil.php | 39 +++++++++---------- 5 files changed, 30 insertions(+), 31 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php index 8a0418d2f0a..2e145ca6c04 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php @@ -55,7 +55,7 @@ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() ); self::assertSame( - $this->getDatabaseNameForConnectionWithoutDatabaseNameParameter(), + static::getDatabaseNameForConnectionWithoutDatabaseNameParameter(), $this->driver->getDatabase($connection) ); } @@ -65,10 +65,7 @@ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() */ abstract protected function createDriver(); - /** - * @return string|null - */ - protected function getDatabaseNameForConnectionWithoutDatabaseNameParameter() + protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string { return null; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php index 2ea657cfa99..347982b24e5 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php @@ -50,9 +50,12 @@ public function testDatabaseParameters($databaseName, $defaultDatabaseName, $exp ); } - public function getDatabaseParameter() + /** + * @return mixed[][] + */ + public static function getDatabaseParameter() : iterable { - $params = TestUtil::getConnection()->getParams(); + $params = TestUtil::getConnectionParams(); $realDatabaseName = $params['dbname'] ?? ''; $dummyDatabaseName = $realDatabaseName . 'a'; @@ -61,7 +64,7 @@ public function getDatabaseParameter() [$realDatabaseName, null, $realDatabaseName], [$realDatabaseName, $dummyDatabaseName, $realDatabaseName], [null, $realDatabaseName, $realDatabaseName], - [null, null, $this->getDatabaseNameForConnectionWithoutDatabaseNameParameter()], + [null, null, static::getDatabaseNameForConnectionWithoutDatabaseNameParameter()], ]; } @@ -108,7 +111,7 @@ protected function createDriver() /** * {@inheritdoc} */ - protected function getDatabaseNameForConnectionWithoutDatabaseNameParameter() + protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string { return 'postgres'; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php index a20bf838a89..955a90cdaf1 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php @@ -36,7 +36,7 @@ protected function createDriver() /** * {@inheritdoc} */ - protected function getDatabaseNameForConnectionWithoutDatabaseNameParameter() + protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string { return 'master'; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php index 0677878063d..21413acec2f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php @@ -34,7 +34,7 @@ protected function createDriver() /** * {@inheritdoc} */ - protected function getDatabaseNameForConnectionWithoutDatabaseNameParameter() + protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string { return 'master'; } diff --git a/tests/Doctrine/Tests/TestUtil.php b/tests/Doctrine/Tests/TestUtil.php index 37553595490..0ff5a42ce8c 100644 --- a/tests/Doctrine/Tests/TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -40,6 +40,11 @@ class TestUtil */ public static function getConnection() { + if (self::hasRequiredConnectionParams() && ! self::$initialized) { + self::initializeDatabase(); + self::$initialized = true; + } + $conn = DriverManager::getConnection(self::getConnectionParams()); self::addDbEventSubscribers($conn); @@ -47,10 +52,10 @@ public static function getConnection() return $conn; } - private static function getConnectionParams() + public static function getConnectionParams() { if (self::hasRequiredConnectionParams()) { - return self::getSpecifiedConnectionParams(); + return self::getParamsForMainConnection(); } return self::getFallbackConnectionParams(); @@ -75,7 +80,7 @@ private static function hasRequiredConnectionParams() ); } - private static function getSpecifiedConnectionParams() + private static function initializeDatabase() : void { $realDbParams = self::getParamsForMainConnection(); $tmpDbParams = self::getParamsForTemporaryConnection(); @@ -87,29 +92,23 @@ private static function getSpecifiedConnectionParams() $platform = $tmpConn->getDatabasePlatform(); - if (! self::$initialized) { - if ($platform->supportsCreateDropDatabase()) { - $dbname = $realConn->getDatabase(); - $realConn->close(); + if ($platform->supportsCreateDropDatabase()) { + $dbname = $realConn->getDatabase(); + $realConn->close(); - $tmpConn->getSchemaManager()->dropAndCreateDatabase($dbname); + $tmpConn->getSchemaManager()->dropAndCreateDatabase($dbname); - $tmpConn->close(); - } else { - $sm = $realConn->getSchemaManager(); + $tmpConn->close(); + } else { + $sm = $realConn->getSchemaManager(); - $schema = $sm->createSchema(); - $stmts = $schema->toDropSql($realConn->getDatabasePlatform()); + $schema = $sm->createSchema(); + $stmts = $schema->toDropSql($realConn->getDatabasePlatform()); - foreach ($stmts as $stmt) { - $realConn->exec($stmt); - } + foreach ($stmts as $stmt) { + $realConn->exec($stmt); } - - self::$initialized = true; } - - return $realDbParams; } private static function getFallbackConnectionParams() From afbae7efa5f12c54d319aba215ad53fff1a5e7a0 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 24 Feb 2019 10:05:49 -0800 Subject: [PATCH 042/106] Remove more hard-coded mock classes --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 21 ++- .../Doctrine/Tests/DBAL/DriverManagerTest.php | 25 ++-- tests/Doctrine/Tests/Mocks/ConnectionMock.php | 70 ---------- .../Tests/Mocks/DatabasePlatformMock.php | 121 ------------------ tests/Doctrine/Tests/Mocks/DriverMock.php | 68 ---------- .../Tests/Mocks/SchemaManagerMock.php | 18 --- 6 files changed, 31 insertions(+), 292 deletions(-) delete mode 100644 tests/Doctrine/Tests/Mocks/ConnectionMock.php delete mode 100644 tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php delete mode 100644 tests/Doctrine/Tests/Mocks/DriverMock.php delete mode 100644 tests/Doctrine/Tests/Mocks/SchemaManagerMock.php diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 3eed3a72650..c036bd89885 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -22,7 +22,6 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\Tests\DbalTestCase; -use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\DriverStatementMock; use Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock; use Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock; @@ -165,10 +164,22 @@ public function testConnectDispatchEvent() public function testEventManagerPassedToPlatform() { - $driverMock = new DriverMock(); - $connection = new Connection($this->params, $driverMock); - self::assertInstanceOf(EventManager::class, $connection->getDatabasePlatform()->getEventManager()); - self::assertSame($connection->getEventManager(), $connection->getDatabasePlatform()->getEventManager()); + $eventManager = new EventManager(); + + /** @var AbstractPlatform|MockObject $driver */ + $platform = $this->createMock(AbstractPlatform::class); + $platform->expects($this->once()) + ->method('setEventManager') + ->with($eventManager); + + /** @var Driver|MockObject $driver */ + $driver = $this->createMock(Driver::class); + $driver->expects($this->any()) + ->method('getDatabasePlatform') + ->willReturn($platform); + + $connection = new Connection($this->params, $driver, null, $eventManager); + $connection->getDatabasePlatform(); } /** diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index 0fe228aa45a..0346405cb82 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -2,8 +2,10 @@ namespace Doctrine\Tests\DBAL; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connections\MasterSlaveConnection; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver as DrizzlePDOMySqlDriver; use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySQLDriver; use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSqliteDriver; @@ -13,11 +15,10 @@ use Doctrine\DBAL\Sharding\PoolingShardConnection; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; use Doctrine\Tests\DbalTestCase; -use Doctrine\Tests\Mocks\ConnectionMock; -use Doctrine\Tests\Mocks\DriverMock; use PDO; use stdClass; use function extension_loaded; +use function get_class; use function in_array; use function is_array; @@ -92,7 +93,8 @@ public function testCustomPlatform() */ public function testCustomWrapper() { - $wrapperClass = ConnectionMock::class; + $wrapper = $this->createMock(Connection::class); + $wrapperClass = get_class($wrapper); $options = [ 'pdo' => new PDO('sqlite::memory:'), @@ -238,6 +240,9 @@ public function testDatabaseUrl($url, $expected) public function databaseUrls() { + $driver = $this->createMock(Driver::class); + $driverClass = get_class($driver); + return [ 'simple URL' => [ 'mysql://foo:bar@localhost/baz', @@ -406,14 +411,14 @@ public function databaseUrls() 'URL without scheme but custom driver' => [ [ 'url' => '//foo:bar@localhost/baz', - 'driverClass' => DriverMock::class, + 'driverClass' => $driverClass, ], [ 'user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', - 'driverClass' => DriverMock::class, + 'driverClass' => $driverClass, ], ], 'URL without scheme but default PDO driver and default driver' => [ @@ -434,14 +439,14 @@ public function databaseUrls() [ 'url' => '//foo:bar@localhost/baz', 'driver' => 'pdo_mysql', - 'driverClass' => DriverMock::class, + 'driverClass' => $driverClass, ], [ 'user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', - 'driverClass' => DriverMock::class, + 'driverClass' => $driverClass, ], ], 'URL with default PDO driver' => [ @@ -473,7 +478,7 @@ public function databaseUrls() 'URL with default custom driver' => [ [ 'url' => 'mysql://foo:bar@localhost/baz', - 'driverClass' => DriverMock::class, + 'driverClass' => $driverClass, ], [ 'user' => 'foo', @@ -501,7 +506,7 @@ public function databaseUrls() [ 'url' => 'mysql://foo:bar@localhost/baz', 'driver' => 'sqlite', - 'driverClass' => DriverMock::class, + 'driverClass' => $driverClass, ], [ 'user' => 'foo', @@ -516,7 +521,7 @@ public function databaseUrls() 'url' => 'mysql://foo:bar@localhost/baz', 'pdo' => true, 'driver' => 'sqlite', - 'driverClass' => DriverMock::class, + 'driverClass' => $driverClass, ], [ 'user' => 'foo', diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php deleted file mode 100644 index 157584f09f7..00000000000 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ /dev/null @@ -1,70 +0,0 @@ -platformMock = new DatabasePlatformMock(); - - parent::__construct($params, $driver, $config, $eventManager); - } - - public function getDatabasePlatform() - { - return $this->platformMock; - } - - /** - * {@inheritDoc} - */ - public function insert($tableName, array $data, array $types = []) - { - $this->inserts[$tableName][] = $data; - } - - public function lastInsertId($seqName = null) - { - return $this->lastInsertId; - } - - public function quote($input, $type = null) - { - if (is_string($input)) { - return "'" . $input . "'"; - } - return $input; - } - - public function setLastInsertId($id) - { - $this->lastInsertId = $id; - } - - public function getInserts() - { - return $this->inserts; - } - - public function reset() - { - $this->inserts = []; - $this->lastInsertId = 0; - } -} diff --git a/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php b/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php deleted file mode 100644 index 690809e308a..00000000000 --- a/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php +++ /dev/null @@ -1,121 +0,0 @@ -prefersIdentityColumns; - } - - public function prefersSequences() - { - return $this->prefersSequences; - } - - public function getSequenceNextValSQL($sequenceName) - { - return $this->sequenceNextValSql; - } - - /** - * {@inheritDoc} - */ - public function getBooleanTypeDeclarationSQL(array $field) - { - } - - /** - * {@inheritDoc} - */ - public function getIntegerTypeDeclarationSQL(array $field) - { - } - - /** - * {@inheritDoc} - */ - public function getBigIntTypeDeclarationSQL(array $field) - { - } - - /** - * {@inheritDoc} - */ - public function getSmallIntTypeDeclarationSQL(array $field) - { - } - - /** - * {@inheritDoc} - */ - protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) - { - } - - /** - * {@inheritDoc} - */ - public function getVarcharTypeDeclarationSQL(array $field) - { - } - - /** - * {@inheritDoc} - */ - public function getClobTypeDeclarationSQL(array $field) - { - } - - /* MOCK API */ - - /** - * @param bool $prefersIdentityColumns - */ - public function setPrefersIdentityColumns($prefersIdentityColumns) - { - $this->prefersIdentityColumns = $prefersIdentityColumns; - } - - public function setPrefersSequences($bool) - { - $this->prefersSequences = $bool; - } - - public function setSequenceNextValSql($sql) - { - $this->sequenceNextValSql = $sql; - } - - public function getName() - { - return 'mock'; - } - protected function initializeDoctrineTypeMappings() - { - } - protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) - { - } - - /** - * {@inheritDoc} - */ - public function getBlobTypeDeclarationSQL(array $field) - { - throw DBALException::notSupported(__METHOD__); - } -} diff --git a/tests/Doctrine/Tests/Mocks/DriverMock.php b/tests/Doctrine/Tests/Mocks/DriverMock.php deleted file mode 100644 index 9b5f4245472..00000000000 --- a/tests/Doctrine/Tests/Mocks/DriverMock.php +++ /dev/null @@ -1,68 +0,0 @@ -platformMock) { - $this->platformMock = new DatabasePlatformMock(); - } - return $this->platformMock; - } - - public function getSchemaManager(Connection $conn) - { - if ($this->schemaManagerMock === null) { - return new SchemaManagerMock($conn); - } - - return $this->schemaManagerMock; - } - - public function setDatabasePlatform(AbstractPlatform $platform) - { - $this->platformMock = $platform; - } - - public function setSchemaManager(AbstractSchemaManager $sm) - { - $this->schemaManagerMock = $sm; - } - - public function getName() - { - return 'mock'; - } - - public function getDatabase(Connection $conn) - { - return; - } - - public function convertExceptionCode(Throwable $exception) - { - return 0; - } -} diff --git a/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php b/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php deleted file mode 100644 index 6eccd68609e..00000000000 --- a/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php +++ /dev/null @@ -1,18 +0,0 @@ - Date: Tue, 26 Feb 2019 23:29:36 -0800 Subject: [PATCH 043/106] Make PHP 7.3 the primary PHP version on Travis CI --- .travis.yml | 162 ++++++++++++++++++++++++++-------------------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9620b0c3c14..17d123db603 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,30 +43,85 @@ jobs: include: - stage: Smoke Testing - php: 7.2 + php: 7.3 env: DB=sqlite COVERAGE=yes - stage: Smoke Testing - php: 7.2 + php: 7.3 env: PHPStan install: travis_retry composer install --prefer-dist script: vendor/bin/phpstan analyse - stage: Smoke Testing - php: 7.2 + php: 7.3 env: PHP_CodeSniffer install: travis_retry composer install --prefer-dist script: vendor/bin/phpcs - stage: Test php: 7.2 - env: DB=mysql COVERAGE=yes + env: DB=mysql.docker MYSQL_VERSION=8.0 + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mysql-8.0.sh + - stage: Test + php: 7.2 + env: DB=mysqli.docker MYSQL_VERSION=8.0 + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mysql-8.0.sh - stage: Test php: 7.2 + env: DB=mariadb MARIADB_VERSION=10.3 + addons: + mariadb: 10.3 + - stage: Test + php: 7.2 + env: DB=mariadb.mysqli MARIADB_VERSION=10.3 + addons: + mariadb: 10.3 + - stage: Test + php: 7.2 + env: DB=pgsql POSTGRESQL_VERSION=11.0 + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-postgres-11.sh + - stage: Test + php: 7.2 + env: DB=sqlite + - stage: Test + php: 7.2 + env: DB=sqlsrv + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mssql-sqlsrv.sh + - bash ./tests/travis/install-mssql.sh + - stage: Test + php: 7.2 + env: DB=pdo_sqlsrv + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh + - bash ./tests/travis/install-mssql.sh + - stage: Test + php: 7.3 + env: DB=mysql COVERAGE=yes + - stage: Test + php: 7.3 env: DB=mysql.docker MYSQL_VERSION=5.7 COVERAGE=yes sudo: required before_script: - bash ./tests/travis/install-mysql-5.7.sh - stage: Test - php: 7.2 + php: 7.3 env: DB=mysql.docker MYSQL_VERSION=8.0 COVERAGE=yes sudo: required services: @@ -74,16 +129,16 @@ jobs: before_script: - bash ./tests/travis/install-mysql-8.0.sh - stage: Test - php: 7.2 + php: 7.3 env: DB=mysqli COVERAGE=yes - stage: Test - php: 7.2 + php: 7.3 env: DB=mysqli.docker MYSQL_VERSION=5.7 COVERAGE=yes sudo: required before_script: - bash ./tests/travis/install-mysql-5.7.sh - stage: Test - php: 7.2 + php: 7.3 env: DB=mysqli.docker MYSQL_VERSION=8.0 COVERAGE=yes sudo: required services: @@ -91,82 +146,82 @@ jobs: before_script: - bash ./tests/travis/install-mysql-8.0.sh - stage: Test - php: 7.2 + php: 7.3 env: DB=mariadb MARIADB_VERSION=10.0 COVERAGE=yes addons: mariadb: 10.0 - stage: Test - php: 7.2 + php: 7.3 env: DB=mariadb MARIADB_VERSION=10.1 COVERAGE=yes addons: mariadb: 10.1 - stage: Test - php: 7.2 + php: 7.3 env: DB=mariadb MARIADB_VERSION=10.2 COVERAGE=yes addons: mariadb: 10.2 - stage: Test - php: 7.2 + php: 7.3 env: DB=mariadb MARIADB_VERSION=10.3 COVERAGE=yes addons: mariadb: 10.3 - stage: Test - php: 7.2 + php: 7.3 env: DB=mariadb.mysqli MARIADB_VERSION=10.0 COVERAGE=yes addons: mariadb: 10.0 - stage: Test - php: 7.2 + php: 7.3 env: DB=mariadb.mysqli MARIADB_VERSION=10.1 COVERAGE=yes addons: mariadb: 10.1 - stage: Test - php: 7.2 + php: 7.3 env: DB=mariadb.mysqli MARIADB_VERSION=10.2 COVERAGE=yes addons: mariadb: 10.2 - stage: Test - php: 7.2 + php: 7.3 env: DB=mariadb.mysqli MARIADB_VERSION=10.3 COVERAGE=yes addons: mariadb: 10.3 - stage: Test - php: 7.2 + php: 7.3 env: DB=pgsql POSTGRESQL_VERSION=9.2 COVERAGE=yes services: - postgresql addons: postgresql: "9.2" - stage: Test - php: 7.2 + php: 7.3 env: DB=pgsql POSTGRESQL_VERSION=9.3 COVERAGE=yes services: - postgresql addons: postgresql: "9.3" - stage: Test - php: 7.2 + php: 7.3 env: DB=pgsql POSTGRESQL_VERSION=9.4 COVERAGE=yes services: - postgresql addons: postgresql: "9.4" - stage: Test - php: 7.2 + php: 7.3 env: DB=pgsql POSTGRESQL_VERSION=9.5 COVERAGE=yes services: - postgresql addons: postgresql: "9.5" - stage: Test - php: 7.2 + php: 7.3 env: DB=pgsql POSTGRESQL_VERSION=9.6 COVERAGE=yes services: - postgresql addons: postgresql: "9.6" - stage: Test - php: 7.2 + php: 7.3 env: DB=pgsql POSTGRESQL_VERSION=10.0 COVERAGE=yes sudo: required services: @@ -176,7 +231,7 @@ jobs: before_script: - bash ./tests/travis/install-postgres-10.sh - stage: Test - php: 7.2 + php: 7.3 env: DB=pgsql POSTGRESQL_VERSION=11.0 COVERAGE=yes sudo: required services: @@ -184,7 +239,7 @@ jobs: before_script: - bash ./tests/travis/install-postgres-11.sh - stage: Test - php: 7.2 + php: 7.3 env: DB=sqlsrv COVERAGE=yes sudo: required services: @@ -193,7 +248,7 @@ jobs: - bash ./tests/travis/install-mssql-sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test - php: 7.2 + php: 7.3 env: DB=pdo_sqlsrv COVERAGE=yes sudo: required services: @@ -211,65 +266,10 @@ jobs: - bash ./tests/travis/install-db2.sh - bash ./tests/travis/install-db2-ibm_db2.sh - stage: Test - php: 7.2 + php: 7.3 env: DB=sqlite DEPENDENCIES=low install: - travis_retry composer update --prefer-dist --prefer-lowest - - stage: Test - php: 7.3 - env: DB=mysql.docker MYSQL_VERSION=8.0 - sudo: required - services: - - docker - before_script: - - bash ./tests/travis/install-mysql-8.0.sh - - stage: Test - php: 7.3 - env: DB=mysqli.docker MYSQL_VERSION=8.0 - sudo: required - services: - - docker - before_script: - - bash ./tests/travis/install-mysql-8.0.sh - - stage: Test - php: 7.3 - env: DB=mariadb MARIADB_VERSION=10.3 - addons: - mariadb: 10.3 - - stage: Test - php: 7.3 - env: DB=mariadb.mysqli MARIADB_VERSION=10.3 - addons: - mariadb: 10.3 - - stage: Test - php: 7.3 - env: DB=pgsql POSTGRESQL_VERSION=11.0 - sudo: required - services: - - docker - before_script: - - bash ./tests/travis/install-postgres-11.sh - - stage: Test - php: 7.3 - env: DB=sqlite - - stage: Test - php: 7.3 - env: DB=sqlsrv - sudo: required - services: - - docker - before_script: - - bash ./tests/travis/install-mssql-sqlsrv.sh - - bash ./tests/travis/install-mssql.sh - - stage: Test - php: 7.3 - env: DB=pdo_sqlsrv - sudo: required - services: - - docker - before_script: - - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - - bash ./tests/travis/install-mssql.sh - stage: Test php: 7.4snapshot env: DB=mysql.docker MYSQL_VERSION=8.0 From d871d6938300e5426dd964eb37f8a8eb682bd69b Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 13 Mar 2019 20:27:58 -0700 Subject: [PATCH 044/106] Updated PHPStan to v0.11.3 --- composer.json | 2 +- composer.lock | 142 +++++++++--------- .../SQLAnywhere/SQLAnywhereException.php | 9 -- .../DBAL/Event/SchemaDropTableEventArgs.php | 5 - .../DBAL/Platforms/DrizzlePlatform.php | 2 +- .../DBAL/Platforms/SQLServerPlatform.php | 2 +- .../DBAL/Schema/AbstractSchemaManager.php | 4 +- 7 files changed, 78 insertions(+), 88 deletions(-) diff --git a/composer.json b/composer.json index 4e5631af098..ac4efe884a4 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "require-dev": { "doctrine/coding-standard": "^5.0", "jetbrains/phpstorm-stubs": "^2018.1.2", - "phpstan/phpstan": "^0.11.1", + "phpstan/phpstan": "^0.11.3", "phpunit/phpunit": "^8.0", "symfony/console": "^2.0.5|^3.0|^4.0", "symfony/phpunit-bridge": "^3.4.5|^4.0.5" diff --git a/composer.lock b/composer.lock index 6cbca943384..596f3097636 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3bc5aa75b3af3332def5f89114986259", + "content-hash": "dc19a584f29861609d085123b65f3961", "packages": [ { "name": "doctrine/cache", @@ -158,16 +158,16 @@ "packages-dev": [ { "name": "composer/xdebug-handler", - "version": "1.3.1", + "version": "1.3.2", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "dc523135366eb68f22268d069ea7749486458562" + "reference": "d17708133b6c276d6e42ef887a877866b909d892" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/dc523135366eb68f22268d069ea7749486458562", - "reference": "dc523135366eb68f22268d069ea7749486458562", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/d17708133b6c276d6e42ef887a877866b909d892", + "reference": "d17708133b6c276d6e42ef887a877866b909d892", "shasum": "" }, "require": { @@ -198,7 +198,7 @@ "Xdebug", "performance" ], - "time": "2018-11-29T10:59:02+00:00" + "time": "2019-01-28T20:25:53+00:00" }, { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -598,23 +598,23 @@ }, { "name": "nette/di", - "version": "v2.4.14", + "version": "v2.4.15", "source": { "type": "git", "url": "https://github.com/nette/di.git", - "reference": "923da3e2c0aa53162ef455472c0ac7787b096c5a" + "reference": "d0561b8f77e8ef2ed6d83328860e16c81a5a8649" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/di/zipball/923da3e2c0aa53162ef455472c0ac7787b096c5a", - "reference": "923da3e2c0aa53162ef455472c0ac7787b096c5a", + "url": "https://api.github.com/repos/nette/di/zipball/d0561b8f77e8ef2ed6d83328860e16c81a5a8649", + "reference": "d0561b8f77e8ef2ed6d83328860e16c81a5a8649", "shasum": "" }, "require": { "ext-tokenizer": "*", "nette/neon": "^2.3.3 || ~3.0.0", - "nette/php-generator": "^2.6.1 || ~3.0.0", - "nette/utils": "^2.4.3 || ~3.0.0", + "nette/php-generator": "^2.6.1 || ^3.0.0", + "nette/utils": "^2.5.0 || ~3.0.0", "php": ">=5.6.0" }, "conflict": { @@ -663,37 +663,37 @@ "nette", "static" ], - "time": "2018-09-17T15:47:40+00:00" + "time": "2019-01-30T13:26:05+00:00" }, { "name": "nette/finder", - "version": "v2.4.2", + "version": "v2.5.0", "source": { "type": "git", "url": "https://github.com/nette/finder.git", - "reference": "ee951a656cb8ac622e5dd33474a01fd2470505a0" + "reference": "6be1b83ea68ac558aff189d640abe242e0306fe2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/finder/zipball/ee951a656cb8ac622e5dd33474a01fd2470505a0", - "reference": "ee951a656cb8ac622e5dd33474a01fd2470505a0", + "url": "https://api.github.com/repos/nette/finder/zipball/6be1b83ea68ac558aff189d640abe242e0306fe2", + "reference": "6be1b83ea68ac558aff189d640abe242e0306fe2", "shasum": "" }, "require": { - "nette/utils": "~2.4", - "php": ">=5.6.0" + "nette/utils": "^2.4 || ~3.0.0", + "php": ">=7.1" }, "conflict": { "nette/nette": "<2.2" }, "require-dev": { - "nette/tester": "~2.0", + "nette/tester": "^2.0", "tracy/tracy": "^2.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.4-dev" + "dev-master": "2.5-dev" } }, "autoload": { @@ -725,35 +725,35 @@ "iterator", "nette" ], - "time": "2018-06-28T11:49:23+00:00" + "time": "2019-02-28T18:13:25+00:00" }, { "name": "nette/neon", - "version": "v2.4.3", + "version": "v3.0.0", "source": { "type": "git", "url": "https://github.com/nette/neon.git", - "reference": "5e72b1dd3e2d34f0863c5561139a19df6a1ef398" + "reference": "cbff32059cbdd8720deccf9e9eace6ee516f02eb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/neon/zipball/5e72b1dd3e2d34f0863c5561139a19df6a1ef398", - "reference": "5e72b1dd3e2d34f0863c5561139a19df6a1ef398", + "url": "https://api.github.com/repos/nette/neon/zipball/cbff32059cbdd8720deccf9e9eace6ee516f02eb", + "reference": "cbff32059cbdd8720deccf9e9eace6ee516f02eb", "shasum": "" }, "require": { "ext-iconv": "*", "ext-json": "*", - "php": ">=5.6.0" + "php": ">=7.0" }, "require-dev": { - "nette/tester": "~2.0", + "nette/tester": "^2.0", "tracy/tracy": "^2.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.4-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -786,25 +786,25 @@ "nette", "yaml" ], - "time": "2018-03-21T12:12:21+00:00" + "time": "2019-02-05T21:30:40+00:00" }, { "name": "nette/php-generator", - "version": "v3.0.5", + "version": "v3.2.1", "source": { "type": "git", "url": "https://github.com/nette/php-generator.git", - "reference": "ea90209c2e8a7cd087b2742ca553c047a8df5eff" + "reference": "9de4e093a130f7a1bd175198799ebc0efbac6924" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/php-generator/zipball/ea90209c2e8a7cd087b2742ca553c047a8df5eff", - "reference": "ea90209c2e8a7cd087b2742ca553c047a8df5eff", + "url": "https://api.github.com/repos/nette/php-generator/zipball/9de4e093a130f7a1bd175198799ebc0efbac6924", + "reference": "9de4e093a130f7a1bd175198799ebc0efbac6924", "shasum": "" }, "require": { "nette/utils": "^2.4.2 || ~3.0.0", - "php": ">=7.0" + "php": ">=7.1" }, "conflict": { "nette/nette": "<2.2" @@ -816,7 +816,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "3.2-dev" } }, "autoload": { @@ -840,7 +840,7 @@ "homepage": "https://nette.org/contributors" } ], - "description": "🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 7.2 features.", + "description": "🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 7.3 features.", "homepage": "https://nette.org", "keywords": [ "code", @@ -848,20 +848,20 @@ "php", "scaffolding" ], - "time": "2018-08-09T14:32:27+00:00" + "time": "2018-11-27T19:00:14+00:00" }, { "name": "nette/robot-loader", - "version": "v3.1.0", + "version": "v3.1.1", "source": { "type": "git", "url": "https://github.com/nette/robot-loader.git", - "reference": "fc76c70e740b10f091e502b2e393d0be912f38d4" + "reference": "3e8d75d6d976e191bdf46752ca40a286671219d2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/robot-loader/zipball/fc76c70e740b10f091e502b2e393d0be912f38d4", - "reference": "fc76c70e740b10f091e502b2e393d0be912f38d4", + "url": "https://api.github.com/repos/nette/robot-loader/zipball/3e8d75d6d976e191bdf46752ca40a286671219d2", + "reference": "3e8d75d6d976e191bdf46752ca40a286671219d2", "shasum": "" }, "require": { @@ -913,7 +913,7 @@ "nette", "trait" ], - "time": "2018-08-13T14:19:06+00:00" + "time": "2019-03-01T20:23:02+00:00" }, { "name": "nette/utils", @@ -999,16 +999,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.2.0", + "version": "v4.2.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "594bcae1fc0bccd3993d2f0d61a018e26ac2865a" + "reference": "5221f49a608808c1e4d436df32884cbc1b821ac0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/594bcae1fc0bccd3993d2f0d61a018e26ac2865a", - "reference": "594bcae1fc0bccd3993d2f0d61a018e26ac2865a", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/5221f49a608808c1e4d436df32884cbc1b821ac0", + "reference": "5221f49a608808c1e4d436df32884cbc1b821ac0", "shasum": "" }, "require": { @@ -1046,20 +1046,20 @@ "parser", "php" ], - "time": "2019-01-12T16:31:37+00:00" + "time": "2019-02-16T20:54:15+00:00" }, { "name": "ocramius/package-versions", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/Ocramius/PackageVersions.git", - "reference": "4489d5002c49d55576fa0ba786f42dbb009be46f" + "reference": "a4d4b60d0e60da2487bd21a2c6ac089f85570dbb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/4489d5002c49d55576fa0ba786f42dbb009be46f", - "reference": "4489d5002c49d55576fa0ba786f42dbb009be46f", + "url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/a4d4b60d0e60da2487bd21a2c6ac089f85570dbb", + "reference": "a4d4b60d0e60da2487bd21a2c6ac089f85570dbb", "shasum": "" }, "require": { @@ -1068,6 +1068,7 @@ }, "require-dev": { "composer/composer": "^1.6.3", + "doctrine/coding-standard": "^5.0.1", "ext-zip": "*", "infection/infection": "^0.7.1", "phpunit/phpunit": "^7.0.0" @@ -1095,7 +1096,7 @@ } ], "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", - "time": "2018-02-05T13:05:30+00:00" + "time": "2019-02-21T12:16:21+00:00" }, { "name": "phar-io/manifest", @@ -1462,16 +1463,16 @@ }, { "name": "phpstan/phpstan", - "version": "0.11.1", + "version": "0.11.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "a138b8a2731b2c19f1dffa2f1411984a638fe977" + "reference": "e4644b4a8fd393c346f1137305fb2f76a7dc20a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/a138b8a2731b2c19f1dffa2f1411984a638fe977", - "reference": "a138b8a2731b2c19f1dffa2f1411984a638fe977", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e4644b4a8fd393c346f1137305fb2f76a7dc20a7", + "reference": "e4644b4a8fd393c346f1137305fb2f76a7dc20a7", "shasum": "" }, "require": { @@ -1531,7 +1532,7 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", - "time": "2019-01-19T20:23:08+00:00" + "time": "2019-03-10T16:25:30+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2575,16 +2576,16 @@ }, { "name": "symfony/console", - "version": "v4.2.2", + "version": "v4.2.4", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "b0a03c1bb0fcbe288629956cf2f1dd3f1dc97522" + "reference": "9dc2299a016497f9ee620be94524e6c0af0280a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/b0a03c1bb0fcbe288629956cf2f1dd3f1dc97522", - "reference": "b0a03c1bb0fcbe288629956cf2f1dd3f1dc97522", + "url": "https://api.github.com/repos/symfony/console/zipball/9dc2299a016497f9ee620be94524e6c0af0280a9", + "reference": "9dc2299a016497f9ee620be94524e6c0af0280a9", "shasum": "" }, "require": { @@ -2596,6 +2597,9 @@ "symfony/dependency-injection": "<3.4", "symfony/process": "<3.3" }, + "provide": { + "psr/log-implementation": "1.0" + }, "require-dev": { "psr/log": "~1.0", "symfony/config": "~3.4|~4.0", @@ -2605,7 +2609,7 @@ "symfony/process": "~3.4|~4.0" }, "suggest": { - "psr/log-implementation": "For using the console logger", + "psr/log": "For using the console logger", "symfony/event-dispatcher": "", "symfony/lock": "", "symfony/process": "" @@ -2640,7 +2644,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2019-01-04T15:13:53+00:00" + "time": "2019-02-23T15:17:42+00:00" }, { "name": "symfony/contracts", @@ -2768,16 +2772,16 @@ }, { "name": "symfony/finder", - "version": "v4.2.2", + "version": "v4.2.4", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "9094d69e8c6ee3fe186a0ec5a4f1401e506071ce" + "reference": "267b7002c1b70ea80db0833c3afe05f0fbde580a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/9094d69e8c6ee3fe186a0ec5a4f1401e506071ce", - "reference": "9094d69e8c6ee3fe186a0ec5a4f1401e506071ce", + "url": "https://api.github.com/repos/symfony/finder/zipball/267b7002c1b70ea80db0833c3afe05f0fbde580a", + "reference": "267b7002c1b70ea80db0833c3afe05f0fbde580a", "shasum": "" }, "require": { @@ -2813,7 +2817,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2019-01-03T09:07:35+00:00" + "time": "2019-02-23T15:42:05+00:00" }, { "name": "symfony/phpunit-bridge", diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php index 9f8aac0608d..0f8bc3e57e6 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Driver\AbstractDriverException; use InvalidArgumentException; -use function is_resource; use function sasql_error; use function sasql_errorcode; use function sasql_sqlstate; @@ -28,14 +27,6 @@ class SQLAnywhereException extends AbstractDriverException */ public static function fromSQLAnywhereError($conn = null, $stmt = null) { - if ($conn !== null && ! is_resource($conn)) { - throw new InvalidArgumentException('Invalid SQL Anywhere connection resource given: ' . $conn); - } - - if ($stmt !== null && ! is_resource($stmt)) { - throw new InvalidArgumentException('Invalid SQL Anywhere statement resource given: ' . $stmt); - } - $state = $conn ? sasql_sqlstate($conn) : sasql_sqlstate(); $code = null; $message = null; diff --git a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php index 900b9fbfd71..387049791d2 100644 --- a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Table; use InvalidArgumentException; -use function is_string; /** * Event Arguments used when the SQL query for dropping tables are generated inside Doctrine\DBAL\Platform\AbstractPlatform. @@ -28,10 +27,6 @@ class SchemaDropTableEventArgs extends SchemaEventArgs */ public function __construct($table, AbstractPlatform $platform) { - if (! $table instanceof Table && ! is_string($table)) { - throw new InvalidArgumentException('SchemaDropTableEventArgs expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); - } - $this->table = $table; $this->platform = $platform; } diff --git a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php index ae25e28ee30..8f6f0966323 100644 --- a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php @@ -576,7 +576,7 @@ public function convertBooleans($item) { if (is_array($item)) { foreach ($item as $key => $value) { - if (! is_bool($value) && ! is_numeric($item)) { + if (! is_bool($value) && ! is_numeric($value)) { continue; } diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 616faf6664a..01417d7e292 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1399,7 +1399,7 @@ public function convertBooleans($item) { if (is_array($item)) { foreach ($item as $key => $value) { - if (! is_bool($value) && ! is_numeric($item)) { + if (! is_bool($value) && ! is_numeric($value)) { continue; } diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index eea98c09be4..8c055921c7c 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -947,9 +947,9 @@ protected function _getPortableUsersList($users) } /** - * @param mixed[] $user + * @param string[] $user * - * @return mixed[] + * @return string[] */ protected function _getPortableUserDefinition($user) { From 71515a9c7c57fff96f162cc12abd6ebe9d4e715a Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 14 Mar 2019 18:31:57 -0700 Subject: [PATCH 045/106] Use latest stable versions of sqlsrv and pdo_sqlsrv on CI --- tests/travis/install-mssql-pdo_sqlsrv.sh | 6 +----- tests/travis/install-mssql-sqlsrv.sh | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/travis/install-mssql-pdo_sqlsrv.sh b/tests/travis/install-mssql-pdo_sqlsrv.sh index 6a82459cc6c..9893d0f8c78 100644 --- a/tests/travis/install-mssql-pdo_sqlsrv.sh +++ b/tests/travis/install-mssql-pdo_sqlsrv.sh @@ -4,8 +4,4 @@ set -ex echo "Installing extension" -if [ "$TRAVIS_PHP_VERSION" == "7.3" ] || [ "$TRAVIS_PHP_VERSION" == "nightly" ] ; then - pecl install pdo_sqlsrv-5.4.0preview -else - pecl install pdo_sqlsrv -fi +pecl install pdo_sqlsrv diff --git a/tests/travis/install-mssql-sqlsrv.sh b/tests/travis/install-mssql-sqlsrv.sh index 18c9453a866..10132619c59 100644 --- a/tests/travis/install-mssql-sqlsrv.sh +++ b/tests/travis/install-mssql-sqlsrv.sh @@ -4,8 +4,4 @@ set -ex echo "Installing extension" -if [ "$TRAVIS_PHP_VERSION" == "7.3" ] || [ "$TRAVIS_PHP_VERSION" == "nightly" ] ; then - pecl install sqlsrv-5.4.0preview -else - pecl install sqlsrv -fi +pecl install sqlsrv From a0b958b99b0b0b110a49671f5b9f1fcda76fd01c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 14 Mar 2019 20:45:03 -0700 Subject: [PATCH 046/106] Temporarily switching to sqlisrv 5.5.0preview on AppVeyor See https://github.com/Microsoft/msphpsql/issues/955 --- .appveyor.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index cfdc76aeb08..63a9c0ddb73 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -68,8 +68,7 @@ install: Add-Content php.ini "`n extension=php_curl.dll" Add-Content php.ini "`n curl.cainfo=C:\tools\cacert\bundle.pem" - # Get and install the latest stable sqlsrv DLL's - $DLLVersion = (Invoke-WebRequest "https://pecl.php.net/rest/r/sqlsrv/stable.txt").Content + $DLLVersion = "5.5.0preview" cd c:\tools\php\ext $source = "https://windows.php.net/downloads/pecl/releases/sqlsrv/$($DLLVersion)/php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc15-x64.zip" $destination = "c:\tools\php\ext\php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc15-x64.zip" @@ -79,7 +78,7 @@ install: $destination = "c:\tools\php\ext\php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc15-x64.zip" Invoke-WebRequest $source -OutFile $destination 7z x -y php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc15-x64.zip > $null - $DLLVersion = "2.6.0" + $DLLVersion = (Invoke-WebRequest "https://pecl.php.net/rest/r/xdebug/stable.txt").Content $source = "https://xdebug.org/files/php_xdebug-$($DLLVersion)-$($env:php)-vc15-nts-x86_64.dll" $destination = "c:\tools\php\ext\php_xdebug.dll" Invoke-WebRequest $source -OutFile $destination From 26d358715019d55f2980fd92ccffc98e4c0d85a5 Mon Sep 17 00:00:00 2001 From: Ahmed Abdou Date: Sun, 17 Mar 2019 13:16:26 +0100 Subject: [PATCH 047/106] Upgrade doctrine cs to 6.0 --- composer.json | 2 +- composer.lock | 77 +++++++++---------- lib/Doctrine/DBAL/Configuration.php | 4 +- lib/Doctrine/DBAL/Connection.php | 1 + .../DBAL/Driver/AbstractMySQLDriver.php | 8 -- .../DBAL/Driver/AbstractOracleDriver.php | 8 -- .../DBAL/Driver/AbstractPostgreSQLDriver.php | 8 -- .../DBAL/Driver/IBMDB2/DB2Statement.php | 6 -- .../DBAL/Driver/Mysqli/MysqliConnection.php | 4 +- .../DBAL/Driver/Mysqli/MysqliStatement.php | 7 +- .../DBAL/Driver/OCI8/OCI8Statement.php | 3 +- .../SQLAnywhere/SQLAnywhereStatement.php | 6 -- .../DBAL/Driver/SQLSrv/SQLSrvConnection.php | 4 +- lib/Doctrine/DBAL/DriverManager.php | 4 +- .../DBAL/Platforms/AbstractPlatform.php | 1 - lib/Doctrine/DBAL/Platforms/DB2Platform.php | 1 + lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 12 +-- .../DBAL/Platforms/OraclePlatform.php | 11 +-- .../DBAL/Platforms/PostgreSqlPlatform.php | 2 +- .../DBAL/Platforms/SQLAnywherePlatform.php | 6 +- .../DBAL/Platforms/SQLServerPlatform.php | 4 +- .../DBAL/Platforms/SqlitePlatform.php | 25 +++--- lib/Doctrine/DBAL/Query/QueryBuilder.php | 3 +- .../DBAL/Schema/AbstractSchemaManager.php | 2 +- lib/Doctrine/DBAL/Schema/DB2SchemaManager.php | 4 +- lib/Doctrine/DBAL/Schema/Index.php | 4 +- .../DBAL/Schema/MySqlSchemaManager.php | 1 + .../DBAL/Schema/SqliteSchemaManager.php | 2 +- .../SingleDatabaseSynchronizer.php | 1 - lib/Doctrine/DBAL/Schema/Table.php | 1 + .../Schema/Visitor/RemoveNamespacedAssets.php | 1 + lib/Doctrine/DBAL/Statement.php | 4 +- .../Tools/Console/Command/ImportCommand.php | 4 +- lib/Doctrine/DBAL/Tools/Dumper.php | 1 + phpcs.xml.dist | 2 +- .../Tests/DBAL/Functional/DataAccessTest.php | 2 +- .../Tests/DBAL/Functional/ResultCacheTest.php | 2 + .../Schema/PostgreSqlSchemaManagerTest.php | 1 + .../SchemaManagerFunctionalTestCase.php | 6 +- .../DBAL/Functional/TypeConversionTest.php | 2 +- .../TypeConversionPerformanceTest.php | 2 - .../AbstractMySQLPlatformTestCase.php | 1 - .../Platforms/AbstractPlatformTestCase.php | 3 + .../Platforms/SQLServer2012PlatformTest.php | 2 - .../Doctrine/Tests/DBAL/Schema/ColumnTest.php | 1 + .../Tests/DBAL/Schema/ComparatorTest.php | 4 +- .../Tests/DBAL/Schema/SchemaDiffTest.php | 1 + .../DBAL/Sharding/PoolingShardManagerTest.php | 2 + .../SQLAzure/SQLAzureShardManagerTest.php | 1 + .../DBAL/Types/ConversionExceptionTest.php | 1 + .../Doctrine/Tests/DbalFunctionalTestCase.php | 4 +- .../Tests/Mocks/DriverConnectionMock.php | 7 ++ 52 files changed, 135 insertions(+), 141 deletions(-) diff --git a/composer.json b/composer.json index ac4efe884a4..e5ff569c2d6 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "doctrine/event-manager": "^1.0" }, "require-dev": { - "doctrine/coding-standard": "^5.0", + "doctrine/coding-standard": "^6.0", "jetbrains/phpstorm-stubs": "^2018.1.2", "phpstan/phpstan": "^0.11.3", "phpunit/phpunit": "^8.0", diff --git a/composer.lock b/composer.lock index 596f3097636..7ba548e3d11 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "dc19a584f29861609d085123b65f3961", + "content-hash": "ddba260b7dfb84d2591b0a71a885166a", "packages": [ { "name": "doctrine/cache", @@ -202,29 +202,27 @@ }, { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v0.4.4", + "version": "v0.5.0", "source": { "type": "git", "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", - "reference": "2e41850d5f7797cbb1af7b030d245b3b24e63a08" + "reference": "e749410375ff6fb7a040a68878c656c2e610b132" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/2e41850d5f7797cbb1af7b030d245b3b24e63a08", - "reference": "2e41850d5f7797cbb1af7b030d245b3b24e63a08", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/e749410375ff6fb7a040a68878c656c2e610b132", + "reference": "e749410375ff6fb7a040a68878c656c2e610b132", "shasum": "" }, "require": { "composer-plugin-api": "^1.0", "php": "^5.3|^7", - "squizlabs/php_codesniffer": "*" + "squizlabs/php_codesniffer": "^2|^3" }, "require-dev": { "composer/composer": "*", - "wimg/php-compatibility": "^8.0" - }, - "suggest": { - "dealerdirect/qa-tools": "All the PHP QA tools you'll need" + "phpcompatibility/php-compatibility": "^9.0", + "sensiolabs/security-checker": "^4.1.0" }, "type": "composer-plugin", "extra": { @@ -242,13 +240,13 @@ "authors": [ { "name": "Franck Nijhof", - "email": "f.nijhof@dealerdirect.nl", - "homepage": "http://workingatdealerdirect.eu", - "role": "Developer" + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" } ], "description": "PHP_CodeSniffer Standards Composer Installer Plugin", - "homepage": "http://workingatdealerdirect.eu", + "homepage": "http://www.dealerdirect.com", "keywords": [ "PHPCodeSniffer", "PHP_CodeSniffer", @@ -266,32 +264,32 @@ "stylecheck", "tests" ], - "time": "2017-12-06T16:27:17+00:00" + "time": "2018-10-26T13:21:45+00:00" }, { "name": "doctrine/coding-standard", - "version": "5.0.0", + "version": "6.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/coding-standard.git", - "reference": "bb8de042a25c4fb59a2c55c350dc55cc00227a8c" + "reference": "d33f69eb98b25aa51ffe3a909f0ec77000af4701" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/bb8de042a25c4fb59a2c55c350dc55cc00227a8c", - "reference": "bb8de042a25c4fb59a2c55c350dc55cc00227a8c", + "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/d33f69eb98b25aa51ffe3a909f0ec77000af4701", + "reference": "d33f69eb98b25aa51ffe3a909f0ec77000af4701", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", + "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0", "php": "^7.1", - "slevomat/coding-standard": "^4.8.0", - "squizlabs/php_codesniffer": "^3.3.2" + "slevomat/coding-standard": "^5.0", + "squizlabs/php_codesniffer": "^3.4.0" }, "type": "phpcodesniffer-standard", "extra": { "branch-alias": { - "dev-master": "5.0.x-dev" + "dev-master": "6.0.x-dev" } }, "autoload": { @@ -327,7 +325,7 @@ "standard", "style" ], - "time": "2018-09-24T19:08:56+00:00" + "time": "2019-03-15T12:45:47+00:00" }, { "name": "doctrine/instantiator", @@ -2486,29 +2484,30 @@ }, { "name": "slevomat/coding-standard", - "version": "4.8.3", + "version": "5.0.2", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "32e1ca205fc34920f323582ed29c0602e3897ae3" + "reference": "223f02b6193fe47b7b483bfa5bf75693535482dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/32e1ca205fc34920f323582ed29c0602e3897ae3", - "reference": "32e1ca205fc34920f323582ed29c0602e3897ae3", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/223f02b6193fe47b7b483bfa5bf75693535482dd", + "reference": "223f02b6193fe47b7b483bfa5bf75693535482dd", "shasum": "" }, "require": { "php": "^7.1", - "squizlabs/php_codesniffer": "^3.3.0" + "phpstan/phpdoc-parser": "^0.3.1", + "squizlabs/php_codesniffer": "^3.4.0" }, "require-dev": { "jakub-onderka/php-parallel-lint": "1.0.0", "phing/phing": "2.16.1", - "phpstan/phpstan": "0.9.2", - "phpstan/phpstan-phpunit": "0.9.4", - "phpstan/phpstan-strict-rules": "0.9", - "phpunit/phpunit": "7.3.5" + "phpstan/phpstan": "0.11.1", + "phpstan/phpstan-phpunit": "0.11", + "phpstan/phpstan-strict-rules": "0.11", + "phpunit/phpunit": "8.0.0" }, "type": "phpcodesniffer-standard", "autoload": { @@ -2521,20 +2520,20 @@ "MIT" ], "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", - "time": "2018-09-25T21:21:11+00:00" + "time": "2019-03-12T20:26:36+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "3.3.2", + "version": "3.4.0", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e" + "reference": "379deb987e26c7cd103a7b387aea178baec96e48" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6ad28354c04b364c3c71a34e4a18b629cc3b231e", - "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/379deb987e26c7cd103a7b387aea178baec96e48", + "reference": "379deb987e26c7cd103a7b387aea178baec96e48", "shasum": "" }, "require": { @@ -2572,7 +2571,7 @@ "phpcs", "standards" ], - "time": "2018-09-23T23:08:17+00:00" + "time": "2018-12-19T23:57:18+00:00" }, { "name": "symfony/console", diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index 9b7b21fb21e..2cc0070d0cb 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -107,6 +107,7 @@ private function buildSchemaAssetsFilterFromExpression($filterExpression) : call if ($assetName instanceof AbstractAsset) { $assetName = $assetName->getName(); } + return preg_match($filterExpression, $assetName); }; } @@ -116,7 +117,8 @@ private function buildSchemaAssetsFilterFromExpression($filterExpression) : call */ public function setSchemaAssetsFilter(?callable $callable = null) : ?callable { - $this->_attributes['filterSchemaAssetsExpression'] = null; + $this->_attributes['filterSchemaAssetsExpression'] = null; + return $this->_attributes['filterSchemaAssetsExpressionCallable'] = $callable; } diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 8016b7da6a1..75b862bf74f 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1161,6 +1161,7 @@ public function transactional(Closure $func) try { $res = $func($this); $this->commit(); + return $res; } catch (Exception $e) { $this->rollBack(); diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php index c46ddc63dd7..8ae86e5c72a 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php @@ -36,34 +36,28 @@ public function convertException($message, DriverException $exception) return new Exception\LockWaitTimeoutException($message, $exception); case '1050': return new Exception\TableExistsException($message, $exception); - case '1051': case '1146': return new Exception\TableNotFoundException($message, $exception); - case '1216': case '1217': case '1451': case '1452': case '1701': return new Exception\ForeignKeyConstraintViolationException($message, $exception); - case '1062': case '1557': case '1569': case '1586': return new Exception\UniqueConstraintViolationException($message, $exception); - case '1054': case '1166': case '1611': return new Exception\InvalidFieldNameException($message, $exception); - case '1052': case '1060': case '1110': return new Exception\NonUniqueFieldNameException($message, $exception); - case '1064': case '1149': case '1287': @@ -77,7 +71,6 @@ public function convertException($message, DriverException $exception) case '1554': case '1626': return new Exception\SyntaxErrorException($message, $exception); - case '1044': case '1045': case '1046': @@ -91,7 +84,6 @@ public function convertException($message, DriverException $exception) case '2002': case '2005': return new Exception\ConnectionException($message, $exception); - case '1048': case '1121': case '1138': diff --git a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php index dcbaaf097f7..f1ba8843a77 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php @@ -24,30 +24,22 @@ public function convertException($message, DriverException $exception) case '2299': case '38911': return new Exception\UniqueConstraintViolationException($message, $exception); - case '904': return new Exception\InvalidFieldNameException($message, $exception); - case '918': case '960': return new Exception\NonUniqueFieldNameException($message, $exception); - case '923': return new Exception\SyntaxErrorException($message, $exception); - case '942': return new Exception\TableNotFoundException($message, $exception); - case '955': return new Exception\TableExistsException($message, $exception); - case '1017': case '12545': return new Exception\ConnectionException($message, $exception); - case '1400': return new Exception\NotNullConstraintViolationException($message, $exception); - case '2266': case '2291': case '2292': diff --git a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php index 916d924980c..70f2f0ca6aa 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php @@ -43,28 +43,20 @@ public function convertException($message, DriverException $exception) break; case '23502': return new Exception\NotNullConstraintViolationException($message, $exception); - case '23503': return new Exception\ForeignKeyConstraintViolationException($message, $exception); - case '23505': return new Exception\UniqueConstraintViolationException($message, $exception); - case '42601': return new Exception\SyntaxErrorException($message, $exception); - case '42702': return new Exception\NonUniqueFieldNameException($message, $exception); - case '42703': return new Exception\InvalidFieldNameException($message, $exception); - case '42P01': return new Exception\TableNotFoundException($message, $exception); - case '42P07': return new Exception\TableExistsException($message, $exception); - case '7': // In some case (mainly connection errors) the PDO exception does not provide a SQLSTATE via its code. // The exception code is always set to 7 here. diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index af6e852bc43..339c9be92d0 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -261,13 +261,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX switch ($fetchMode) { case FetchMode::COLUMN: return $this->fetchColumn(); - case FetchMode::MIXED: return db2_fetch_both($this->stmt); - case FetchMode::ASSOCIATIVE: return db2_fetch_assoc($this->stmt); - case FetchMode::CUSTOM_OBJECT: $className = $this->defaultFetchClass; $ctorArgs = $this->defaultFetchClassCtorArgs; @@ -285,13 +282,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX } return $result; - case FetchMode::NUMERIC: return db2_fetch_array($this->stmt); - case FetchMode::STANDARD_OBJECT: return db2_fetch_object($this->stmt); - default: throw new DB2Exception('Given Fetch-Style ' . $fetchMode . ' is not supported.'); } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index 1f1a1d218c3..54ad02d37e4 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -57,7 +57,7 @@ public function __construct(array $params, $username, $password, array $driverOp $socket = $params['unix_socket'] ?? ini_get('mysqli.default_socket'); $dbname = $params['dbname'] ?? null; - $flags = $driverOptions[static::OPTION_FLAGS] ?? null; + $flags = $driverOptions[self::OPTION_FLAGS] ?? null; $this->conn = mysqli_init(); @@ -239,7 +239,7 @@ private function setDriverOptions(array $driverOptions = []) $exceptionMsg = "%s option '%s' with value '%s'"; foreach ($driverOptions as $option => $value) { - if ($option === static::OPTION_FLAGS) { + if ($option === self::OPTION_FLAGS) { continue; } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 893b3be4688..f284d838486 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -225,9 +225,9 @@ private function bindTypedParameters() $streams[$parameter] = $value; $values[$parameter] = null; continue; - } else { - $types[$parameter - 1] = static::$_paramTypeMap[ParameterType::STRING]; } + + $types[$parameter - 1] = static::$_paramTypeMap[ParameterType::STRING]; } $values[$parameter] = $value; @@ -338,13 +338,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX switch ($fetchMode) { case FetchMode::ASSOCIATIVE: return $assoc; - case FetchMode::MIXED: return $assoc + $values; - case FetchMode::STANDARD_OBJECT: return (object) $assoc; - default: throw new MysqliException(sprintf("Unknown fetch type '%s'", $fetchMode)); } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index f5a141c1732..b2d9476501f 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -254,6 +254,7 @@ private static function findToken($statement, &$offset, $regex) { if (preg_match($regex, $statement, $matches, PREG_OFFSET_CAPTURE, $offset)) { $offset = $matches[0][1]; + return $matches[0][0]; } @@ -305,10 +306,8 @@ private function convertParameterType(int $type) : int switch ($type) { case ParameterType::BINARY: return OCI_B_BIN; - case ParameterType::LARGE_OBJECT: return OCI_B_BLOB; - default: return SQLT_CHR; } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 886bb245873..0f65d66f205 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -210,13 +210,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX switch ($fetchMode) { case FetchMode::COLUMN: return $this->fetchColumn(); - case FetchMode::ASSOCIATIVE: return sasql_fetch_assoc($this->result); - case FetchMode::MIXED: return sasql_fetch_array($this->result, SASQL_BOTH); - case FetchMode::CUSTOM_OBJECT: $className = $this->defaultFetchClass; $ctorArgs = $this->defaultFetchClassCtorArgs; @@ -234,13 +231,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX } return $result; - case FetchMode::NUMERIC: return sasql_fetch_row($this->result); - case FetchMode::STANDARD_OBJECT: return sasql_fetch_object($this->result); - default: throw new SQLAnywhereException('Fetch mode is not supported: ' . $fetchMode); } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index e36bc9051cf..35ad913ff5b 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -100,7 +100,9 @@ public function quote($value, $type = ParameterType::STRING) { if (is_int($value)) { return $value; - } elseif (is_float($value)) { + } + + if (is_float($value)) { return sprintf('%F', $value); } diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index cb9db2c0221..6888d73b0c4 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -174,7 +174,9 @@ public static function getConnection( // check for existing pdo object if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) { throw DBALException::invalidPdoInstance(); - } elseif (isset($params['pdo'])) { + } + + if (isset($params['pdo'])) { $params['pdo']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $params['driver'] = 'pdo_' . $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME); } else { diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 6a6c65a4092..abb7333ac1d 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -2968,7 +2968,6 @@ public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) return $this->getDateTimeTypeDeclarationSQL($fieldDeclaration); } - /** * Obtains DBMS specific SQL to be used to create date fields in statements * like CREATE TABLE. diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index 88c9b187f9d..60457146fd0 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -501,6 +501,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options foreach ($indexes as $definition) { $sqls[] = $this->getCreateIndexSQL($definition, $tableName); } + return $sqls; } diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 9679a8447e7..ae1f9cd33c8 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -247,15 +247,15 @@ public function getClobTypeDeclarationSQL(array $field) if (! empty($field['length']) && is_numeric($field['length'])) { $length = $field['length']; - if ($length <= static::LENGTH_LIMIT_TINYTEXT) { + if ($length <= self::LENGTH_LIMIT_TINYTEXT) { return 'TINYTEXT'; } - if ($length <= static::LENGTH_LIMIT_TEXT) { + if ($length <= self::LENGTH_LIMIT_TEXT) { return 'TEXT'; } - if ($length <= static::LENGTH_LIMIT_MEDIUMTEXT) { + if ($length <= self::LENGTH_LIMIT_MEDIUMTEXT) { return 'MEDIUMTEXT'; } } @@ -1137,15 +1137,15 @@ public function getBlobTypeDeclarationSQL(array $field) if (! empty($field['length']) && is_numeric($field['length'])) { $length = $field['length']; - if ($length <= static::LENGTH_LIMIT_TINYBLOB) { + if ($length <= self::LENGTH_LIMIT_TINYBLOB) { return 'TINYBLOB'; } - if ($length <= static::LENGTH_LIMIT_BLOB) { + if ($length <= self::LENGTH_LIMIT_BLOB) { return 'BLOB'; } - if ($length <= static::LENGTH_LIMIT_MEDIUMBLOB) { + if ($length <= self::LENGTH_LIMIT_MEDIUMBLOB) { return 'MEDIUMBLOB'; } } diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 711fbccbd53..c091d483064 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -114,7 +114,6 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv } return 'ADD_MONTHS(' . $date . ', ' . $operator . $interval . ')'; - default: $calculationClause = ''; @@ -201,9 +200,13 @@ private function getSequenceCacheSQL(Sequence $sequence) { if ($sequence->getCache() === 0) { return ' NOCACHE'; - } elseif ($sequence->getCache() === 1) { + } + + if ($sequence->getCache() === 1) { return ' NOCACHE'; - } elseif ($sequence->getCache() > 1) { + } + + if ($sequence->getCache() > 1) { return ' CACHE ' . $sequence->getCache(); } @@ -739,11 +742,9 @@ public function getForeignKeyReferentialActionSQL($action) // NO ACTION cannot be declared explicitly, // therefore returning empty string to indicate to OMIT the referential clause. return ''; - case 'CASCADE': case 'SET NULL': return $action; - default: // SET DEFAULT is not supported, throw exception instead. throw new InvalidArgumentException('Invalid foreign key action: ' . $action); diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 806d59e6c97..4458ae27750 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -821,7 +821,7 @@ private function convertSingleBooleanValue($value, $callback) } if (is_bool($value) || is_numeric($value)) { - return $callback($value ? true : false); + return $callback((bool) $value); } if (! is_string($value)) { diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index 510c153e65f..f01905e7b74 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -49,13 +49,10 @@ public function appendLockHint($fromClause, $lockMode) switch (true) { case $lockMode === LockMode::NONE: return $fromClause . ' WITH (NOLOCK)'; - case $lockMode === LockMode::PESSIMISTIC_READ: return $fromClause . ' WITH (UPDLOCK)'; - case $lockMode === LockMode::PESSIMISTIC_WRITE: return $fromClause . ' WITH (XLOCK)'; - default: return $fromClause; } @@ -627,12 +624,15 @@ public function getForeignKeyMatchClauseSQL($type) switch ((int) $type) { case self::FOREIGN_KEY_MATCH_SIMPLE: return 'SIMPLE'; + break; case self::FOREIGN_KEY_MATCH_FULL: return 'FULL'; + break; case self::FOREIGN_KEY_MATCH_SIMPLE_UNIQUE: return 'UNIQUE SIMPLE'; + break; case self::FOREIGN_KEY_MATCH_FULL_UNIQUE: return 'UNIQUE FULL'; diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 01417d7e292..2722137ab66 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1349,6 +1349,7 @@ private function scrubInnerOrderBy($query) $query = substr($query, 0, $orderByPos) . substr($query, $currentPosition - 1); $offset = $orderByPos; } + return $query; } @@ -1547,13 +1548,10 @@ public function appendLockHint($fromClause, $lockMode) switch (true) { case $lockMode === LockMode::NONE: return $fromClause . ' WITH (NOLOCK)'; - case $lockMode === LockMode::PESSIMISTIC_READ: return $fromClause . ' WITH (HOLDLOCK, ROWLOCK)'; - case $lockMode === LockMode::PESSIMISTIC_WRITE: return $fromClause . ' WITH (UPDLOCK, ROWLOCK)'; - default: return $fromClause; } diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 009a8f23df4..4fc8c72bb87 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -128,7 +128,6 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv case DateIntervalUnit::MINUTE: case DateIntervalUnit::HOUR: return 'DATETIME(' . $date . ",'" . $operator . $interval . ' ' . $unit . "')"; - default: switch ($unit) { case DateIntervalUnit::WEEK: @@ -1070,12 +1069,14 @@ private function getIndexesInAlteredTable(TableDiff $diff) if (! isset($columnNames[$normalizedColumnName])) { unset($indexes[$key]); continue 2; - } else { - $indexColumns[] = $columnNames[$normalizedColumnName]; - if ($columnName !== $columnNames[$normalizedColumnName]) { - $changed = true; - } } + + $indexColumns[] = $columnNames[$normalizedColumnName]; + if ($columnName === $columnNames[$normalizedColumnName]) { + continue; + } + + $changed = true; } if (! $changed) { @@ -1122,12 +1123,14 @@ private function getForeignKeysInAlteredTable(TableDiff $diff) if (! isset($columnNames[$normalizedColumnName])) { unset($foreignKeys[$key]); continue 2; - } else { - $localColumns[] = $columnNames[$normalizedColumnName]; - if ($columnName !== $columnNames[$normalizedColumnName]) { - $changed = true; - } } + + $localColumns[] = $columnNames[$normalizedColumnName]; + if ($columnName === $columnNames[$normalizedColumnName]) { + continue; + } + + $changed = true; } if (! $changed) { diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 773afa23d87..1c08db193dd 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -866,7 +866,6 @@ public function groupBy($groupBy) return $this->add('groupBy', $groupBy, false); } - /** * Adds a grouping expression to the query. * @@ -1188,6 +1187,7 @@ private function getSQLForInsert() private function getSQLForUpdate() { $table = $this->sqlParts['from']['table'] . ($this->sqlParts['from']['alias'] ? ' ' . $this->sqlParts['from']['alias'] : ''); + return 'UPDATE ' . $table . ' SET ' . implode(', ', $this->sqlParts['set']) . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : ''); @@ -1201,6 +1201,7 @@ private function getSQLForUpdate() private function getSQLForDelete() { $table = $this->sqlParts['from']['table'] . ($this->sqlParts['from']['alias'] ? ' ' . $this->sqlParts['from']['alias'] : ''); + return 'DELETE FROM ' . $table . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : ''); } diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 8c055921c7c..5c92c2e3f7b 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -854,7 +854,7 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName = nu $result[$keyName] = [ 'name' => $indexName, 'columns' => [], - 'unique' => $tableIndex['non_unique'] ? false : true, + 'unique' => ! $tableIndex['non_unique'], 'primary' => $tableIndex['primary'], 'flags' => $tableIndex['flags'] ?? [], 'options' => $options, diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index 0307a0d537d..0ae7aba2cf4 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -178,7 +178,9 @@ protected function _getPortableForeignKeyRuleDef($def) { if ($def === 'C') { return 'CASCADE'; - } elseif ($def === 'N') { + } + + if ($def === 'N') { return 'SET NULL'; } diff --git a/lib/Doctrine/DBAL/Schema/Index.php b/lib/Doctrine/DBAL/Schema/Index.php index 91ffd472465..7a31c7824bf 100644 --- a/lib/Doctrine/DBAL/Schema/Index.php +++ b/lib/Doctrine/DBAL/Schema/Index.php @@ -243,7 +243,9 @@ public function overrules(Index $other) { if ($other->isPrimary()) { return false; - } elseif ($this->isSimpleIndex() && $other->isUnique()) { + } + + if ($this->isSimpleIndex() && $other->isUnique()) { return false; } diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 4cc31a9258a..fb957f247ff 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -230,6 +230,7 @@ private function getMariaDb1027ColumnDefault(MariaDb1027Platform $platform, ?str case 'curtime()': return $platform->getCurrentTimeSQL(); } + return $columnDefault; } diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 9d03552b667..e819d963f03 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -205,7 +205,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null $idx = []; $idx['key_name'] = $keyName; $idx['primary'] = false; - $idx['non_unique'] = $tableIndex['unique']?false:true; + $idx['non_unique'] = ! $tableIndex['unique']; $stmt = $this->_conn->executeQuery(sprintf( 'PRAGMA INDEX_INFO (%s)', diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php index 0925b7743c8..dd4b1ca5f40 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php @@ -31,7 +31,6 @@ public function getCreateSchema(Schema $createSchema) return $createSchema->toSql($this->platform); } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 6030f25cffa..af853c277d5 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -610,6 +610,7 @@ private function getForeignKeyColumns() foreach ($this->getForeignKeys() as $foreignKey) { $foreignKeyColumns = array_merge($foreignKeyColumns, $foreignKey->getColumns()); } + return $this->filterColumns($foreignKeyColumns); } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php b/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php index 9b23b395885..001ea2a0d70 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php @@ -65,6 +65,7 @@ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkCons // point to nowhere. if (! $this->schema->hasTable($fkConstraint->getForeignTableName())) { $localTable->removeForeignKey($fkConstraint->getName()); + return; } diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index b65fa95e33a..09913bb56ae 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -217,7 +217,9 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) { if ($arg2 === null) { return $this->stmt->setFetchMode($fetchMode); - } elseif ($arg3 === null) { + } + + if ($arg3 === null) { return $this->stmt->setFetchMode($fetchMode, $arg2); } diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index 22bce134061..a45a60c6085 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -73,7 +73,9 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new InvalidArgumentException( sprintf("SQL file '%s' does not exist.", $filePath) ); - } elseif (! is_readable($filePath)) { + } + + if (! is_readable($filePath)) { throw new InvalidArgumentException( sprintf("SQL file '%s' does not have read permissions.", $filePath) ); diff --git a/lib/Doctrine/DBAL/Tools/Dumper.php b/lib/Doctrine/DBAL/Tools/Dumper.php index 6174b7ad865..3668efbe4d1 100644 --- a/lib/Doctrine/DBAL/Tools/Dumper.php +++ b/lib/Doctrine/DBAL/Tools/Dumper.php @@ -73,6 +73,7 @@ public static function dump($var, int $maxDepth = 2) : string try { $output = ob_get_clean(); assert(is_string($output)); + return strip_tags(html_entity_decode($output)); } finally { ini_set('html_errors', $html); diff --git a/phpcs.xml.dist b/phpcs.xml.dist index c38da21aa70..6567098ebf3 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -60,7 +60,7 @@ - + lib/Doctrine/DBAL/Schema/Comparator.php diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index fdb0ace7078..205f3fd6a75 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -36,7 +36,7 @@ class DataAccessTest extends DbalFunctionalTestCase { /** @var bool */ - static private $generated = false; + private static $generated = false; protected function setUp() : void { diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index 82f9e6541ed..06f6c18bbe3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -223,6 +223,7 @@ private function hydrateStmt($stmt, $fetchMode = FetchMode::ASSOCIATIVE) $data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row; } $stmt->closeCursor(); + return $data; } @@ -234,6 +235,7 @@ private function hydrateStmtIterator($stmt, $fetchMode = FetchMode::ASSOCIATIVE) $data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row; } $stmt->closeCursor(); + return $data; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index b30c861f704..597947d4575 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -390,6 +390,7 @@ public function testJsonbColumn(string $type) : void { if (! $this->schemaManager->getDatabasePlatform() instanceof PostgreSQL94Platform) { $this->markTestSkipped('Requires PostgresSQL 9.4+'); + return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index c9826f14243..aeb9f4c90dd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -56,6 +56,7 @@ protected function getPlatformName() $class = static::class; $e = explode('\\', $class); $testClass = end($e); + return strtolower(str_replace('SchemaManagerTest', null, $testClass)); } @@ -72,7 +73,6 @@ protected function setUp() : void $this->schemaManager = $this->connection->getSchemaManager(); } - protected function tearDown() : void { parent::tearDown(); @@ -88,7 +88,6 @@ protected function tearDown() : void } } - /** * @group DBAL-1220 */ @@ -632,7 +631,6 @@ public function testAlterTableScenario() self::assertEquals(['id'], array_map('strtolower', $foreignKey->getForeignColumns())); } - public function testTableInNamespace() { if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) { @@ -982,6 +980,7 @@ protected function getTestTable($name, $options = []) $table->setPrimaryKey(['id']); $table->addColumn('test', 'string', ['length' => 255]); $table->addColumn('foreign_key_test', 'integer'); + return $table; } @@ -993,6 +992,7 @@ protected function getTestCompositeTable($name) $table->addColumn('other_id', 'integer', ['notnull' => true]); $table->setPrimaryKey(['id', 'other_id']); $table->addColumn('test', 'string', ['length' => 255]); + return $table; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php index 768b65275f7..d5d917474ce 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php @@ -13,7 +13,7 @@ class TypeConversionTest extends DbalFunctionalTestCase { /** @var int */ - static private $typeCounter = 0; + private static $typeCounter = 0; protected function setUp() : void { diff --git a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php index c4efa1b8377..a0bf8936f50 100644 --- a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php +++ b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php @@ -8,8 +8,6 @@ use Doctrine\Tests\DbalPerformanceTestCase; /** - * Class TypeConversionPerformanceTest - * * @group performance */ class TypeConversionPerformanceTest extends DbalPerformanceTestCase diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index 79dbc0040b1..ea6a6ffe59e 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -75,7 +75,6 @@ public function testGeneratesTransactionsCommands() ); } - public function testGeneratesDDLSnippets() { self::assertEquals('SHOW DATABASES', $this->platform->getListDatabasesSQL()); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 5feba5f96f6..910f2daa2c1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -628,8 +628,11 @@ public function testQuotedColumnInPrimaryKeyPropagation() } abstract protected function getQuotedColumnInPrimaryKeySQL(); + abstract protected function getQuotedColumnInIndexSQL(); + abstract protected function getQuotedNameInIndexSQL(); + abstract protected function getQuotedColumnInForeignKeySQL(); /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php index b908c427c28..91f8cfe2dc2 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php @@ -44,7 +44,6 @@ public function testGeneratesSequenceSqlCommands() ); } - public function testModifyLimitQuery() { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); @@ -270,7 +269,6 @@ public function testModifyLimitQueryWithComplexOrderByExpression() self::assertEquals($sql, $expected); } - /** * @throws DBALException */ diff --git a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php index 51fe749e28e..caf93439244 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php @@ -99,6 +99,7 @@ public function createColumn() ]; $string = Type::getType('string'); + return new Column('foo', $string, $options); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index 4376448072d..5222a1ee548 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -795,7 +795,6 @@ public function testDetectChangeIdentifierType() self::assertArrayHasKey('id', $tableDiff->changedColumns); } - /** * @group DBAL-105 */ @@ -823,7 +822,6 @@ public function testDiff() self::assertCount(0, $tableDiff->removedColumns); } - /** * @group DBAL-112 */ @@ -963,7 +961,6 @@ public function testAutoIncrementSequences() self::assertCount(0, $diff->removedSequences); } - /** * Check that added autoincrement sequence is not populated in newSequences * @@ -987,6 +984,7 @@ public function testAutoIncrementNoSequences() self::assertCount(0, $diff->newSequences); } + /** * You can get multiple drops for a FK when a table referenced by a foreign * key is deleted, as this FK is referenced twice, once on the orphanedForeignKeys diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php index 78d4582d880..8400e952ef6 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php @@ -118,6 +118,7 @@ public function createSchemaDiff() $fk = new ForeignKeyConstraint(['id'], 'foreign_table', ['id']); $fk->setLocalTable(new Table('local_table')); $diff->orphanedForeignKeys[] = $fk; + return $diff; } } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php index 78fd894de05..f1f6cc0e2e7 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php @@ -25,6 +25,7 @@ private function createPassthroughShardChoser() ->will($this->returnCallback(static function ($value) { return $value; })); + return $mock; } @@ -34,6 +35,7 @@ private function createStaticShardChooser() $mock->expects($this->any()) ->method('pickShard') ->willReturn(1); + return $mock; } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php index b96a9eaa173..3a0d37ab4ce 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php @@ -89,6 +89,7 @@ private function createConnection(array $params) ->disableOriginalConstructor() ->getMock(); $conn->expects($this->at(0))->method('getParams')->will($this->returnValue($params)); + return $conn; } } diff --git a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php index f0183ef854c..3030899cd51 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php @@ -26,6 +26,7 @@ public function testConversionFailedInvalidTypeWithScalar($scalarValue) $exception->getMessage() ); } + /** * @param mixed $nonScalar * diff --git a/tests/Doctrine/Tests/DbalFunctionalTestCase.php b/tests/Doctrine/Tests/DbalFunctionalTestCase.php index 1e37c3060e8..2ae17cf9165 100644 --- a/tests/Doctrine/Tests/DbalFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DbalFunctionalTestCase.php @@ -74,7 +74,9 @@ protected function onNotSuccessfulTest(Throwable $t) : void $params = array_map(static function ($p) { if (is_object($p)) { return get_class($p); - } elseif (is_scalar($p)) { + } + + if (is_scalar($p)) { return "'" . $p . "'"; } diff --git a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php index 7b8872f2ea8..fa22cc5f91b 100644 --- a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php @@ -10,6 +10,7 @@ class DriverConnectionMock implements Connection public function prepare($prepareString) { } + public function query() { } @@ -21,21 +22,27 @@ public function quote($input, $type = ParameterType::STRING) public function exec($statement) { } + public function lastInsertId($name = null) { } + public function beginTransaction() { } + public function commit() { } + public function rollBack() { } + public function errorCode() { } + public function errorInfo() { } From bf0684430e2c27bec1aa245e35ec4fcc50a4427e Mon Sep 17 00:00:00 2001 From: Ahmed Abdou Date: Sun, 17 Mar 2019 22:38:13 +0100 Subject: [PATCH 048/106] disable two rules for phpcs --- lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php | 8 ++++++++ lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php | 8 ++++++++ .../DBAL/Driver/AbstractPostgreSQLDriver.php | 8 ++++++++ lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php | 6 ++++++ lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php | 4 ++-- lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php | 3 +++ lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php | 2 ++ .../DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php | 6 ++++++ lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 12 ++++++------ lib/Doctrine/DBAL/Platforms/OraclePlatform.php | 3 +++ lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php | 3 +++ lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php | 3 +++ lib/Doctrine/DBAL/Platforms/SqlitePlatform.php | 1 + phpcs.xml.dist | 2 ++ 14 files changed, 61 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php index 8ae86e5c72a..c46ddc63dd7 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php @@ -36,28 +36,34 @@ public function convertException($message, DriverException $exception) return new Exception\LockWaitTimeoutException($message, $exception); case '1050': return new Exception\TableExistsException($message, $exception); + case '1051': case '1146': return new Exception\TableNotFoundException($message, $exception); + case '1216': case '1217': case '1451': case '1452': case '1701': return new Exception\ForeignKeyConstraintViolationException($message, $exception); + case '1062': case '1557': case '1569': case '1586': return new Exception\UniqueConstraintViolationException($message, $exception); + case '1054': case '1166': case '1611': return new Exception\InvalidFieldNameException($message, $exception); + case '1052': case '1060': case '1110': return new Exception\NonUniqueFieldNameException($message, $exception); + case '1064': case '1149': case '1287': @@ -71,6 +77,7 @@ public function convertException($message, DriverException $exception) case '1554': case '1626': return new Exception\SyntaxErrorException($message, $exception); + case '1044': case '1045': case '1046': @@ -84,6 +91,7 @@ public function convertException($message, DriverException $exception) case '2002': case '2005': return new Exception\ConnectionException($message, $exception); + case '1048': case '1121': case '1138': diff --git a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php index f1ba8843a77..dcbaaf097f7 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php @@ -24,22 +24,30 @@ public function convertException($message, DriverException $exception) case '2299': case '38911': return new Exception\UniqueConstraintViolationException($message, $exception); + case '904': return new Exception\InvalidFieldNameException($message, $exception); + case '918': case '960': return new Exception\NonUniqueFieldNameException($message, $exception); + case '923': return new Exception\SyntaxErrorException($message, $exception); + case '942': return new Exception\TableNotFoundException($message, $exception); + case '955': return new Exception\TableExistsException($message, $exception); + case '1017': case '12545': return new Exception\ConnectionException($message, $exception); + case '1400': return new Exception\NotNullConstraintViolationException($message, $exception); + case '2266': case '2291': case '2292': diff --git a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php index 70f2f0ca6aa..916d924980c 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php @@ -43,20 +43,28 @@ public function convertException($message, DriverException $exception) break; case '23502': return new Exception\NotNullConstraintViolationException($message, $exception); + case '23503': return new Exception\ForeignKeyConstraintViolationException($message, $exception); + case '23505': return new Exception\UniqueConstraintViolationException($message, $exception); + case '42601': return new Exception\SyntaxErrorException($message, $exception); + case '42702': return new Exception\NonUniqueFieldNameException($message, $exception); + case '42703': return new Exception\InvalidFieldNameException($message, $exception); + case '42P01': return new Exception\TableNotFoundException($message, $exception); + case '42P07': return new Exception\TableExistsException($message, $exception); + case '7': // In some case (mainly connection errors) the PDO exception does not provide a SQLSTATE via its code. // The exception code is always set to 7 here. diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 339c9be92d0..af6e852bc43 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -261,10 +261,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX switch ($fetchMode) { case FetchMode::COLUMN: return $this->fetchColumn(); + case FetchMode::MIXED: return db2_fetch_both($this->stmt); + case FetchMode::ASSOCIATIVE: return db2_fetch_assoc($this->stmt); + case FetchMode::CUSTOM_OBJECT: $className = $this->defaultFetchClass; $ctorArgs = $this->defaultFetchClassCtorArgs; @@ -282,10 +285,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX } return $result; + case FetchMode::NUMERIC: return db2_fetch_array($this->stmt); + case FetchMode::STANDARD_OBJECT: return db2_fetch_object($this->stmt); + default: throw new DB2Exception('Given Fetch-Style ' . $fetchMode . ' is not supported.'); } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index 54ad02d37e4..1f1a1d218c3 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -57,7 +57,7 @@ public function __construct(array $params, $username, $password, array $driverOp $socket = $params['unix_socket'] ?? ini_get('mysqli.default_socket'); $dbname = $params['dbname'] ?? null; - $flags = $driverOptions[self::OPTION_FLAGS] ?? null; + $flags = $driverOptions[static::OPTION_FLAGS] ?? null; $this->conn = mysqli_init(); @@ -239,7 +239,7 @@ private function setDriverOptions(array $driverOptions = []) $exceptionMsg = "%s option '%s' with value '%s'"; foreach ($driverOptions as $option => $value) { - if ($option === self::OPTION_FLAGS) { + if ($option === static::OPTION_FLAGS) { continue; } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index f284d838486..43d70853ef5 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -338,10 +338,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX switch ($fetchMode) { case FetchMode::ASSOCIATIVE: return $assoc; + case FetchMode::MIXED: return $assoc + $values; + case FetchMode::STANDARD_OBJECT: return (object) $assoc; + default: throw new MysqliException(sprintf("Unknown fetch type '%s'", $fetchMode)); } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index b2d9476501f..f9540110263 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -306,8 +306,10 @@ private function convertParameterType(int $type) : int switch ($type) { case ParameterType::BINARY: return OCI_B_BIN; + case ParameterType::LARGE_OBJECT: return OCI_B_BLOB; + default: return SQLT_CHR; } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 0f65d66f205..886bb245873 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -210,10 +210,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX switch ($fetchMode) { case FetchMode::COLUMN: return $this->fetchColumn(); + case FetchMode::ASSOCIATIVE: return sasql_fetch_assoc($this->result); + case FetchMode::MIXED: return sasql_fetch_array($this->result, SASQL_BOTH); + case FetchMode::CUSTOM_OBJECT: $className = $this->defaultFetchClass; $ctorArgs = $this->defaultFetchClassCtorArgs; @@ -231,10 +234,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX } return $result; + case FetchMode::NUMERIC: return sasql_fetch_row($this->result); + case FetchMode::STANDARD_OBJECT: return sasql_fetch_object($this->result); + default: throw new SQLAnywhereException('Fetch mode is not supported: ' . $fetchMode); } diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index ae1f9cd33c8..9679a8447e7 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -247,15 +247,15 @@ public function getClobTypeDeclarationSQL(array $field) if (! empty($field['length']) && is_numeric($field['length'])) { $length = $field['length']; - if ($length <= self::LENGTH_LIMIT_TINYTEXT) { + if ($length <= static::LENGTH_LIMIT_TINYTEXT) { return 'TINYTEXT'; } - if ($length <= self::LENGTH_LIMIT_TEXT) { + if ($length <= static::LENGTH_LIMIT_TEXT) { return 'TEXT'; } - if ($length <= self::LENGTH_LIMIT_MEDIUMTEXT) { + if ($length <= static::LENGTH_LIMIT_MEDIUMTEXT) { return 'MEDIUMTEXT'; } } @@ -1137,15 +1137,15 @@ public function getBlobTypeDeclarationSQL(array $field) if (! empty($field['length']) && is_numeric($field['length'])) { $length = $field['length']; - if ($length <= self::LENGTH_LIMIT_TINYBLOB) { + if ($length <= static::LENGTH_LIMIT_TINYBLOB) { return 'TINYBLOB'; } - if ($length <= self::LENGTH_LIMIT_BLOB) { + if ($length <= static::LENGTH_LIMIT_BLOB) { return 'BLOB'; } - if ($length <= self::LENGTH_LIMIT_MEDIUMBLOB) { + if ($length <= static::LENGTH_LIMIT_MEDIUMBLOB) { return 'MEDIUMBLOB'; } } diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index c091d483064..ced7fbf9bdc 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -114,6 +114,7 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv } return 'ADD_MONTHS(' . $date . ', ' . $operator . $interval . ')'; + default: $calculationClause = ''; @@ -742,9 +743,11 @@ public function getForeignKeyReferentialActionSQL($action) // NO ACTION cannot be declared explicitly, // therefore returning empty string to indicate to OMIT the referential clause. return ''; + case 'CASCADE': case 'SET NULL': return $action; + default: // SET DEFAULT is not supported, throw exception instead. throw new InvalidArgumentException('Invalid foreign key action: ' . $action); diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index f01905e7b74..6e3b2fcb958 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -49,10 +49,13 @@ public function appendLockHint($fromClause, $lockMode) switch (true) { case $lockMode === LockMode::NONE: return $fromClause . ' WITH (NOLOCK)'; + case $lockMode === LockMode::PESSIMISTIC_READ: return $fromClause . ' WITH (UPDLOCK)'; + case $lockMode === LockMode::PESSIMISTIC_WRITE: return $fromClause . ' WITH (XLOCK)'; + default: return $fromClause; } diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 2722137ab66..a2e68049d68 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1548,10 +1548,13 @@ public function appendLockHint($fromClause, $lockMode) switch (true) { case $lockMode === LockMode::NONE: return $fromClause . ' WITH (NOLOCK)'; + case $lockMode === LockMode::PESSIMISTIC_READ: return $fromClause . ' WITH (HOLDLOCK, ROWLOCK)'; + case $lockMode === LockMode::PESSIMISTIC_WRITE: return $fromClause . ' WITH (UPDLOCK, ROWLOCK)'; + default: return $fromClause; } diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 4fc8c72bb87..b7382ec08b0 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -128,6 +128,7 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv case DateIntervalUnit::MINUTE: case DateIntervalUnit::HOUR: return 'DATETIME(' . $date . ",'" . $operator . $interval . ' ' . $unit . "')"; + default: switch ($unit) { case DateIntervalUnit::WEEK: diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 6567098ebf3..6fdaaf512c4 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -19,6 +19,8 @@ + + From 105e5c581a7707eedec4c0bd5048176893508019 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Wed, 3 Apr 2019 12:55:07 +0200 Subject: [PATCH 049/106] Fix the branch alias for master Version was bumped to 2.10-dev in 27023276734da75a08cfdd31995884df8030975c but the branch alias was forgotten. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e5ff569c2d6..3ba89fcd764 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.9.x-dev", + "dev-master": "2.10.x-dev", "dev-develop": "3.0.x-dev" } } From e555e16fed3de782afcb7e363b6169f42d3755ff Mon Sep 17 00:00:00 2001 From: David Bruchmann Date: Thu, 4 Apr 2019 08:20:21 +0700 Subject: [PATCH 050/106] fix #3479 (typos in example-code in QueryBuilder) fix two typos in QueryBuilder, on of them reported in #3479 --- lib/Doctrine/DBAL/Query/QueryBuilder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 1c08db193dd..50c08655ff3 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -504,7 +504,7 @@ public function addSelect($select = null) * * $qb = $conn->createQueryBuilder() * ->delete('users', 'u') - * ->where('u.id = :user_id'); + * ->where('u.id = :user_id') * ->setParameter(':user_id', 1); * * @@ -873,8 +873,8 @@ public function groupBy($groupBy) * $qb = $conn->createQueryBuilder() * ->select('u.name') * ->from('users', 'u') - * ->groupBy('u.lastLogin'); - * ->addGroupBy('u.createdAt') + * ->groupBy('u.lastLogin') + * ->addGroupBy('u.createdAt'); * * * @param mixed $groupBy The grouping expression. From 74a2714de32d7de161790d0f54561c5b2b3e4e4b Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 6 Apr 2019 09:03:53 -0700 Subject: [PATCH 051/106] Enabled the build against IBM DB2 on PHP 7.3 on Travis CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 17d123db603..6b1fd5913a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -257,7 +257,7 @@ jobs: - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test - php: 7.2 + php: 7.3 env: DB=ibm_db2 COVERAGE=yes sudo: required services: From 089f32e63a0774c9ecfdba32bb3f2684c9aaab55 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sat, 18 Aug 2018 23:12:47 +0200 Subject: [PATCH 052/106] Extract type factory and registry from Type into TypeRegistry --- lib/Doctrine/DBAL/DBALException.php | 14 ++ lib/Doctrine/DBAL/Types/Type.php | 151 ++++++++--------- lib/Doctrine/DBAL/Types/TypeRegistry.php | 118 ++++++++++++++ .../Tests/DBAL/Types/TypeRegistryTest.php | 154 ++++++++++++++++++ tests/Doctrine/Tests/DBAL/Types/TypeTest.php | 34 ++++ 5 files changed, 398 insertions(+), 73 deletions(-) create mode 100644 lib/Doctrine/DBAL/Types/TypeRegistry.php create mode 100644 tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php create mode 100644 tests/Doctrine/Tests/DBAL/Types/TypeTest.php diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index 02cad00cc43..4961af2f35f 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\ExceptionConverterDriver; use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Type; use Exception; use Throwable; use function array_map; @@ -18,6 +19,7 @@ use function is_string; use function json_encode; use function preg_replace; +use function spl_object_hash; use function sprintf; class DBALException extends Exception @@ -277,4 +279,16 @@ public static function typeNotFound($name) { return new self('Type to be overwritten ' . $name . ' does not exist.'); } + + public static function typeNotRegistered(Type $type) : self + { + return new self(sprintf('Type of the class %s@%s is not registered.', get_class($type), spl_object_hash($type))); + } + + public static function typeAlreadyRegistered(Type $type) : self + { + return new self( + sprintf('Type of the class %s@%s is already registered.', get_class($type), spl_object_hash($type)) + ); + } } diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 025eb14cbda..f6aa3dde046 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -5,6 +5,8 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; +use function array_map; +use function get_class; use function str_replace; use function strrpos; use function substr; @@ -16,76 +18,70 @@ */ abstract class Type { - public const TARRAY = 'array'; - public const SIMPLE_ARRAY = 'simple_array'; - public const JSON_ARRAY = 'json_array'; - public const JSON = 'json'; public const BIGINT = 'bigint'; + public const BINARY = 'binary'; + public const BLOB = 'blob'; public const BOOLEAN = 'boolean'; + public const DATE = 'date'; + public const DATE_IMMUTABLE = 'date_immutable'; + public const DATEINTERVAL = 'dateinterval'; public const DATETIME = 'datetime'; public const DATETIME_IMMUTABLE = 'datetime_immutable'; public const DATETIMETZ = 'datetimetz'; public const DATETIMETZ_IMMUTABLE = 'datetimetz_immutable'; - public const DATE = 'date'; - public const DATE_IMMUTABLE = 'date_immutable'; - public const TIME = 'time'; - public const TIME_IMMUTABLE = 'time_immutable'; public const DECIMAL = 'decimal'; + public const FLOAT = 'float'; + public const GUID = 'guid'; public const INTEGER = 'integer'; + public const JSON = 'json'; + public const JSON_ARRAY = 'json_array'; public const OBJECT = 'object'; + public const SIMPLE_ARRAY = 'simple_array'; public const SMALLINT = 'smallint'; public const STRING = 'string'; + public const TARRAY = 'array'; public const TEXT = 'text'; - public const BINARY = 'binary'; - public const BLOB = 'blob'; - public const FLOAT = 'float'; - public const GUID = 'guid'; - public const DATEINTERVAL = 'dateinterval'; - - /** - * Map of already instantiated type objects. One instance per type (flyweight). - * - * @var self[] - */ - private static $_typeObjects = []; + public const TIME = 'time'; + public const TIME_IMMUTABLE = 'time_immutable'; /** * The map of supported doctrine mapping types. - * - * @var string[] */ - private static $_typesMap = [ - self::TARRAY => ArrayType::class, - self::SIMPLE_ARRAY => SimpleArrayType::class, - self::JSON_ARRAY => JsonArrayType::class, - self::JSON => JsonType::class, - self::OBJECT => ObjectType::class, - self::BOOLEAN => BooleanType::class, - self::INTEGER => IntegerType::class, - self::SMALLINT => SmallIntType::class, - self::BIGINT => BigIntType::class, - self::STRING => StringType::class, - self::TEXT => TextType::class, - self::DATETIME => DateTimeType::class, - self::DATETIME_IMMUTABLE => DateTimeImmutableType::class, - self::DATETIMETZ => DateTimeTzType::class, + private const BUILTIN_TYPES_MAP = [ + self::BIGINT => BigIntType::class, + self::BINARY => BinaryType::class, + self::BLOB => BlobType::class, + self::BOOLEAN => BooleanType::class, + self::DATE => DateType::class, + self::DATE_IMMUTABLE => DateImmutableType::class, + self::DATEINTERVAL => DateIntervalType::class, + self::DATETIME => DateTimeType::class, + self::DATETIME_IMMUTABLE => DateTimeImmutableType::class, + self::DATETIMETZ => DateTimeTzType::class, self::DATETIMETZ_IMMUTABLE => DateTimeTzImmutableType::class, - self::DATE => DateType::class, - self::DATE_IMMUTABLE => DateImmutableType::class, - self::TIME => TimeType::class, - self::TIME_IMMUTABLE => TimeImmutableType::class, - self::DECIMAL => DecimalType::class, - self::FLOAT => FloatType::class, - self::BINARY => BinaryType::class, - self::BLOB => BlobType::class, - self::GUID => GuidType::class, - self::DATEINTERVAL => DateIntervalType::class, + self::DECIMAL => DecimalType::class, + self::FLOAT => FloatType::class, + self::GUID => GuidType::class, + self::INTEGER => IntegerType::class, + self::JSON => JsonType::class, + self::JSON_ARRAY => JsonArrayType::class, + self::OBJECT => ObjectType::class, + self::SIMPLE_ARRAY => SimpleArrayType::class, + self::SMALLINT => SmallIntType::class, + self::STRING => StringType::class, + self::TARRAY => ArrayType::class, + self::TEXT => TextType::class, + self::TIME => TimeType::class, + self::TIME_IMMUTABLE => TimeImmutableType::class, ]; + /** @var TypeRegistry|null */ + private static $typeRegistry; + /** - * Prevents instantiation and forces use of the factory method. + * @internal Do not instantiate directly - use {@see Type::addType()} method instead. */ - final private function __construct() + final public function __construct() { } @@ -148,6 +144,29 @@ abstract public function getSQLDeclaration(array $fieldDeclaration, AbstractPlat */ abstract public function getName(); + /** + * @internal This method is only to be used within DBAL for forward compatibility purposes. Do not use directly. + */ + final public static function getTypeRegistry() : TypeRegistry + { + if (self::$typeRegistry === null) { + self::$typeRegistry = self::createTypeRegistry(); + } + + return self::$typeRegistry; + } + + private static function createTypeRegistry() : TypeRegistry + { + $registry = new TypeRegistry(); + + foreach (self::BUILTIN_TYPES_MAP as $name => $class) { + $registry->register($name, new $class()); + } + + return $registry; + } + /** * Factory method to create type instances. * Type instances are implemented as flyweights. @@ -160,14 +179,7 @@ abstract public function getName(); */ public static function getType($name) { - if (! isset(self::$_typeObjects[$name])) { - if (! isset(self::$_typesMap[$name])) { - throw DBALException::unknownColumnType($name); - } - self::$_typeObjects[$name] = new self::$_typesMap[$name](); - } - - return self::$_typeObjects[$name]; + return self::getTypeRegistry()->get($name); } /** @@ -182,11 +194,7 @@ public static function getType($name) */ public static function addType($name, $className) { - if (isset(self::$_typesMap[$name])) { - throw DBALException::typeExists($name); - } - - self::$_typesMap[$name] = $className; + self::getTypeRegistry()->register($name, new $className()); } /** @@ -198,7 +206,7 @@ public static function addType($name, $className) */ public static function hasType($name) { - return isset(self::$_typesMap[$name]); + return self::getTypeRegistry()->has($name); } /** @@ -213,15 +221,7 @@ public static function hasType($name) */ public static function overrideType($name, $className) { - if (! isset(self::$_typesMap[$name])) { - throw DBALException::typeNotFound($name); - } - - if (isset(self::$_typeObjects[$name])) { - unset(self::$_typeObjects[$name]); - } - - self::$_typesMap[$name] = $className; + self::getTypeRegistry()->override($name, new $className()); } /** @@ -245,7 +245,12 @@ public function getBindingType() */ public static function getTypesMap() { - return self::$_typesMap; + return array_map( + static function (Type $type) : string { + return get_class($type); + }, + self::getTypeRegistry()->getMap() + ); } /** diff --git a/lib/Doctrine/DBAL/Types/TypeRegistry.php b/lib/Doctrine/DBAL/Types/TypeRegistry.php new file mode 100644 index 00000000000..7e8093cf749 --- /dev/null +++ b/lib/Doctrine/DBAL/Types/TypeRegistry.php @@ -0,0 +1,118 @@ + Map of type names and their corresponding flyweight objects. */ + private $instances = []; + + /** + * Finds a type by the given name. + * + * @throws DBALException + */ + public function get(string $name) : Type + { + if (! isset($this->instances[$name])) { + throw DBALException::unknownColumnType($name); + } + + return $this->instances[$name]; + } + + /** + * Finds a name for the given type. + * + * @throws DBALException + */ + public function lookupName(Type $type) : string + { + $name = $this->findTypeName($type); + + if ($name === null) { + throw DBALException::typeNotRegistered($type); + } + + return $name; + } + + /** + * Checks if there is a type of the given name. + */ + public function has(string $name) : bool + { + return isset($this->instances[$name]); + } + + /** + * Registers a custom type to the type map. + * + * @throws DBALException + */ + public function register(string $name, Type $type) : void + { + if (isset($this->instances[$name])) { + throw DBALException::typeExists($name); + } + + if ($this->findTypeName($type) !== null) { + throw DBALException::typeAlreadyRegistered($type); + } + + $this->instances[$name] = $type; + } + + /** + * Overrides an already defined type to use a different implementation. + * + * @throws DBALException + */ + public function override(string $name, Type $type) : void + { + if (! isset($this->instances[$name])) { + throw DBALException::typeNotFound($name); + } + + if (! in_array($this->findTypeName($type), [$name, null], true)) { + throw DBALException::typeAlreadyRegistered($type); + } + + $this->instances[$name] = $type; + } + + /** + * Gets the map of all registered types and their corresponding type instances. + * + * @internal + * + * @return array + */ + public function getMap() : array + { + return $this->instances; + } + + private function findTypeName(Type $type) : ?string + { + $name = array_search($type, $this->instances, true); + + if ($name === false) { + return null; + } + + return $name; + } +} diff --git a/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php b/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php new file mode 100644 index 00000000000..14cd7497385 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php @@ -0,0 +1,154 @@ +testType = new BlobType(); + $this->otherTestType = new BinaryType(); + + $this->registry = new TypeRegistry(); + $this->registry->register(self::TEST_TYPE_NAME, $this->testType); + $this->registry->register(self::OTHER_TEST_TYPE_NAME, $this->otherTestType); + } + + public function testGet() : void + { + self::assertSame($this->testType, $this->registry->get(self::TEST_TYPE_NAME)); + self::assertSame($this->otherTestType, $this->registry->get(self::OTHER_TEST_TYPE_NAME)); + + $this->expectException(DBALException::class); + $this->registry->get('unknown'); + } + + public function testGetReturnsSameInstances() : void + { + self::assertSame( + $this->registry->get(self::TEST_TYPE_NAME), + $this->registry->get(self::TEST_TYPE_NAME) + ); + } + + public function testLookupName() : void + { + self::assertSame( + self::TEST_TYPE_NAME, + $this->registry->lookupName($this->testType) + ); + self::assertSame( + self::OTHER_TEST_TYPE_NAME, + $this->registry->lookupName($this->otherTestType) + ); + + $this->expectException(DBALException::class); + $this->registry->lookupName(new TextType()); + } + + public function testHas() : void + { + self::assertTrue($this->registry->has(self::TEST_TYPE_NAME)); + self::assertTrue($this->registry->has(self::OTHER_TEST_TYPE_NAME)); + self::assertFalse($this->registry->has('unknown')); + } + + public function testRegister() : void + { + $newType = new TextType(); + + $this->registry->register('some', $newType); + + self::assertTrue($this->registry->has('some')); + self::assertSame($newType, $this->registry->get('some')); + } + + public function testRegisterWithAlradyRegisteredName() : void + { + $this->registry->register('some', new TextType()); + + $this->expectException(DBALException::class); + $this->registry->register('some', new TextType()); + } + + public function testRegisterWithAlreadyRegisteredInstance() : void + { + $newType = new TextType(); + + $this->registry->register('some', $newType); + + $this->expectException(DBALException::class); + $this->registry->register('other', $newType); + } + + public function testOverride() : void + { + $baseType = new TextType(); + $overrideType = new StringType(); + + $this->registry->register('some', $baseType); + $this->registry->override('some', $overrideType); + + self::assertSame($overrideType, $this->registry->get('some')); + } + + public function testOverrideAllowsExistingInstance() : void + { + $type = new TextType(); + + $this->registry->register('some', $type); + $this->registry->override('some', $type); + + self::assertSame($type, $this->registry->get('some')); + } + + public function testOverrideWithAlreadyRegisteredInstance() : void + { + $newType = new TextType(); + + $this->registry->register('first', $newType); + $this->registry->register('second', new StringType()); + + $this->expectException(DBALException::class); + $this->registry->override('second', $newType); + } + + public function testOverrideWithUnknownType() : void + { + $this->expectException(DBALException::class); + $this->registry->override('unknown', new TextType()); + } + + public function testGetMap() : void + { + $registeredTypes = $this->registry->getMap(); + + self::assertCount(2, $registeredTypes); + self::assertArrayHasKey(self::TEST_TYPE_NAME, $registeredTypes); + self::assertArrayHasKey(self::OTHER_TEST_TYPE_NAME, $registeredTypes); + self::assertSame($this->testType, $registeredTypes[self::TEST_TYPE_NAME]); + self::assertSame($this->otherTestType, $registeredTypes[self::OTHER_TEST_TYPE_NAME]); + } +} diff --git a/tests/Doctrine/Tests/DBAL/Types/TypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TypeTest.php new file mode 100644 index 00000000000..59440f062c6 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Types/TypeTest.php @@ -0,0 +1,34 @@ +getReflectionConstants() as $constant) { + if (! $constant->isPublic()) { + continue; + } + + yield [$constant->getValue()]; + } + } +} From 4d40444b5c9d2dedb9b029fe62d25d9b375b368d Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sun, 25 Nov 2018 00:51:26 +0100 Subject: [PATCH 053/106] Extract constants for built-in types from Type to DefaultTypes --- UPGRADE.md | 13 ++ lib/Doctrine/DBAL/Platforms/DB2Platform.php | 3 +- .../DBAL/Platforms/MariaDb1027Platform.php | 4 +- .../DBAL/Platforms/MySQL57Platform.php | 4 +- .../DBAL/Platforms/PostgreSQL92Platform.php | 4 +- .../DBAL/Platforms/PostgreSQL94Platform.php | 4 +- .../DBAL/Schema/PostgreSqlSchemaManager.php | 3 +- .../SQLAzureFederationsSynchronizer.php | 9 +- lib/Doctrine/DBAL/Types/ArrayType.php | 2 +- lib/Doctrine/DBAL/Types/BigIntType.php | 2 +- lib/Doctrine/DBAL/Types/BinaryType.php | 4 +- lib/Doctrine/DBAL/Types/BlobType.php | 4 +- lib/Doctrine/DBAL/Types/BooleanType.php | 2 +- lib/Doctrine/DBAL/Types/DateImmutableType.php | 2 +- lib/Doctrine/DBAL/Types/DateIntervalType.php | 2 +- .../DBAL/Types/DateTimeImmutableType.php | 2 +- lib/Doctrine/DBAL/Types/DateTimeType.php | 2 +- .../DBAL/Types/DateTimeTzImmutableType.php | 2 +- lib/Doctrine/DBAL/Types/DateTimeTzType.php | 2 +- lib/Doctrine/DBAL/Types/DateType.php | 2 +- lib/Doctrine/DBAL/Types/DecimalType.php | 2 +- lib/Doctrine/DBAL/Types/FloatType.php | 2 +- lib/Doctrine/DBAL/Types/GuidType.php | 2 +- lib/Doctrine/DBAL/Types/IntegerType.php | 2 +- lib/Doctrine/DBAL/Types/JsonArrayType.php | 2 +- lib/Doctrine/DBAL/Types/JsonType.php | 2 +- lib/Doctrine/DBAL/Types/ObjectType.php | 2 +- lib/Doctrine/DBAL/Types/SimpleArrayType.php | 2 +- lib/Doctrine/DBAL/Types/SmallIntType.php | 2 +- lib/Doctrine/DBAL/Types/StringType.php | 2 +- lib/Doctrine/DBAL/Types/TextType.php | 2 +- lib/Doctrine/DBAL/Types/TimeImmutableType.php | 2 +- lib/Doctrine/DBAL/Types/TimeType.php | 2 +- lib/Doctrine/DBAL/Types/Type.php | 149 ++++++++++++------ lib/Doctrine/DBAL/Types/Types.php | 43 +++++ .../DBAL/Types/VarDateTimeImmutableType.php | 2 +- .../Tests/DBAL/Functional/ConnectionTest.php | 4 +- .../Tests/DBAL/Functional/DataAccessTest.php | 35 ++-- .../Schema/MySqlSchemaManagerTest.php | 3 +- .../Schema/OracleSchemaManagerTest.php | 4 +- .../Schema/PostgreSqlSchemaManagerTest.php | 5 +- .../Schema/SqliteSchemaManagerTest.php | 5 +- .../Tests/DBAL/Platforms/DB2PlatformTest.php | 3 +- .../Platforms/MariaDb1027PlatformTest.php | 4 +- .../DBAL/Platforms/MySQL57PlatformTest.php | 4 +- .../Platforms/PostgreSQL92PlatformTest.php | 4 +- .../Platforms/PostgreSQL94PlatformTest.php | 4 +- .../Tests/DBAL/Schema/ColumnDiffTest.php | 5 +- .../Doctrine/Tests/DBAL/Schema/ColumnTest.php | 5 +- .../Doctrine/Tests/DBAL/Types/BinaryTest.php | 3 +- .../Tests/DBAL/Types/JsonArrayTest.php | 3 +- tests/Doctrine/Tests/DBAL/Types/JsonTest.php | 3 +- 52 files changed, 260 insertions(+), 126 deletions(-) create mode 100644 lib/Doctrine/DBAL/Types/Types.php diff --git a/UPGRADE.md b/UPGRADE.md index 53bf9420dde..a5ca5ddb6d5 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,16 @@ +# Upgrade to 2.10 + +## Deprecated `Type::*` constants + +The constants for built-in types have been moved from `Doctrine\DBAL\Types\Type` to a separate class `Doctrine\DBAL\Types\Types`. + +Some of the constants were renamed in the process: +* `TARRAY`-> `ARRAY` +* `DATE` -> `DATE_MUTABLE` +* `DATETIME` -> `DATETIME_MUTABLE` +* `DATETIMETZ` -> `DATETIMETZ_MUTABLE` +* `TIME` -> `TIME_MUTABLE` + # Upgrade to 2.9 ## Deprecated `Statement::fetchColumn()` with an invalid index diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index 60457146fd0..fcc8c1c67f4 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use function array_merge; use function count; use function current; @@ -96,7 +97,7 @@ public function initializeDoctrineTypeMappings() */ public function isCommentedDoctrineType(Type $doctrineType) { - if ($doctrineType->getName() === Type::BOOLEAN) { + if ($doctrineType->getName() === Types::BOOLEAN) { // We require a commented boolean type in order to distinguish between boolean and smallint // as both (have to) map to the same native type. return true; diff --git a/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php b/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php index 25420a0476e..6c57082c586 100644 --- a/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php +++ b/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Platforms; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; /** * Provides the behavior, features and SQL dialect of the MariaDB 10.2 (10.2.7 GA) database platform. @@ -36,6 +36,6 @@ protected function initializeDoctrineTypeMappings() : void { parent::initializeDoctrineTypeMappings(); - $this->doctrineTypeMapping['json'] = Type::JSON; + $this->doctrineTypeMapping['json'] = Types::JSON; } } diff --git a/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php b/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php index 71ef6ca96c7..1db7d6689b7 100644 --- a/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php +++ b/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\TableDiff; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; /** * Provides the behavior, features and SQL dialect of the MySQL 5.7 (5.7.9 GA) database platform. @@ -66,6 +66,6 @@ protected function initializeDoctrineTypeMappings() { parent::initializeDoctrineTypeMappings(); - $this->doctrineTypeMapping['json'] = Type::JSON; + $this->doctrineTypeMapping['json'] = Types::JSON; } } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php index b302c0ceb83..1703056143f 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Platforms; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use function sprintf; /** @@ -53,7 +53,7 @@ protected function initializeDoctrineTypeMappings() { parent::initializeDoctrineTypeMappings(); - $this->doctrineTypeMapping['json'] = Type::JSON; + $this->doctrineTypeMapping['json'] = Types::JSON; } /** diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php index 9db0ecbbd2a..fb559dea2ac 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Platforms; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; /** * Provides the behavior, features and SQL dialect of the PostgreSQL 9.4 database platform. @@ -36,6 +36,6 @@ protected function initializeDoctrineTypeMappings() { parent::initializeDoctrineTypeMappings(); - $this->doctrineTypeMapping['jsonb'] = Type::JSON; + $this->doctrineTypeMapping['jsonb'] = Types::JSON; } } diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index d0f50562785..8b2ac98457e 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use const CASE_LOWER; use function array_change_key_case; use function array_filter; @@ -456,7 +457,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) $column->setPlatformOption('collation', $tableColumn['collation']); } - if (in_array($column->getType()->getName(), [Type::JSON_ARRAY, Type::JSON], true)) { + if (in_array($column->getType()->getName(), [Types::JSON_ARRAY, Types::JSON], true)) { $column->setPlatformOption('jsonb', $jsonb); } diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php index 32d642365b0..417f674a3e0 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer; use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use RuntimeException; use function array_merge; @@ -240,12 +241,12 @@ private function getFederationTypeDefaultValue() $federationType = Type::getType($this->shardManager->getDistributionType()); switch ($federationType->getName()) { - case Type::GUID: + case Types::GUID: $defaultValue = '00000000-0000-0000-0000-000000000000'; break; - case Type::INTEGER: - case Type::SMALLINT: - case Type::BIGINT: + case Types::INTEGER: + case Types::SMALLINT: + case Types::BIGINT: $defaultValue = '0'; break; default: diff --git a/lib/Doctrine/DBAL/Types/ArrayType.php b/lib/Doctrine/DBAL/Types/ArrayType.php index 9bb8e578b23..e981ded1eca 100644 --- a/lib/Doctrine/DBAL/Types/ArrayType.php +++ b/lib/Doctrine/DBAL/Types/ArrayType.php @@ -59,7 +59,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function getName() { - return Type::TARRAY; + return Types::ARRAY; } /** diff --git a/lib/Doctrine/DBAL/Types/BigIntType.php b/lib/Doctrine/DBAL/Types/BigIntType.php index 1d320d624d4..69cd5341d84 100644 --- a/lib/Doctrine/DBAL/Types/BigIntType.php +++ b/lib/Doctrine/DBAL/Types/BigIntType.php @@ -15,7 +15,7 @@ class BigIntType extends Type implements PhpIntegerMappingType */ public function getName() { - return Type::BIGINT; + return Types::BIGINT; } /** diff --git a/lib/Doctrine/DBAL/Types/BinaryType.php b/lib/Doctrine/DBAL/Types/BinaryType.php index 2894f8c864d..d604b3bff69 100644 --- a/lib/Doctrine/DBAL/Types/BinaryType.php +++ b/lib/Doctrine/DBAL/Types/BinaryType.php @@ -42,7 +42,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } if (! is_resource($value)) { - throw ConversionException::conversionFailed($value, self::BINARY); + throw ConversionException::conversionFailed($value, Types::BINARY); } return $value; @@ -53,7 +53,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function getName() { - return Type::BINARY; + return Types::BINARY; } /** diff --git a/lib/Doctrine/DBAL/Types/BlobType.php b/lib/Doctrine/DBAL/Types/BlobType.php index c9c8d88ec1c..e4bb22f08d8 100644 --- a/lib/Doctrine/DBAL/Types/BlobType.php +++ b/lib/Doctrine/DBAL/Types/BlobType.php @@ -42,7 +42,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } if (! is_resource($value)) { - throw ConversionException::conversionFailed($value, self::BLOB); + throw ConversionException::conversionFailed($value, Types::BLOB); } return $value; @@ -53,7 +53,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function getName() { - return Type::BLOB; + return Types::BLOB; } /** diff --git a/lib/Doctrine/DBAL/Types/BooleanType.php b/lib/Doctrine/DBAL/Types/BooleanType.php index 976f00e1fb7..bf9be9b19fe 100644 --- a/lib/Doctrine/DBAL/Types/BooleanType.php +++ b/lib/Doctrine/DBAL/Types/BooleanType.php @@ -39,7 +39,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function getName() { - return Type::BOOLEAN; + return Types::BOOLEAN; } /** diff --git a/lib/Doctrine/DBAL/Types/DateImmutableType.php b/lib/Doctrine/DBAL/Types/DateImmutableType.php index 196fc88c7b4..a4c5d266d92 100644 --- a/lib/Doctrine/DBAL/Types/DateImmutableType.php +++ b/lib/Doctrine/DBAL/Types/DateImmutableType.php @@ -15,7 +15,7 @@ class DateImmutableType extends DateType */ public function getName() { - return Type::DATE_IMMUTABLE; + return Types::DATE_IMMUTABLE; } /** diff --git a/lib/Doctrine/DBAL/Types/DateIntervalType.php b/lib/Doctrine/DBAL/Types/DateIntervalType.php index 30e61c9eaa5..96a446e8607 100644 --- a/lib/Doctrine/DBAL/Types/DateIntervalType.php +++ b/lib/Doctrine/DBAL/Types/DateIntervalType.php @@ -19,7 +19,7 @@ class DateIntervalType extends Type */ public function getName() { - return Type::DATEINTERVAL; + return Types::DATEINTERVAL; } /** diff --git a/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php b/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php index fdda50faa44..51960a8c344 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php @@ -16,7 +16,7 @@ class DateTimeImmutableType extends DateTimeType */ public function getName() { - return Type::DATETIME_IMMUTABLE; + return Types::DATETIME_IMMUTABLE; } /** diff --git a/lib/Doctrine/DBAL/Types/DateTimeType.php b/lib/Doctrine/DBAL/Types/DateTimeType.php index 962d9d38da0..65071a6b188 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeType.php @@ -17,7 +17,7 @@ class DateTimeType extends Type implements PhpDateTimeMappingType */ public function getName() { - return Type::DATETIME; + return Types::DATETIME_MUTABLE; } /** diff --git a/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php b/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php index 253c02e002b..b888624796e 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php @@ -15,7 +15,7 @@ class DateTimeTzImmutableType extends DateTimeTzType */ public function getName() { - return Type::DATETIMETZ_IMMUTABLE; + return Types::DATETIMETZ_IMMUTABLE; } /** diff --git a/lib/Doctrine/DBAL/Types/DateTimeTzType.php b/lib/Doctrine/DBAL/Types/DateTimeTzType.php index 0b78720ec3e..6240da8926c 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeTzType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeTzType.php @@ -29,7 +29,7 @@ class DateTimeTzType extends Type implements PhpDateTimeMappingType */ public function getName() { - return Type::DATETIMETZ; + return Types::DATETIMETZ_MUTABLE; } /** diff --git a/lib/Doctrine/DBAL/Types/DateType.php b/lib/Doctrine/DBAL/Types/DateType.php index b5ad5356f69..15d9362f288 100644 --- a/lib/Doctrine/DBAL/Types/DateType.php +++ b/lib/Doctrine/DBAL/Types/DateType.php @@ -16,7 +16,7 @@ class DateType extends Type */ public function getName() { - return Type::DATE; + return Types::DATE_MUTABLE; } /** diff --git a/lib/Doctrine/DBAL/Types/DecimalType.php b/lib/Doctrine/DBAL/Types/DecimalType.php index 318cb2476b7..b2d37f00b3e 100644 --- a/lib/Doctrine/DBAL/Types/DecimalType.php +++ b/lib/Doctrine/DBAL/Types/DecimalType.php @@ -14,7 +14,7 @@ class DecimalType extends Type */ public function getName() { - return Type::DECIMAL; + return Types::DECIMAL; } /** diff --git a/lib/Doctrine/DBAL/Types/FloatType.php b/lib/Doctrine/DBAL/Types/FloatType.php index 3ad9aa737fa..4988d7253dc 100644 --- a/lib/Doctrine/DBAL/Types/FloatType.php +++ b/lib/Doctrine/DBAL/Types/FloatType.php @@ -11,7 +11,7 @@ class FloatType extends Type */ public function getName() { - return Type::FLOAT; + return Types::FLOAT; } /** diff --git a/lib/Doctrine/DBAL/Types/GuidType.php b/lib/Doctrine/DBAL/Types/GuidType.php index a9ab21537c5..dd4516505ec 100644 --- a/lib/Doctrine/DBAL/Types/GuidType.php +++ b/lib/Doctrine/DBAL/Types/GuidType.php @@ -22,7 +22,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function getName() { - return Type::GUID; + return Types::GUID; } /** diff --git a/lib/Doctrine/DBAL/Types/IntegerType.php b/lib/Doctrine/DBAL/Types/IntegerType.php index f04f3c7e008..d7ab8fd80f2 100644 --- a/lib/Doctrine/DBAL/Types/IntegerType.php +++ b/lib/Doctrine/DBAL/Types/IntegerType.php @@ -15,7 +15,7 @@ class IntegerType extends Type implements PhpIntegerMappingType */ public function getName() { - return Type::INTEGER; + return Types::INTEGER; } /** diff --git a/lib/Doctrine/DBAL/Types/JsonArrayType.php b/lib/Doctrine/DBAL/Types/JsonArrayType.php index beae8038737..bc468fba0f3 100644 --- a/lib/Doctrine/DBAL/Types/JsonArrayType.php +++ b/lib/Doctrine/DBAL/Types/JsonArrayType.php @@ -33,7 +33,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function getName() { - return Type::JSON_ARRAY; + return Types::JSON_ARRAY; } /** diff --git a/lib/Doctrine/DBAL/Types/JsonType.php b/lib/Doctrine/DBAL/Types/JsonType.php index 00cd3f80fcf..127f3fa8ee1 100644 --- a/lib/Doctrine/DBAL/Types/JsonType.php +++ b/lib/Doctrine/DBAL/Types/JsonType.php @@ -69,7 +69,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function getName() { - return Type::JSON; + return Types::JSON; } /** diff --git a/lib/Doctrine/DBAL/Types/ObjectType.php b/lib/Doctrine/DBAL/Types/ObjectType.php index 081ec483b16..32f5f4efd02 100644 --- a/lib/Doctrine/DBAL/Types/ObjectType.php +++ b/lib/Doctrine/DBAL/Types/ObjectType.php @@ -58,7 +58,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function getName() { - return Type::OBJECT; + return Types::OBJECT; } /** diff --git a/lib/Doctrine/DBAL/Types/SimpleArrayType.php b/lib/Doctrine/DBAL/Types/SimpleArrayType.php index d23776f5f0a..31c22b8e6f6 100644 --- a/lib/Doctrine/DBAL/Types/SimpleArrayType.php +++ b/lib/Doctrine/DBAL/Types/SimpleArrayType.php @@ -54,7 +54,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function getName() { - return Type::SIMPLE_ARRAY; + return Types::SIMPLE_ARRAY; } /** diff --git a/lib/Doctrine/DBAL/Types/SmallIntType.php b/lib/Doctrine/DBAL/Types/SmallIntType.php index bca8a533f06..5fa3cb74bbc 100644 --- a/lib/Doctrine/DBAL/Types/SmallIntType.php +++ b/lib/Doctrine/DBAL/Types/SmallIntType.php @@ -15,7 +15,7 @@ class SmallIntType extends Type implements PhpIntegerMappingType */ public function getName() { - return Type::SMALLINT; + return Types::SMALLINT; } /** diff --git a/lib/Doctrine/DBAL/Types/StringType.php b/lib/Doctrine/DBAL/Types/StringType.php index 879359a13d8..e0d1a552f5d 100644 --- a/lib/Doctrine/DBAL/Types/StringType.php +++ b/lib/Doctrine/DBAL/Types/StringType.php @@ -30,6 +30,6 @@ public function getDefaultLength(AbstractPlatform $platform) */ public function getName() { - return Type::STRING; + return Types::STRING; } } diff --git a/lib/Doctrine/DBAL/Types/TextType.php b/lib/Doctrine/DBAL/Types/TextType.php index 635d4f7de49..76dd7c48cf0 100644 --- a/lib/Doctrine/DBAL/Types/TextType.php +++ b/lib/Doctrine/DBAL/Types/TextType.php @@ -32,6 +32,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function getName() { - return Type::TEXT; + return Types::TEXT; } } diff --git a/lib/Doctrine/DBAL/Types/TimeImmutableType.php b/lib/Doctrine/DBAL/Types/TimeImmutableType.php index 8cb870fb393..cc437695564 100644 --- a/lib/Doctrine/DBAL/Types/TimeImmutableType.php +++ b/lib/Doctrine/DBAL/Types/TimeImmutableType.php @@ -15,7 +15,7 @@ class TimeImmutableType extends TimeType */ public function getName() { - return Type::TIME_IMMUTABLE; + return Types::TIME_IMMUTABLE; } /** diff --git a/lib/Doctrine/DBAL/Types/TimeType.php b/lib/Doctrine/DBAL/Types/TimeType.php index c9895294e03..1eeb2c01d1f 100644 --- a/lib/Doctrine/DBAL/Types/TimeType.php +++ b/lib/Doctrine/DBAL/Types/TimeType.php @@ -16,7 +16,7 @@ class TimeType extends Type */ public function getName() { - return Type::TIME; + return Types::TIME_MUTABLE; } /** diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index f6aa3dde046..ac7ab7bec13 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -18,61 +18,110 @@ */ abstract class Type { - public const BIGINT = 'bigint'; - public const BINARY = 'binary'; - public const BLOB = 'blob'; - public const BOOLEAN = 'boolean'; - public const DATE = 'date'; - public const DATE_IMMUTABLE = 'date_immutable'; - public const DATEINTERVAL = 'dateinterval'; - public const DATETIME = 'datetime'; - public const DATETIME_IMMUTABLE = 'datetime_immutable'; - public const DATETIMETZ = 'datetimetz'; - public const DATETIMETZ_IMMUTABLE = 'datetimetz_immutable'; - public const DECIMAL = 'decimal'; - public const FLOAT = 'float'; - public const GUID = 'guid'; - public const INTEGER = 'integer'; - public const JSON = 'json'; - public const JSON_ARRAY = 'json_array'; - public const OBJECT = 'object'; - public const SIMPLE_ARRAY = 'simple_array'; - public const SMALLINT = 'smallint'; - public const STRING = 'string'; - public const TARRAY = 'array'; - public const TEXT = 'text'; - public const TIME = 'time'; - public const TIME_IMMUTABLE = 'time_immutable'; + /** @deprecated Use {@see DefaultTypes::BIGINT} instead. */ + public const BIGINT = Types::BIGINT; + + /** @deprecated Use {@see DefaultTypes::BINARY} instead. */ + public const BINARY = Types::BINARY; + + /** @deprecated Use {@see DefaultTypes::BLOB} instead. */ + public const BLOB = Types::BLOB; + + /** @deprecated Use {@see DefaultTypes::BOOLEAN} instead. */ + public const BOOLEAN = Types::BOOLEAN; + + /** @deprecated Use {@see DefaultTypes::DATE_MUTABLE} instead. */ + public const DATE = Types::DATE_MUTABLE; + + /** @deprecated Use {@see DefaultTypes::DATE_IMMUTABLE} instead. */ + public const DATE_IMMUTABLE = Types::DATE_IMMUTABLE; + + /** @deprecated Use {@see DefaultTypes::DATEINTERVAL} instead. */ + public const DATEINTERVAL = Types::DATEINTERVAL; + + /** @deprecated Use {@see DefaultTypes::DATETIME_MUTABLE} instead. */ + public const DATETIME = Types::DATETIME_MUTABLE; + + /** @deprecated Use {@see DefaultTypes::DATETIME_IMMUTABLE} instead. */ + public const DATETIME_IMMUTABLE = Types::DATETIME_IMMUTABLE; + + /** @deprecated Use {@see DefaultTypes::DATETIMETZ_MUTABLE} instead. */ + public const DATETIMETZ = Types::DATETIMETZ_MUTABLE; + + /** @deprecated Use {@see DefaultTypes::DATETIMETZ_IMMUTABLE} instead. */ + public const DATETIMETZ_IMMUTABLE = Types::DATETIMETZ_IMMUTABLE; + + /** @deprecated Use {@see DefaultTypes::DECIMAL} instead. */ + public const DECIMAL = Types::DECIMAL; + + /** @deprecated Use {@see DefaultTypes::FLOAT} instead. */ + public const FLOAT = Types::FLOAT; + + /** @deprecated Use {@see DefaultTypes::GUID} instead. */ + public const GUID = Types::GUID; + + /** @deprecated Use {@see DefaultTypes::INTEGER} instead. */ + public const INTEGER = Types::INTEGER; + + /** @deprecated Use {@see DefaultTypes::JSON} instead. */ + public const JSON = Types::JSON; + + /** @deprecated Use {@see DefaultTypes::JSON_ARRAY} instead. */ + public const JSON_ARRAY = Types::JSON_ARRAY; + + /** @deprecated Use {@see DefaultTypes::OBJECT} instead. */ + public const OBJECT = Types::OBJECT; + + /** @deprecated Use {@see DefaultTypes::SIMPLE_ARRAY} instead. */ + public const SIMPLE_ARRAY = Types::SIMPLE_ARRAY; + + /** @deprecated Use {@see DefaultTypes::SMALLINT} instead. */ + public const SMALLINT = Types::SMALLINT; + + /** @deprecated Use {@see DefaultTypes::STRING} instead. */ + public const STRING = Types::STRING; + + /** @deprecated Use {@see DefaultTypes::ARRAY} instead. */ + public const TARRAY = Types::ARRAY; + + /** @deprecated Use {@see DefaultTypes::TEXT} instead. */ + public const TEXT = Types::TEXT; + + /** @deprecated Use {@see DefaultTypes::TIME_MUTABLE} instead. */ + public const TIME = Types::TIME_MUTABLE; + + /** @deprecated Use {@see DefaultTypes::TIME_IMMUTABLE} instead. */ + public const TIME_IMMUTABLE = Types::TIME_IMMUTABLE; /** * The map of supported doctrine mapping types. */ private const BUILTIN_TYPES_MAP = [ - self::BIGINT => BigIntType::class, - self::BINARY => BinaryType::class, - self::BLOB => BlobType::class, - self::BOOLEAN => BooleanType::class, - self::DATE => DateType::class, - self::DATE_IMMUTABLE => DateImmutableType::class, - self::DATEINTERVAL => DateIntervalType::class, - self::DATETIME => DateTimeType::class, - self::DATETIME_IMMUTABLE => DateTimeImmutableType::class, - self::DATETIMETZ => DateTimeTzType::class, - self::DATETIMETZ_IMMUTABLE => DateTimeTzImmutableType::class, - self::DECIMAL => DecimalType::class, - self::FLOAT => FloatType::class, - self::GUID => GuidType::class, - self::INTEGER => IntegerType::class, - self::JSON => JsonType::class, - self::JSON_ARRAY => JsonArrayType::class, - self::OBJECT => ObjectType::class, - self::SIMPLE_ARRAY => SimpleArrayType::class, - self::SMALLINT => SmallIntType::class, - self::STRING => StringType::class, - self::TARRAY => ArrayType::class, - self::TEXT => TextType::class, - self::TIME => TimeType::class, - self::TIME_IMMUTABLE => TimeImmutableType::class, + Types::ARRAY => ArrayType::class, + Types::BIGINT => BigIntType::class, + Types::BINARY => BinaryType::class, + Types::BLOB => BlobType::class, + Types::BOOLEAN => BooleanType::class, + Types::DATE_MUTABLE => DateType::class, + Types::DATE_IMMUTABLE => DateImmutableType::class, + Types::DATEINTERVAL => DateIntervalType::class, + Types::DATETIME_MUTABLE => DateTimeType::class, + Types::DATETIME_IMMUTABLE => DateTimeImmutableType::class, + Types::DATETIMETZ_MUTABLE => DateTimeTzType::class, + Types::DATETIMETZ_IMMUTABLE => DateTimeTzImmutableType::class, + Types::DECIMAL => DecimalType::class, + Types::FLOAT => FloatType::class, + Types::GUID => GuidType::class, + Types::INTEGER => IntegerType::class, + Types::JSON => JsonType::class, + Types::JSON_ARRAY => JsonArrayType::class, + Types::OBJECT => ObjectType::class, + Types::SIMPLE_ARRAY => SimpleArrayType::class, + Types::SMALLINT => SmallIntType::class, + Types::STRING => StringType::class, + Types::TEXT => TextType::class, + Types::TIME_MUTABLE => TimeType::class, + Types::TIME_IMMUTABLE => TimeImmutableType::class, ]; /** @var TypeRegistry|null */ diff --git a/lib/Doctrine/DBAL/Types/Types.php b/lib/Doctrine/DBAL/Types/Types.php new file mode 100644 index 00000000000..f8d0cf913c3 --- /dev/null +++ b/lib/Doctrine/DBAL/Types/Types.php @@ -0,0 +1,43 @@ +connection->quote('foo', Type::STRING), + $this->connection->quote('foo', Types::STRING), $this->connection->quote('foo', ParameterType::STRING) ); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index 205f3fd6a75..a0b8db003da 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -16,7 +16,7 @@ use Doctrine\DBAL\Platforms\TrimMode; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Statement; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalFunctionalTestCase; use PDO; use const CASE_LOWER; @@ -225,7 +225,11 @@ public function testFetchAllWithTypes() $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; - $data = $this->connection->fetchAll($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); + $data = $this->connection->fetchAll( + $sql, + [1, $datetime], + [ParameterType::STRING, Types::DATETIME_MUTABLE] + ); self::assertCount(1, $data); @@ -297,7 +301,11 @@ public function testFetchAssocWithTypes() $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; - $row = $this->connection->fetchAssoc($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); + $row = $this->connection->fetchAssoc( + $sql, + [1, $datetime], + [ParameterType::STRING, Types::DATETIME_MUTABLE] + ); self::assertNotFalse($row); @@ -338,7 +346,11 @@ public function testFetchArrayWithTypes() $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; - $row = $this->connection->fetchArray($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); + $row = $this->connection->fetchArray( + $sql, + [1, $datetime], + [ParameterType::STRING, Types::DATETIME_MUTABLE] + ); self::assertNotFalse($row); @@ -383,7 +395,12 @@ public function testFetchColumnWithTypes() $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; - $column = $this->connection->fetchColumn($sql, [1, $datetime], 1, [ParameterType::STRING, Type::DATETIME]); + $column = $this->connection->fetchColumn( + $sql, + [1, $datetime], + 1, + [ParameterType::STRING, Types::DATETIME_MUTABLE] + ); self::assertNotFalse($column); @@ -415,7 +432,7 @@ public function testExecuteQueryBindDateTimeType() $stmt = $this->connection->executeQuery( $sql, [1 => new DateTime('2010-01-01 10:10:10')], - [1 => Type::DATETIME] + [1 => Types::DATETIME_MUTABLE] ); self::assertEquals(1, $stmt->fetchColumn()); @@ -436,14 +453,14 @@ public function testExecuteUpdateBindDateTimeType() ], [ 1 => ParameterType::INTEGER, 2 => ParameterType::STRING, - 3 => Type::DATETIME, + 3 => Types::DATETIME_MUTABLE, ]); self::assertEquals(1, $affectedRows); self::assertEquals(1, $this->connection->executeQuery( 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?', [1 => $datetime], - [1 => Type::DATETIME] + [1 => Types::DATETIME_MUTABLE] )->fetchColumn()); } @@ -454,7 +471,7 @@ public function testPrepareQueryBindValueDateTimeType() { $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; $stmt = $this->connection->prepare($sql); - $stmt->bindValue(1, new DateTime('2010-01-01 10:10:10'), Type::DATETIME); + $stmt->bindValue(1, new DateTime('2010-01-01 10:10:10'), Types::DATETIME_MUTABLE); $stmt->execute(); self::assertEquals(1, $stmt->fetchColumn()); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 92e0f497a6d..41754e3e672 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\Tests\Types\MySqlPointType; use function implode; use function sprintf; @@ -415,7 +416,7 @@ public function testJsonColumnType() : void $columns = $this->schemaManager->listTableColumns('test_mysql_json'); - self::assertSame(Type::JSON, $columns['col_json']->getType()->getName()); + self::assertSame(Types::JSON, $columns['col_json']->getType()->getName()); } public function testColumnDefaultCurrentTimestamp() : void diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index 14e082c07dc..3fc8bee811b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -5,7 +5,7 @@ use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BinaryType; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\Tests\TestUtil; use function array_map; @@ -232,7 +232,7 @@ public function testListTableColumnsSameTableNamesInDifferentSchemas() $this->schemaManager->dropAndCreateTable($table); $otherTable = new Table($table->getName()); - $otherTable->addColumn('id', Type::STRING); + $otherTable->addColumn('id', Types::STRING); TestUtil::getTempConnection()->getSchemaManager()->dropAndCreateTable($otherTable); $columns = $this->schemaManager->listTableColumns($table->getName(), $this->connection->getUsername()); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index 597947d4575..e388bf607da 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -12,6 +12,7 @@ use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\DecimalType; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use function array_map; use function array_pop; use function count; @@ -410,8 +411,8 @@ public function testJsonbColumn(string $type) : void public function jsonbColumnTypeProvider() : array { return [ - [Type::JSON], - [Type::JSON_ARRAY], + [Types::JSON], + [Types::JSON_ARRAY], ]; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index a9f0ccdcfec..dc4e01c5ade 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use SQLite3; use function array_map; use function dirname; @@ -206,8 +207,8 @@ public function testListTableColumnsWithWhitespacesInTypeDeclarations() self::assertArrayHasKey('foo', $columns); self::assertArrayHasKey('bar', $columns); - self::assertSame(Type::getType(Type::STRING), $columns['foo']->getType()); - self::assertSame(Type::getType(Type::TEXT), $columns['bar']->getType()); + self::assertSame(Type::getType(Types::STRING), $columns['foo']->getType()); + self::assertSame(Type::getType(Types::TEXT), $columns['bar']->getType()); self::assertSame(64, $columns['foo']->getLength()); self::assertSame(100, $columns['bar']->getLength()); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php index 5969e9d0355..f1260b2d5c1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php @@ -10,6 +10,7 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class DB2PlatformTest extends AbstractPlatformTestCase { @@ -279,7 +280,7 @@ public function getIsCommentedDoctrineType() { $data = parent::getIsCommentedDoctrineType(); - $data[Type::BOOLEAN] = [Type::getType(Type::BOOLEAN), true]; + $data[Types::BOOLEAN] = [Type::getType(Types::BOOLEAN), true]; return $data; } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php index 7171ad714d6..0903a511612 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php @@ -3,7 +3,7 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\Platforms\MariaDb1027Platform; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase { @@ -33,7 +33,7 @@ public function testReturnsJsonTypeDeclarationSQL() : void public function testInitializesJsonTypeMapping() : void { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('json')); - self::assertSame(Type::JSON, $this->platform->getDoctrineTypeMapping('json')); + self::assertSame(Types::JSON, $this->platform->getDoctrineTypeMapping('json')); } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php index 52d7ca0708b..90e3827566c 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php @@ -3,7 +3,7 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\Platforms\MySQL57Platform; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class MySQL57PlatformTest extends AbstractMySQLPlatformTestCase { @@ -28,7 +28,7 @@ public function testReturnsJsonTypeDeclarationSQL() public function testInitializesJsonTypeMapping() { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('json')); - self::assertSame(Type::JSON, $this->platform->getDoctrineTypeMapping('json')); + self::assertSame(Types::JSON, $this->platform->getDoctrineTypeMapping('json')); } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php index fb36beb334a..123425b3879 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php @@ -3,7 +3,7 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\Platforms\PostgreSQL92Platform; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class PostgreSQL92PlatformTest extends AbstractPostgreSqlPlatformTestCase { @@ -55,7 +55,7 @@ public function testReturnsSmallIntTypeDeclarationSQL() public function testInitializesJsonTypeMapping() { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('json')); - self::assertEquals(Type::JSON, $this->platform->getDoctrineTypeMapping('json')); + self::assertEquals(Types::JSON, $this->platform->getDoctrineTypeMapping('json')); } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php index ed118aec406..9643bdb5fd7 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php @@ -3,7 +3,7 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class PostgreSQL94PlatformTest extends PostgreSQL92PlatformTest { @@ -26,6 +26,6 @@ public function testInitializesJsonTypeMapping() { parent::testInitializesJsonTypeMapping(); self::assertTrue($this->platform->hasDoctrineTypeMappingFor('jsonb')); - self::assertEquals(Type::JSON, $this->platform->getDoctrineTypeMapping('jsonb')); + self::assertEquals(Types::JSON, $this->platform->getDoctrineTypeMapping('jsonb')); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php index 046118f91fa..099fb788b55 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\TestCase; class ColumnDiffTest extends TestCase @@ -14,8 +15,8 @@ class ColumnDiffTest extends TestCase */ public function testPreservesOldColumnNameQuotation() { - $fromColumn = new Column('"foo"', Type::getType(Type::INTEGER)); - $toColumn = new Column('bar', Type::getType(Type::INTEGER)); + $fromColumn = new Column('"foo"', Type::getType(Types::INTEGER)); + $toColumn = new Column('bar', Type::getType(Types::INTEGER)); $columnDiff = new ColumnDiff('"foo"', $toColumn, []); self::assertTrue($columnDiff->getOldColumnName()->isQuoted()); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php index caf93439244..150e5263f93 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\TestCase; class ColumnTest extends TestCase @@ -74,10 +75,10 @@ public function testSettingUnknownOptionIsStillSupported() : void */ public function testOptionsShouldNotBeIgnored() : void { - $col1 = new Column('bar', Type::getType(Type::INTEGER), ['unknown_option' => 'bar', 'notnull' => true]); + $col1 = new Column('bar', Type::getType(Types::INTEGER), ['unknown_option' => 'bar', 'notnull' => true]); self::assertTrue($col1->getNotnull()); - $col2 = new Column('bar', Type::getType(Type::INTEGER), ['unknown_option' => 'bar', 'notnull' => false]); + $col2 = new Column('bar', Type::getType(Types::INTEGER), ['unknown_option' => 'bar', 'notnull' => false]); self::assertFalse($col2->getNotnull()); } diff --git a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php index b26a35cab42..4eed8f7e4fd 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; use function base64_encode; @@ -37,7 +38,7 @@ public function testReturnsBindingType() public function testReturnsName() { - self::assertSame(Type::BINARY, $this->type->getName()); + self::assertSame(Types::BINARY, $this->type->getName()); } public function testReturnsSQLDeclaration() diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index 730234dc85f..2f76d14b503 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\JsonArrayType; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; use function base64_encode; @@ -36,7 +37,7 @@ public function testReturnsBindingType() public function testReturnsName() { - self::assertSame(Type::JSON_ARRAY, $this->type->getName()); + self::assertSame(Types::JSON_ARRAY, $this->type->getName()); } public function testReturnsSQLDeclaration() diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index 123291f53b6..796f5b1464f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\JsonType; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; use function base64_encode; @@ -37,7 +38,7 @@ public function testReturnsBindingType() public function testReturnsName() { - self::assertSame(Type::JSON, $this->type->getName()); + self::assertSame(Types::JSON, $this->type->getName()); } public function testReturnsSQLDeclaration() From 58f793e360e957de1e31febb6ad5c58cb309c417 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sun, 14 Apr 2019 03:55:43 +0200 Subject: [PATCH 054/106] Expand list of keywords in composer.json --- composer.json | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 3ba89fcd764..f7db597bec2 100644 --- a/composer.json +++ b/composer.json @@ -3,14 +3,25 @@ "type": "library", "description": "Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.", "keywords": [ - "php", + "abstraction", + "database", + "dbal", + "db2", + "mariadb", + "mssql", "mysql", "pgsql", - "dbal", - "database", - "abstraction", - "persistence", - "queryobject" + "postgresql", + "oci8", + "oracle", + "pdo", + "queryobject", + "sasql", + "sql", + "sqlanywhere", + "sqlite", + "sqlserver", + "sqlsrv" ], "homepage": "https://www.doctrine-project.org/projects/dbal.html", "license": "MIT", From f202e76b8d52ea9c1180bff8a67052bb52f545a4 Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Wed, 17 Apr 2019 12:29:12 -0500 Subject: [PATCH 055/106] Maintain platform parameter in connection params but remove it before using params in query cache key generation. --- lib/Doctrine/DBAL/Connection.php | 6 ++- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 51 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 75b862bf74f..78bc38023b0 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -200,7 +200,6 @@ public function __construct( } $this->platform = $params['platform']; - unset($this->params['platform']); } // Create default config and event manager if none given @@ -932,7 +931,10 @@ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qc throw CacheException::noResultDriverConfigured(); } - [$cacheKey, $realKey] = $qcp->generateCacheKeys($query, $params, $types, $this->getParams()); + $connectionParams = $this->getParams(); + unset($connectionParams['platform']); + + [$cacheKey, $realKey] = $qcp->generateCacheKeys($query, $params, $types, $connectionParams); // fetch the row pointers entry $data = $resultCache->fetch($cacheKey); diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index c036bd89885..3c3bc9f9b50 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -880,4 +880,55 @@ public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnecting $connection->getDatabasePlatform(); } + + /** + * @group #3194 + */ + public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGeneratingCacheKeys() : void + { + /** @var Driver|MockObject $driver */ + $driver = $this->createMock(Driver::class); + + /** @var AbstractPlatform|MockObject $platform */ + $platform = $this->createMock(AbstractPlatform::class); + + /** @var QueryCacheProfile|MockObject $queryCacheProfile */ + $queryCacheProfile = $this->createMock(QueryCacheProfile::class); + + /** @var Cache|MockObject $resultCacheDriver */ + $resultCacheDriver = $this->createMock(Cache::class); + + $queryCacheProfile + ->expects($this->any()) + ->method('getResultCacheDriver') + ->will($this->returnValue($resultCacheDriver)); + + $resultCacheDriver + ->expects($this->atLeastOnce()) + ->method('fetch') + ->with('cacheKey') + ->will($this->returnValue(['realKey' => []])); + + $query = 'SELECT 1'; + + $params = [ + 'dbname' => 'foo', + 'platform' => $platform, + ]; + + $paramsWithoutPlatform = $params; + unset($paramsWithoutPlatform['platform']); + + $queryCacheProfile + ->expects($this->once()) + ->method('generateCacheKeys') + ->with($query, [], [], $paramsWithoutPlatform) + ->will($this->returnValue(['cacheKey', 'realKey'])); + + $connection = new Connection($params, $driver); + + self::assertSame($params, $connection->getParams()); + + $connection->executeCacheQuery($query, [], [], $queryCacheProfile); + } } From 8515d7f08073dc72be91626e07c4ee91488650f0 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 10 Apr 2019 07:43:45 -0700 Subject: [PATCH 056/106] Restored relevant changes from #2850, PowerKiKi/default-values-with-backslashes --- UPGRADE.md | 12 ++++ .../DBAL/Platforms/AbstractPlatform.php | 2 +- .../DBAL/Schema/PostgreSqlSchemaManager.php | 19 +++++- .../DBAL/Schema/SqliteSchemaManager.php | 5 +- .../SchemaManagerFunctionalTestCase.php | 61 +++++++++++++++++++ 5 files changed, 93 insertions(+), 6 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index a5ca5ddb6d5..60bc45c4915 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,17 @@ # Upgrade to 2.10 +## MINOR BC BREAK: escaped default values + +Default values will be automatically escaped. So default values must now be specified non-escaped. + +Before: + + $column->setDefault('Foo\\\\Bar\\\\Baz'); + +After: + + $column->setDefault('Foo\\Bar\\Baz'); + ## Deprecated `Type::*` constants The constants for built-in types have been moved from `Doctrine\DBAL\Types\Type` to a separate class `Doctrine\DBAL\Types\Types`. diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index abb7333ac1d..57664e6b8d6 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -2311,7 +2311,7 @@ public function getDefaultValueDeclarationSQL($field) return " DEFAULT '" . $this->convertBooleans($default) . "'"; } - return " DEFAULT '" . $default . "'"; + return ' DEFAULT ' . $this->quoteStringLiteral($default); } /** diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 8b2ac98457e..509b3641f6f 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -395,11 +395,12 @@ protected function _getPortableTableColumnDefinition($tableColumn) $length = null; break; case 'text': - $fixed = false; - break; + case '_varchar': case 'varchar': + $tableColumn['default'] = $this->parseDefaultExpression($tableColumn['default']); + $fixed = false; + break; case 'interval': - case '_varchar': $fixed = false; break; case 'char': @@ -479,4 +480,16 @@ private function fixVersion94NegativeNumericDefaultValue($defaultValue) return $defaultValue; } + + /** + * Parses a default value expression as given by PostgreSQL + */ + private function parseDefaultExpression(?string $default) : ?string + { + if ($default === null) { + return $default; + } + + return str_replace("''", "'", $default); + } } diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index e819d963f03..94c3e936fbd 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -325,8 +325,9 @@ protected function _getPortableTableColumnDefinition($tableColumn) $default = null; } if ($default !== null) { - // SQLite returns strings wrapped in single quotes, so we need to strip them - $default = preg_replace("/^'(.*)'$/", '\1', $default); + // SQLite returns strings wrapped in single quotes and escaped, so we need to strip them + $default = preg_replace("/^'(.*)'$/s", '\1', $default); + $default = str_replace("''", "'", $default); } $notnull = (bool) $tableColumn['notnull']; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index aeb9f4c90dd..15c99c0395a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -1495,6 +1495,67 @@ public function testCreateAndListSequences() : void self::assertEquals($sequence2InitialValue, $actualSequence2->getInitialValue()); } + /** + * Returns potential escaped literals from all platforms combined. + * + * @see https://dev.mysql.com/doc/refman/5.7/en/string-literals.html + * @see http://www.sqlite.org/lang_expr.html + * @see https://www.postgresql.org/docs/9.6/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE + * + * @return mixed[][] + */ + private function getEscapedLiterals() : iterable + { + return [ + ['An ASCII NUL (X\'00\')', "foo\\0bar"], + ['Single quote, C-style', "foo\\'bar"], + ['Single quote, doubled-style', "foo''bar"], + ['Double quote, C-style', 'foo\\"bar'], + ['Double quote, double-style', 'foo""bar'], + ['Backspace', 'foo\\bbar'], + ['New-line', 'foo\\nbar'], + ['Carriage return', 'foo\\rbar'], + ['Tab', 'foo\\tbar'], + ['ASCII 26 (Control+Z)', 'foo\\Zbar'], + ['Backslash (\)', 'foo\\\\bar'], + ['Percent (%)', 'foo\\%bar'], + ['Underscore (_)', 'foo\\_bar'], + ]; + } + + private function createTableForDefaultValues() : void + { + $table = new Table('string_escaped_default_value'); + foreach ($this->getEscapedLiterals() as $i => $literal) { + $table->addColumn('field' . $i, 'string', ['default' => $literal[1]]); + } + + $table->addColumn('def_foo', 'string'); + $this->schemaManager->dropAndCreateTable($table); + } + + public function testEscapedDefaultValueCanBeIntrospected() : void + { + $this->createTableForDefaultValues(); + + $onlineTable = $this->schemaManager->listTableDetails('string_escaped_default_value'); + foreach ($this->getEscapedLiterals() as $i => $literal) { + self::assertSame($literal[1], $onlineTable->getColumn('field' . $i)->getDefault(), 'should be able introspect the value of default for: ' . $literal[0]); + } + } + + public function testEscapedDefaultValueCanBeInserted() : void + { + $this->createTableForDefaultValues(); + + $this->connection->insert('string_escaped_default_value', ['def_foo' => 'foo']); + + foreach ($this->getEscapedLiterals() as $i => $literal) { + $value = $this->connection->fetchColumn('SELECT field' . $i . ' FROM string_escaped_default_value'); + self::assertSame($literal[1], $value, 'inserted default value should be the configured default value for: ' . $literal[0]); + } + } + /** * @group #3086 */ From 64c18da1a9f14cc72c99bdeb44a9db498f9ec802 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 3 Jan 2018 13:15:59 -0800 Subject: [PATCH 057/106] Reworked the tests and fixed other platforms --- UPGRADE.md | 4 +- .../DBAL/Platforms/SQLServerPlatform.php | 2 +- lib/Doctrine/DBAL/Schema/DB2SchemaManager.php | 9 +- .../DBAL/Schema/MySqlSchemaManager.php | 25 ++- .../DBAL/Schema/OracleSchemaManager.php | 7 +- .../DBAL/Schema/PostgreSqlSchemaManager.php | 7 +- .../DBAL/Schema/SQLServerSchemaManager.php | 17 +- .../DBAL/Schema/SqliteSchemaManager.php | 9 +- .../Functional/Schema/DefaultValueTest.php | 151 ++++++++++++++++++ .../Schema/MySqlSchemaManagerTest.php | 41 ----- .../SchemaManagerFunctionalTestCase.php | 61 ------- 11 files changed, 208 insertions(+), 125 deletions(-) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Schema/DefaultValueTest.php diff --git a/UPGRADE.md b/UPGRADE.md index 60bc45c4915..91e57013d29 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,8 +1,8 @@ # Upgrade to 2.10 -## MINOR BC BREAK: escaped default values +## MINOR BC BREAK: Default values are no longer handled as SQL expressions -Default values will be automatically escaped. So default values must now be specified non-escaped. +They are converted to SQL literals (e.g. escaped). Clients must now specify default values in their initial form, not in the form of an SQL literal (e.g. escaped). Before: diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index a2e68049d68..dc9f88da327 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1629,7 +1629,7 @@ public function getDefaultValueDeclarationSQL($field) return " DEFAULT '" . $this->convertBooleans($field['default']) . "'"; } - return " DEFAULT '" . $field['default'] . "'"; + return ' DEFAULT ' . $this->quoteStringLiteral($field['default']); } /** diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index 0ae7aba2cf4..201d6015b96 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -6,10 +6,11 @@ use const CASE_LOWER; use function array_change_key_case; use function is_resource; +use function preg_match; +use function str_replace; use function strpos; use function strtolower; use function substr; -use function trim; /** * IBM Db2 Schema Manager. @@ -47,7 +48,11 @@ protected function _getPortableTableColumnDefinition($tableColumn) $default = null; if ($tableColumn['default'] !== null && $tableColumn['default'] !== 'NULL') { - $default = trim($tableColumn['default'], "'"); + $default = $tableColumn['default']; + + if (preg_match('/^\'(.*)\'$/s', $default, $matches)) { + $default = str_replace("''", "'", $matches[1]); + } } $type = $this->_platform->getDoctrineTypeMapping($tableColumn['typename']); diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index fb957f247ff..5e0368509f7 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -13,17 +13,36 @@ use function explode; use function is_string; use function preg_match; -use function str_replace; -use function stripslashes; use function strpos; use function strtok; use function strtolower; +use function strtr; /** * Schema manager for the MySql RDBMS. */ class MySqlSchemaManager extends AbstractSchemaManager { + /** + * @see https://mariadb.com/kb/en/library/string-literals/#escape-sequences + */ + private const MARIADB_ESCAPE_SEQUENCES = [ + '\\0' => "\0", + "\\'" => "'", + '\\"' => '"', + '\\b' => "\b", + '\\n' => "\n", + '\\r' => "\r", + '\\t' => "\t", + '\\Z' => "\x1a", + '\\\\' => '\\', + '\\%' => '%', + '\\_' => '_', + + // Internally, MariaDB escapes single quotes using the standard syntax + "''" => "'", + ]; + /** * {@inheritdoc} */ @@ -219,7 +238,7 @@ private function getMariaDb1027ColumnDefault(MariaDb1027Platform $platform, ?str } if (preg_match('/^\'(.*)\'$/', $columnDefault, $matches)) { - return stripslashes(str_replace("''", "'", $matches[1])); + return strtr($matches[1], self::MARIADB_ESCAPE_SEQUENCES); } switch ($columnDefault) { diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index 0a3e76b1c51..0e9700a616d 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -13,6 +13,7 @@ use function assert; use function preg_match; use function sprintf; +use function str_replace; use function strpos; use function strtolower; use function strtoupper; @@ -144,8 +145,10 @@ protected function _getPortableTableColumnDefinition($tableColumn) } if ($tableColumn['data_default'] !== null) { - // Default values returned from database are enclosed in single quotes. - $tableColumn['data_default'] = trim($tableColumn['data_default'], "'"); + // Default values returned from database are represented as literal expressions + if (preg_match('/^\'(.*)\'$/s', $tableColumn['data_default'], $matches)) { + $tableColumn['data_default'] = str_replace("''", "'", $matches[1]); + } } if ($tableColumn['data_precision'] !== null) { diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 509b3641f6f..d84077d5268 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -21,7 +21,6 @@ use function preg_replace; use function sprintf; use function str_replace; -use function stripos; use function strlen; use function strpos; use function strtolower; @@ -330,11 +329,9 @@ protected function _getPortableTableColumnDefinition($tableColumn) $autoincrement = true; } - if (preg_match("/^['(](.*)[')]::.*$/", $tableColumn['default'], $matches)) { + if (preg_match("/^['(](.*)[')]::/", $tableColumn['default'], $matches)) { $tableColumn['default'] = $matches[1]; - } - - if (stripos($tableColumn['default'], 'NULL') === 0) { + } elseif (preg_match('/^NULL::/', $tableColumn['default'])) { $tableColumn['default'] = null; } diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index bd6b02cb9a0..31ec6fffd50 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -16,7 +16,6 @@ use function str_replace; use function strpos; use function strtok; -use function trim; /** * SQL Server Schema Manager. @@ -107,7 +106,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) 'length' => $length === 0 || ! in_array($type, ['text', 'string']) ? null : $length, 'unsigned' => false, 'fixed' => (bool) $fixed, - 'default' => $default !== 'NULL' ? $default : null, + 'default' => $default, 'notnull' => (bool) $tableColumn['notnull'], 'scale' => $tableColumn['scale'], 'precision' => $tableColumn['precision'], @@ -124,10 +123,18 @@ protected function _getPortableTableColumnDefinition($tableColumn) return $column; } - private function parseDefaultExpression(string $value) : string + private function parseDefaultExpression(string $value) : ?string { - while (preg_match('/^\((.*)\)$/', $value, $matches)) { - $value = trim($matches[1], "'"); + while (preg_match('/^\((.*)\)$/s', $value, $matches)) { + $value = $matches[1]; + } + + if ($value === 'NULL') { + return null; + } + + if (preg_match('/^\'(.*)\'$/s', $value, $matches)) { + $value = str_replace("''", "'", $matches[1]); } if ($value === 'getdate()') { diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 94c3e936fbd..66d3c8503d5 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -324,11 +324,14 @@ protected function _getPortableTableColumnDefinition($tableColumn) if ($default === 'NULL') { $default = null; } + if ($default !== null) { - // SQLite returns strings wrapped in single quotes and escaped, so we need to strip them - $default = preg_replace("/^'(.*)'$/s", '\1', $default); - $default = str_replace("''", "'", $default); + // SQLite returns the default value as a literal expression, so we need to parse it + if (preg_match('/^\'(.*)\'$/s', $default, $matches)) { + $default = str_replace("''", "'", $matches[1]); + } } + $notnull = (bool) $tableColumn['notnull']; if (! isset($tableColumn['name'])) { diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/DefaultValueTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/DefaultValueTest.php new file mode 100644 index 00000000000..a65305a2e13 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/DefaultValueTest.php @@ -0,0 +1,151 @@ +addColumn('id', 'integer'); + + foreach (self::columnProvider() as [$name, $default]) { + $table->addColumn($name, 'string', [ + 'default' => $default, + 'notnull' => false, + ]); + } + + $this->connection->getSchemaManager() + ->dropAndCreateTable($table); + + $this->connection->insert('default_value', ['id' => 1]); + } + + /** + * @dataProvider columnProvider + */ + public function testEscapedDefaultValueCanBeIntrospected(string $name, $expectedDefault) : void + { + self::assertSame( + $expectedDefault, + $this->connection + ->getSchemaManager() + ->listTableDetails('default_value') + ->getColumn($name) + ->getDefault() + ); + } + + /** + * @dataProvider columnProvider + */ + public function testEscapedDefaultValueCanBeInserted(string $name, $expectedDefault) : void + { + $value = $this->connection->fetchColumn( + sprintf('SELECT %s FROM default_value', $name) + ); + + self::assertSame($expectedDefault, $value); + } + + /** + * Returns potential escaped literals from all platforms combined. + * + * @see https://dev.mysql.com/doc/refman/5.7/en/string-literals.html + * @see http://www.sqlite.org/lang_expr.html + * @see https://www.postgresql.org/docs/9.6/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE + * + * @return mixed[][] + */ + public static function columnProvider() : iterable + { + return [ + 'Single quote' => [ + 'single_quote', + "foo'bar", + ], + 'Single quote, doubled' => [ + 'single_quote_doubled', + "foo''bar", + ], + 'Double quote' => [ + 'double_quote', + 'foo"bar', + ], + 'Double quote, doubled' => [ + 'double_quote_doubled', + 'foo""bar', + ], + 'Backspace' => [ + 'backspace', + "foo\x08bar", + ], + 'New line' => [ + 'new_line', + "foo\nbar", + ], + 'Carriage return' => [ + 'carriage_return', + "foo\rbar", + ], + 'Tab' => [ + 'tab', + "foo\tbar", + ], + 'Substitute' => [ + 'substitute', + "foo\x1abar", + ], + 'Backslash' => [ + 'backslash', + 'foo\\bar', + ], + 'Backslash, doubled' => [ + 'backslash_doubled', + 'foo\\\\bar', + ], + 'Percent' => [ + 'percent_sign', + 'foo%bar', + ], + 'Underscore' => [ + 'underscore', + 'foo_bar', + ], + 'NULL string' => [ + 'null_string', + 'NULL', + ], + 'NULL value' => [ + 'null_value', + null, + ], + 'SQL expression' => [ + 'sql_expression', + "'; DROP DATABASE doctrine --", + ], + 'No double conversion' => [ + 'no_double_conversion', + "\\'", + ], + ]; + } +} diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 41754e3e672..558159b7fa4 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -11,8 +11,6 @@ use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Doctrine\Tests\Types\MySqlPointType; -use function implode; -use function sprintf; class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase { @@ -517,45 +515,6 @@ public function testColumnDefaultValuesCurrentTimeAndDate() : void self::assertFalse($diff, 'Tables should be identical with column defauts time and date.'); } - /** - * Ensure default values (un-)escaping is properly done by mysql platforms. - * The test is voluntarily relying on schema introspection due to current - * doctrine limitations. Once #2850 is landed, this test can be removed. - * - * @see https://dev.mysql.com/doc/refman/5.7/en/string-literals.html - */ - public function testEnsureDefaultsAreUnescapedFromSchemaIntrospection() : void - { - $platform = $this->schemaManager->getDatabasePlatform(); - $this->connection->query('DROP TABLE IF EXISTS test_column_defaults_with_create'); - - $escapeSequences = [ - "\\0", // An ASCII NUL (X'00') character - "\\'", - "''", // Single quote - '\\"', - '""', // Double quote - '\\b', // A backspace character - '\\n', // A new-line character - '\\r', // A carriage return character - '\\t', // A tab character - '\\Z', // ASCII 26 (Control+Z) - '\\\\', // A backslash (\) character - '\\%', // A percent (%) character - '\\_', // An underscore (_) character - ]; - - $default = implode('+', $escapeSequences); - - $sql = sprintf( - 'CREATE TABLE test_column_defaults_with_create(col1 VARCHAR(255) NULL DEFAULT %s)', - $platform->quoteStringLiteral($default) - ); - $this->connection->query($sql); - $onlineTable = $this->schemaManager->listTableDetails('test_column_defaults_with_create'); - self::assertSame($default, $onlineTable->getColumn('col1')->getDefault()); - } - public function testEnsureTableOptionsAreReflectedInMetadata() : void { $this->connection->query('DROP TABLE IF EXISTS test_table_metadata'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 15c99c0395a..aeb9f4c90dd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -1495,67 +1495,6 @@ public function testCreateAndListSequences() : void self::assertEquals($sequence2InitialValue, $actualSequence2->getInitialValue()); } - /** - * Returns potential escaped literals from all platforms combined. - * - * @see https://dev.mysql.com/doc/refman/5.7/en/string-literals.html - * @see http://www.sqlite.org/lang_expr.html - * @see https://www.postgresql.org/docs/9.6/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE - * - * @return mixed[][] - */ - private function getEscapedLiterals() : iterable - { - return [ - ['An ASCII NUL (X\'00\')', "foo\\0bar"], - ['Single quote, C-style', "foo\\'bar"], - ['Single quote, doubled-style', "foo''bar"], - ['Double quote, C-style', 'foo\\"bar'], - ['Double quote, double-style', 'foo""bar'], - ['Backspace', 'foo\\bbar'], - ['New-line', 'foo\\nbar'], - ['Carriage return', 'foo\\rbar'], - ['Tab', 'foo\\tbar'], - ['ASCII 26 (Control+Z)', 'foo\\Zbar'], - ['Backslash (\)', 'foo\\\\bar'], - ['Percent (%)', 'foo\\%bar'], - ['Underscore (_)', 'foo\\_bar'], - ]; - } - - private function createTableForDefaultValues() : void - { - $table = new Table('string_escaped_default_value'); - foreach ($this->getEscapedLiterals() as $i => $literal) { - $table->addColumn('field' . $i, 'string', ['default' => $literal[1]]); - } - - $table->addColumn('def_foo', 'string'); - $this->schemaManager->dropAndCreateTable($table); - } - - public function testEscapedDefaultValueCanBeIntrospected() : void - { - $this->createTableForDefaultValues(); - - $onlineTable = $this->schemaManager->listTableDetails('string_escaped_default_value'); - foreach ($this->getEscapedLiterals() as $i => $literal) { - self::assertSame($literal[1], $onlineTable->getColumn('field' . $i)->getDefault(), 'should be able introspect the value of default for: ' . $literal[0]); - } - } - - public function testEscapedDefaultValueCanBeInserted() : void - { - $this->createTableForDefaultValues(); - - $this->connection->insert('string_escaped_default_value', ['def_foo' => 'foo']); - - foreach ($this->getEscapedLiterals() as $i => $literal) { - $value = $this->connection->fetchColumn('SELECT field' . $i . ' FROM string_escaped_default_value'); - self::assertSame($literal[1], $value, 'inserted default value should be the configured default value for: ' . $literal[0]); - } - } - /** * @group #3086 */ From a3a8bd4a01ae43be5548f56e51dff338bb307d10 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 22 Apr 2019 21:57:10 -0700 Subject: [PATCH 058/106] Reworked SQL Server installer on Travis CI --- .travis.yml | 6 ++++++ tests/travis/install-mssql.sh | 24 ++------------------- tests/travis/install-sqlsrv-dependencies.sh | 10 +++++++++ 3 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 tests/travis/install-sqlsrv-dependencies.sh diff --git a/.travis.yml b/.travis.yml index 6b1fd5913a1..e0d87665991 100644 --- a/.travis.yml +++ b/.travis.yml @@ -100,6 +100,7 @@ jobs: services: - docker before_script: + - bash ./tests/travis/install-sqlsrv-dependencies.sh - bash ./tests/travis/install-mssql-sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test @@ -109,6 +110,7 @@ jobs: services: - docker before_script: + - bash ./tests/travis/install-sqlsrv-dependencies.sh - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test @@ -245,6 +247,7 @@ jobs: services: - docker before_script: + - bash ./tests/travis/install-sqlsrv-dependencies.sh - bash ./tests/travis/install-mssql-sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test @@ -254,6 +257,7 @@ jobs: services: - docker before_script: + - bash ./tests/travis/install-sqlsrv-dependencies.sh - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test @@ -314,6 +318,7 @@ jobs: services: - docker before_script: + - bash ./tests/travis/install-sqlsrv-dependencies.sh - bash ./tests/travis/install-mssql-sqlsrv.sh - bash ./tests/travis/install-mssql.sh - stage: Test @@ -323,6 +328,7 @@ jobs: services: - docker before_script: + - bash ./tests/travis/install-sqlsrv-dependencies.sh - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - bash ./tests/travis/install-mssql.sh diff --git a/tests/travis/install-mssql.sh b/tests/travis/install-mssql.sh index 7a28b10065f..e4ce49b2c4a 100644 --- a/tests/travis/install-mssql.sh +++ b/tests/travis/install-mssql.sh @@ -2,12 +2,6 @@ set -ex -echo Installing drivers -curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - -curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql.list -sudo apt-get update -ACCEPT_EULA=Y sudo apt-get install -qy msodbcsql17 mssql-tools unixodbc libssl1.0.0 - echo Setting up Microsoft SQL Server sudo docker pull microsoft/mssql-server-linux:2017-latest @@ -15,24 +9,10 @@ sudo docker run \ -e 'ACCEPT_EULA=Y' \ -e 'SA_PASSWORD=Doctrine2018' \ -p 127.0.0.1:1433:1433 \ - --name db \ + --name mssql \ -d \ microsoft/mssql-server-linux:2017-latest - -retries=10 -until (echo quit | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -l 1 -U sa -P Doctrine2018 &> /dev/null) -do - if [[ "$retries" -le 0 ]]; then - echo SQL Server did not start - exit 1 - fi - - retries=$((retries - 1)) - - echo Waiting for SQL Server to start... - - sleep 2s -done +sudo docker exec -i mssql bash <<< 'until echo quit | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -l 1 -U sa -P Doctrine2018 > /dev/null 2>&1 ; do sleep 1; done' echo SQL Server started diff --git a/tests/travis/install-sqlsrv-dependencies.sh b/tests/travis/install-sqlsrv-dependencies.sh new file mode 100644 index 00000000000..137b2a95705 --- /dev/null +++ b/tests/travis/install-sqlsrv-dependencies.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -ex + +echo Installing driver dependencies + +curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - +curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql.list +sudo apt-get update +ACCEPT_EULA=Y sudo apt-get install -qy msodbcsql17 unixodbc unixodbc-dev libssl1.0.0 From b244b9e67eb498a73cdcd21a51b21594a843ffb4 Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Tue, 23 Apr 2019 11:44:36 -0500 Subject: [PATCH 059/106] Improve ExceptionTest::testConnectionExceptionSqLite so that it passes on linux running as root. --- .../Tests/DBAL/Functional/ExceptionTest.php | 61 +++++++++++++------ 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php index 54b4bc1d90a..b43f7371f43 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php @@ -9,10 +9,13 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalFunctionalTestCase; use Throwable; +use const PHP_OS; use function array_merge; use function chmod; -use function defined; +use function exec; use function file_exists; +use function posix_geteuid; +use function posix_getpwuid; use function sprintf; use function sys_get_temp_dir; use function touch; @@ -284,25 +287,28 @@ public function testSyntaxErrorException() $this->connection->executeQuery($sql); } - /** - * @dataProvider getSqLiteOpenConnection - */ - public function testConnectionExceptionSqLite($mode, $exceptionClass) + public function testConnectionExceptionSqLite() { if ($this->connection->getDatabasePlatform()->getName() !== 'sqlite') { $this->markTestSkipped('Only fails this way on sqlite'); } + // mode 0 is considered read-only on Windows + $mode = PHP_OS === 'Linux' ? 0444 : 0000; + $filename = sprintf('%s/%s', sys_get_temp_dir(), 'doctrine_failed_connection_' . $mode . '.db'); if (file_exists($filename)) { - chmod($filename, 0200); // make the file writable again, so it can be removed on Windows - unlink($filename); + $this->cleanupReadOnlyFile($filename); } touch($filename); chmod($filename, $mode); + if ($this->isLinuxRoot()) { + exec(sprintf('chattr +i %s', $filename)); + } + $params = [ 'driver' => 'pdo_sqlite', 'path' => $filename, @@ -313,19 +319,21 @@ public function testConnectionExceptionSqLite($mode, $exceptionClass) $table = $schema->createTable('no_connection'); $table->addColumn('id', 'integer'); - $this->expectException($exceptionClass); - foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) { - $conn->exec($sql); - } - } + $this->expectException(Exception\ReadOnlyException::class); + $this->expectExceptionMessage(<<toSql($conn->getDatabasePlatform()) as $sql) { + $conn->exec($sql); + } + } finally { + $this->cleanupReadOnlyFile($filename); + } } /** @@ -395,4 +403,19 @@ private function tearDownForeignKeyConstraintViolationExceptionTest() $schemaManager->dropTable('owning_table'); $schemaManager->dropTable('constraint_error_table'); } + + private function isLinuxRoot() : bool + { + return PHP_OS === 'Linux' && posix_getpwuid(posix_geteuid())['name'] === 'root'; + } + + private function cleanupReadOnlyFile(string $filename) : void + { + if ($this->isLinuxRoot()) { + exec(sprintf('chattr -i %s', $filename)); + } + + chmod($filename, 0200); // make the file writable again, so it can be removed on Windows + unlink($filename); + } } From 1a3c9b782f675c6e9333efb102805df69df06f34 Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Wed, 8 May 2019 13:23:55 -0500 Subject: [PATCH 060/106] Deprecate SQLSrvStatement::LAST_INSERT_ID_SQL constant. --- UPGRADE.md | 6 +++++- lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/UPGRADE.md b/UPGRADE.md index 91e57013d29..8d75a81b1ac 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -23,6 +23,10 @@ Some of the constants were renamed in the process: * `DATETIMETZ` -> `DATETIMETZ_MUTABLE` * `TIME` -> `TIME_MUTABLE` +## Deprecated `SQLSrvStatement::LAST_INSERT_ID_SQL` constant + +The `Doctrine\DBAL\Driver\SQLSrv\SQLSrvStatement::LAST_INSERT_ID_SQL` constant has been deprecated and will be made private in 3.0. + # Upgrade to 2.9 ## Deprecated `Statement::fetchColumn()` with an invalid index @@ -92,7 +96,7 @@ This method now throws SPL ``UnexpectedValueException`` instead of accidentally ## Doctrine\DBAL\Connection::TRANSACTION_* constants deprecated -``Doctrine\DBAL\Connection::TRANSACTION_*`` were moved into ``Doctrine\DBAL\TransactionIsolationLevel`` class without the ``TRANSACTION_`` prefix. +``Doctrine\DBAL\Connection::TRANSACTION_*`` were moved into ``Doctrine\DBAL\TransactionIsolationLevel`` class without the ``TRANSACTION_`` prefix. ## DEPRECATION: direct usage of the PDO APIs in the DBAL API diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index 453bc8b3f3f..5e7016c5a74 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -123,6 +123,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement /** * Append to any INSERT query to retrieve the last insert id. + * + * @deprecated This constant has been deprecated and will be made private in 3.0 */ public const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;'; From 2a1c2085e003a09bd135707d6ce15c3e9af455e3 Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Wed, 8 May 2019 13:16:43 -0500 Subject: [PATCH 061/106] Deprecate the public constants in SQLParserUtils --- UPGRADE.md | 4 ++++ lib/Doctrine/DBAL/SQLParserUtils.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 8d75a81b1ac..329c92b226a 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -27,6 +27,10 @@ Some of the constants were renamed in the process: The `Doctrine\DBAL\Driver\SQLSrv\SQLSrvStatement::LAST_INSERT_ID_SQL` constant has been deprecated and will be made private in 3.0. +## Deprecated `SQLParserUtils` constants + +The constants in `Doctrine\DBAL\SQLParserUtils` have been deprecated and will be made private in 3.0. + # Upgrade to 2.9 ## Deprecated `Statement::fetchColumn()` with an invalid index diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 0ff0456a00e..9768883846e 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -30,12 +30,12 @@ class SQLParserUtils */ public const POSITIONAL_TOKEN = '\?'; public const NAMED_TOKEN = '(? Date: Wed, 15 May 2019 22:45:53 -0700 Subject: [PATCH 062/106] Reworked driver exception tests 1. Got rid of hard-coded exception mocks in favor of PHPUnit-generated ones where possible. 2. Reworked AbstractDriverTest::testConvertsException() to use a data provider to make testing all types of exceptions independent. 3. Updated PHPUnit since the reworked code relies on sebastianbergmann/phpunit#3604. --- composer.json | 2 +- composer.lock | 124 +++++++++--------- .../Doctrine/Tests/DBAL/DBALExceptionTest.php | 22 +--- .../Tests/DBAL/Driver/AbstractDriverTest.php | 121 ++++++----------- .../DBAL/Driver/AbstractMySQLDriverTest.php | 5 +- .../DBAL/Driver/AbstractOracleDriverTest.php | 5 +- .../Driver/AbstractPostgreSQLDriverTest.php | 5 +- .../Driver/AbstractSQLAnywhereDriverTest.php | 5 +- .../DBAL/Driver/AbstractSQLiteDriverTest.php | 5 +- 9 files changed, 132 insertions(+), 162 deletions(-) diff --git a/composer.json b/composer.json index f7db597bec2..93ce76f3195 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "doctrine/coding-standard": "^6.0", "jetbrains/phpstorm-stubs": "^2018.1.2", "phpstan/phpstan": "^0.11.3", - "phpunit/phpunit": "^8.0", + "phpunit/phpunit": "^8.1.5", "symfony/console": "^2.0.5|^3.0|^4.0", "symfony/phpunit-bridge": "^3.4.5|^4.0.5" }, diff --git a/composer.lock b/composer.lock index 7ba548e3d11..f017f2cd53b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ddba260b7dfb84d2591b0a71a885166a", + "content-hash": "07e2f7f05586700d8d7bde1f2fd023e6", "packages": [ { "name": "doctrine/cache", @@ -329,27 +329,29 @@ }, { "name": "doctrine/instantiator", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda" + "reference": "a2c590166b2133a4633738648b6b064edae0814a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", - "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", + "reference": "a2c590166b2133a4633738648b6b064edae0814a", "shasum": "" }, "require": { "php": "^7.1" }, "require-dev": { - "athletic/athletic": "~0.1.8", + "doctrine/coding-standard": "^6.0", "ext-pdo": "*", "ext-phar": "*", - "phpunit/phpunit": "^6.2.3", - "squizlabs/php_codesniffer": "^3.0.2" + "phpbench/phpbench": "^0.13", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { @@ -374,12 +376,12 @@ } ], "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://github.com/doctrine/instantiator", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", "keywords": [ "constructor", "instantiate" ], - "time": "2017-07-22T11:58:36+00:00" + "time": "2019-03-17T17:37:11+00:00" }, { "name": "jean85/pretty-package-versions", @@ -472,16 +474,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.8.1", + "version": "1.9.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" + "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", - "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72", + "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72", "shasum": "" }, "require": { @@ -516,7 +518,7 @@ "object", "object graph" ], - "time": "2018-06-11T23:09:50+00:00" + "time": "2019-04-07T13:18:21+00:00" }, { "name": "nette/bootstrap", @@ -1254,16 +1256,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.0", + "version": "4.3.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08" + "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", + "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", "shasum": "" }, "require": { @@ -1301,7 +1303,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-11-30T07:14:17+00:00" + "time": "2019-04-30T17:48:53+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -1534,16 +1536,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "7.0.1", + "version": "7.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "4832739a02c418397e404da6c3e4fe680b7a4de7" + "reference": "0317a769a81845c390e19684d9ba25d7f6aa4707" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/4832739a02c418397e404da6c3e4fe680b7a4de7", - "reference": "4832739a02c418397e404da6c3e4fe680b7a4de7", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/0317a769a81845c390e19684d9ba25d7f6aa4707", + "reference": "0317a769a81845c390e19684d9ba25d7f6aa4707", "shasum": "" }, "require": { @@ -1593,7 +1595,7 @@ "testing", "xunit" ], - "time": "2019-02-01T07:29:14+00:00" + "time": "2019-02-26T07:38:26+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1688,16 +1690,16 @@ }, { "name": "phpunit/php-timer", - "version": "2.0.0", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "8b8454ea6958c3dee38453d3bd571e023108c91f" + "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b8454ea6958c3dee38453d3bd571e023108c91f", - "reference": "8b8454ea6958c3dee38453d3bd571e023108c91f", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b389aebe1b8b0578430bda0c7c95a829608e059", + "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059", "shasum": "" }, "require": { @@ -1709,7 +1711,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -1733,7 +1735,7 @@ "keywords": [ "timer" ], - "time": "2018-02-01T13:07:23+00:00" + "time": "2019-02-20T10:12:59+00:00" }, { "name": "phpunit/php-token-stream", @@ -1786,16 +1788,16 @@ }, { "name": "phpunit/phpunit", - "version": "8.0.0", + "version": "8.1.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "130104cf796a88dd1547dc5beb8bd555c2deb55e" + "reference": "01392d4b5878aa617e8d9bc7a529e5febc8fe956" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/130104cf796a88dd1547dc5beb8bd555c2deb55e", - "reference": "130104cf796a88dd1547dc5beb8bd555c2deb55e", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/01392d4b5878aa617e8d9bc7a529e5febc8fe956", + "reference": "01392d4b5878aa617e8d9bc7a529e5febc8fe956", "shasum": "" }, "require": { @@ -1814,7 +1816,7 @@ "phpunit/php-code-coverage": "^7.0", "phpunit/php-file-iterator": "^2.0.1", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^2.0", + "phpunit/php-timer": "^2.1", "sebastian/comparator": "^3.0", "sebastian/diff": "^3.0", "sebastian/environment": "^4.1", @@ -1838,7 +1840,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "8.0-dev" + "dev-master": "8.1-dev" } }, "autoload": { @@ -1864,7 +1866,7 @@ "testing", "xunit" ], - "time": "2019-02-01T05:41:59+00:00" + "time": "2019-05-14T04:57:31+00:00" }, { "name": "psr/log", @@ -2024,23 +2026,23 @@ }, { "name": "sebastian/diff", - "version": "3.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "366541b989927187c4ca70490a35615d3fef2dce" + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/366541b989927187c4ca70490a35615d3fef2dce", - "reference": "366541b989927187c4ca70490a35615d3fef2dce", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", "shasum": "" }, "require": { "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "^7.5 || ^8.0", "symfony/process": "^2 || ^3.3 || ^4" }, "type": "library", @@ -2076,20 +2078,20 @@ "unidiff", "unified diff" ], - "time": "2018-06-10T07:54:39+00:00" + "time": "2019-02-04T06:01:07+00:00" }, { "name": "sebastian/environment", - "version": "4.1.0", + "version": "4.2.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "6fda8ce1974b62b14935adc02a9ed38252eca656" + "reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6fda8ce1974b62b14935adc02a9ed38252eca656", - "reference": "6fda8ce1974b62b14935adc02a9ed38252eca656", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/f2a2c8e1c97c11ace607a7a667d73d47c19fe404", + "reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404", "shasum": "" }, "require": { @@ -2104,7 +2106,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -2129,7 +2131,7 @@ "environment", "hhvm" ], - "time": "2019-02-01T05:27:49+00:00" + "time": "2019-05-05T09:05:15+00:00" }, { "name": "sebastian/exporter", @@ -2886,16 +2888,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.10.0", + "version": "v1.11.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" + "reference": "82ebae02209c21113908c229e9883c419720738a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", + "reference": "82ebae02209c21113908c229e9883c419720738a", "shasum": "" }, "require": { @@ -2907,7 +2909,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.9-dev" + "dev-master": "1.11-dev" } }, "autoload": { @@ -2940,7 +2942,7 @@ "polyfill", "portable" ], - "time": "2018-08-06T14:22:27+00:00" + "time": "2019-02-06T07:57:58+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -3003,16 +3005,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.1.0", + "version": "1.1.2", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b" + "reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b", - "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/1c42705be2b6c1de5904f8afacef5895cab44bf8", + "reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8", "shasum": "" }, "require": { @@ -3039,7 +3041,7 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "time": "2017-04-07T12:08:54+00:00" + "time": "2019-04-04T09:56:43+00:00" }, { "name": "webmozart/assert", diff --git a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php index ccd1becfac9..d827fdc3b7d 100644 --- a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php @@ -35,24 +35,12 @@ public function testAvoidOverWrappingOnDriverException() { /** @var Driver $driver */ $driver = $this->createMock(Driver::class); - $inner = new class extends Exception implements InnerDriverException - { - /** - * {@inheritDoc} - */ - public function getErrorCode() - { - } - /** - * {@inheritDoc} - */ - public function getSQLState() - { - } - }; - $ex = new DriverException('', $inner); - $e = DBALException::driverExceptionDuringQuery($driver, $ex, ''); + /** @var InnerDriverException $inner */ + $inner = $this->createMock(InnerDriverException::class); + + $ex = new DriverException('', $inner); + $e = DBALException::driverExceptionDuringQuery($driver, $ex, ''); self::assertSame($ex, $e); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index 6a16dd65a91..e02c29da435 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -30,6 +30,7 @@ use Doctrine\Tests\DbalTestCase; use Exception; use ReflectionProperty; +use function array_merge; use function get_class; use function sprintf; @@ -67,29 +68,31 @@ protected function setUp() : void $this->driver = $this->createDriver(); } - public function testConvertsException() + /** + * @dataProvider exceptionConversionProvider + */ + public function testConvertsException($errorCode, $sqlState, $message, string $expectedClass) : void { if (! $this->driver instanceof ExceptionConverterDriver) { $this->markTestSkipped('This test is only intended for exception converter drivers.'); } - $data = $this->getExceptionConversions(); + $driverException = new class ($errorCode, $sqlState, $message) + extends Exception + implements DriverExceptionInterface + { + /** @var mixed */ + private $errorCode; - if (empty($data)) { - $this->fail( - sprintf( - 'No test data found for test %s. You have to return test data from %s.', - static::class . '::' . __FUNCTION__, - static::class . '::getExceptionConversionData' - ) - ); - } + /** @var mixed */ + private $sqlState; - $driverException = new class extends Exception implements DriverExceptionInterface - { - public function __construct() + public function __construct($errorCode, $sqlState, $message) { - parent::__construct('baz'); + parent::__construct($message); + + $this->errorCode = $errorCode; + $this->sqlState = $sqlState; } /** @@ -97,7 +100,7 @@ public function __construct() */ public function getErrorCode() { - return 'foo'; + return $this->errorCode; } /** @@ -105,26 +108,19 @@ public function getErrorCode() */ public function getSQLState() { - return 'bar'; + return $this->sqlState; } }; - $data[] = [$driverException, self::EXCEPTION_DRIVER]; - - $message = 'DBAL exception message'; - - foreach ($data as $item) { - /** @var $driverException \Doctrine\DBAL\Driver\DriverException */ - [$driverException, $convertedExceptionClassName] = $item; - - $convertedException = $this->driver->convertException($message, $driverException); + $dbalMessage = 'DBAL exception message'; + $dbalException = $this->driver->convertException($dbalMessage, $driverException); - self::assertSame($convertedExceptionClassName, get_class($convertedException)); + self::assertInstanceOf($expectedClass, $dbalException); - self::assertSame($driverException->getErrorCode(), $convertedException->getErrorCode()); - self::assertSame($driverException->getSQLState(), $convertedException->getSQLState()); - self::assertSame($message, $convertedException->getMessage()); - } + self::assertSame($driverException->getErrorCode(), $dbalException->getErrorCode()); + self::assertSame($driverException->getSQLState(), $dbalException->getSQLState()); + self::assertSame($driverException, $dbalException->getPrevious()); + self::assertSame($dbalMessage, $dbalException->getMessage()); } public function testCreatesDatabasePlatformForVersion() @@ -246,56 +242,25 @@ protected function getDatabasePlatformsForVersions() return []; } - protected function getExceptionConversionData() - { - return []; - } - - private function getExceptionConversions() + /** + * @return mixed[][] + */ + public static function exceptionConversionProvider() : iterable { - $data = []; - - foreach ($this->getExceptionConversionData() as $convertedExceptionClassName => $errors) { - foreach ($errors as $error) { - $driverException = new class ($error[0], $error[1], $error[2]) - extends Exception - implements DriverExceptionInterface - { - /** @var mixed */ - private $errorCode; - - /** @var mixed */ - private $sqlState; - - public function __construct($errorCode, $sqlState, $message) - { - parent::__construct($message); - - $this->errorCode = $errorCode; - $this->sqlState = $sqlState; - } - - /** - * {@inheritDoc} - */ - public function getErrorCode() - { - return $this->errorCode; - } - - /** - * {@inheritDoc} - */ - public function getSQLState() - { - return $this->sqlState; - } - }; - - $data[] = [$driverException, $convertedExceptionClassName]; + foreach (static::getExceptionConversionData() as $expectedClass => $items) { + foreach ($items as $item) { + yield array_merge($item, [$expectedClass]); } } - return $data; + yield ['foo', 'bar', 'baz', self::EXCEPTION_DRIVER]; + } + + /** + * @return array + */ + protected static function getExceptionConversionData() : array + { + return []; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php index cde381653a9..8a2374e2497 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php @@ -83,7 +83,10 @@ protected function getDatabasePlatformsForVersions() : array ]; } - protected function getExceptionConversionData() + /** + * {@inheritDoc} + */ + protected static function getExceptionConversionData() : array { return [ self::EXCEPTION_CONNECTION => [ diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php index d88040e10a7..6d272571f49 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php @@ -60,7 +60,10 @@ protected function createSchemaManager(Connection $connection) return new OracleSchemaManager($connection); } - protected function getExceptionConversionData() + /** + * {@inheritDoc} + */ + protected static function getExceptionConversionData() : array { return [ self::EXCEPTION_CONNECTION => [ diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php index d1159c80308..2807a715c8b 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php @@ -77,7 +77,10 @@ protected function getDatabasePlatformsForVersions() ]; } - protected function getExceptionConversionData() + /** + * {@inheritDoc} + */ + protected static function getExceptionConversionData() : array { return [ self::EXCEPTION_CONNECTION => [ diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php index cbd23505bae..e541285a568 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php @@ -62,7 +62,10 @@ protected function getDatabasePlatformsForVersions() ]; } - protected function getExceptionConversionData() + /** + * {@inheritDoc} + */ + protected static function getExceptionConversionData() : array { return [ self::EXCEPTION_CONNECTION => [ diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php index d92aa5d0d8d..2e97496958b 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php @@ -42,7 +42,10 @@ protected function createSchemaManager(Connection $connection) return new SqliteSchemaManager($connection); } - protected function getExceptionConversionData() + /** + * {@inheritDoc} + */ + protected static function getExceptionConversionData() : array { return [ self::EXCEPTION_CONNECTION => [ From 682003690879a625d97db3602e61786390992112 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 21 May 2019 19:38:21 -0700 Subject: [PATCH 063/106] Removed the assertion which doesn't work with a user-provided PDO connection --- lib/Doctrine/DBAL/Connection.php | 1 - .../Tests/DBAL/Functional/ConnectionTest.php | 13 +++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 78bc38023b0..d514557ff79 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1429,7 +1429,6 @@ public function rollbackSavepoint($savepoint) public function getWrappedConnection() { $this->connect(); - assert($this->_conn instanceof DriverConnection); return $this->_conn; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index c8684a60498..8e6dc21222b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -12,6 +12,7 @@ use Doctrine\Tests\DbalFunctionalTestCase; use Error; use Exception; +use PDO; use RuntimeException; use Throwable; use function in_array; @@ -311,4 +312,16 @@ public function testDeterminesDatabasePlatformWhenConnectingToNonExistentDatabas $connection->close(); } + + /** + * @requires extension pdo_sqlite + */ + public function testUserProvidedPDOConnection() : void + { + self::assertTrue( + DriverManager::getConnection([ + 'pdo' => new PDO('sqlite::memory:'), + ])->ping() + ); + } } From 48c38b08c533387aa235e3b25fe657c26e6a1d64 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 20 May 2019 13:25:18 -0700 Subject: [PATCH 064/106] Default column expressions do not work on SQL Server --- .../DBAL/Platforms/SQLServerPlatform.php | 31 -------- .../Platform/DefaultExpressionTest.php | 78 +++++++++++++++++++ .../Schema/SQLServerSchemaManagerTest.php | 17 +--- .../AbstractSQLServerPlatformTestCase.php | 2 +- 4 files changed, 81 insertions(+), 47 deletions(-) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Platform/DefaultExpressionTest.php diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index dc9f88da327..3258a6623ad 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -10,7 +10,6 @@ use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; -use Doctrine\DBAL\Types; use InvalidArgumentException; use function array_merge; use function array_unique; @@ -1602,36 +1601,6 @@ public function getBlobTypeDeclarationSQL(array $field) return 'VARBINARY(MAX)'; } - /** - * {@inheritDoc} - */ - public function getDefaultValueDeclarationSQL($field) - { - if (! isset($field['default'])) { - return empty($field['notnull']) ? ' NULL' : ''; - } - - if (! isset($field['type'])) { - return " DEFAULT '" . $field['default'] . "'"; - } - - $type = $field['type']; - - if ($type instanceof Types\PhpIntegerMappingType) { - return ' DEFAULT ' . $field['default']; - } - - if ($type instanceof Types\PhpDateTimeMappingType && $field['default'] === $this->getCurrentTimestampSQL()) { - return ' DEFAULT ' . $this->getCurrentTimestampSQL(); - } - - if ($type instanceof Types\BooleanType) { - return " DEFAULT '" . $this->convertBooleans($field['default']) . "'"; - } - - return ' DEFAULT ' . $this->quoteStringLiteral($field['default']); - } - /** * {@inheritdoc} * diff --git a/tests/Doctrine/Tests/DBAL/Functional/Platform/DefaultExpressionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Platform/DefaultExpressionTest.php new file mode 100644 index 00000000000..5365693af43 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Platform/DefaultExpressionTest.php @@ -0,0 +1,78 @@ +connection->getDatabasePlatform(); + + if ($platform instanceof MySqlPlatform) { + self::markTestSkipped('Not supported on MySQL'); + } + + $this->assertDefaultExpression(Types::DATE_MUTABLE, static function (AbstractPlatform $platform) : string { + return $platform->getCurrentDateSQL(); + }); + } + + public function testCurrentTime() : void + { + $platform = $this->connection->getDatabasePlatform(); + + if ($platform instanceof MySqlPlatform) { + self::markTestSkipped('Not supported on MySQL'); + } + + if ($platform instanceof OraclePlatform) { + self::markTestSkipped('Not supported on Oracle'); + } + + $this->assertDefaultExpression(Types::TIME_MUTABLE, static function (AbstractPlatform $platform) : string { + return $platform->getCurrentTimeSQL(); + }); + } + + public function testCurrentTimestamp() : void + { + $this->assertDefaultExpression(Types::DATETIME_MUTABLE, static function (AbstractPlatform $platform) : string { + return $platform->getCurrentTimestampSQL(); + }); + } + + private function assertDefaultExpression(string $type, callable $expression) : void + { + $platform = $this->connection->getDatabasePlatform(); + $defaultSql = $expression($platform, $this); + + $table = new Table('default_expr_test'); + $table->addColumn('actual_value', $type); + $table->addColumn('default_value', $type, ['default' => $defaultSql]); + $this->connection->getSchemaManager()->dropAndCreateTable($table); + + $this->connection->exec( + sprintf( + 'INSERT INTO default_expr_test (actual_value) VALUES (%s)', + $defaultSql + ) + ); + + [$actualValue, $defaultValue] = $this->connection->query( + 'SELECT default_value, actual_value FROM default_expr_test' + )->fetch(FetchMode::NUMERIC); + + self::assertEquals($actualValue, $defaultValue); + } +} diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php index cb7f37f15d5..d4598bccdb8 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php @@ -54,8 +54,7 @@ public function testColumnCollation() public function testDefaultConstraints() { - $platform = $this->schemaManager->getDatabasePlatform(); - $table = new Table('sqlsrv_default_constraints'); + $table = new Table('sqlsrv_default_constraints'); $table->addColumn('no_default', 'string'); $table->addColumn('df_integer', 'integer', ['default' => 666]); $table->addColumn('df_string_1', 'string', ['default' => 'foobar']); @@ -63,8 +62,6 @@ public function testDefaultConstraints() $table->addColumn('df_string_3', 'string', ['default' => 'another default value']); $table->addColumn('df_string_4', 'string', ['default' => 'column to rename']); $table->addColumn('df_boolean', 'boolean', ['default' => true]); - $table->addColumn('df_current_date', 'date', ['default' => $platform->getCurrentDateSQL()]); - $table->addColumn('df_current_time', 'time', ['default' => $platform->getCurrentTimeSQL()]); $this->schemaManager->createTable($table); $columns = $this->schemaManager->listTableColumns('sqlsrv_default_constraints'); @@ -75,12 +72,10 @@ public function testDefaultConstraints() self::assertEquals('Doctrine rocks!!!', $columns['df_string_2']->getDefault()); self::assertEquals('another default value', $columns['df_string_3']->getDefault()); self::assertEquals(1, $columns['df_boolean']->getDefault()); - self::assertSame($platform->getCurrentDateSQL(), $columns['df_current_date']->getDefault()); - self::assertSame($platform->getCurrentTimeSQL(), $columns['df_current_time']->getDefault()); $diff = new TableDiff( 'sqlsrv_default_constraints', - [new Column('df_current_timestamp', Type::getType('datetime'), ['default' => 'CURRENT_TIMESTAMP'])], + [], [ 'df_integer' => new ColumnDiff( 'df_integer', @@ -126,7 +121,6 @@ public function testDefaultConstraints() $columns = $this->schemaManager->listTableColumns('sqlsrv_default_constraints'); self::assertNull($columns['no_default']->getDefault()); - self::assertEquals('CURRENT_TIMESTAMP', $columns['df_current_timestamp']->getDefault()); self::assertEquals(0, $columns['df_integer']->getDefault()); self::assertNull($columns['df_string_2']->getDefault()); self::assertEquals('another default value', $columns['df_string_3']->getDefault()); @@ -140,12 +134,6 @@ public function testDefaultConstraints() 'sqlsrv_default_constraints', [], [ - 'df_current_timestamp' => new ColumnDiff( - 'df_current_timestamp', - new Column('df_current_timestamp', Type::getType('datetime')), - ['default'], - new Column('df_current_timestamp', Type::getType('datetime'), ['default' => 'CURRENT_TIMESTAMP']) - ), 'df_integer' => new ColumnDiff( 'df_integer', new Column('df_integer', Type::getType('integer'), ['default' => 666]), @@ -163,7 +151,6 @@ public function testDefaultConstraints() $this->schemaManager->alterTable($diff); $columns = $this->schemaManager->listTableColumns('sqlsrv_default_constraints'); - self::assertNull($columns['df_current_timestamp']->getDefault()); self::assertEquals(666, $columns['df_integer']->getDefault()); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index b43facd2406..db36f8c7ca6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -1496,7 +1496,7 @@ public function testGetDefaultValueDeclarationSQLForDateType() : void ]; self::assertSame( - " DEFAULT '" . $currentDateSql . "'", + ' DEFAULT CONVERT(date, GETDATE())', $this->platform->getDefaultValueDeclarationSQL($field) ); } From fa24a9ebcc95caa748a4f7ffc2ef0aa5ae299f2c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 23 May 2019 15:03:35 -0700 Subject: [PATCH 065/106] The usage of user-provided `PDO` instance is deprecated --- UPGRADE.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 329c92b226a..9639a6065a6 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,12 @@ # Upgrade to 2.10 +## Deprecated usage of user-provided `PDO` instance + +The usage of user-provided `PDO` instance is deprecated. The known use cases are: + +1. **Persistent PDO connections.** DBAL 3.0 will supported establishing persistent connections, therefore, providing a pre-created persistent PDO connection will be no longer needed. +2. **Sharing `PDO` instance between DBAL and legacy components.** In order to share a PDO instance, initialize the connection in DBAL and access it using `Connection::getWrappedConnection()->getWrappedConnection()`. + ## MINOR BC BREAK: Default values are no longer handled as SQL expressions They are converted to SQL literals (e.g. escaped). Clients must now specify default values in their initial form, not in the form of an SQL literal (e.g. escaped). From 808ba3f51b70d2e320440b2dc3a3506a89cf1efc Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 23 May 2019 16:35:29 -0700 Subject: [PATCH 066/106] Removed the rest of mock classes --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 25 +++++----- .../DBAL/Driver/AbstractMySQLDriverTest.php | 4 +- .../Driver/AbstractPostgreSQLDriverTest.php | 4 +- .../Tests/DBAL/Portability/StatementTest.php | 11 +---- .../Tests/Mocks/DriverConnectionMock.php | 49 ------------------- .../Tests/Mocks/DriverResultStatementMock.php | 10 ---- .../Tests/Mocks/DriverStatementMock.php | 10 ---- .../Mocks/ServerInfoAwareConnectionMock.php | 10 ---- .../Mocks/VersionAwarePlatformDriverMock.php | 10 ---- 9 files changed, 17 insertions(+), 116 deletions(-) delete mode 100644 tests/Doctrine/Tests/Mocks/DriverConnectionMock.php delete mode 100644 tests/Doctrine/Tests/Mocks/DriverResultStatementMock.php delete mode 100644 tests/Doctrine/Tests/Mocks/DriverStatementMock.php delete mode 100644 tests/Doctrine/Tests/Mocks/ServerInfoAwareConnectionMock.php delete mode 100644 tests/Doctrine/Tests/Mocks/VersionAwarePlatformDriverMock.php diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 3c3bc9f9b50..2b18a203e05 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -12,6 +12,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\Connection as DriverConnection; +use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Events; @@ -21,10 +22,8 @@ use Doctrine\DBAL\Logging\EchoSQLLogger; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\VersionAwarePlatformDriver; use Doctrine\Tests\DbalTestCase; -use Doctrine\Tests\Mocks\DriverStatementMock; -use Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock; -use Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock; use Exception; use PHPUnit\Framework\MockObject\MockObject; use stdClass; @@ -525,7 +524,7 @@ public function testFetchAssoc() $this->createMock(DriverConnection::class) )); - $driverStatementMock = $this->createMock(DriverStatementMock::class); + $driverStatementMock = $this->createMock(Statement::class); $driverStatementMock->expects($this->once()) ->method('fetch') @@ -561,7 +560,7 @@ public function testFetchArray() $this->createMock(DriverConnection::class) )); - $driverStatementMock = $this->createMock(DriverStatementMock::class); + $driverStatementMock = $this->createMock(Statement::class); $driverStatementMock->expects($this->once()) ->method('fetch') @@ -598,7 +597,7 @@ public function testFetchColumn() $this->createMock(DriverConnection::class) )); - $driverStatementMock = $this->createMock(DriverStatementMock::class); + $driverStatementMock = $this->createMock(Statement::class); $driverStatementMock->expects($this->once()) ->method('fetchColumn') @@ -634,7 +633,7 @@ public function testFetchAll() $this->createMock(DriverConnection::class) )); - $driverStatementMock = $this->createMock(DriverStatementMock::class); + $driverStatementMock = $this->createMock(Statement::class); $driverStatementMock->expects($this->once()) ->method('fetchAll') @@ -732,11 +731,11 @@ public function testCallConnectOnce($method, $params) */ public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() { - /** @var VersionAwarePlatformDriverMock|MockObject $driverMock */ - $driverMock = $this->createMock(VersionAwarePlatformDriverMock::class); + /** @var Driver|VersionAwarePlatformDriver|MockObject $driverMock */ + $driverMock = $this->createMock([Driver::class, VersionAwarePlatformDriver::class]); - /** @var ServerInfoAwareConnectionMock|MockObject $driverConnectionMock */ - $driverConnectionMock = $this->createMock(ServerInfoAwareConnectionMock::class); + /** @var ServerInfoAwareConnection|MockObject $driverConnectionMock */ + $driverConnectionMock = $this->createMock(ServerInfoAwareConnection::class); /** @var AbstractPlatform|MockObject $platformMock */ $platformMock = $this->getMockForAbstractClass(AbstractPlatform::class); @@ -861,8 +860,8 @@ public function testThrowsExceptionWhenInValidPlatformSpecified() : void */ public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnectingToNonExistentDatabase() { - /** @var VersionAwarePlatformDriverMock|MockObject $driverMock */ - $driverMock = $this->createMock(VersionAwarePlatformDriverMock::class); + /** @var Driver|VersionAwarePlatformDriver|MockObject $driverMock */ + $driverMock = $this->createMock([Driver::class, VersionAwarePlatformDriver::class]); $connection = new Connection(['dbname' => 'foo'], $driverMock); $originalException = new Exception('Original exception'); diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php index 8a2374e2497..fdb1668f5a1 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php @@ -4,12 +4,12 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\AbstractMySQLDriver; +use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySQL57Platform; use Doctrine\DBAL\Platforms\MySQL80Platform; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\MySqlSchemaManager; -use Doctrine\Tests\Mocks\DriverResultStatementMock; class AbstractMySQLDriverTest extends AbstractDriverTest { @@ -23,7 +23,7 @@ public function testReturnsDatabaseName() 'password' => 'bar', ]; - $statement = $this->createMock(DriverResultStatementMock::class); + $statement = $this->createMock(ResultStatement::class); $statement->expects($this->once()) ->method('fetchColumn') diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php index 2807a715c8b..1f508882484 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php @@ -4,13 +4,13 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; +use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Platforms\PostgreSQL100Platform; use Doctrine\DBAL\Platforms\PostgreSQL91Platform; use Doctrine\DBAL\Platforms\PostgreSQL92Platform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Schema\PostgreSqlSchemaManager; -use Doctrine\Tests\Mocks\DriverResultStatementMock; class AbstractPostgreSQLDriverTest extends AbstractDriverTest { @@ -24,7 +24,7 @@ public function testReturnsDatabaseName() 'password' => 'bar', ]; - $statement = $this->createMock(DriverResultStatementMock::class); + $statement = $this->createMock(ResultStatement::class); $statement->expects($this->once()) ->method('fetchColumn') diff --git a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php index 74ace7cc042..4d0c066d618 100644 --- a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php @@ -8,7 +8,6 @@ use Doctrine\DBAL\Portability\Connection; use Doctrine\DBAL\Portability\Statement; use Doctrine\Tests\DbalTestCase; -use Doctrine\Tests\Mocks\DriverStatementMock; use PHPUnit\Framework\MockObject\MockObject; use ReflectionProperty; use function iterator_to_array; @@ -29,7 +28,7 @@ class StatementTest extends DbalTestCase */ protected function setUp() : void { - $this->wrappedStmt = $this->createWrappedStatement(); + $this->wrappedStmt = $this->createMock(DriverStatement::class); $this->conn = $this->createConnection(); $this->stmt = $this->createStatement($this->wrappedStmt, $this->conn); } @@ -179,12 +178,4 @@ protected function createStatement(DriverStatement $wrappedStatement, Connection { return new Statement($wrappedStatement, $connection); } - - /** - * @return DriverStatement|MockObject - */ - protected function createWrappedStatement() - { - return $this->createMock(DriverStatementMock::class); - } } diff --git a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php deleted file mode 100644 index fa22cc5f91b..00000000000 --- a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php +++ /dev/null @@ -1,49 +0,0 @@ - Date: Thu, 23 May 2019 17:10:12 -0700 Subject: [PATCH 067/106] Removed 2.8 from README --- README.md | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 2dabbf4e0b1..7495d20d7ee 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Doctrine DBAL -| [Master][Master] | [2.9][2.9] | [2.8][2.8] | [Develop][develop] | -|:----------------:|:----------:|:----------:|:------------------:| -| [![Build status][Master image]][Master] | [![Build status][2.9 image]][2.9] | [![Build status][2.8 image]][2.8] | [![Build status][develop image]][develop] | -| [![Build Status][ContinuousPHP image]][ContinuousPHP] | [![Build Status][ContinuousPHP 2.9 image]][ContinuousPHP] | [![Build Status][ContinuousPHP 2.8 image]][ContinuousPHP] | [![Build Status][ContinuousPHP develop image]][ContinuousPHP] | -| [![Code Coverage][Coverage image]][Scrutinizer Master] | [![Code Coverage][Coverage 2.9 image]][Scrutinizer 2.9] | [![Code Coverage][Coverage 2.8 image]][Scrutinizer 2.8] | [![Code Coverage][Coverage develop image]][Scrutinizer develop] | -| [![Code Quality][Quality image]][Scrutinizer Master] | [![Code Quality][Quality 2.9 image]][Scrutinizer 2.9] | [![Code Quality][Quality 2.8 image]][Scrutinizer 2.8] | [![Code Quality][Quality develop image]][Scrutinizer develop] | -| [![AppVeyor][AppVeyor master image]][AppVeyor master] | [![AppVeyor][AppVeyor 2.9 image]][AppVeyor 2.9] | [![AppVeyor][AppVeyor 2.8 image]][AppVeyor 2.8] | [![AppVeyor][AppVeyor develop image]][AppVeyor develop] | +| [Master][Master] | [2.9][2.9] | [Develop][develop] | +|:----------------:|:----------:|:------------------:| +| [![Build status][Master image]][Master] | [![Build status][2.9 image]][2.9] | [![Build status][develop image]][develop] | +| [![Build Status][ContinuousPHP image]][ContinuousPHP] | [![Build Status][ContinuousPHP 2.9 image]][ContinuousPHP] | [![Build Status][ContinuousPHP develop image]][ContinuousPHP] | +| [![Code Coverage][Coverage image]][Scrutinizer Master] | [![Code Coverage][Coverage 2.9 image]][Scrutinizer 2.9] | [![Code Coverage][Coverage develop image]][Scrutinizer develop] | +| [![Code Quality][Quality image]][Scrutinizer Master] | [![Code Quality][Quality 2.9 image]][Scrutinizer 2.9] | [![Code Quality][Quality develop image]][Scrutinizer develop] | +| [![AppVeyor][AppVeyor master image]][AppVeyor master] | [![AppVeyor][AppVeyor 2.9 image]][AppVeyor 2.9] | [![AppVeyor][AppVeyor develop image]][AppVeyor develop] | Powerful database abstraction layer with many features for database schema introspection, schema management and PDO abstraction. @@ -35,15 +35,6 @@ Powerful database abstraction layer with many features for database schema intro [AppVeyor 2.9]: https://ci.appveyor.com/project/doctrine/dbal/branch/2.9 [AppVeyor 2.9 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/2.9?svg=true - [2.8 image]: https://img.shields.io/travis/doctrine/dbal/2.8.svg?style=flat-square - [Coverage 2.8 image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/dbal/2.8.svg?style=flat-square - [Quality 2.8 image]: https://img.shields.io/scrutinizer/g/doctrine/dbal/2.8.svg?style=flat-square - [ContinuousPHP 2.8 image]: https://img.shields.io/continuousphp/git-hub/doctrine/dbal/2.8.svg?style=flat-square - [2.8]: https://github.com/doctrine/dbal/tree/2.8 - [Scrutinizer 2.8]: https://scrutinizer-ci.com/g/doctrine/dbal/?branch=2.8 - [AppVeyor 2.8]: https://ci.appveyor.com/project/doctrine/dbal/branch/2.8 - [AppVeyor 2.8 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/2.8?svg=true - [develop]: https://github.com/doctrine/dbal/tree/develop [develop image]: https://img.shields.io/travis/doctrine/dbal/develop.svg?style=flat-square [Coverage develop image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/dbal/develop.svg?style=flat-square From 4074ae933de3bef5130bf99a20c797f6b8a4adc7 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 23 May 2019 13:27:41 -0700 Subject: [PATCH 068/106] Deprecated Driver::getName() The method is not used for anything else than skipping tests for specific drivers. Cross-driver portability should be established by drivers, not outside of them based on their name. --- UPGRADE.md | 4 +++ lib/Doctrine/DBAL/Driver.php | 2 ++ .../DBAL/Driver/DrizzlePDOMySql/Driver.php | 2 ++ lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php | 2 ++ lib/Doctrine/DBAL/Driver/OCI8/Driver.php | 2 ++ lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php | 2 ++ lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php | 2 ++ lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php | 2 ++ lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php | 2 ++ lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php | 2 ++ .../DBAL/Driver/SQLAnywhere/Driver.php | 2 ++ lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php | 2 ++ .../Functional/Driver/PDOConnectionTest.php | 32 +++++++++++-------- .../SchemaManagerFunctionalTestCase.php | 17 +++++++--- 14 files changed, 58 insertions(+), 17 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 9639a6065a6..ad366845ef7 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 2.10 +## Deprecated `Doctrine\DBAL\Driver::getName()` + +Relying on the name of the driver is discouraged. For referencing the driver, use its class name. + ## Deprecated usage of user-provided `PDO` instance The usage of user-provided `PDO` instance is deprecated. The known use cases are: diff --git a/lib/Doctrine/DBAL/Driver.php b/lib/Doctrine/DBAL/Driver.php index dcb03b29492..8a80d4a428a 100644 --- a/lib/Doctrine/DBAL/Driver.php +++ b/lib/Doctrine/DBAL/Driver.php @@ -42,6 +42,8 @@ public function getSchemaManager(Connection $conn); /** * Gets the name of the driver. * + * @deprecated + * * @return string The name of the driver. */ public function getName(); diff --git a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php index 851f0ee23c4..dbf342814f9 100644 --- a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php @@ -49,6 +49,8 @@ public function getSchemaManager(\Doctrine\DBAL\Connection $conn) /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php index 43497fd6026..fe79fe6bd37 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php @@ -39,6 +39,8 @@ public function connect(array $params, $username = null, $password = null, array /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php index 48195f1517e..edda32d6a56 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php @@ -44,6 +44,8 @@ protected function _constructDsn(array $params) /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php index 4291e1e17f0..12fb14ef5cb 100644 --- a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php @@ -49,6 +49,8 @@ private function _constructPdoDsn(array $params) /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php index 59d27d3844f..dcd4ff51895 100644 --- a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php @@ -62,6 +62,8 @@ protected function constructPdoDsn(array $params) /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php index 972dbadcd5d..f25cd5cded3 100644 --- a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php @@ -108,6 +108,8 @@ private function _constructPdoDsn(array $params) /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php index 7a28b831027..d08c6a2c848 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -73,6 +73,8 @@ protected function _constructPdoDsn(array $params) /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php index 8bc8671620f..6d6c4844d57 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php @@ -83,6 +83,8 @@ private function getConnectionOptionsDsn(array $connectionOptions) : string /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php index 294d5c7a5e9..9564dc2981d 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php @@ -40,6 +40,8 @@ public function connect(array $params, $username = null, $password = null, array /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php index a9be26e9dea..848ab5eef91 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php @@ -48,6 +48,8 @@ public function connect(array $params, $username = null, $password = null, array /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php index 9a12cb8f714..94c8bf00223 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php @@ -4,9 +4,13 @@ use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOException; +use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver; +use Doctrine\DBAL\Driver\PDOPgSql\Driver as PDOPgSQLDriver; +use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSRVDriver; use Doctrine\Tests\DbalFunctionalTestCase; use PDO; use function extension_loaded; +use function get_class; use function sprintf; class PDOConnectionTest extends DbalFunctionalTestCase @@ -66,10 +70,24 @@ public function testThrowsWrappedExceptionOnExec() public function testThrowsWrappedExceptionOnPrepare() { - if ($this->connection->getDriver()->getName() === 'pdo_sqlsrv') { + $driver = $this->connection->getDriver(); + + if ($driver instanceof PDOSQLSRVDriver) { $this->markTestSkipped('pdo_sqlsrv does not allow setting PDO::ATTR_EMULATE_PREPARES at connection level.'); } + // Some PDO adapters do not check the query server-side + // even though emulated prepared statements are disabled, + // so an exception is thrown only eventually. + if ($driver instanceof PDOOracleDriver + || $driver instanceof PDOPgSQLDriver + ) { + self::markTestSkipped(sprintf( + 'The underlying implementation of the %s driver does not check the query to be prepared server-side.', + get_class($driver) + )); + } + // Emulated prepared statements have to be disabled for this test // so that PDO actually communicates with the database server to check the query. $this->driverConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); @@ -77,18 +95,6 @@ public function testThrowsWrappedExceptionOnPrepare() $this->expectException(PDOException::class); $this->driverConnection->prepare('foo'); - - // Some PDO adapters like PostgreSQL do not check the query server-side - // even though emulated prepared statements are disabled, - // so an exception is thrown only eventually. - // Skip the test otherwise. - $this->markTestSkipped( - sprintf( - 'The PDO adapter %s does not check the query to be prepared server-side, ' . - 'so no assertions can be made.', - $this->connection->getDriver()->getName() - ) - ); } public function testThrowsWrappedExceptionOnQuery() diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index aeb9f4c90dd..c9b95066010 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -40,6 +40,7 @@ use function end; use function explode; use function in_array; +use function sprintf; use function str_replace; use function strcasecmp; use function strlen; @@ -130,8 +131,12 @@ public function testDropsDatabaseWithActiveConnections() */ public function testDropAndCreateSequence() { - if (! $this->connection->getDatabasePlatform()->supportsSequences()) { - $this->markTestSkipped($this->connection->getDriver()->getName() . ' does not support sequences.'); + $platform = $this->connection->getDatabasePlatform(); + + if (! $platform->supportsSequences()) { + $this->markTestSkipped( + sprintf('The "%s" platform does not support sequences.', $platform->getName()) + ); } $name = 'dropcreate_sequences_test_seq'; @@ -158,8 +163,12 @@ static function (AbstractAsset $item) use ($name) : bool { public function testListSequences() { - if (! $this->connection->getDatabasePlatform()->supportsSequences()) { - $this->markTestSkipped($this->connection->getDriver()->getName() . ' does not support sequences.'); + $platform = $this->connection->getDatabasePlatform(); + + if (! $platform->supportsSequences()) { + $this->markTestSkipped( + sprintf('The "%s" platform does not support sequences.', $platform->getName()) + ); } $sequence = new Sequence('list_sequences_test_seq', 20, 10); From 76950f51143fea6f65a735ac60d1e63367d57c7c Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Fri, 24 May 2019 12:36:03 -0500 Subject: [PATCH 069/106] add .github/FUNDING.yml --- .github/FUNDING.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000000..84fcd6afad7 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +patreon: phpdoctrine +tidelift: packagist/doctrine%2Fdbal +custom: https://www.doctrine-project.org/sponsorship.html From 248953c71a6805b56032d2a85167f39b1d281626 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 28 May 2019 16:37:34 +0200 Subject: [PATCH 070/106] Allow Symfony 5 --- composer.json | 4 ++-- composer.lock | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 93ce76f3195..1964cb3a7bd 100644 --- a/composer.json +++ b/composer.json @@ -42,8 +42,8 @@ "jetbrains/phpstorm-stubs": "^2018.1.2", "phpstan/phpstan": "^0.11.3", "phpunit/phpunit": "^8.1.5", - "symfony/console": "^2.0.5|^3.0|^4.0", - "symfony/phpunit-bridge": "^3.4.5|^4.0.5" + "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", + "symfony/phpunit-bridge": "^3.4.5|^4.0.5|^5.0" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." diff --git a/composer.lock b/composer.lock index f017f2cd53b..564b026c6cc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "07e2f7f05586700d8d7bde1f2fd023e6", + "content-hash": "7c55573f97bd2526e2b02609d5e5290c", "packages": [ { "name": "doctrine/cache", From a7acb477a72a056e3dd9b192d82ed7f81aff8668 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 15 May 2019 22:45:53 -0700 Subject: [PATCH 071/106] Upgraded to PHPUnit 8.1.6 and reworked the remaining driver exception mock --- composer.json | 2 +- composer.lock | 12 ++--- .../Tests/DBAL/Driver/AbstractDriverTest.php | 44 ++++--------------- 3 files changed, 16 insertions(+), 42 deletions(-) diff --git a/composer.json b/composer.json index 1964cb3a7bd..0012752347a 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "doctrine/coding-standard": "^6.0", "jetbrains/phpstorm-stubs": "^2018.1.2", "phpstan/phpstan": "^0.11.3", - "phpunit/phpunit": "^8.1.5", + "phpunit/phpunit": "^8.1.6", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", "symfony/phpunit-bridge": "^3.4.5|^4.0.5|^5.0" }, diff --git a/composer.lock b/composer.lock index 564b026c6cc..ebe32e583c5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7c55573f97bd2526e2b02609d5e5290c", + "content-hash": "20970a03470d26a047432b1e25bb4a2a", "packages": [ { "name": "doctrine/cache", @@ -1788,16 +1788,16 @@ }, { "name": "phpunit/phpunit", - "version": "8.1.5", + "version": "8.1.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "01392d4b5878aa617e8d9bc7a529e5febc8fe956" + "reference": "e3c9da6e645492c461e0a11eca117f83f4f4c840" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/01392d4b5878aa617e8d9bc7a529e5febc8fe956", - "reference": "01392d4b5878aa617e8d9bc7a529e5febc8fe956", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e3c9da6e645492c461e0a11eca117f83f4f4c840", + "reference": "e3c9da6e645492c461e0a11eca117f83f4f4c840", "shasum": "" }, "require": { @@ -1866,7 +1866,7 @@ "testing", "xunit" ], - "time": "2019-05-14T04:57:31+00:00" + "time": "2019-05-28T11:53:42+00:00" }, { "name": "psr/log", diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index e02c29da435..a9d1602a828 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -28,7 +28,7 @@ use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\VersionAwarePlatformDriver; use Doctrine\Tests\DbalTestCase; -use Exception; +use PHPUnit\Framework\MockObject\MockObject; use ReflectionProperty; use function array_merge; use function get_class; @@ -77,40 +77,14 @@ public function testConvertsException($errorCode, $sqlState, $message, string $e $this->markTestSkipped('This test is only intended for exception converter drivers.'); } - $driverException = new class ($errorCode, $sqlState, $message) - extends Exception - implements DriverExceptionInterface - { - /** @var mixed */ - private $errorCode; - - /** @var mixed */ - private $sqlState; - - public function __construct($errorCode, $sqlState, $message) - { - parent::__construct($message); - - $this->errorCode = $errorCode; - $this->sqlState = $sqlState; - } - - /** - * {@inheritDoc} - */ - public function getErrorCode() - { - return $this->errorCode; - } - - /** - * {@inheritDoc} - */ - public function getSQLState() - { - return $this->sqlState; - } - }; + /** @var DriverExceptionInterface|MockObject $driverException */ + $driverException = $this->getMockBuilder(DriverExceptionInterface::class) + ->setConstructorArgs([$message]) + ->getMock(); + $driverException->method('getErrorCode') + ->willReturn($errorCode); + $driverException->method('getSQLState') + ->willReturn($sqlState); $dbalMessage = 'DBAL exception message'; $dbalException = $this->driver->convertException($dbalMessage, $driverException); From 631ff640fc5803f5b157bd1393d8edfb9500e7ef Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 30 May 2019 10:45:22 -0700 Subject: [PATCH 072/106] Enforced parameter and return value types in test classes --- phpcs.xml.dist | 11 +- .../DBAL/Cache/QueryCacheProfileTest.php | 10 +- .../Doctrine/Tests/DBAL/ConfigurationTest.php | 4 +- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 92 ++--- .../Doctrine/Tests/DBAL/DBALExceptionTest.php | 8 +- .../DBAL/Driver/AbstractDB2DriverTest.php | 9 +- .../Tests/DBAL/Driver/AbstractDriverTest.php | 33 +- .../DBAL/Driver/AbstractMySQLDriverTest.php | 13 +- .../DBAL/Driver/AbstractOracleDriverTest.php | 13 +- .../Driver/AbstractPostgreSQLDriverTest.php | 16 +- .../Driver/AbstractSQLAnywhereDriverTest.php | 14 +- .../Driver/AbstractSQLServerDriverTest.php | 14 +- .../DBAL/Driver/AbstractSQLiteDriverTest.php | 11 +- .../Driver/DrizzlePDOMySql/DriverTest.php | 13 +- .../DBAL/Driver/IBMDB2/DB2ConnectionTest.php | 2 +- .../DBAL/Driver/IBMDB2/DB2DriverTest.php | 5 +- .../Tests/DBAL/Driver/Mysqli/DriverTest.php | 5 +- .../Driver/Mysqli/MysqliConnectionTest.php | 6 +- .../Tests/DBAL/Driver/OCI8/DriverTest.php | 5 +- .../DBAL/Driver/OCI8/OCI8ConnectionTest.php | 2 +- .../DBAL/Driver/OCI8/OCI8StatementTest.php | 14 +- .../Tests/DBAL/Driver/PDOExceptionTest.php | 10 +- .../Tests/DBAL/Driver/PDOIbm/DriverTest.php | 5 +- .../Tests/DBAL/Driver/PDOMySql/DriverTest.php | 5 +- .../DBAL/Driver/PDOOracle/DriverTest.php | 5 +- .../Tests/DBAL/Driver/PDOPgSql/DriverTest.php | 17 +- .../DBAL/Driver/PDOSqlite/DriverTest.php | 5 +- .../DBAL/Driver/PDOSqlsrv/DriverTest.php | 5 +- .../DBAL/Driver/SQLAnywhere/DriverTest.php | 5 +- .../SQLAnywhere/SQLAnywhereConnectionTest.php | 2 +- .../Tests/DBAL/Driver/SQLSrv/DriverTest.php | 5 +- .../Driver/SQLSrv/SQLSrvConnectionTest.php | 2 +- .../Doctrine/Tests/DBAL/DriverManagerTest.php | 34 +- .../DBAL/Events/MysqlSessionInitTest.php | 4 +- .../DBAL/Events/OracleSessionInitTest.php | 11 +- .../Tests/DBAL/Events/SQLSessionInitTest.php | 4 +- .../InvalidArgumentExceptionTest.php | 2 +- .../Tests/DBAL/Functional/BlobTest.php | 14 +- .../Tests/DBAL/Functional/ConnectionTest.php | 44 +-- .../Tests/DBAL/Functional/DataAccessTest.php | 97 +++--- .../Functional/Driver/AbstractDriverTest.php | 9 +- .../Driver/IBMDB2/DB2DriverTest.php | 7 +- .../Driver/IBMDB2/DB2StatementTest.php | 2 +- .../Driver/Mysqli/ConnectionTest.php | 8 +- .../Functional/Driver/Mysqli/DriverTest.php | 3 +- .../Functional/Driver/OCI8/DriverTest.php | 7 +- .../Driver/OCI8/OCI8ConnectionTest.php | 2 +- .../Functional/Driver/OCI8/StatementTest.php | 7 +- .../Functional/Driver/PDOConnectionTest.php | 10 +- .../Functional/Driver/PDOMySql/DriverTest.php | 3 +- .../Driver/PDOOracle/DriverTest.php | 7 +- .../Functional/Driver/PDOPgSql/DriverTest.php | 7 +- .../Driver/PDOPgsqlConnectionTest.php | 6 +- .../Driver/PDOSqlite/DriverTest.php | 3 +- .../Driver/PDOSqlsrv/DriverTest.php | 3 +- .../Driver/SQLAnywhere/ConnectionTest.php | 4 +- .../Driver/SQLAnywhere/DriverTest.php | 5 +- .../Driver/SQLAnywhere/StatementTest.php | 4 +- .../Functional/Driver/SQLSrv/DriverTest.php | 3 +- .../Driver/SQLSrv/StatementTest.php | 2 +- .../Tests/DBAL/Functional/ExceptionTest.php | 39 ++- .../Tests/DBAL/Functional/LoggingTest.php | 6 +- .../Functional/MasterSlaveConnectionTest.php | 16 +- .../DBAL/Functional/ModifyLimitQueryTest.php | 21 +- .../DBAL/Functional/NamedParametersTest.php | 8 +- .../DBAL/Functional/PDOStatementTest.php | 2 +- ...imaryKeyWithNewAutoIncrementColumnTest.php | 5 +- .../Tests/DBAL/Functional/PortabilityTest.php | 36 +- .../Tests/DBAL/Functional/ResultCacheTest.php | 50 +-- .../Schema/Db2SchemaManagerTest.php | 4 +- .../Functional/Schema/DefaultValueTest.php | 8 +- .../Schema/DrizzleSchemaManagerTest.php | 4 +- .../Schema/MySqlSchemaManagerTest.php | 32 +- .../Schema/OracleSchemaManagerTest.php | 16 +- .../Schema/PostgreSqlSchemaManagerTest.php | 41 +-- .../Schema/SQLAnywhereSchemaManagerTest.php | 6 +- .../Schema/SQLServerSchemaManagerTest.php | 12 +- .../SchemaManagerFunctionalTestCase.php | 108 +++--- .../Schema/SqliteSchemaManagerTest.php | 26 +- .../Tests/DBAL/Functional/StatementTest.php | 38 ++- .../DBAL/Functional/TableGeneratorTest.php | 4 +- .../DBAL/Functional/TemporaryTableTest.php | 8 +- .../DBAL/Functional/Ticket/DBAL168Test.php | 2 +- .../DBAL/Functional/Ticket/DBAL202Test.php | 4 +- .../DBAL/Functional/Ticket/DBAL421Test.php | 6 +- .../DBAL/Functional/Ticket/DBAL461Test.php | 2 +- .../DBAL/Functional/Ticket/DBAL510Test.php | 2 +- .../DBAL/Functional/Ticket/DBAL630Test.php | 22 +- .../DBAL/Functional/Ticket/DBAL752Test.php | 2 +- .../DBAL/Functional/TypeConversionTest.php | 14 + .../DBAL/Functional/Types/BinaryTest.php | 5 +- .../Tests/DBAL/Functional/WriteTest.php | 42 +-- .../Tests/DBAL/Logging/DebugStackTest.php | 4 +- .../TypeConversionPerformanceTest.php | 7 +- .../AbstractMySQLPlatformTestCase.php | 184 ++++++---- .../Platforms/AbstractPlatformTestCase.php | 320 ++++++++++-------- .../AbstractPostgreSqlPlatformTestCase.php | 225 ++++++------ .../AbstractSQLServerPlatformTestCase.php | 233 ++++++++----- .../Tests/DBAL/Platforms/DB2PlatformTest.php | 158 +++++---- .../Platforms/MariaDb1027PlatformTest.php | 3 +- .../DBAL/Platforms/MySQL57PlatformTest.php | 27 +- .../DBAL/Platforms/MySqlPlatformTest.php | 5 +- .../DBAL/Platforms/OraclePlatformTest.php | 217 +++++++----- .../Platforms/PostgreSQL100PlatformTest.php | 3 +- .../Platforms/PostgreSQL91PlatformTest.php | 3 +- .../Platforms/PostgreSQL92PlatformTest.php | 13 +- .../Platforms/PostgreSQL94PlatformTest.php | 7 +- .../DBAL/Platforms/PostgreSqlPlatformTest.php | 5 +- .../ReservedKeywordsValidatorTest.php | 4 +- .../Platforms/SQLAnywhere11PlatformTest.php | 7 +- .../Platforms/SQLAnywhere12PlatformTest.php | 17 +- .../Platforms/SQLAnywhere16PlatformTest.php | 7 +- .../Platforms/SQLAnywherePlatformTest.php | 246 ++++++++------ .../DBAL/Platforms/SQLAzurePlatformTest.php | 2 +- .../Platforms/SQLServer2008PlatformTest.php | 5 +- .../Platforms/SQLServer2012PlatformTest.php | 59 ++-- .../DBAL/Platforms/SQLServerPlatformTest.php | 19 +- .../DBAL/Platforms/SqlitePlatformTest.php | 145 ++++---- .../Tests/DBAL/Portability/StatementTest.php | 25 +- .../Expression/CompositeExpressionTest.php | 13 +- .../Expression/ExpressionBuilderTest.php | 57 ++-- .../Tests/DBAL/Query/QueryBuilderTest.php | 132 ++++---- .../Tests/DBAL/SQLParserUtilsTest.php | 41 ++- .../Tests/DBAL/Schema/ColumnDiffTest.php | 2 +- .../Doctrine/Tests/DBAL/Schema/ColumnTest.php | 20 +- .../Tests/DBAL/Schema/ComparatorTest.php | 131 ++++--- .../DBAL/Schema/DB2SchemaManagerTest.php | 23 +- .../DBAL/Schema/ForeignKeyConstraintTest.php | 6 +- .../Doctrine/Tests/DBAL/Schema/IndexTest.php | 27 +- .../DBAL/Schema/MySqlSchemaManagerTest.php | 7 +- .../DBAL/Schema/Platforms/MySQLSchemaTest.php | 6 +- .../Tests/DBAL/Schema/SchemaDiffTest.php | 6 +- .../Doctrine/Tests/DBAL/Schema/SchemaTest.php | 46 +-- .../Tests/DBAL/Schema/SequenceTest.php | 4 +- .../DBAL/Schema/SqliteSchemaManagerTest.php | 10 +- .../SingleDatabaseSynchronizerTest.php | 8 +- .../Tests/DBAL/Schema/TableDiffTest.php | 6 +- .../Doctrine/Tests/DBAL/Schema/TableTest.php | 111 +++--- .../Visitor/CreateSchemaSqlCollectorTest.php | 10 +- .../Visitor/DropSchemaSqlCollectorTest.php | 29 +- .../Visitor/RemoveNamespacedAssetsTest.php | 6 +- .../Schema/Visitor/SchemaSqlCollectorTest.php | 9 +- .../Sharding/PoolingShardConnectionTest.php | 30 +- .../DBAL/Sharding/PoolingShardManagerTest.php | 20 +- .../Sharding/SQLAzure/AbstractTestCase.php | 2 +- .../DBAL/Sharding/SQLAzure/FunctionalTest.php | 2 +- .../SQLAzure/MultiTenantVisitorTest.php | 4 +- .../SQLAzureFederationsSynchronizerTest.php | 6 +- .../SQLAzure/SQLAzureShardManagerTest.php | 16 +- .../MultiTenantShardChoserTest.php | 4 +- tests/Doctrine/Tests/DBAL/StatementTest.php | 8 +- .../DBAL/Tools/Console/RunSqlCommandTest.php | 14 +- .../Doctrine/Tests/DBAL/Tools/DumperTest.php | 21 +- tests/Doctrine/Tests/DBAL/Types/ArrayTest.php | 10 +- .../Tests/DBAL/Types/BaseDateTypeTestCase.php | 15 +- .../Doctrine/Tests/DBAL/Types/BinaryTest.php | 21 +- tests/Doctrine/Tests/DBAL/Types/BlobTest.php | 10 +- .../Doctrine/Tests/DBAL/Types/BooleanTest.php | 6 +- .../DBAL/Types/ConversionExceptionTest.php | 11 +- .../DBAL/Types/DateImmutableTypeTest.php | 24 +- .../Tests/DBAL/Types/DateIntervalTest.php | 5 +- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 8 +- .../DBAL/Types/DateTimeImmutableTypeTest.php | 24 +- .../Tests/DBAL/Types/DateTimeTest.php | 8 +- .../Types/DateTimeTzImmutableTypeTest.php | 22 +- .../Tests/DBAL/Types/DateTimeTzTest.php | 6 +- .../Doctrine/Tests/DBAL/Types/DecimalTest.php | 4 +- tests/Doctrine/Tests/DBAL/Types/FloatTest.php | 8 +- .../Tests/DBAL/Types/GuidTypeTest.php | 6 +- .../Doctrine/Tests/DBAL/Types/IntegerTest.php | 4 +- .../Tests/DBAL/Types/JsonArrayTest.php | 16 +- tests/Doctrine/Tests/DBAL/Types/JsonTest.php | 23 +- .../Doctrine/Tests/DBAL/Types/ObjectTest.php | 10 +- .../Tests/DBAL/Types/SmallIntTest.php | 4 +- .../Doctrine/Tests/DBAL/Types/StringTest.php | 10 +- .../DBAL/Types/TimeImmutableTypeTest.php | 24 +- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 6 +- .../Types/VarDateTimeImmutableTypeTest.php | 20 +- .../Tests/DBAL/Types/VarDateTimeTest.php | 12 +- tests/Doctrine/Tests/DBAL/UtilTest.php | 9 +- .../Doctrine/Tests/DbalFunctionalTestCase.php | 2 +- .../Tests/DbalPerformanceTestCase.php | 6 +- tests/Doctrine/Tests/TestUtil.php | 31 +- 183 files changed, 2469 insertions(+), 1952 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 6fdaaf512c4..6c4117a7c52 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -15,14 +15,20 @@ - - + + */lib/* + + + + */lib/* + + */tests/* @@ -43,6 +49,7 @@ lib/Doctrine/DBAL/Platforms/AbstractPlatform.php lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php + tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php diff --git a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php index 2a8fe528c9d..217b27d1f2f 100644 --- a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php +++ b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php @@ -38,7 +38,7 @@ protected function setUp() : void $this->queryCacheProfile = new QueryCacheProfile(self::LIFETIME, self::CACHE_KEY); } - public function testShouldUseTheGivenCacheKeyIfPresent() + public function testShouldUseTheGivenCacheKeyIfPresent() : void { [$cacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, @@ -50,7 +50,7 @@ public function testShouldUseTheGivenCacheKeyIfPresent() self::assertEquals(self::CACHE_KEY, $cacheKey, 'The returned cache key should match the given one'); } - public function testShouldGenerateAnAutomaticKeyIfNoKeyHasBeenGiven() + public function testShouldGenerateAnAutomaticKeyIfNoKeyHasBeenGiven() : void { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); @@ -70,7 +70,7 @@ public function testShouldGenerateAnAutomaticKeyIfNoKeyHasBeenGiven() self::assertNotEmpty($cacheKey, 'The generated cache key should not be empty'); } - public function testShouldGenerateDifferentKeysForSameQueryAndParamsAndDifferentConnections() + public function testShouldGenerateDifferentKeysForSameQueryAndParamsAndDifferentConnections() : void { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); @@ -93,7 +93,7 @@ public function testShouldGenerateDifferentKeysForSameQueryAndParamsAndDifferent self::assertNotEquals($firstCacheKey, $secondCacheKey, 'Cache keys should be different'); } - public function testConnectionParamsShouldBeHashed() + public function testConnectionParamsShouldBeHashed() : void { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); @@ -114,7 +114,7 @@ public function testConnectionParamsShouldBeHashed() } } - public function testShouldGenerateSameKeysIfNoneOfTheParamsChanges() + public function testShouldGenerateSameKeysIfNoneOfTheParamsChanges() : void { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); diff --git a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php index 87189bec852..6b478e82b5e 100644 --- a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php +++ b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php @@ -30,7 +30,7 @@ protected function setUp() : void * * @group DBAL-81 */ - public function testReturnsDefaultConnectionAutoCommitMode() + public function testReturnsDefaultConnectionAutoCommitMode() : void { self::assertTrue($this->config->getAutoCommit()); } @@ -40,7 +40,7 @@ public function testReturnsDefaultConnectionAutoCommitMode() * * @group DBAL-81 */ - public function testSetsDefaultConnectionAutoCommitMode() + public function testSetsDefaultConnectionAutoCommitMode() : void { $this->config->setAutoCommit(false); diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 2b18a203e05..dfd89f80dd6 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -72,78 +72,78 @@ private function getExecuteUpdateMockConnection() ->getMock(); } - public function testIsConnected() + public function testIsConnected() : void { self::assertFalse($this->connection->isConnected()); } - public function testNoTransactionActiveByDefault() + public function testNoTransactionActiveByDefault() : void { self::assertFalse($this->connection->isTransactionActive()); } - public function testCommitWithNoActiveTransactionThrowsException() + public function testCommitWithNoActiveTransactionThrowsException() : void { $this->expectException(ConnectionException::class); $this->connection->commit(); } - public function testRollbackWithNoActiveTransactionThrowsException() + public function testRollbackWithNoActiveTransactionThrowsException() : void { $this->expectException(ConnectionException::class); $this->connection->rollBack(); } - public function testSetRollbackOnlyNoActiveTransactionThrowsException() + public function testSetRollbackOnlyNoActiveTransactionThrowsException() : void { $this->expectException(ConnectionException::class); $this->connection->setRollbackOnly(); } - public function testIsRollbackOnlyNoActiveTransactionThrowsException() + public function testIsRollbackOnlyNoActiveTransactionThrowsException() : void { $this->expectException(ConnectionException::class); $this->connection->isRollbackOnly(); } - public function testGetConfiguration() + public function testGetConfiguration() : void { $config = $this->connection->getConfiguration(); self::assertInstanceOf(Configuration::class, $config); } - public function testGetHost() + public function testGetHost() : void { self::assertEquals('localhost', $this->connection->getHost()); } - public function testGetPort() + public function testGetPort() : void { self::assertEquals('1234', $this->connection->getPort()); } - public function testGetUsername() + public function testGetUsername() : void { self::assertEquals('root', $this->connection->getUsername()); } - public function testGetPassword() + public function testGetPassword() : void { self::assertEquals('password', $this->connection->getPassword()); } - public function testGetDriver() + public function testGetDriver() : void { self::assertInstanceOf(\Doctrine\DBAL\Driver\PDOMySql\Driver::class, $this->connection->getDriver()); } - public function testGetEventManager() + public function testGetEventManager() : void { self::assertInstanceOf(EventManager::class, $this->connection->getEventManager()); } - public function testConnectDispatchEvent() + public function testConnectDispatchEvent() : void { $listenerMock = $this->getMockBuilder('ConnectDispatchEventListener') ->setMethods(['postConnect']) @@ -161,7 +161,7 @@ public function testConnectDispatchEvent() $conn->connect(); } - public function testEventManagerPassedToPlatform() + public function testEventManagerPassedToPlatform() : void { $eventManager = new EventManager(); @@ -185,7 +185,7 @@ public function testEventManagerPassedToPlatform() * @requires extension pdo_sqlite * @dataProvider getQueryMethods */ - public function testDriverExceptionIsWrapped($method) + public function testDriverExceptionIsWrapped(string $method) : void { $this->expectException(DBALException::class); $this->expectExceptionMessage("An exception occurred while executing 'MUUHAAAAHAAAA':\n\nSQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\""); @@ -198,7 +198,10 @@ public function testDriverExceptionIsWrapped($method) $connection->$method('MUUHAAAAHAAAA'); } - public function getQueryMethods() + /** + * @return array> + */ + public static function getQueryMethods() : iterable { return [ ['exec'], @@ -214,7 +217,7 @@ public function getQueryMethods() * * @group DBAL-11 */ - public function testEchoSQLLogger() + public function testEchoSQLLogger() : void { $logger = new EchoSQLLogger(); $this->connection->getConfiguration()->setSQLLogger($logger); @@ -226,7 +229,7 @@ public function testEchoSQLLogger() * * @group DBAL-11 */ - public function testDebugSQLStack() + public function testDebugSQLStack() : void { $logger = new DebugStack(); $this->connection->getConfiguration()->setSQLLogger($logger); @@ -236,7 +239,7 @@ public function testDebugSQLStack() /** * @group DBAL-81 */ - public function testIsAutoCommit() + public function testIsAutoCommit() : void { self::assertTrue($this->connection->isAutoCommit()); } @@ -244,7 +247,7 @@ public function testIsAutoCommit() /** * @group DBAL-81 */ - public function testSetAutoCommit() + public function testSetAutoCommit() : void { $this->connection->setAutoCommit(false); self::assertFalse($this->connection->isAutoCommit()); @@ -255,7 +258,7 @@ public function testSetAutoCommit() /** * @group DBAL-81 */ - public function testConnectStartsTransactionInNoAutoCommitMode() + public function testConnectStartsTransactionInNoAutoCommitMode() : void { $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) @@ -277,7 +280,7 @@ public function testConnectStartsTransactionInNoAutoCommitMode() /** * @group DBAL-81 */ - public function testCommitStartsTransactionInNoAutoCommitMode() + public function testCommitStartsTransactionInNoAutoCommitMode() : void { $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) @@ -297,7 +300,7 @@ public function testCommitStartsTransactionInNoAutoCommitMode() /** * @group DBAL-81 */ - public function testRollBackStartsTransactionInNoAutoCommitMode() + public function testRollBackStartsTransactionInNoAutoCommitMode() : void { $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) @@ -317,7 +320,7 @@ public function testRollBackStartsTransactionInNoAutoCommitMode() /** * @group DBAL-81 */ - public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() + public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() : void { $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) @@ -341,7 +344,7 @@ public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() self::assertFalse($conn->isTransactionActive()); } - public function testEmptyInsert() + public function testEmptyInsert() : void { $conn = $this->getExecuteUpdateMockConnection(); @@ -355,7 +358,7 @@ public function testEmptyInsert() /** * @group DBAL-2511 */ - public function testUpdateWithDifferentColumnsInDataAndIdentifiers() + public function testUpdateWithDifferentColumnsInDataAndIdentifiers() : void { $conn = $this->getExecuteUpdateMockConnection(); @@ -399,7 +402,7 @@ public function testUpdateWithDifferentColumnsInDataAndIdentifiers() /** * @group DBAL-2511 */ - public function testUpdateWithSameColumnInDataAndIdentifiers() + public function testUpdateWithSameColumnInDataAndIdentifiers() : void { $conn = $this->getExecuteUpdateMockConnection(); @@ -442,7 +445,7 @@ public function testUpdateWithSameColumnInDataAndIdentifiers() /** * @group DBAL-2688 */ - public function testUpdateWithIsNull() + public function testUpdateWithIsNull() : void { $conn = $this->getExecuteUpdateMockConnection(); @@ -484,7 +487,7 @@ public function testUpdateWithIsNull() /** * @group DBAL-2688 */ - public function testDeleteWithIsNull() + public function testDeleteWithIsNull() : void { $conn = $this->getExecuteUpdateMockConnection(); @@ -509,7 +512,7 @@ public function testDeleteWithIsNull() ); } - public function testFetchAssoc() + public function testFetchAssoc() : void { $statement = 'SELECT * FROM foo WHERE bar = ?'; $params = [666]; @@ -545,7 +548,7 @@ public function testFetchAssoc() self::assertSame($result, $conn->fetchAssoc($statement, $params, $types)); } - public function testFetchArray() + public function testFetchArray() : void { $statement = 'SELECT * FROM foo WHERE bar = ?'; $params = [666]; @@ -581,7 +584,7 @@ public function testFetchArray() self::assertSame($result, $conn->fetchArray($statement, $params, $types)); } - public function testFetchColumn() + public function testFetchColumn() : void { $statement = 'SELECT * FROM foo WHERE bar = ?'; $params = [666]; @@ -618,7 +621,7 @@ public function testFetchColumn() self::assertSame($result, $conn->fetchColumn($statement, $params, $column, $types)); } - public function testFetchAll() + public function testFetchAll() : void { $statement = 'SELECT * FROM foo WHERE bar = ?'; $params = [666]; @@ -653,7 +656,7 @@ public function testFetchAll() self::assertSame($result, $conn->fetchAll($statement, $params, $types)); } - public function testConnectionDoesNotMaintainTwoReferencesToExternalPDO() + public function testConnectionDoesNotMaintainTwoReferencesToExternalPDO() : void { $params['pdo'] = new stdClass(); @@ -664,7 +667,7 @@ public function testConnectionDoesNotMaintainTwoReferencesToExternalPDO() self::assertArrayNotHasKey('pdo', $conn->getParams(), 'Connection is maintaining additional reference to the PDO connection'); } - public function testPassingExternalPDOMeansConnectionIsConnected() + public function testPassingExternalPDOMeansConnectionIsConnected() : void { $params['pdo'] = new stdClass(); @@ -675,7 +678,7 @@ public function testPassingExternalPDOMeansConnectionIsConnected() self::assertTrue($conn->isConnected(), 'Connection is not connected after passing external PDO'); } - public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException() + public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException() : void { /** @var Driver $driver */ $driver = $this->createMock(Driver::class); @@ -691,7 +694,10 @@ public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentE $conn->delete('kittens', []); } - public function dataCallConnectOnce() + /** + * @return array> + */ + public static function dataCallConnectOnce() : iterable { return [ ['delete', ['tbl', ['id' => 12345]]], @@ -703,9 +709,11 @@ public function dataCallConnectOnce() } /** + * @param array $params + * * @dataProvider dataCallConnectOnce */ - public function testCallConnectOnce($method, $params) + public function testCallConnectOnce(string $method, array $params) : void { $driverMock = $this->createMock(Driver::class); $pdoMock = $this->createMock(Connection::class); @@ -729,7 +737,7 @@ public function testCallConnectOnce($method, $params) /** * @group DBAL-1127 */ - public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() + public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() : void { /** @var Driver|VersionAwarePlatformDriver|MockObject $driverMock */ $driverMock = $this->createMock([Driver::class, VersionAwarePlatformDriver::class]); @@ -762,7 +770,7 @@ public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() self::assertSame($platformMock, $connection->getDatabasePlatform()); } - public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCacheQuery() + public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCacheQuery() : void { $resultCacheDriverMock = $this->createMock(Cache::class); @@ -858,7 +866,7 @@ public function testThrowsExceptionWhenInValidPlatformSpecified() : void /** * @group DBAL-990 */ - public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnectingToNonExistentDatabase() + public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnectingToNonExistentDatabase() : void { /** @var Driver|VersionAwarePlatformDriver|MockObject $driverMock */ $driverMock = $this->createMock([Driver::class, VersionAwarePlatformDriver::class]); diff --git a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php index d827fdc3b7d..7db5921ba79 100644 --- a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php @@ -15,7 +15,7 @@ class DBALExceptionTest extends DbalTestCase { - public function testDriverExceptionDuringQueryAcceptsBinaryData() + public function testDriverExceptionDuringQueryAcceptsBinaryData() : void { /** @var Driver $driver */ $driver = $this->createMock(Driver::class); @@ -23,7 +23,7 @@ public function testDriverExceptionDuringQueryAcceptsBinaryData() self::assertStringContainsString('with params ["ABC", "\x80"]', $e->getMessage()); } - public function testDriverExceptionDuringQueryAcceptsResource() + public function testDriverExceptionDuringQueryAcceptsResource() : void { /** @var Driver $driver */ $driver = $this->createMock(Driver::class); @@ -31,7 +31,7 @@ public function testDriverExceptionDuringQueryAcceptsResource() self::assertStringContainsString('Resource', $e->getMessage()); } - public function testAvoidOverWrappingOnDriverException() + public function testAvoidOverWrappingOnDriverException() : void { /** @var Driver $driver */ $driver = $this->createMock(Driver::class); @@ -44,7 +44,7 @@ public function testAvoidOverWrappingOnDriverException() self::assertSame($ex, $e); } - public function testDriverRequiredWithUrl() + public function testDriverRequiredWithUrl() : void { $url = 'mysql://localhost'; $exception = DBALException::driverRequired($url); diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDB2DriverTest.php index e6a54060c71..7038f5f8340 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDB2DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDB2DriverTest.php @@ -3,23 +3,26 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\AbstractDB2Driver; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\DB2Platform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\DB2SchemaManager; class AbstractDB2DriverTest extends AbstractDriverTest { - protected function createDriver() + protected function createDriver() : Driver { return $this->getMockForAbstractClass(AbstractDB2Driver::class); } - protected function createPlatform() + protected function createPlatform() : AbstractPlatform { return new DB2Platform(); } - protected function createSchemaManager(Connection $connection) + protected function createSchemaManager(Connection $connection) : AbstractSchemaManager { return new DB2SchemaManager($connection); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index a9d1602a828..d2a5422a179 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -69,9 +69,11 @@ protected function setUp() : void } /** + * @param int|string $errorCode + * * @dataProvider exceptionConversionProvider */ - public function testConvertsException($errorCode, $sqlState, $message, string $expectedClass) : void + public function testConvertsException($errorCode, ?string $sqlState, ?string $message, string $expectedClass) : void { if (! $this->driver instanceof ExceptionConverterDriver) { $this->markTestSkipped('This test is only intended for exception converter drivers.'); @@ -97,7 +99,7 @@ public function testConvertsException($errorCode, $sqlState, $message, string $e self::assertSame($dbalMessage, $dbalException->getMessage()); } - public function testCreatesDatabasePlatformForVersion() + public function testCreatesDatabasePlatformForVersion() : void { if (! $this->driver instanceof VersionAwarePlatformDriver) { $this->markTestSkipped('This test is only intended for version aware platform drivers.'); @@ -130,7 +132,7 @@ public function testCreatesDatabasePlatformForVersion() } } - public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion() + public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion() : void { if (! $this->driver instanceof VersionAwarePlatformDriver) { $this->markTestSkipped('This test is only intended for version aware platform drivers.'); @@ -140,7 +142,7 @@ public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion( $this->driver->createDatabasePlatformForVersion('foo'); } - public function testReturnsDatabaseName() + public function testReturnsDatabaseName() : void { $params = [ 'user' => 'foo', @@ -157,12 +159,12 @@ public function testReturnsDatabaseName() self::assertSame($params['dbname'], $this->driver->getDatabase($connection)); } - public function testReturnsDatabasePlatform() + public function testReturnsDatabasePlatform() : void { self::assertEquals($this->createPlatform(), $this->driver->getDatabasePlatform()); } - public function testReturnsSchemaManager() + public function testReturnsSchemaManager() : void { $connection = $this->getConnectionMock(); $schemaManager = $this->driver->getSchemaManager($connection); @@ -177,20 +179,16 @@ public function testReturnsSchemaManager() /** * Factory method for creating the driver instance under test. - * - * @return Driver */ - abstract protected function createDriver(); + abstract protected function createDriver() : Driver; /** * Factory method for creating the the platform instance return by the driver under test. * * The platform instance returned by this method must be the same as returned by * the driver's getDatabasePlatform() method. - * - * @return AbstractPlatform */ - abstract protected function createPlatform(); + abstract protected function createPlatform() : AbstractPlatform; /** * Factory method for creating the the schema manager instance return by the driver under test. @@ -199,19 +197,20 @@ abstract protected function createPlatform(); * the driver's getSchemaManager() method. * * @param Connection $connection The underlying connection to use. - * - * @return AbstractSchemaManager */ - abstract protected function createSchemaManager(Connection $connection); + abstract protected function createSchemaManager(Connection $connection) : AbstractSchemaManager; - protected function getConnectionMock() + protected function getConnectionMock() : Connection { return $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->getMock(); } - protected function getDatabasePlatformsForVersions() + /** + * @return array> + */ + protected function getDatabasePlatformsForVersions() : array { return []; } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php index fdb1668f5a1..4982a189e05 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php @@ -3,17 +3,20 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\AbstractMySQLDriver; use Doctrine\DBAL\Driver\ResultStatement; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySQL57Platform; use Doctrine\DBAL\Platforms\MySQL80Platform; use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\MySqlSchemaManager; class AbstractMySQLDriverTest extends AbstractDriverTest { - public function testReturnsDatabaseName() + public function testReturnsDatabaseName() : void { parent::testReturnsDatabaseName(); @@ -42,23 +45,23 @@ public function testReturnsDatabaseName() self::assertSame($database, $this->driver->getDatabase($connection)); } - protected function createDriver() + protected function createDriver() : Driver { return $this->getMockForAbstractClass(AbstractMySQLDriver::class); } - protected function createPlatform() + protected function createPlatform() : AbstractPlatform { return new MySqlPlatform(); } - protected function createSchemaManager(Connection $connection) + protected function createSchemaManager(Connection $connection) : AbstractSchemaManager { return new MySqlSchemaManager($connection); } /** - * @return mixed[][] + * {@inheritDoc} */ protected function getDatabasePlatformsForVersions() : array { diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php index 6d272571f49..f95705a8a88 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php @@ -3,13 +3,16 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\AbstractOracleDriver; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\OracleSchemaManager; class AbstractOracleDriverTest extends AbstractDriverTest { - public function testReturnsDatabaseName() + public function testReturnsDatabaseName() : void { $params = [ 'user' => 'foo', @@ -26,7 +29,7 @@ public function testReturnsDatabaseName() self::assertSame($params['user'], $this->driver->getDatabase($connection)); } - public function testReturnsDatabaseNameWithConnectDescriptor() + public function testReturnsDatabaseNameWithConnectDescriptor() : void { $params = [ 'user' => 'foo', @@ -45,17 +48,17 @@ public function testReturnsDatabaseNameWithConnectDescriptor() self::assertSame($params['user'], $this->driver->getDatabase($connection)); } - protected function createDriver() + protected function createDriver() : Driver { return $this->getMockForAbstractClass(AbstractOracleDriver::class); } - protected function createPlatform() + protected function createPlatform() : AbstractPlatform { return new OraclePlatform(); } - protected function createSchemaManager(Connection $connection) + protected function createSchemaManager(Connection $connection) : AbstractSchemaManager { return new OracleSchemaManager($connection); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php index 1f508882484..2ba6a732bd4 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php @@ -3,18 +3,21 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; use Doctrine\DBAL\Driver\ResultStatement; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSQL100Platform; use Doctrine\DBAL\Platforms\PostgreSQL91Platform; use Doctrine\DBAL\Platforms\PostgreSQL92Platform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\PostgreSqlSchemaManager; class AbstractPostgreSQLDriverTest extends AbstractDriverTest { - public function testReturnsDatabaseName() + public function testReturnsDatabaseName() : void { parent::testReturnsDatabaseName(); @@ -43,22 +46,25 @@ public function testReturnsDatabaseName() self::assertSame($database, $this->driver->getDatabase($connection)); } - protected function createDriver() + protected function createDriver() : Driver { return $this->getMockForAbstractClass(AbstractPostgreSQLDriver::class); } - protected function createPlatform() + protected function createPlatform() : AbstractPlatform { return new PostgreSqlPlatform(); } - protected function createSchemaManager(Connection $connection) + protected function createSchemaManager(Connection $connection) : AbstractSchemaManager { return new PostgreSqlSchemaManager($connection); } - protected function getDatabasePlatformsForVersions() + /** + * {@inheritDoc} + */ + protected function getDatabasePlatformsForVersions() : array { return [ ['9.0.9', PostgreSqlPlatform::class], diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php index e541285a568..4c51e7cb35f 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php @@ -3,31 +3,37 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\AbstractSQLAnywhereDriver; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLAnywhere11Platform; use Doctrine\DBAL\Platforms\SQLAnywhere12Platform; use Doctrine\DBAL\Platforms\SQLAnywhere16Platform; use Doctrine\DBAL\Platforms\SQLAnywherePlatform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\SQLAnywhereSchemaManager; class AbstractSQLAnywhereDriverTest extends AbstractDriverTest { - protected function createDriver() + protected function createDriver() : Driver { return $this->getMockForAbstractClass(AbstractSQLAnywhereDriver::class); } - protected function createPlatform() + protected function createPlatform() : AbstractPlatform { return new SQLAnywhere12Platform(); } - protected function createSchemaManager(Connection $connection) + protected function createSchemaManager(Connection $connection) : AbstractSchemaManager { return new SQLAnywhereSchemaManager($connection); } - protected function getDatabasePlatformsForVersions() + /** + * {@inheritDoc} + */ + protected function getDatabasePlatformsForVersions() : array { return [ ['10', SQLAnywherePlatform::class], diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php index 48fb3b29f3e..0d34df8e81b 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php @@ -3,31 +3,37 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\AbstractSQLServerDriver; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLServer2005Platform; use Doctrine\DBAL\Platforms\SQLServer2008Platform; use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Platforms\SQLServerPlatform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\SQLServerSchemaManager; class AbstractSQLServerDriverTest extends AbstractDriverTest { - protected function createDriver() + protected function createDriver() : Driver { return $this->getMockForAbstractClass(AbstractSQLServerDriver::class); } - protected function createPlatform() + protected function createPlatform() : AbstractPlatform { return new SQLServer2008Platform(); } - protected function createSchemaManager(Connection $connection) + protected function createSchemaManager(Connection $connection) : AbstractSchemaManager { return new SQLServerSchemaManager($connection); } - protected function getDatabasePlatformsForVersions() + /** + * {@inheritDoc} + */ + protected function getDatabasePlatformsForVersions() : array { return [ ['9', SQLServerPlatform::class], diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php index 2e97496958b..338f9126077 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php @@ -3,13 +3,16 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\AbstractSQLiteDriver; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\SqliteSchemaManager; class AbstractSQLiteDriverTest extends AbstractDriverTest { - public function testReturnsDatabaseName() + public function testReturnsDatabaseName() : void { $params = [ 'user' => 'foo', @@ -27,17 +30,17 @@ public function testReturnsDatabaseName() self::assertSame($params['path'], $this->driver->getDatabase($connection)); } - protected function createDriver() + protected function createDriver() : Driver { return $this->getMockForAbstractClass(AbstractSQLiteDriver::class); } - protected function createPlatform() + protected function createPlatform() : AbstractPlatform { return new SqlitePlatform(); } - protected function createSchemaManager(Connection $connection) + protected function createSchemaManager(Connection $connection) : AbstractSchemaManager { return new SqliteSchemaManager($connection); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/DrizzlePDOMySql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/DrizzlePDOMySql/DriverTest.php index 520a732a0c3..5af24b8454a 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/DrizzlePDOMySql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/DrizzlePDOMySql/DriverTest.php @@ -3,34 +3,37 @@ namespace Doctrine\Tests\DBAL\Driver\DrizzlePDOMySql; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\DrizzlePlatform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\DrizzleSchemaManager; use Doctrine\Tests\DBAL\Driver\PDOMySql\DriverTest as PDOMySQLDriverTest; class DriverTest extends PDOMySQLDriverTest { - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('drizzle_pdo_mysql', $this->driver->getName()); } - public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion() + public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion() : void { $this->markTestSkipped('This test does not work on Drizzle as it is not version aware.'); } - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } - protected function createPlatform() + protected function createPlatform() : AbstractPlatform { return new DrizzlePlatform(); } - protected function createSchemaManager(Connection $connection) + protected function createSchemaManager(Connection $connection) : AbstractSchemaManager { return new DrizzleSchemaManager($connection); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php index b6b32751262..cf2db940b33 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php @@ -29,7 +29,7 @@ protected function setUp() : void ->getMockForAbstractClass(); } - public function testDoesNotRequireQueryForServerVersion() + public function testDoesNotRequireQueryForServerVersion() : void { self::assertFalse($this->connectionMock->requiresQueryForServerVersion()); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php index 93f390b628a..dcf9f6083e3 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php @@ -2,17 +2,18 @@ namespace Doctrine\Tests\DBAL\Driver\IBMDB2; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; use Doctrine\Tests\DBAL\Driver\AbstractDB2DriverTest; class DB2DriverTest extends AbstractDB2DriverTest { - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('ibm_db2', $this->driver->getName()); } - protected function createDriver() + protected function createDriver() : DriverInterface { return new DB2Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/DriverTest.php index f38ff8a5529..bbe16b34717 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/DriverTest.php @@ -2,17 +2,18 @@ namespace Doctrine\Tests\DBAL\Driver\Mysqli; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\Mysqli\Driver; use Doctrine\Tests\DBAL\Driver\AbstractMySQLDriverTest; class DriverTest extends AbstractMySQLDriverTest { - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('mysqli', $this->driver->getName()); } - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php index a192edf6f52..dcfbe715608 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php @@ -37,14 +37,14 @@ protected function setUp() : void ->getMockForAbstractClass(); } - public function testDoesNotRequireQueryForServerVersion() + public function testDoesNotRequireQueryForServerVersion() : void { self::assertFalse($this->connectionMock->requiresQueryForServerVersion()); } - public function testRestoresErrorHandlerOnException() + public function testRestoresErrorHandlerOnException() : void { - $handler = static function () { + $handler = static function () : void { self::fail('Never expected this to be called'); }; $default_handler = set_error_handler($handler); diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/DriverTest.php index 77e763a66bb..7b6ed1d5a55 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/DriverTest.php @@ -2,17 +2,18 @@ namespace Doctrine\Tests\DBAL\Driver\OCI8; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\OCI8\Driver; use Doctrine\Tests\DBAL\Driver\AbstractOracleDriverTest; class DriverTest extends AbstractOracleDriverTest { - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('oci8', $this->driver->getName()); } - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php index 81466a3a72e..4c3868f4a95 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php @@ -29,7 +29,7 @@ protected function setUp() : void ->getMockForAbstractClass(); } - public function testDoesNotRequireQueryForServerVersion() + public function testDoesNotRequireQueryForServerVersion() : void { self::assertFalse($this->connectionMock->requiresQueryForServerVersion()); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php index 86d57105cbb..b28b2d83887 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php @@ -33,7 +33,7 @@ protected function setUp() : void * * @dataProvider executeDataProvider */ - public function testExecute(array $params) + public function testExecute(array $params) : void { $statement = $this->getMockBuilder(OCI8Statement::class) ->setMethods(['bindValue', 'errorInfo']) @@ -76,7 +76,10 @@ public function testExecute(array $params) $statement->execute($params); } - public static function executeDataProvider() + /** + * @return array> + */ + public static function executeDataProvider() : iterable { return [ // $hasZeroIndex = isset($params[0]); == true @@ -93,14 +96,17 @@ public static function executeDataProvider() /** * @dataProvider nonTerminatedLiteralProvider */ - public function testConvertNonTerminatedLiteral($sql, $message) + public function testConvertNonTerminatedLiteral(string $sql, string $message) : void { $this->expectException(OCI8Exception::class); $this->expectExceptionMessageRegExp($message); OCI8Statement::convertPositionalToNamedPlaceholders($sql); } - public static function nonTerminatedLiteralProvider() + /** + * @return array> + */ + public static function nonTerminatedLiteralProvider() : iterable { return [ 'no-matching-quote' => [ diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php index c7564470252..9ed9a06aa5b 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php @@ -44,27 +44,27 @@ protected function setUp() : void $this->exception = new PDOException($this->wrappedException); } - public function testReturnsCode() + public function testReturnsCode() : void { self::assertSame(self::SQLSTATE, $this->exception->getCode()); } - public function testReturnsErrorCode() + public function testReturnsErrorCode() : void { self::assertSame(self::ERROR_CODE, $this->exception->getErrorCode()); } - public function testReturnsMessage() + public function testReturnsMessage() : void { self::assertSame(self::MESSAGE, $this->exception->getMessage()); } - public function testReturnsSQLState() + public function testReturnsSQLState() : void { self::assertSame(self::SQLSTATE, $this->exception->getSQLState()); } - public function testOriginalExceptionIsInChain() + public function testOriginalExceptionIsInChain() : void { self::assertSame($this->wrappedException, $this->exception->getPrevious()); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOIbm/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOIbm/DriverTest.php index 6361f05575c..9eeeafb78aa 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOIbm/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOIbm/DriverTest.php @@ -2,17 +2,18 @@ namespace Doctrine\Tests\DBAL\Driver\PDOIbm; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\PDOIbm\Driver; use Doctrine\Tests\DBAL\Driver\AbstractDB2DriverTest; class DriverTest extends AbstractDB2DriverTest { - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('pdo_ibm', $this->driver->getName()); } - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOMySql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOMySql/DriverTest.php index a965765780d..6e3ef7d5a03 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOMySql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOMySql/DriverTest.php @@ -2,17 +2,18 @@ namespace Doctrine\Tests\DBAL\Driver\PDOMySql; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\PDOMySql\Driver; use Doctrine\Tests\DBAL\Driver\AbstractMySQLDriverTest; class DriverTest extends AbstractMySQLDriverTest { - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('pdo_mysql', $this->driver->getName()); } - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOOracle/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOOracle/DriverTest.php index f9e0da70f1c..42353be376d 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOOracle/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOOracle/DriverTest.php @@ -2,17 +2,18 @@ namespace Doctrine\Tests\DBAL\Driver\PDOOracle; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\PDOOracle\Driver; use Doctrine\Tests\DBAL\Driver\AbstractOracleDriverTest; class DriverTest extends AbstractOracleDriverTest { - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('pdo_oracle', $this->driver->getName()); } - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php index a6ac2456b64..2b976233c27 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php @@ -2,17 +2,17 @@ namespace Doctrine\Tests\DBAL\Driver\PDOPgSql; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOPgSql\Driver; use Doctrine\Tests\DBAL\Driver\AbstractPostgreSQLDriverTest; use PDO; use PDOException; -use PHPUnit_Framework_SkippedTestError; use function defined; class DriverTest extends AbstractPostgreSQLDriverTest { - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('pdo_pgsql', $this->driver->getName()); } @@ -20,7 +20,7 @@ public function testReturnsName() /** * @group DBAL-920 */ - public function testConnectionDisablesPreparesOnPhp56() + public function testConnectionDisablesPreparesOnPhp56() : void { $this->skipWhenNotUsingPhp56AndPdoPgsql(); @@ -46,7 +46,7 @@ public function testConnectionDisablesPreparesOnPhp56() /** * @group DBAL-920 */ - public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined() + public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined() : void { $this->skipWhenNotUsingPhp56AndPdoPgsql(); @@ -73,7 +73,7 @@ public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined( /** * @group DBAL-920 */ - public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplicitlyDefined() + public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplicitlyDefined() : void { $this->skipWhenNotUsingPhp56AndPdoPgsql(); @@ -100,15 +100,12 @@ public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplici /** * {@inheritDoc} */ - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } - /** - * @throws PHPUnit_Framework_SkippedTestError - */ - private function skipWhenNotUsingPhp56AndPdoPgsql() + private function skipWhenNotUsingPhp56AndPdoPgsql() : void { if (! defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')) { $this->markTestSkipped('Test requires PHP 5.6+'); diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOSqlite/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOSqlite/DriverTest.php index 49a604ccd07..9092b091e3a 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOSqlite/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOSqlite/DriverTest.php @@ -2,17 +2,18 @@ namespace Doctrine\Tests\DBAL\Driver\PDOSqlite; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\PDOSqlite\Driver; use Doctrine\Tests\DBAL\Driver\AbstractSQLiteDriverTest; class DriverTest extends AbstractSQLiteDriverTest { - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('pdo_sqlite', $this->driver->getName()); } - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOSqlsrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOSqlsrv/DriverTest.php index bf060365838..c92dc86d5ba 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOSqlsrv/DriverTest.php @@ -2,17 +2,18 @@ namespace Doctrine\Tests\DBAL\Driver\PDOSqlsrv; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\PDOSqlsrv\Driver; use Doctrine\Tests\DBAL\Driver\AbstractSQLServerDriverTest; class DriverTest extends AbstractSQLServerDriverTest { - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('pdo_sqlsrv', $this->driver->getName()); } - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/DriverTest.php index 54b1912a911..d6f1595a45e 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/DriverTest.php @@ -2,17 +2,18 @@ namespace Doctrine\Tests\DBAL\Driver\SQLAnywhere; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\SQLAnywhere\Driver; use Doctrine\Tests\DBAL\Driver\AbstractSQLAnywhereDriverTest; class DriverTest extends AbstractSQLAnywhereDriverTest { - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('sqlanywhere', $this->driver->getName()); } - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php index ccf6e3358f2..effeb483362 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php @@ -29,7 +29,7 @@ protected function setUp() : void ->getMockForAbstractClass(); } - public function testRequiresQueryForServerVersion() + public function testRequiresQueryForServerVersion() : void { self::assertTrue($this->connectionMock->requiresQueryForServerVersion()); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/DriverTest.php index b99516f7048..9ab6635ecf4 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/DriverTest.php @@ -2,17 +2,18 @@ namespace Doctrine\Tests\DBAL\Driver\SQLSrv; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\SQLSrv\Driver; use Doctrine\Tests\DBAL\Driver\AbstractSQLServerDriverTest; class DriverTest extends AbstractSQLServerDriverTest { - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('sqlsrv', $this->driver->getName()); } - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php index 13ce72a942f..8d457d8eb23 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php @@ -29,7 +29,7 @@ protected function setUp() : void ->getMockForAbstractClass(); } - public function testDoesNotRequireQueryForServerVersion() + public function testDoesNotRequireQueryForServerVersion() : void { self::assertFalse($this->connectionMock->requiresQueryForServerVersion()); } diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index 0346405cb82..ced3e5d993f 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -27,7 +27,7 @@ class DriverManagerTest extends DbalTestCase /** * @requires extension pdo_sqlite */ - public function testInvalidPdoInstance() + public function testInvalidPdoInstance() : void { $this->expectException(DBALException::class); DriverManager::getConnection(['pdo' => 'test']); @@ -36,7 +36,7 @@ public function testInvalidPdoInstance() /** * @requires extension pdo_sqlite */ - public function testValidPdoInstance() + public function testValidPdoInstance() : void { $conn = DriverManager::getConnection([ 'pdo' => new PDO('sqlite::memory:'), @@ -49,7 +49,7 @@ public function testValidPdoInstance() * @group DBAL-32 * @requires extension pdo_sqlite */ - public function testPdoInstanceSetErrorMode() + public function testPdoInstanceSetErrorMode() : void { $pdo = new PDO('sqlite::memory:'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); @@ -59,14 +59,14 @@ public function testPdoInstanceSetErrorMode() self::assertEquals(PDO::ERRMODE_EXCEPTION, $pdo->getAttribute(PDO::ATTR_ERRMODE)); } - public function testCheckParams() + public function testCheckParams() : void { $this->expectException(DBALException::class); DriverManager::getConnection([]); } - public function testInvalidDriver() + public function testInvalidDriver() : void { $this->expectException(DBALException::class); @@ -76,7 +76,7 @@ public function testInvalidDriver() /** * @requires extension pdo_sqlite */ - public function testCustomPlatform() + public function testCustomPlatform() : void { $platform = $this->createMock(AbstractPlatform::class); $options = [ @@ -91,7 +91,7 @@ public function testCustomPlatform() /** * @requires extension pdo_sqlite */ - public function testCustomWrapper() + public function testCustomWrapper() : void { $wrapper = $this->createMock(Connection::class); $wrapperClass = get_class($wrapper); @@ -108,7 +108,7 @@ public function testCustomWrapper() /** * @requires extension pdo_sqlite */ - public function testInvalidWrapperClass() + public function testInvalidWrapperClass() : void { $this->expectException(DBALException::class); @@ -120,7 +120,7 @@ public function testInvalidWrapperClass() DriverManager::getConnection($options); } - public function testInvalidDriverClass() + public function testInvalidDriverClass() : void { $this->expectException(DBALException::class); @@ -129,7 +129,7 @@ public function testInvalidDriverClass() DriverManager::getConnection($options); } - public function testValidDriverClass() + public function testValidDriverClass() : void { $options = ['driverClass' => PDOMySQLDriver::class]; @@ -137,7 +137,7 @@ public function testValidDriverClass() self::assertInstanceOf(PDOMySQLDriver::class, $conn->getDriver()); } - public function testDatabaseUrlMasterSlave() + public function testDatabaseUrlMasterSlave() : void { $options = [ 'driver' => 'pdo_mysql', @@ -169,7 +169,7 @@ public function testDatabaseUrlMasterSlave() self::assertEquals('baz_slave', $params['slaves']['slave1']['dbname']); } - public function testDatabaseUrlShard() + public function testDatabaseUrlShard() : void { $options = [ 'driver' => 'pdo_mysql', @@ -206,9 +206,12 @@ public function testDatabaseUrlShard() } /** + * @param mixed $url + * @param mixed $expected + * * @dataProvider databaseUrls */ - public function testDatabaseUrl($url, $expected) + public function testDatabaseUrl($url, $expected) : void { $options = is_array($url) ? $url : ['url' => $url]; @@ -238,7 +241,10 @@ public function testDatabaseUrl($url, $expected) } } - public function databaseUrls() + /** + * @return array> + */ + public function databaseUrls() : iterable { $driver = $this->createMock(Driver::class); $driverClass = get_class($driver); diff --git a/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php b/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php index 0f9be11edda..daea3a754c6 100644 --- a/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php +++ b/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php @@ -10,7 +10,7 @@ class MysqlSessionInitTest extends DbalTestCase { - public function testPostConnect() + public function testPostConnect() : void { $connectionMock = $this->createMock(Connection::class); $connectionMock->expects($this->once()) @@ -23,7 +23,7 @@ public function testPostConnect() $listener->postConnect($eventArgs); } - public function testGetSubscribedEvents() + public function testGetSubscribedEvents() : void { $listener = new MysqlSessionInit(); self::assertEquals([Events::postConnect], $listener->getSubscribedEvents()); diff --git a/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php b/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php index 2ea510a0543..998b1dc916e 100644 --- a/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php +++ b/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php @@ -11,7 +11,7 @@ class OracleSessionInitTest extends DbalTestCase { - public function testPostConnect() + public function testPostConnect() : void { $connectionMock = $this->createMock(Connection::class); $connectionMock->expects($this->once()) @@ -28,7 +28,7 @@ public function testPostConnect() * @group DBAL-1824 * @dataProvider getPostConnectWithSessionParameterValuesData */ - public function testPostConnectQuotesSessionParameterValues($name, $value) + public function testPostConnectQuotesSessionParameterValues(string $name, string $value) : void { $connectionMock = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() @@ -43,14 +43,17 @@ public function testPostConnectQuotesSessionParameterValues($name, $value) $listener->postConnect($eventArgs); } - public function getPostConnectWithSessionParameterValuesData() + /** + * @return array> + */ + public static function getPostConnectWithSessionParameterValuesData() : iterable { return [ ['CURRENT_SCHEMA', 'foo'], ]; } - public function testGetSubscribedEvents() + public function testGetSubscribedEvents() : void { $listener = new OracleSessionInit(); self::assertEquals([Events::postConnect], $listener->getSubscribedEvents()); diff --git a/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php b/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php index f42458de74d..c69b2996827 100644 --- a/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php +++ b/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php @@ -13,7 +13,7 @@ */ class SQLSessionInitTest extends DbalTestCase { - public function testPostConnect() + public function testPostConnect() : void { $connectionMock = $this->createMock(Connection::class); $connectionMock->expects($this->once()) @@ -26,7 +26,7 @@ public function testPostConnect() $listener->postConnect($eventArgs); } - public function testGetSubscribedEvents() + public function testGetSubscribedEvents() : void { $listener = new SQLSessionInit("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'"); self::assertEquals([Events::postConnect], $listener->getSubscribedEvents()); diff --git a/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php b/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php index 54cfea89596..7718a6bc9d8 100644 --- a/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php @@ -12,7 +12,7 @@ */ class InvalidArgumentExceptionTest extends TestCase { - public function testFromEmptyCriteria() + public function testFromEmptyCriteria() : void { $exception = InvalidArgumentException::fromEmptyCriteria(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php index 69094c97838..a12d0600201 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php @@ -38,7 +38,7 @@ protected function setUp() : void $sm->dropAndCreateTable($table); } - public function testInsert() + public function testInsert() : void { $ret = $this->connection->insert('blob_table', [ 'id' => 1, @@ -53,7 +53,7 @@ public function testInsert() self::assertEquals(1, $ret); } - public function testInsertProcessesStream() + public function testInsertProcessesStream() : void { // https://github.com/doctrine/dbal/issues/3290 if ($this->connection->getDriver() instanceof OCI8Driver) { @@ -74,7 +74,7 @@ public function testInsertProcessesStream() $this->assertBlobContains($longBlob); } - public function testSelect() + public function testSelect() : void { $this->connection->insert('blob_table', [ 'id' => 1, @@ -89,7 +89,7 @@ public function testSelect() $this->assertBlobContains('test'); } - public function testUpdate() + public function testUpdate() : void { $this->connection->insert('blob_table', [ 'id' => 1, @@ -109,7 +109,7 @@ public function testUpdate() $this->assertBlobContains('test2'); } - public function testUpdateProcessesStream() + public function testUpdateProcessesStream() : void { // https://github.com/doctrine/dbal/issues/3290 if ($this->connection->getDriver() instanceof OCI8Driver) { @@ -137,7 +137,7 @@ public function testUpdateProcessesStream() $this->assertBlobContains('test2'); } - public function testBindParamProcessesStream() + public function testBindParamProcessesStream() : void { if ($this->connection->getDriver() instanceof OCI8Driver) { $this->markTestIncomplete('The oci8 driver does not support stream resources as parameters'); @@ -156,7 +156,7 @@ public function testBindParamProcessesStream() $this->assertBlobContains('test'); } - private function assertBlobContains($text) + private function assertBlobContains(string $text) : void { $rows = $this->connection->query('SELECT blobfield FROM blob_table')->fetchAll(FetchMode::COLUMN); diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index 8e6dc21222b..2c88a127e33 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -31,12 +31,12 @@ protected function tearDown() : void $this->resetSharedConn(); } - public function testGetWrappedConnection() + public function testGetWrappedConnection() : void { self::assertInstanceOf(DriverConnection::class, $this->connection->getWrappedConnection()); } - public function testCommitWithRollbackOnlyThrowsException() + public function testCommitWithRollbackOnlyThrowsException() : void { $this->connection->beginTransaction(); $this->connection->setRollbackOnly(); @@ -45,7 +45,7 @@ public function testCommitWithRollbackOnlyThrowsException() $this->connection->commit(); } - public function testTransactionNestingBehavior() + public function testTransactionNestingBehavior() : void { try { $this->connection->beginTransaction(); @@ -72,7 +72,7 @@ public function testTransactionNestingBehavior() } } - public function testTransactionNestingBehaviorWithSavepoints() + public function testTransactionNestingBehaviorWithSavepoints() : void { if (! $this->connection->getDatabasePlatform()->supportsSavepoints()) { $this->markTestSkipped('This test requires the platform to support savepoints.'); @@ -111,7 +111,7 @@ public function testTransactionNestingBehaviorWithSavepoints() } } - public function testTransactionNestingBehaviorCantBeChangedInActiveTransaction() + public function testTransactionNestingBehaviorCantBeChangedInActiveTransaction() : void { if (! $this->connection->getDatabasePlatform()->supportsSavepoints()) { $this->markTestSkipped('This test requires the platform to support savepoints.'); @@ -122,7 +122,7 @@ public function testTransactionNestingBehaviorCantBeChangedInActiveTransaction() $this->connection->setNestTransactionsWithSavepoints(true); } - public function testSetNestedTransactionsThroughSavepointsNotSupportedThrowsException() + public function testSetNestedTransactionsThroughSavepointsNotSupportedThrowsException() : void { if ($this->connection->getDatabasePlatform()->supportsSavepoints()) { $this->markTestSkipped('This test requires the platform not to support savepoints.'); @@ -134,7 +134,7 @@ public function testSetNestedTransactionsThroughSavepointsNotSupportedThrowsExce $this->connection->setNestTransactionsWithSavepoints(true); } - public function testCreateSavepointsNotSupportedThrowsException() + public function testCreateSavepointsNotSupportedThrowsException() : void { if ($this->connection->getDatabasePlatform()->supportsSavepoints()) { $this->markTestSkipped('This test requires the platform not to support savepoints.'); @@ -146,7 +146,7 @@ public function testCreateSavepointsNotSupportedThrowsException() $this->connection->createSavepoint('foo'); } - public function testReleaseSavepointsNotSupportedThrowsException() + public function testReleaseSavepointsNotSupportedThrowsException() : void { if ($this->connection->getDatabasePlatform()->supportsSavepoints()) { $this->markTestSkipped('This test requires the platform not to support savepoints.'); @@ -158,7 +158,7 @@ public function testReleaseSavepointsNotSupportedThrowsException() $this->connection->releaseSavepoint('foo'); } - public function testRollbackSavepointsNotSupportedThrowsException() + public function testRollbackSavepointsNotSupportedThrowsException() : void { if ($this->connection->getDatabasePlatform()->supportsSavepoints()) { $this->markTestSkipped('This test requires the platform not to support savepoints.'); @@ -170,7 +170,7 @@ public function testRollbackSavepointsNotSupportedThrowsException() $this->connection->rollbackSavepoint('foo'); } - public function testTransactionBehaviorWithRollback() + public function testTransactionBehaviorWithRollback() : void { try { $this->connection->beginTransaction(); @@ -186,7 +186,7 @@ public function testTransactionBehaviorWithRollback() } } - public function testTransactionBehaviour() + public function testTransactionBehaviour() : void { try { $this->connection->beginTransaction(); @@ -200,10 +200,10 @@ public function testTransactionBehaviour() self::assertEquals(0, $this->connection->getTransactionNestingLevel()); } - public function testTransactionalWithException() + public function testTransactionalWithException() : void { try { - $this->connection->transactional(static function ($conn) { + $this->connection->transactional(static function ($conn) : void { /** @var Connection $conn */ $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); throw new RuntimeException('Ooops!'); @@ -214,10 +214,10 @@ public function testTransactionalWithException() } } - public function testTransactionalWithThrowable() + public function testTransactionalWithThrowable() : void { try { - $this->connection->transactional(static function ($conn) { + $this->connection->transactional(static function ($conn) : void { /** @var Connection $conn */ $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); throw new Error('Ooops!'); @@ -228,9 +228,9 @@ public function testTransactionalWithThrowable() } } - public function testTransactional() + public function testTransactional() : void { - $res = $this->connection->transactional(static function ($conn) { + $res = $this->connection->transactional(static function ($conn) : void { /** @var Connection $conn */ $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); }); @@ -238,7 +238,7 @@ public function testTransactional() self::assertNull($res); } - public function testTransactionalReturnValue() + public function testTransactionalReturnValue() : void { $res = $this->connection->transactional(static function () { return 42; @@ -250,7 +250,7 @@ public function testTransactionalReturnValue() /** * Tests that the quote function accepts DBAL and PDO types. */ - public function testQuote() + public function testQuote() : void { self::assertEquals( $this->connection->quote('foo', Types::STRING), @@ -258,7 +258,7 @@ public function testQuote() ); } - public function testPingDoesTriggersConnect() + public function testPingDoesTriggersConnect() : void { self::assertTrue($this->connection->ping()); self::assertTrue($this->connection->isConnected()); @@ -267,7 +267,7 @@ public function testPingDoesTriggersConnect() /** * @group DBAL-1025 */ - public function testConnectWithoutExplicitDatabaseName() + public function testConnectWithoutExplicitDatabaseName() : void { if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { $this->markTestSkipped('Platform does not support connecting without database name.'); @@ -290,7 +290,7 @@ public function testConnectWithoutExplicitDatabaseName() /** * @group DBAL-990 */ - public function testDeterminesDatabasePlatformWhenConnectingToNonExistentDatabase() + public function testDeterminesDatabasePlatformWhenConnectingToNonExistentDatabase() : void { if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { $this->markTestSkipped('Platform does not support connecting without database name.'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index a0b8db003da..b7d625c8600 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -59,7 +59,7 @@ protected function setUp() : void self::$generated = true; } - public function testPrepareWithBindValue() + public function testPrepareWithBindValue() : void { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->connection->prepare($sql); @@ -74,7 +74,7 @@ public function testPrepareWithBindValue() self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $row); } - public function testPrepareWithBindParam() + public function testPrepareWithBindParam() : void { $paramInt = 1; $paramStr = 'foo'; @@ -92,7 +92,7 @@ public function testPrepareWithBindParam() self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $row); } - public function testPrepareWithFetchAll() + public function testPrepareWithFetchAll() : void { $paramInt = 1; $paramStr = 'foo'; @@ -113,7 +113,7 @@ public function testPrepareWithFetchAll() /** * @group DBAL-228 */ - public function testPrepareWithFetchAllBoth() + public function testPrepareWithFetchAllBoth() : void { $paramInt = 1; $paramStr = 'foo'; @@ -131,7 +131,7 @@ public function testPrepareWithFetchAllBoth() self::assertEquals(['test_int' => 1, 'test_string' => 'foo', 0 => 1, 1 => 'foo'], $rows[0]); } - public function testPrepareWithFetchColumn() + public function testPrepareWithFetchColumn() : void { $paramInt = 1; $paramStr = 'foo'; @@ -148,7 +148,7 @@ public function testPrepareWithFetchColumn() self::assertEquals(1, $column); } - public function testPrepareWithIterator() + public function testPrepareWithIterator() : void { $paramInt = 1; $paramStr = 'foo'; @@ -170,7 +170,7 @@ public function testPrepareWithIterator() self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $rows[0]); } - public function testPrepareWithQuoted() + public function testPrepareWithQuoted() : void { $table = 'fetch_table'; $paramInt = 1; @@ -185,7 +185,7 @@ public function testPrepareWithQuoted() self::assertInstanceOf(Statement::class, $stmt); } - public function testPrepareWithExecuteParams() + public function testPrepareWithExecuteParams() : void { $paramInt = 1; $paramStr = 'foo'; @@ -201,7 +201,7 @@ public function testPrepareWithExecuteParams() self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $row); } - public function testFetchAll() + public function testFetchAll() : void { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $data = $this->connection->fetchAll($sql, [1, 'foo']); @@ -219,7 +219,7 @@ public function testFetchAll() /** * @group DBAL-209 */ - public function testFetchAllWithTypes() + public function testFetchAllWithTypes() : void { $datetimeString = '2010-01-01 10:10:10'; $datetime = new DateTime($datetimeString); @@ -244,7 +244,7 @@ public function testFetchAllWithTypes() /** * @group DBAL-209 */ - public function testFetchAllWithMissingTypes() + public function testFetchAllWithMissingTypes() : void { if ($this->connection->getDriver() instanceof MySQLiDriver || $this->connection->getDriver() instanceof SQLSrvDriver) { @@ -260,7 +260,7 @@ public function testFetchAllWithMissingTypes() $this->connection->fetchAll($sql, [1, $datetime]); } - public function testFetchBoth() + public function testFetchBoth() : void { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $row = $this->connection->executeQuery($sql, [1, 'foo'])->fetch(FetchMode::MIXED); @@ -275,14 +275,14 @@ public function testFetchBoth() self::assertEquals('foo', $row[1]); } - public function testFetchNoResult() + public function testFetchNoResult() : void { self::assertFalse( $this->connection->executeQuery('SELECT test_int FROM fetch_table WHERE test_int = ?', [-1])->fetch() ); } - public function testFetchAssoc() + public function testFetchAssoc() : void { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $row = $this->connection->fetchAssoc($sql, [1, 'foo']); @@ -295,7 +295,7 @@ public function testFetchAssoc() self::assertEquals('foo', $row['test_string']); } - public function testFetchAssocWithTypes() + public function testFetchAssocWithTypes() : void { $datetimeString = '2010-01-01 10:10:10'; $datetime = new DateTime($datetimeString); @@ -315,7 +315,7 @@ public function testFetchAssocWithTypes() self::assertStringStartsWith($datetimeString, $row['test_datetime']); } - public function testFetchAssocWithMissingTypes() + public function testFetchAssocWithMissingTypes() : void { if ($this->connection->getDriver() instanceof MySQLiDriver || $this->connection->getDriver() instanceof SQLSrvDriver) { @@ -331,7 +331,7 @@ public function testFetchAssocWithMissingTypes() $this->connection->fetchAssoc($sql, [1, $datetime]); } - public function testFetchArray() + public function testFetchArray() : void { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $row = $this->connection->fetchArray($sql, [1, 'foo']); @@ -340,7 +340,7 @@ public function testFetchArray() self::assertEquals('foo', $row[1]); } - public function testFetchArrayWithTypes() + public function testFetchArrayWithTypes() : void { $datetimeString = '2010-01-01 10:10:10'; $datetime = new DateTime($datetimeString); @@ -360,7 +360,7 @@ public function testFetchArrayWithTypes() self::assertStringStartsWith($datetimeString, $row[1]); } - public function testFetchArrayWithMissingTypes() + public function testFetchArrayWithMissingTypes() : void { if ($this->connection->getDriver() instanceof MySQLiDriver || $this->connection->getDriver() instanceof SQLSrvDriver) { @@ -376,7 +376,7 @@ public function testFetchArrayWithMissingTypes() $this->connection->fetchArray($sql, [1, $datetime]); } - public function testFetchColumn() + public function testFetchColumn() : void { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $testInt = $this->connection->fetchColumn($sql, [1, 'foo'], 0); @@ -389,7 +389,7 @@ public function testFetchColumn() self::assertEquals('foo', $testString); } - public function testFetchColumnWithTypes() + public function testFetchColumnWithTypes() : void { $datetimeString = '2010-01-01 10:10:10'; $datetime = new DateTime($datetimeString); @@ -407,7 +407,7 @@ public function testFetchColumnWithTypes() self::assertStringStartsWith($datetimeString, $column); } - public function testFetchColumnWithMissingTypes() + public function testFetchColumnWithMissingTypes() : void { if ($this->connection->getDriver() instanceof MySQLiDriver || $this->connection->getDriver() instanceof SQLSrvDriver) { @@ -426,7 +426,7 @@ public function testFetchColumnWithMissingTypes() /** * @group DDC-697 */ - public function testExecuteQueryBindDateTimeType() + public function testExecuteQueryBindDateTimeType() : void { $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; $stmt = $this->connection->executeQuery( @@ -441,7 +441,7 @@ public function testExecuteQueryBindDateTimeType() /** * @group DDC-697 */ - public function testExecuteUpdateBindDateTimeType() + public function testExecuteUpdateBindDateTimeType() : void { $datetime = new DateTime('2010-02-02 20:20:20'); @@ -467,7 +467,7 @@ public function testExecuteUpdateBindDateTimeType() /** * @group DDC-697 */ - public function testPrepareQueryBindValueDateTimeType() + public function testPrepareQueryBindValueDateTimeType() : void { $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; $stmt = $this->connection->prepare($sql); @@ -480,7 +480,7 @@ public function testPrepareQueryBindValueDateTimeType() /** * @group DBAL-78 */ - public function testNativeArrayListSupport() + public function testNativeArrayListSupport() : void { for ($i = 100; $i < 110; $i++) { $this->connection->insert('fetch_table', ['test_int' => $i, 'test_string' => 'foo' . $i, 'test_datetime' => '2010-01-01 10:10:10']); @@ -508,9 +508,11 @@ public function testNativeArrayListSupport() } /** + * @param string|false $char + * * @dataProvider getTrimExpressionData */ - public function testTrimExpression($value, $position, $char, $expectedResult) + public function testTrimExpression(string $value, int $position, $char, string $expectedResult) : void { $sql = 'SELECT ' . $this->connection->getDatabasePlatform()->getTrimExpression($value, $position, $char) . ' AS trimmed ' . @@ -522,7 +524,10 @@ public function testTrimExpression($value, $position, $char, $expectedResult) self::assertEquals($expectedResult, $row['trimmed']); } - public function getTrimExpressionData() + /** + * @return array> + */ + public static function getTrimExpressionData() : iterable { return [ ['test_string', TrimMode::UNSPECIFIED, false, 'foo'], @@ -567,7 +572,7 @@ public function getTrimExpressionData() /** * @group DDC-1014 */ - public function testDateArithmetics() + public function testDateArithmetics() : void { $p = $this->connection->getDatabasePlatform(); $sql = 'SELECT '; @@ -610,7 +615,7 @@ public function testDateArithmetics() self::assertEquals('2004-01-01', date('Y-m-d', strtotime($row['sub_years'])), 'Subtracting years should end up on 2004-01-01'); } - public function testSqliteDateArithmeticWithDynamicInterval() + public function testSqliteDateArithmeticWithDynamicInterval() : void { $platform = $this->connection->getDatabasePlatform(); @@ -637,7 +642,7 @@ public function testSqliteDateArithmeticWithDynamicInterval() $this->assertEquals(1, $rowCount); } - public function testLocateExpression() + public function testLocateExpression() : void { $platform = $this->connection->getDatabasePlatform(); @@ -667,7 +672,7 @@ public function testLocateExpression() self::assertEquals(0, $row['locate9']); } - public function testQuoteSQLInjection() + public function testQuoteSQLInjection() : void { $sql = 'SELECT * FROM fetch_table WHERE test_string = ' . $this->connection->quote("bar' OR '1'='1"); $rows = $this->connection->fetchAll($sql); @@ -678,7 +683,7 @@ public function testQuoteSQLInjection() /** * @group DDC-1213 */ - public function testBitComparisonExpressionSupport() + public function testBitComparisonExpressionSupport() : void { $this->connection->exec('DELETE FROM fetch_table'); $platform = $this->connection->getDatabasePlatform(); @@ -726,7 +731,7 @@ public function testBitComparisonExpressionSupport() } } - public function testSetDefaultFetchMode() + public function testSetDefaultFetchMode() : void { $stmt = $this->connection->query('SELECT * FROM fetch_table'); $stmt->setFetchMode(FetchMode::NUMERIC); @@ -740,7 +745,7 @@ public function testSetDefaultFetchMode() /** * @group DBAL-1091 */ - public function testFetchAllStyleObject() + public function testFetchAllStyleObject() : void { $this->setupFixture(); @@ -771,7 +776,7 @@ public function testFetchAllStyleObject() /** * @group DBAL-196 */ - public function testFetchAllSupportFetchClass() + public function testFetchAllSupportFetchClass() : void { $this->beforeFetchClassTest(); $this->setupFixture(); @@ -796,7 +801,7 @@ public function testFetchAllSupportFetchClass() /** * @group DBAL-241 */ - public function testFetchAllStyleColumn() + public function testFetchAllStyleColumn() : void { $sql = 'DELETE FROM fetch_table'; $this->connection->executeUpdate($sql); @@ -813,7 +818,7 @@ public function testFetchAllStyleColumn() /** * @group DBAL-214 */ - public function testSetFetchModeClassFetchAll() + public function testSetFetchModeClassFetchAll() : void { $this->beforeFetchClassTest(); $this->setupFixture(); @@ -835,7 +840,7 @@ public function testSetFetchModeClassFetchAll() /** * @group DBAL-214 */ - public function testSetFetchModeClassFetch() + public function testSetFetchModeClassFetch() : void { $this->beforeFetchClassTest(); $this->setupFixture(); @@ -860,7 +865,7 @@ public function testSetFetchModeClassFetch() /** * @group DBAL-257 */ - public function testEmptyFetchColumnReturnsFalse() + public function testEmptyFetchColumnReturnsFalse() : void { $this->connection->beginTransaction(); $this->connection->exec('DELETE FROM fetch_table'); @@ -872,7 +877,7 @@ public function testEmptyFetchColumnReturnsFalse() /** * @group DBAL-339 */ - public function testSetFetchModeOnDbalStatement() + public function testSetFetchModeOnDbalStatement() : void { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->connection->executeQuery($sql, [1, 'foo']); @@ -888,7 +893,7 @@ public function testSetFetchModeOnDbalStatement() /** * @group DBAL-435 */ - public function testEmptyParameters() + public function testEmptyParameters() : void { $sql = 'SELECT * FROM fetch_table WHERE test_int IN (?)'; $stmt = $this->connection->executeQuery($sql, [[]], [Connection::PARAM_INT_ARRAY]); @@ -900,7 +905,7 @@ public function testEmptyParameters() /** * @group DBAL-1028 */ - public function testFetchColumnNullValue() + public function testFetchColumnNullValue() : void { $this->connection->executeUpdate( 'INSERT INTO fetch_table (test_int, test_string) VALUES (?, ?)', @@ -915,14 +920,14 @@ public function testFetchColumnNullValue() /** * @group DBAL-1028 */ - public function testFetchColumnNoResult() + public function testFetchColumnNoResult() : void { self::assertFalse( $this->connection->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', [-1]) ); } - private function setupFixture() + private function setupFixture() : void { $this->connection->exec('DELETE FROM fetch_table'); $this->connection->insert('fetch_table', [ @@ -932,7 +937,7 @@ private function setupFixture() ]); } - private function beforeFetchClassTest() + private function beforeFetchClassTest() : void { $driver = $this->connection->getDriver(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php index 2e145ca6c04..3adf3c2bb89 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php @@ -26,7 +26,7 @@ protected function setUp() : void /** * @group DBAL-1215 */ - public function testConnectsWithoutDatabaseNameParameter() + public function testConnectsWithoutDatabaseNameParameter() : void { $params = $this->connection->getParams(); unset($params['dbname']); @@ -42,7 +42,7 @@ public function testConnectsWithoutDatabaseNameParameter() /** * @group DBAL-1215 */ - public function testReturnsDatabaseNameWithoutDatabaseNameParameter() + public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void { $params = $this->connection->getParams(); unset($params['dbname']); @@ -60,10 +60,7 @@ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() ); } - /** - * @return Driver - */ - abstract protected function createDriver(); + abstract protected function createDriver() : Driver; protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string { diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php index 144365e0d4d..4021bb2fff7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\IBMDB2; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use function extension_loaded; @@ -26,7 +27,7 @@ protected function setUp() : void /** * {@inheritdoc} */ - public function testConnectsWithoutDatabaseNameParameter() + public function testConnectsWithoutDatabaseNameParameter() : void { $this->markTestSkipped('IBM DB2 does not support connecting without database name.'); } @@ -34,7 +35,7 @@ public function testConnectsWithoutDatabaseNameParameter() /** * {@inheritdoc} */ - public function testReturnsDatabaseNameWithoutDatabaseNameParameter() + public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void { $this->markTestSkipped('IBM DB2 does not support connecting without database name.'); } @@ -42,7 +43,7 @@ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() /** * {@inheritdoc} */ - protected function createDriver() + protected function createDriver() : Driver { return new DB2Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php index 536c1093073..c839d20d916 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php @@ -26,7 +26,7 @@ protected function setUp() : void $this->markTestSkipped('ibm_db2 only test.'); } - public function testExecutionErrorsAreNotSuppressed() + public function testExecutionErrorsAreNotSuppressed() : void { $stmt = $this->connection->prepare('SELECT * FROM SYSIBM.SYSDUMMY1 WHERE \'foo\' = ?'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php index d2ced1912c4..4a3a315f296 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php @@ -31,7 +31,7 @@ protected function tearDown() : void parent::tearDown(); } - public function testDriverOptions() + public function testDriverOptions() : void { $driverOptions = [MYSQLI_OPT_CONNECT_TIMEOUT => 1]; @@ -39,14 +39,14 @@ public function testDriverOptions() self::assertInstanceOf(MysqliConnection::class, $connection); } - public function testUnsupportedDriverOption() + public function testUnsupportedDriverOption() : void { $this->expectException(MysqliException::class); $this->getConnection(['hello' => 'world']); // use local infile } - public function testPing() + public function testPing() : void { $conn = $this->getConnection([]); self::assertTrue($conn->ping()); @@ -55,7 +55,7 @@ public function testPing() /** * @param mixed[] $driverOptions */ - private function getConnection(array $driverOptions) + private function getConnection(array $driverOptions) : MysqliConnection { return new MysqliConnection( [ diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php index a7b7338beed..d4bbf9a1df7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\Mysqli; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\Mysqli\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use function extension_loaded; @@ -26,7 +27,7 @@ protected function setUp() : void /** * {@inheritdoc} */ - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php index b617b2bb0d3..861ce650e76 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\OCI8; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\OCI8\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use function extension_loaded; @@ -26,7 +27,7 @@ protected function setUp() : void /** * {@inheritdoc} */ - public function testConnectsWithoutDatabaseNameParameter() + public function testConnectsWithoutDatabaseNameParameter() : void { $this->markTestSkipped('Oracle does not support connecting without database name.'); } @@ -34,7 +35,7 @@ public function testConnectsWithoutDatabaseNameParameter() /** * {@inheritdoc} */ - public function testReturnsDatabaseNameWithoutDatabaseNameParameter() + public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void { $this->markTestSkipped('Oracle does not support connecting without database name.'); } @@ -42,7 +43,7 @@ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() /** * {@inheritdoc} */ - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php index 4e23a2a059a..d6184316fac 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php @@ -31,7 +31,7 @@ protected function setUp() : void /** * @group DBAL-2595 */ - public function testLastInsertIdAcceptsFqn() + public function testLastInsertIdAcceptsFqn() : void { $platform = $this->connection->getDatabasePlatform(); $schemaManager = $this->connection->getSchemaManager(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php index fce2820bde8..8ecbed68082 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php @@ -29,7 +29,7 @@ protected function setUp() : void * * @dataProvider queryConversionProvider */ - public function testQueryConversion($query, array $params, array $expected) + public function testQueryConversion(string $query, array $params, array $expected) : void { self::assertEquals( $expected, @@ -37,7 +37,10 @@ public function testQueryConversion($query, array $params, array $expected) ); } - public static function queryConversionProvider() + /** + * @return array> + */ + public static function queryConversionProvider() : iterable { return [ 'simple' => [ diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php index 94c8bf00223..6dfb1b85c3d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php @@ -46,12 +46,12 @@ protected function tearDown() : void parent::tearDown(); } - public function testDoesNotRequireQueryForServerVersion() + public function testDoesNotRequireQueryForServerVersion() : void { self::assertFalse($this->driverConnection->requiresQueryForServerVersion()); } - public function testThrowsWrappedExceptionOnConstruct() + public function testThrowsWrappedExceptionOnConstruct() : void { $this->expectException(PDOException::class); @@ -61,14 +61,14 @@ public function testThrowsWrappedExceptionOnConstruct() /** * @group DBAL-1022 */ - public function testThrowsWrappedExceptionOnExec() + public function testThrowsWrappedExceptionOnExec() : void { $this->expectException(PDOException::class); $this->driverConnection->exec('foo'); } - public function testThrowsWrappedExceptionOnPrepare() + public function testThrowsWrappedExceptionOnPrepare() : void { $driver = $this->connection->getDriver(); @@ -97,7 +97,7 @@ public function testThrowsWrappedExceptionOnPrepare() $this->driverConnection->prepare('foo'); } - public function testThrowsWrappedExceptionOnQuery() + public function testThrowsWrappedExceptionOnQuery() : void { $this->expectException(PDOException::class); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php index 9fe297278f6..7f77ea542f9 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\PDOMySql; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\PDOMySql\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use function extension_loaded; @@ -26,7 +27,7 @@ protected function setUp() : void /** * {@inheritdoc} */ - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php index 3a5b44c22fa..b096fa47e94 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\PDOOracle; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\PDOOracle\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use function extension_loaded; @@ -26,7 +27,7 @@ protected function setUp() : void /** * {@inheritdoc} */ - public function testConnectsWithoutDatabaseNameParameter() + public function testConnectsWithoutDatabaseNameParameter() : void { $this->markTestSkipped('Oracle does not support connecting without database name.'); } @@ -34,7 +35,7 @@ public function testConnectsWithoutDatabaseNameParameter() /** * {@inheritdoc} */ - public function testReturnsDatabaseNameWithoutDatabaseNameParameter() + public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void { $this->markTestSkipped('Oracle does not support connecting without database name.'); } @@ -42,7 +43,7 @@ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() /** * {@inheritdoc} */ - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php index 347982b24e5..b5f9d3eda9d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\PDOPgSql; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\PDOPgSql\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use Doctrine\Tests\TestUtil; @@ -31,7 +32,7 @@ protected function setUp() : void /** * @dataProvider getDatabaseParameter */ - public function testDatabaseParameters($databaseName, $defaultDatabaseName, $expectedDatabaseName) + public function testDatabaseParameters(?string $databaseName, ?string $defaultDatabaseName, ?string $expectedDatabaseName) : void { $params = $this->connection->getParams(); $params['dbname'] = $databaseName; @@ -71,7 +72,7 @@ public static function getDatabaseParameter() : iterable /** * @group DBAL-1146 */ - public function testConnectsWithApplicationNameParameter() + public function testConnectsWithApplicationNameParameter() : void { $parameters = $this->connection->getParams(); $parameters['application_name'] = 'doctrine'; @@ -103,7 +104,7 @@ public function testConnectsWithApplicationNameParameter() /** * {@inheritdoc} */ - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php index 7bfde54a6f3..8336a3900d1 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php @@ -26,13 +26,11 @@ protected function setUp() : void } /** - * @param string $charset - * * @group DBAL-1183 * @group DBAL-1189 * @dataProvider getValidCharsets */ - public function testConnectsWithValidCharsetOption($charset) + public function testConnectsWithValidCharsetOption(string $charset) : void { $params = $this->connection->getParams(); $params['charset'] = $charset; @@ -53,7 +51,7 @@ public function testConnectsWithValidCharsetOption($charset) /** * @return mixed[][] */ - public function getValidCharsets() + public static function getValidCharsets() : iterable { return [ ['UTF8'], diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php index 3df6d7a6540..efc0382d85f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\PDOSqlite; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\PDOSqlite\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use function extension_loaded; @@ -26,7 +27,7 @@ protected function setUp() : void /** * {@inheritdoc} */ - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php index 955a90cdaf1..d2dfd5925f5 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\PDOSqlsrv; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\PDOSqlsrv\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; @@ -28,7 +29,7 @@ protected function setUp() : void /** * {@inheritdoc} */ - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php index e1df07bbac2..4de7b7cde03 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php @@ -24,7 +24,7 @@ protected function setUp() : void $this->markTestSkipped('sqlanywhere only test.'); } - public function testNonPersistentConnection() + public function testNonPersistentConnection() : void { $params = $this->connection->getParams(); $params['persistent'] = false; @@ -36,7 +36,7 @@ public function testNonPersistentConnection() self::assertTrue($conn->isConnected(), 'No SQLAnywhere-nonpersistent connection established'); } - public function testPersistentConnection() + public function testPersistentConnection() : void { $params = $this->connection->getParams(); $params['persistent'] = true; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php index 4e42e863a46..f2d54c62845 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\SQLAnywhere; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\SQLAnywhere\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use function extension_loaded; @@ -24,7 +25,7 @@ protected function setUp() : void $this->markTestSkipped('sqlanywhere only test.'); } - public function testReturnsDatabaseNameWithoutDatabaseNameParameter() + public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void { $params = $this->connection->getParams(); unset($params['dbname']); @@ -44,7 +45,7 @@ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() /** * {@inheritdoc} */ - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php index b67c8e571b4..c09eb0a5d56 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php @@ -24,7 +24,7 @@ protected function setUp() : void $this->markTestSkipped('sqlanywhere only test.'); } - public function testNonPersistentStatement() + public function testNonPersistentStatement() : void { $params = $this->connection->getParams(); $params['persistent'] = false; @@ -39,7 +39,7 @@ public function testNonPersistentStatement() self::assertTrue($prepStmt->execute(), ' Statement non-persistent failed'); } - public function testPersistentStatement() + public function testPersistentStatement() : void { $params = $this->connection->getParams(); $params['persistent'] = true; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php index 21413acec2f..eb9931a43dc 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\SQLSrv; +use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\SQLSrv\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use function extension_loaded; @@ -26,7 +27,7 @@ protected function setUp() : void /** * {@inheritdoc} */ - protected function createDriver() + protected function createDriver() : DriverInterface { return new Driver(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php index 2d52b5c0cd3..4e34f693c0c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php @@ -24,7 +24,7 @@ protected function setUp() : void self::markTestSkipped('sqlsrv only test'); } - public function testFailureToPrepareResultsInException() + public function testFailureToPrepareResultsInException() : void { // use the driver connection directly to avoid having exception wrapped $stmt = $this->connection->getWrappedConnection()->prepare(null); diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php index b43f7371f43..7f4a8145cfe 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php @@ -34,7 +34,7 @@ protected function setUp() : void $this->markTestSkipped('Driver does not support special exception handling.'); } - public function testPrimaryConstraintViolationException() + public function testPrimaryConstraintViolationException() : void { $table = new Table('duplicatekey_table'); $table->addColumn('id', 'integer', []); @@ -48,7 +48,7 @@ public function testPrimaryConstraintViolationException() $this->connection->insert('duplicatekey_table', ['id' => 1]); } - public function testTableNotFoundException() + public function testTableNotFoundException() : void { $sql = 'SELECT * FROM unknown_table'; @@ -56,7 +56,7 @@ public function testTableNotFoundException() $this->connection->executeQuery($sql); } - public function testTableExistsException() + public function testTableExistsException() : void { $schemaManager = $this->connection->getSchemaManager(); $table = new Table('alreadyexist_table'); @@ -68,7 +68,7 @@ public function testTableExistsException() $schemaManager->createTable($table); } - public function testForeignKeyConstraintViolationExceptionOnInsert() + public function testForeignKeyConstraintViolationExceptionOnInsert() : void { if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); @@ -102,7 +102,7 @@ public function testForeignKeyConstraintViolationExceptionOnInsert() $this->tearDownForeignKeyConstraintViolationExceptionTest(); } - public function testForeignKeyConstraintViolationExceptionOnUpdate() + public function testForeignKeyConstraintViolationExceptionOnUpdate() : void { if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); @@ -136,7 +136,7 @@ public function testForeignKeyConstraintViolationExceptionOnUpdate() $this->tearDownForeignKeyConstraintViolationExceptionTest(); } - public function testForeignKeyConstraintViolationExceptionOnDelete() + public function testForeignKeyConstraintViolationExceptionOnDelete() : void { if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); @@ -170,7 +170,7 @@ public function testForeignKeyConstraintViolationExceptionOnDelete() $this->tearDownForeignKeyConstraintViolationExceptionTest(); } - public function testForeignKeyConstraintViolationExceptionOnTruncate() + public function testForeignKeyConstraintViolationExceptionOnTruncate() : void { $platform = $this->connection->getDatabasePlatform(); @@ -206,7 +206,7 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate() $this->tearDownForeignKeyConstraintViolationExceptionTest(); } - public function testNotNullConstraintViolationException() + public function testNotNullConstraintViolationException() : void { $schema = new Schema(); @@ -223,7 +223,7 @@ public function testNotNullConstraintViolationException() $this->connection->insert('notnull_table', ['id' => 1, 'value' => null]); } - public function testInvalidFieldNameException() + public function testInvalidFieldNameException() : void { $schema = new Schema(); @@ -238,7 +238,7 @@ public function testInvalidFieldNameException() $this->connection->insert('bad_fieldname_table', ['name' => 5]); } - public function testNonUniqueFieldNameException() + public function testNonUniqueFieldNameException() : void { $schema = new Schema(); @@ -257,7 +257,7 @@ public function testNonUniqueFieldNameException() $this->connection->executeQuery($sql); } - public function testUniqueConstraintViolationException() + public function testUniqueConstraintViolationException() : void { $schema = new Schema(); @@ -274,7 +274,7 @@ public function testUniqueConstraintViolationException() $this->connection->insert('unique_field_table', ['id' => 5]); } - public function testSyntaxErrorException() + public function testSyntaxErrorException() : void { $table = new Table('syntax_error_table'); $table->addColumn('id', 'integer', []); @@ -287,7 +287,7 @@ public function testSyntaxErrorException() $this->connection->executeQuery($sql); } - public function testConnectionExceptionSqLite() + public function testConnectionExceptionSqLite() : void { if ($this->connection->getDatabasePlatform()->getName() !== 'sqlite') { $this->markTestSkipped('Only fails this way on sqlite'); @@ -337,9 +337,11 @@ public function testConnectionExceptionSqLite() } /** + * @param array $params + * * @dataProvider getConnectionParams */ - public function testConnectionException($params) + public function testConnectionException(array $params) : void { if ($this->connection->getDatabasePlatform()->getName() === 'sqlite') { $this->markTestSkipped('Only skipped if platform is not sqlite'); @@ -369,7 +371,10 @@ public function testConnectionException($params) } } - public function getConnectionParams() + /** + * @return array> + */ + public static function getConnectionParams() : iterable { return [ [['user' => 'not_existing']], @@ -378,7 +383,7 @@ public function getConnectionParams() ]; } - private function setUpForeignKeyConstraintViolationExceptionTest() + private function setUpForeignKeyConstraintViolationExceptionTest() : void { $schemaManager = $this->connection->getSchemaManager(); @@ -396,7 +401,7 @@ private function setUpForeignKeyConstraintViolationExceptionTest() $schemaManager->createTable($owningTable); } - private function tearDownForeignKeyConstraintViolationExceptionTest() + private function tearDownForeignKeyConstraintViolationExceptionTest() : void { $schemaManager = $this->connection->getSchemaManager(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php b/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php index 99ca533e742..aa63af708df 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php @@ -7,7 +7,7 @@ class LoggingTest extends DbalFunctionalTestCase { - public function testLogExecuteQuery() + public function testLogExecuteQuery() : void { $sql = $this->connection->getDatabasePlatform()->getDummySelectSQL(); @@ -21,7 +21,7 @@ public function testLogExecuteQuery() $this->connection->executeQuery($sql, []); } - public function testLogExecuteUpdate() + public function testLogExecuteUpdate() : void { $this->markTestSkipped('Test breaks MySQL but works on all other platforms (Unbuffered Queries stuff).'); @@ -37,7 +37,7 @@ public function testLogExecuteUpdate() $this->connection->executeUpdate($sql, []); } - public function testLogPrepareExecute() + public function testLogPrepareExecute() : void { $sql = $this->connection->getDatabasePlatform()->getDummySelectSQL(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php index d927285e2a3..2731ac995b8 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php @@ -98,7 +98,7 @@ public function testInheritCharsetFromMaster() : void } } - public function testMasterOnConnect() + public function testMasterOnConnect() : void { $conn = $this->createMasterSlaveConnection(); @@ -109,7 +109,7 @@ public function testMasterOnConnect() self::assertTrue($conn->isConnectedToMaster()); } - public function testNoMasterOnExecuteQuery() + public function testNoMasterOnExecuteQuery() : void { $conn = $this->createMasterSlaveConnection(); @@ -121,7 +121,7 @@ public function testNoMasterOnExecuteQuery() self::assertFalse($conn->isConnectedToMaster()); } - public function testMasterOnWriteOperation() + public function testMasterOnWriteOperation() : void { $conn = $this->createMasterSlaveConnection(); $conn->insert('master_slave_table', ['test_int' => 30]); @@ -139,7 +139,7 @@ public function testMasterOnWriteOperation() /** * @group DBAL-335 */ - public function testKeepSlaveBeginTransactionStaysOnMaster() + public function testKeepSlaveBeginTransactionStaysOnMaster() : void { $conn = $this->createMasterSlaveConnection($keepSlave = true); $conn->connect('slave'); @@ -160,7 +160,7 @@ public function testKeepSlaveBeginTransactionStaysOnMaster() /** * @group DBAL-335 */ - public function testKeepSlaveInsertStaysOnMaster() + public function testKeepSlaveInsertStaysOnMaster() : void { $conn = $this->createMasterSlaveConnection($keepSlave = true); $conn->connect('slave'); @@ -176,7 +176,7 @@ public function testKeepSlaveInsertStaysOnMaster() self::assertFalse($conn->isConnectedToMaster()); } - public function testMasterSlaveConnectionCloseAndReconnect() + public function testMasterSlaveConnectionCloseAndReconnect() : void { $conn = $this->createMasterSlaveConnection(); $conn->connect('master'); @@ -189,7 +189,7 @@ public function testMasterSlaveConnectionCloseAndReconnect() self::assertTrue($conn->isConnectedToMaster()); } - public function testQueryOnMaster() + public function testQueryOnMaster() : void { $conn = $this->createMasterSlaveConnection(); @@ -213,7 +213,7 @@ public function testQueryOnMaster() self::assertEquals(1, $data[0]['num']); } - public function testQueryOnSlave() + public function testQueryOnSlave() : void { $conn = $this->createMasterSlaveConnection(); $conn->connect('slave'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php index 88c28661634..a14f9b17582 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php @@ -36,7 +36,7 @@ protected function setUp() : void $this->connection->exec($this->connection->getDatabasePlatform()->getTruncateTableSQL('modify_limit_table2')); } - public function testModifyLimitQuerySimpleQuery() + public function testModifyLimitQuerySimpleQuery() : void { $this->connection->insert('modify_limit_table', ['test_int' => 1]); $this->connection->insert('modify_limit_table', ['test_int' => 2]); @@ -51,7 +51,7 @@ public function testModifyLimitQuerySimpleQuery() $this->assertLimitResult([2, 3, 4], $sql, null, 1); } - public function testModifyLimitQueryJoinQuery() + public function testModifyLimitQueryJoinQuery() : void { $this->connection->insert('modify_limit_table', ['test_int' => 1]); $this->connection->insert('modify_limit_table', ['test_int' => 2]); @@ -69,7 +69,7 @@ public function testModifyLimitQueryJoinQuery() $this->assertLimitResult([2, 2], $sql, 2, 0); } - public function testModifyLimitQueryNonDeterministic() + public function testModifyLimitQueryNonDeterministic() : void { $this->connection->insert('modify_limit_table', ['test_int' => 1]); $this->connection->insert('modify_limit_table', ['test_int' => 2]); @@ -83,7 +83,7 @@ public function testModifyLimitQueryNonDeterministic() $this->assertLimitResult([2, 1], $sql, 2, 2, false); } - public function testModifyLimitQueryGroupBy() + public function testModifyLimitQueryGroupBy() : void { $this->connection->insert('modify_limit_table', ['test_int' => 1]); $this->connection->insert('modify_limit_table', ['test_int' => 2]); @@ -103,7 +103,7 @@ public function testModifyLimitQueryGroupBy() $this->assertLimitResult([2], $sql, 1, 1); } - public function testModifyLimitQuerySubSelect() + public function testModifyLimitQuerySubSelect() : void { $this->connection->insert('modify_limit_table', ['test_int' => 1]); $this->connection->insert('modify_limit_table', ['test_int' => 2]); @@ -117,7 +117,7 @@ public function testModifyLimitQuerySubSelect() $this->assertLimitResult([2, 1], $sql, 2, 2); } - public function testModifyLimitQueryFromSubSelect() + public function testModifyLimitQueryFromSubSelect() : void { $this->connection->insert('modify_limit_table', ['test_int' => 1]); $this->connection->insert('modify_limit_table', ['test_int' => 2]); @@ -131,7 +131,7 @@ public function testModifyLimitQueryFromSubSelect() $this->assertLimitResult([2, 1], $sql, 2, 2); } - public function testModifyLimitQueryLineBreaks() + public function testModifyLimitQueryLineBreaks() : void { $this->connection->insert('modify_limit_table', ['test_int' => 1]); $this->connection->insert('modify_limit_table', ['test_int' => 2]); @@ -151,7 +151,7 @@ public function testModifyLimitQueryLineBreaks() $this->assertLimitResult([2], $sql, 1, 1); } - public function testModifyLimitQueryZeroOffsetNoLimit() + public function testModifyLimitQueryZeroOffsetNoLimit() : void { $this->connection->insert('modify_limit_table', ['test_int' => 1]); $this->connection->insert('modify_limit_table', ['test_int' => 2]); @@ -161,7 +161,10 @@ public function testModifyLimitQueryZeroOffsetNoLimit() $this->assertLimitResult([1, 2], $sql, null, 0); } - public function assertLimitResult($expectedResults, $sql, $limit, $offset, $deterministic = true) + /** + * @param array $expectedResults + */ + private function assertLimitResult(array $expectedResults, string $sql, ?int $limit, int $offset, bool $deterministic = true) : void { $p = $this->connection->getDatabasePlatform(); $data = []; diff --git a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php index 4dec0809fb4..33e116ec368 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php @@ -16,7 +16,10 @@ */ class NamedParametersTest extends DbalFunctionalTestCase { - public function ticketProvider() + /** + * @return iterable> + */ + public static function ticketProvider() : iterable { return [ [ @@ -201,14 +204,13 @@ protected function setUp() : void } /** - * @param string $query * @param mixed[] $params * @param int[] $types * @param int[] $expected * * @dataProvider ticketProvider */ - public function testTicket($query, $params, $types, $expected) + public function testTicket(string $query, array $params, array $types, array $expected) : void { $stmt = $this->connection->executeQuery($query, $params, $types); $result = $stmt->fetchAll(FetchMode::ASSOCIATIVE); diff --git a/tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php index 1ba37b61394..42b8104a9e7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php @@ -32,7 +32,7 @@ protected function setUp() : void * @group legacy * @expectedDeprecation Using a PDO fetch mode or their combination (%d given) is deprecated and will cause an error in Doctrine 3.0 */ - public function testPDOSpecificModeIsAccepted() + public function testPDOSpecificModeIsAccepted() : void { $this->connection->insert('stmt_test', [ 'id' => 1, diff --git a/tests/Doctrine/Tests/DBAL/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php b/tests/Doctrine/Tests/DBAL/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php index 64efb1aad6a..42e08f3f6d7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Platform; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Comparator; use Doctrine\Tests\DbalFunctionalTestCase; use function in_array; @@ -30,7 +31,7 @@ protected function setUp() : void * SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto * column and it must be defined as a key */ - public function testAlterPrimaryKeyToAutoIncrementColumn() + public function testAlterPrimaryKeyToAutoIncrementColumn() : void { $schemaManager = $this->connection->getSchemaManager(); $schema = $schemaManager->createSchema(); @@ -62,7 +63,7 @@ public function testAlterPrimaryKeyToAutoIncrementColumn() $this->assertSame(['new_id'], $validationTable->getPrimaryKeyColumns()); } - private function getPlatform() + private function getPlatform() : AbstractPlatform { return $this->connection->getDatabasePlatform(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php index 73308f8e7b3..72fb9dd2213 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php @@ -29,16 +29,10 @@ protected function tearDown() : void parent::tearDown(); } - /** - * @param int $portabilityMode - * @param int $case - * - * @return Connection - */ private function getPortableConnection( - $portabilityMode = ConnectionPortability::PORTABILITY_ALL, - $case = ColumnCase::LOWER - ) { + int $portabilityMode = ConnectionPortability::PORTABILITY_ALL, + int $case = ColumnCase::LOWER + ) : Connection { if (! $this->portableConnection) { $params = $this->connection->getParams(); @@ -67,7 +61,7 @@ private function getPortableConnection( return $this->portableConnection; } - public function testFullFetchMode() + public function testFullFetchMode() : void { $rows = $this->getPortableConnection()->fetchAll('SELECT * FROM portability_table'); $this->assertFetchResultRows($rows); @@ -93,7 +87,7 @@ public function testFullFetchMode() } } - public function testConnFetchMode() + public function testConnFetchMode() : void { $conn = $this->getPortableConnection(); $conn->setFetchMode(FetchMode::ASSOCIATIVE); @@ -118,7 +112,10 @@ public function testConnFetchMode() } } - public function assertFetchResultRows($rows) + /** + * @param array> $rows + */ + private function assertFetchResultRows(array $rows) : void { self::assertCount(2, $rows); foreach ($rows as $row) { @@ -126,7 +123,10 @@ public function assertFetchResultRows($rows) } } - public function assertFetchResultRow($row) + /** + * @param array $row + */ + public function assertFetchResultRow(array $row) : void { self::assertContains($row['test_int'], [1, 2], 'Primary key test_int should either be 1 or 2.'); self::assertArrayHasKey('test_string', $row, 'Case should be lowered.'); @@ -136,12 +136,11 @@ public function assertFetchResultRow($row) } /** - * @param string $field * @param mixed[] $expected * * @dataProvider fetchAllColumnProvider */ - public function testFetchAllColumn($field, array $expected) + public function testFetchAllColumn(string $field, array $expected) : void { $conn = $this->getPortableConnection(); $stmt = $conn->query('SELECT ' . $field . ' FROM portability_table'); @@ -150,7 +149,10 @@ public function testFetchAllColumn($field, array $expected) self::assertEquals($expected, $column); } - public static function fetchAllColumnProvider() + /** + * @return iterable> + */ + public static function fetchAllColumnProvider() : iterable { return [ 'int' => [ @@ -164,7 +166,7 @@ public static function fetchAllColumnProvider() ]; } - public function testFetchAllNullColumn() + public function testFetchAllNullColumn() : void { $conn = $this->getPortableConnection(); $stmt = $conn->query('SELECT Test_Null FROM portability_table'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index 06f6c18bbe3..35ce061b5b9 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -4,6 +4,7 @@ use Doctrine\Common\Cache\ArrayCache; use Doctrine\DBAL\Cache\QueryCacheProfile; +use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Schema\Table; @@ -20,7 +21,7 @@ */ class ResultCacheTest extends DbalFunctionalTestCase { - /** @var int[][]|string[][] */ + /** @var array> */ private $expectedResult = [['test_int' => 100, 'test_string' => 'foo'], ['test_int' => 200, 'test_string' => 'bar'], ['test_int' => 300, 'test_string' => 'baz']]; /** @var DebugStack */ @@ -56,45 +57,45 @@ protected function tearDown() : void parent::tearDown(); } - public function testCacheFetchAssoc() + public function testCacheFetchAssoc() : void { - self::assertCacheNonCacheSelectSameFetchModeAreEqual( + $this->assertCacheNonCacheSelectSameFetchModeAreEqual( $this->expectedResult, FetchMode::ASSOCIATIVE ); } - public function testFetchNum() + public function testFetchNum() : void { $expectedResult = []; foreach ($this->expectedResult as $v) { $expectedResult[] = array_values($v); } - self::assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, FetchMode::NUMERIC); + $this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, FetchMode::NUMERIC); } - public function testFetchBoth() + public function testFetchBoth() : void { $expectedResult = []; foreach ($this->expectedResult as $v) { $expectedResult[] = array_merge($v, array_values($v)); } - self::assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, FetchMode::MIXED); + $this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, FetchMode::MIXED); } - public function testFetchColumn() + public function testFetchColumn() : void { $expectedResult = []; foreach ($this->expectedResult as $v) { $expectedResult[] = array_shift($v); } - self::assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, FetchMode::COLUMN); + $this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, FetchMode::COLUMN); } - public function testMixingFetch() + public function testMixingFetch() : void { $numExpectedResult = []; foreach ($this->expectedResult as $v) { @@ -113,14 +114,14 @@ public function testMixingFetch() self::assertEquals($numExpectedResult, $data); } - public function testIteratorFetch() + public function testIteratorFetch() : void { self::assertStandardAndIteratorFetchAreEqual(FetchMode::MIXED); self::assertStandardAndIteratorFetchAreEqual(FetchMode::ASSOCIATIVE); self::assertStandardAndIteratorFetchAreEqual(FetchMode::NUMERIC); } - public function assertStandardAndIteratorFetchAreEqual($fetchMode) + private function assertStandardAndIteratorFetchAreEqual(int $fetchMode) : void { $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data = $this->hydrateStmt($stmt, $fetchMode); @@ -131,7 +132,7 @@ public function assertStandardAndIteratorFetchAreEqual($fetchMode) self::assertEquals($data, $data_iterator); } - public function testDontCloseNoCache() + public function testDontCloseNoCache() : void { $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); @@ -152,7 +153,7 @@ public function testDontCloseNoCache() self::assertCount(2, $this->sqlLogger->queries); } - public function testDontFinishNoCache() + public function testDontFinishNoCache() : void { $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); @@ -166,7 +167,7 @@ public function testDontFinishNoCache() self::assertCount(2, $this->sqlLogger->queries); } - public function testFetchAllAndFinishSavesCache() + public function testFetchAllAndFinishSavesCache() : void { $layerCache = new ArrayCache(); $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'testcachekey', $layerCache)); @@ -176,7 +177,10 @@ public function testFetchAllAndFinishSavesCache() self::assertCount(1, $layerCache->fetch('testcachekey')); } - public function assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, $fetchMode) + /** + * @param array> $expectedResult + */ + private function assertCacheNonCacheSelectSameFetchModeAreEqual(array $expectedResult, int $fetchMode) : void { $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); @@ -192,7 +196,7 @@ public function assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, self::assertCount(1, $this->sqlLogger->queries, 'just one dbal hit'); } - public function testEmptyResultCache() + public function testEmptyResultCache() : void { $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $data = $this->hydrateStmt($stmt); @@ -203,7 +207,7 @@ public function testEmptyResultCache() self::assertCount(1, $this->sqlLogger->queries, 'just one dbal hit'); } - public function testChangeCacheImpl() + public function testChangeCacheImpl() : void { $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $data = $this->hydrateStmt($stmt); @@ -216,7 +220,10 @@ public function testChangeCacheImpl() self::assertCount(1, $secondCache->fetch('emptycachekey')); } - private function hydrateStmt($stmt, $fetchMode = FetchMode::ASSOCIATIVE) + /** + * @return array + */ + private function hydrateStmt(ResultStatement $stmt, int $fetchMode = FetchMode::ASSOCIATIVE) : array { $data = []; while ($row = $stmt->fetch($fetchMode)) { @@ -227,7 +234,10 @@ private function hydrateStmt($stmt, $fetchMode = FetchMode::ASSOCIATIVE) return $data; } - private function hydrateStmtIterator($stmt, $fetchMode = FetchMode::ASSOCIATIVE) + /** + * @return array + */ + private function hydrateStmtIterator(ResultStatement $stmt, int $fetchMode = FetchMode::ASSOCIATIVE) : array { $data = []; $stmt->setFetchMode($fetchMode); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php index 102fd1bb495..330198e9ca9 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php @@ -10,7 +10,7 @@ class Db2SchemaManagerTest extends SchemaManagerFunctionalTestCase /** * @group DBAL-939 */ - public function testGetBooleanColumn() + public function testGetBooleanColumn() : void { $table = new Table('boolean_column_test'); $table->addColumn('bool', 'boolean'); @@ -27,7 +27,7 @@ public function testGetBooleanColumn() self::assertSame("That's a comment", $columns['bool_commented']->getComment()); } - public function testListTableWithBinary() + public function testListTableWithBinary() : void { self::markTestSkipped('Binary data type is currently not supported on DB2 LUW'); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/DefaultValueTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/DefaultValueTest.php index a65305a2e13..3dd362e2263 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/DefaultValueTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/DefaultValueTest.php @@ -40,9 +40,11 @@ protected function setUp() : void } /** + * @param mixed $expectedDefault + * * @dataProvider columnProvider */ - public function testEscapedDefaultValueCanBeIntrospected(string $name, $expectedDefault) : void + public function testEscapedDefaultValueCanBeIntrospected(string $name, ?string $expectedDefault) : void { self::assertSame( $expectedDefault, @@ -55,9 +57,11 @@ public function testEscapedDefaultValueCanBeIntrospected(string $name, $expected } /** + * @param mixed $expectedDefault + * * @dataProvider columnProvider */ - public function testEscapedDefaultValueCanBeInserted(string $name, $expectedDefault) : void + public function testEscapedDefaultValueCanBeInserted(string $name, ?string $expectedDefault) : void { $value = $this->connection->fetchColumn( sprintf('SELECT %s FROM default_value', $name) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php index 070e2173d63..422740476da 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php @@ -7,7 +7,7 @@ class DrizzleSchemaManagerTest extends SchemaManagerFunctionalTestCase { - public function testListTableWithBinary() + public function testListTableWithBinary() : void { $tableName = 'test_binary_table'; @@ -28,7 +28,7 @@ public function testListTableWithBinary() self::assertFalse($table->getColumn('column_binary')->getFixed()); } - public function testColumnCollation() + public function testColumnCollation() : void { $table = new Table('test_collation'); $table->addOption('collate', $collation = 'utf8_unicode_ci'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 558159b7fa4..e9a88e52096 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -27,7 +27,7 @@ protected function setUp() : void Type::addType('point', MySqlPointType::class); } - public function testSwitchPrimaryKeyColumns() + public function testSwitchPrimaryKeyColumns() : void { $tableOld = new Table('switch_primary_key_columns'); $tableOld->addColumn('foo_id', 'integer'); @@ -49,7 +49,7 @@ public function testSwitchPrimaryKeyColumns() self::assertContains('foo_id', $primaryKey); } - public function testDiffTableBug() + public function testDiffTableBug() : void { $schema = new Schema(); $table = $schema->createTable('diffbug_routing_translations'); @@ -72,7 +72,7 @@ public function testDiffTableBug() self::assertFalse($diff, 'no changes expected.'); } - public function testFulltextIndex() + public function testFulltextIndex() : void { $table = new Table('fulltext_index'); $table->addColumn('text', 'text'); @@ -89,7 +89,7 @@ public function testFulltextIndex() self::assertTrue($indexes['f_index']->hasFlag('fulltext')); } - public function testSpatialIndex() + public function testSpatialIndex() : void { $table = new Table('spatial_index'); $table->addColumn('point', 'point'); @@ -122,7 +122,7 @@ public function testIndexWithLength() : void /** * @group DBAL-400 */ - public function testAlterTableAddPrimaryKey() + public function testAlterTableAddPrimaryKey() : void { $table = new Table('alter_table_add_pk'); $table->addColumn('id', 'integer'); @@ -148,7 +148,7 @@ public function testAlterTableAddPrimaryKey() /** * @group DBAL-464 */ - public function testDropPrimaryKeyWithAutoincrementColumn() + public function testDropPrimaryKeyWithAutoincrementColumn() : void { $table = new Table('drop_primary_key'); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -174,7 +174,7 @@ public function testDropPrimaryKeyWithAutoincrementColumn() /** * @group DBAL-789 */ - public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() + public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() : void { if ($this->schemaManager->getDatabasePlatform() instanceof MariaDb1027Platform) { $this->markTestSkipped( @@ -213,7 +213,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() self::assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull()); } - public function testColumnCharset() + public function testColumnCharset() : void { $table = new Table('test_column_charset'); $table->addColumn('id', 'integer'); @@ -230,7 +230,7 @@ public function testColumnCharset() self::assertEquals('latin1', $columns['bar']->getPlatformOption('charset')); } - public function testAlterColumnCharset() + public function testAlterColumnCharset() : void { $tableName = 'test_alter_column_charset'; @@ -251,7 +251,7 @@ public function testAlterColumnCharset() self::assertEquals('ascii', $table->getColumn('col_text')->getPlatformOption('charset')); } - public function testColumnCharsetChange() + public function testColumnCharsetChange() : void { $table = new Table('test_column_charset_change'); $table->addColumn('col_string', 'string')->setLength(100)->setNotnull(true)->setPlatformOption('charset', 'utf8'); @@ -266,7 +266,7 @@ public function testColumnCharsetChange() self::assertContains('ALTER TABLE test_column_charset_change CHANGE col_string col_string VARCHAR(100) CHARACTER SET ascii NOT NULL', $diff); } - public function testColumnCollation() + public function testColumnCollation() : void { $table = new Table('test_collation'); $table->addOption('collate', $collation = 'latin1_swedish_ci'); @@ -288,7 +288,7 @@ public function testColumnCollation() /** * @group DBAL-843 */ - public function testListLobTypeColumns() + public function testListLobTypeColumns() : void { $tableName = 'lob_type_columns'; $table = new Table($tableName); @@ -347,7 +347,7 @@ public function testListLobTypeColumns() /** * @group DBAL-423 */ - public function testDiffListGuidTableColumn() + public function testDiffListGuidTableColumn() : void { $offlineTable = new Table('list_guid_table_column'); $offlineTable->addColumn('col_guid', 'guid'); @@ -367,7 +367,7 @@ public function testDiffListGuidTableColumn() /** * @group DBAL-1082 */ - public function testListDecimalTypeColumns() + public function testListDecimalTypeColumns() : void { $tableName = 'test_list_decimal_columns'; $table = new Table($tableName); @@ -388,7 +388,7 @@ public function testListDecimalTypeColumns() /** * @group DBAL-1082 */ - public function testListFloatTypeColumns() + public function testListFloatTypeColumns() : void { $tableName = 'test_list_float_columns'; $table = new Table($tableName); @@ -440,7 +440,7 @@ public function testColumnDefaultCurrentTimestamp() : void self::assertFalse($diff, 'Tables should be identical with column defaults.'); } - public function testColumnDefaultsAreValid() + public function testColumnDefaultsAreValid() : void { $table = new Table('test_column_defaults_are_valid'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index 3fc8bee811b..b2363b639f0 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -32,7 +32,7 @@ protected function setUp() : void self::$privilegesGranted = true; } - public function testRenameTable() + public function testRenameTable() : void { $this->schemaManager->tryMethod('DropTable', 'list_tables_test'); $this->schemaManager->tryMethod('DropTable', 'list_tables_test_new_name'); @@ -45,7 +45,7 @@ public function testRenameTable() self::assertHasTable($tables, 'list_tables_test_new_name'); } - public function testListTableWithBinary() + public function testListTableWithBinary() : void { $tableName = 'test_binary_table'; @@ -70,7 +70,7 @@ public function testListTableWithBinary() * @group DBAL-472 * @group DBAL-1001 */ - public function testAlterTableColumnNotNull() + public function testAlterTableColumnNotNull() : void { $comparator = new Schema\Comparator(); $tableName = 'list_table_column_notnull'; @@ -102,7 +102,7 @@ public function testAlterTableColumnNotNull() self::assertTrue($columns['bar']->getNotnull()); } - public function testListDatabases() + public function testListDatabases() : void { // We need the temp connection that has privileges to create a database. $sm = TestUtil::getTempConnection()->getSchemaManager(); @@ -118,7 +118,7 @@ public function testListDatabases() /** * @group DBAL-831 */ - public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() + public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() : void { $primaryTableName = '"Primary_Table"'; $offlinePrimaryTable = new Schema\Table($primaryTableName); @@ -226,7 +226,7 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() ); } - public function testListTableColumnsSameTableNamesInDifferentSchemas() + public function testListTableColumnsSameTableNamesInDifferentSchemas() : void { $table = $this->createListTableColumns(); $this->schemaManager->dropAndCreateTable($table); @@ -242,7 +242,7 @@ public function testListTableColumnsSameTableNamesInDifferentSchemas() /** * @group DBAL-1234 */ - public function testListTableIndexesPrimaryKeyConstraintNameDiffersFromIndexName() + public function testListTableIndexesPrimaryKeyConstraintNameDiffersFromIndexName() : void { $table = new Table('list_table_indexes_pk_id_test'); $table->setSchemaConfig($this->schemaManager->createSchemaConfig()); @@ -265,7 +265,7 @@ public function testListTableIndexesPrimaryKeyConstraintNameDiffersFromIndexName /** * @group DBAL-2555 */ - public function testListTableDateTypeColumns() + public function testListTableDateTypeColumns() : void { $table = new Table('tbl_date'); $table->addColumn('col_date', 'date'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index e388bf607da..35326968798 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -34,7 +34,7 @@ protected function tearDown() : void /** * @group DBAL-177 */ - public function testGetSearchPath() + public function testGetSearchPath() : void { $params = $this->connection->getParams(); @@ -45,7 +45,7 @@ public function testGetSearchPath() /** * @group DBAL-244 */ - public function testGetSchemaNames() + public function testGetSchemaNames() : void { $names = $this->schemaManager->getSchemaNames(); @@ -57,7 +57,7 @@ public function testGetSchemaNames() /** * @group DBAL-21 */ - public function testSupportDomainTypeFallback() + public function testSupportDomainTypeFallback() : void { $createDomainTypeSQL = 'CREATE DOMAIN MyMoney AS DECIMAL(18,2)'; $this->connection->exec($createDomainTypeSQL); @@ -78,7 +78,7 @@ public function testSupportDomainTypeFallback() /** * @group DBAL-37 */ - public function testDetectsAutoIncrement() + public function testDetectsAutoIncrement() : void { $autoincTable = new Table('autoinc_table'); $column = $autoincTable->addColumn('id', 'integer'); @@ -92,7 +92,7 @@ public function testDetectsAutoIncrement() /** * @group DBAL-37 */ - public function testAlterTableAutoIncrementAdd() + public function testAlterTableAutoIncrementAdd() : void { $tableFrom = new Table('autoinc_table_add'); $column = $tableFrom->addColumn('id', 'integer'); @@ -121,7 +121,7 @@ public function testAlterTableAutoIncrementAdd() /** * @group DBAL-37 */ - public function testAlterTableAutoIncrementDrop() + public function testAlterTableAutoIncrementDrop() : void { $tableFrom = new Table('autoinc_table_drop'); $column = $tableFrom->addColumn('id', 'integer'); @@ -146,7 +146,7 @@ public function testAlterTableAutoIncrementDrop() /** * @group DBAL-75 */ - public function testTableWithSchema() + public function testTableWithSchema() : void { $this->connection->exec('CREATE SCHEMA nested'); @@ -181,7 +181,7 @@ public function testTableWithSchema() * @group DBAL-91 * @group DBAL-88 */ - public function testReturnQuotedAssets() + public function testReturnQuotedAssets() : void { $sql = 'create table dbal91_something ( id integer CONSTRAINT id_something PRIMARY KEY NOT NULL ,"table" integer );'; $this->connection->exec($sql); @@ -203,7 +203,7 @@ public function testReturnQuotedAssets() /** * @group DBAL-204 */ - public function testFilterSchemaExpression() + public function testFilterSchemaExpression() : void { $testTable = new Table('dbal204_test_prefix'); $column = $testTable->addColumn('id', 'integer'); @@ -221,7 +221,7 @@ public function testFilterSchemaExpression() self::assertCount(1, $names); } - public function testListForeignKeys() + public function testListForeignKeys() : void { if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Does not support foreign key constraints.'); @@ -263,7 +263,7 @@ public function testListForeignKeys() /** * @group DBAL-511 */ - public function testDefaultValueCharacterVarying() + public function testDefaultValueCharacterVarying() : void { $testTable = new Table('dbal511_default'); $testTable->addColumn('id', 'integer'); @@ -280,7 +280,7 @@ public function testDefaultValueCharacterVarying() /** * @group DDC-2843 */ - public function testBooleanDefault() + public function testBooleanDefault() : void { $table = new Table('ddc2843_bools'); $table->addColumn('id', 'integer'); @@ -296,7 +296,7 @@ public function testBooleanDefault() self::assertFalse($diff); } - public function testListTableWithBinary() + public function testListTableWithBinary() : void { $tableName = 'test_binary_table'; @@ -317,7 +317,7 @@ public function testListTableWithBinary() self::assertFalse($table->getColumn('column_binary')->getFixed()); } - public function testListQuotedTable() + public function testListQuotedTable() : void { $offlineTable = new Schema\Table('user'); $offlineTable->addColumn('id', 'integer'); @@ -335,7 +335,7 @@ public function testListQuotedTable() self::assertFalse($comparator->diffTable($offlineTable, $onlineTable)); } - public function testListTablesExcludesViews() + public function testListTablesExcludesViews() : void { $this->createTestTable('list_tables_excludes_views'); @@ -364,7 +364,7 @@ public function testListTablesExcludesViews() /** * @group DBAL-1033 */ - public function testPartialIndexes() + public function testPartialIndexes() : void { $offlineTable = new Schema\Table('person'); $offlineTable->addColumn('id', 'integer'); @@ -419,7 +419,7 @@ public function jsonbColumnTypeProvider() : array /** * @group DBAL-2427 */ - public function testListNegativeColumnDefaultValue() + public function testListNegativeColumnDefaultValue() : void { $table = new Schema\Table('test_default_negative'); $table->addColumn('col_smallint', 'smallint', ['default' => -1]); @@ -444,7 +444,7 @@ public function testListNegativeColumnDefaultValue() /** * @return mixed[][] */ - public static function serialTypes() : array + public static function serialTypes() : iterable { return [ ['integer'], @@ -518,7 +518,7 @@ public function testAlterTableAutoIncrementIntToBigInt(string $from, string $to, /** * @return mixed[][] */ - public function autoIncrementTypeMigrations() : array + public static function autoIncrementTypeMigrations() : iterable { return [ 'int->bigint' => ['integer', 'bigint', 'BIGINT'], @@ -529,6 +529,9 @@ public function autoIncrementTypeMigrations() : array class MoneyType extends Type { + /** + * {@inheritDoc} + */ public function getName() { return 'MyMoney'; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php index 73eb07ea178..ffb5d6cf5ec 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php @@ -8,7 +8,7 @@ class SQLAnywhereSchemaManagerTest extends SchemaManagerFunctionalTestCase { - public function testCreateAndListViews() + public function testCreateAndListViews() : void { $this->createTestTable('view_test_table'); @@ -27,7 +27,7 @@ public function testCreateAndListViews() self::assertRegExp('/^SELECT \* from "?DBA"?\."?view_test_table"?$/', $views[$name]->getSql()); } - public function testDropAndCreateAdvancedIndex() + public function testDropAndCreateAdvancedIndex() : void { $table = $this->getTestTable('test_create_advanced_index'); $this->schemaManager->dropAndCreateTable($table); @@ -47,7 +47,7 @@ public function testDropAndCreateAdvancedIndex() self::assertTrue($tableIndexes['test']->hasFlag('for_olap_workload')); } - public function testListTableColumnsWithFixedStringTypeColumn() + public function testListTableColumnsWithFixedStringTypeColumn() : void { $table = new Table('list_table_columns_char'); $table->addColumn('id', 'integer', ['notnull' => true]); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php index d4598bccdb8..f8b3b66c15c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php @@ -11,7 +11,7 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase { - protected function getPlatformName() + protected function getPlatformName() : string { return 'mssql'; } @@ -19,7 +19,7 @@ protected function getPlatformName() /** * @group DBAL-255 */ - public function testDropColumnConstraints() + public function testDropColumnConstraints() : void { $table = new Table('sqlsrv_drop_column'); $table->addColumn('id', 'integer'); @@ -34,7 +34,7 @@ public function testDropColumnConstraints() self::assertCount(1, $columns); } - public function testColumnCollation() + public function testColumnCollation() : void { $table = new Table($tableName = 'test_collation'); $column = $table->addColumn($columnName = 'test', 'string'); @@ -52,7 +52,7 @@ public function testColumnCollation() self::assertEquals($collation, $columns[$columnName]->getPlatformOption('collation')); } - public function testDefaultConstraints() + public function testDefaultConstraints() : void { $table = new Table('sqlsrv_default_constraints'); $table->addColumn('no_default', 'string'); @@ -157,7 +157,7 @@ public function testDefaultConstraints() /** * @group DBAL-543 */ - public function testColumnComments() + public function testColumnComments() : void { $table = new Table('sqlsrv_column_comment'); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -319,7 +319,7 @@ public function testColumnComments() self::assertEquals('666', $columns['added_commented_type_with_comment']->getComment()); } - public function testPkOrdering() + public function testPkOrdering() : void { // SQL Server stores index column information in a system table with two // columns that almost always have the same value: index_column_id and key_ordinal. diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index c9b95066010..241662b56d3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -52,7 +52,7 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase /** @var AbstractSchemaManager */ protected $schemaManager; - protected function getPlatformName() + protected function getPlatformName() : string { $class = static::class; $e = explode('\\', $class); @@ -92,7 +92,7 @@ protected function tearDown() : void /** * @group DBAL-1220 */ - public function testDropsDatabaseWithActiveConnections() + public function testDropsDatabaseWithActiveConnections() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsCreateDropDatabase()) { $this->markTestSkipped('Cannot drop Database client side with this Driver.'); @@ -129,7 +129,7 @@ public function testDropsDatabaseWithActiveConnections() /** * @group DBAL-195 */ - public function testDropAndCreateSequence() + public function testDropAndCreateSequence() : void { $platform = $this->connection->getDatabasePlatform(); @@ -161,7 +161,7 @@ static function (AbstractAsset $item) use ($name) : bool { return count($filteredList) === 1; } - public function testListSequences() + public function testListSequences() : void { $platform = $this->connection->getDatabasePlatform(); @@ -193,7 +193,7 @@ public function testListSequences() self::assertSame(10, $foundSequence->getInitialValue(), 'Initial Value is expected to be 10.'); } - public function testListDatabases() + public function testListDatabases() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsCreateDropDatabase()) { $this->markTestSkipped('Cannot drop Database client side with this Driver.'); @@ -210,7 +210,7 @@ public function testListDatabases() /** * @group DBAL-1058 */ - public function testListNamespaceNames() + public function testListNamespaceNames() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) { $this->markTestSkipped('Platform does not support schemas.'); @@ -230,7 +230,7 @@ public function testListNamespaceNames() self::assertContains('test_create_schema', $namespaces); } - public function testListTables() + public function testListTables() : void { $this->createTestTable('list_tables_test'); $tables = $this->schemaManager->listTables(); @@ -255,7 +255,7 @@ public function testListTables() self::assertTrue($foundTable, "The 'list_tables_test' table has to be found."); } - public function createListTableColumns() + public function createListTableColumns() : Table { $table = new Table('list_table_columns'); $table->addColumn('id', 'integer', ['notnull' => true]); @@ -270,7 +270,7 @@ public function createListTableColumns() return $table; } - public function testListTableColumns() + public function testListTableColumns() : void { $table = $this->createListTableColumns(); @@ -344,7 +344,7 @@ public function testListTableColumns() /** * @group DBAL-1078 */ - public function testListTableColumnsWithFixedStringColumn() + public function testListTableColumnsWithFixedStringColumn() : void { $tableName = 'test_list_table_fixed_string'; @@ -361,7 +361,7 @@ public function testListTableColumnsWithFixedStringColumn() self::assertSame(2, $columns['column_char']->getLength()); } - public function testListTableColumnsDispatchEvent() + public function testListTableColumnsDispatchEvent() : void { $table = $this->createListTableColumns(); @@ -387,7 +387,7 @@ public function testListTableColumnsDispatchEvent() $this->schemaManager->getDatabasePlatform()->setEventManager($oldEventManager); } - public function testListTableIndexesDispatchEvent() + public function testListTableIndexesDispatchEvent() : void { $table = $this->getTestTable('list_table_indexes_test'); $table->addUniqueIndex(['test'], 'test_index_name'); @@ -415,7 +415,7 @@ public function testListTableIndexesDispatchEvent() $this->schemaManager->getDatabasePlatform()->setEventManager($oldEventManager); } - public function testDiffListTableColumns() + public function testDiffListTableColumns() : void { if ($this->schemaManager->getDatabasePlatform()->getName() === 'oracle') { $this->markTestSkipped('Does not work with Oracle, since it cannot detect DateTime, Date and Time differenecs (at the moment).'); @@ -431,7 +431,7 @@ public function testDiffListTableColumns() self::assertFalse($diff, 'No differences should be detected with the offline vs online schema.'); } - public function testListTableIndexes() + public function testListTableIndexes() : void { $table = $this->getTestCompositeTable('list_table_indexes_test'); $table->addUniqueIndex(['test'], 'test_index_name'); @@ -459,7 +459,7 @@ public function testListTableIndexes() self::assertFalse($tableIndexes['test_composite_idx']->isPrimary()); } - public function testDropAndCreateIndex() + public function testDropAndCreateIndex() : void { $table = $this->getTestTable('test_create_index'); $table->addUniqueIndex(['test'], 'test'); @@ -475,7 +475,7 @@ public function testDropAndCreateIndex() self::assertFalse($tableIndexes['test']->isPrimary()); } - public function testCreateTableWithForeignKeys() + public function testCreateTableWithForeignKeys() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Platform does not support foreign keys.'); @@ -503,7 +503,7 @@ public function testCreateTableWithForeignKeys() self::assertTrue($fkTable->columnsAreIndexed($fkConstraint->getColumns()), 'The columns of a foreign key constraint should always be indexed.'); } - public function testListForeignKeys() + public function testListForeignKeys() : void { if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Does not support foreign key constraints.'); @@ -538,12 +538,12 @@ public function testListForeignKeys() self::assertEquals('CASCADE', $fkeys[0]->getOption('onDelete')); } - protected function getCreateExampleViewSql() + protected function getCreateExampleViewSql() : void { $this->markTestSkipped('No Create Example View SQL was defined for this SchemaManager'); } - public function testCreateSchema() + public function testCreateSchema() : void { $this->createTestTable('test_table'); @@ -551,7 +551,7 @@ public function testCreateSchema() self::assertTrue($schema->hasTable('test_table')); } - public function testAlterTableScenario() + public function testAlterTableScenario() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsAlterTable()) { $this->markTestSkipped('Alter Table is not supported by this platform.'); @@ -640,7 +640,7 @@ public function testAlterTableScenario() self::assertEquals(['id'], array_map('strtolower', $foreignKey->getForeignColumns())); } - public function testTableInNamespace() + public function testTableInNamespace() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) { $this->markTestSkipped('Schema definition is not supported by this platform.'); @@ -664,7 +664,7 @@ public function testTableInNamespace() self::assertContains('my_table_not_in_namespace', $this->schemaManager->listTableNames()); } - public function testCreateAndListViews() + public function testCreateAndListViews() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsViews()) { $this->markTestSkipped('Views is not supported by this platform.'); @@ -682,7 +682,7 @@ public function testCreateAndListViews() self::assertTrue($this->hasElementWithName($this->schemaManager->listViews(), $name)); } - public function testAutoincrementDetection() + public function testAutoincrementDetection() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsIdentityColumns()) { $this->markTestSkipped('This test is only supported on platforms that have autoincrement'); @@ -703,7 +703,7 @@ public function testAutoincrementDetection() /** * @group DBAL-792 */ - public function testAutoincrementDetectionMulticolumns() + public function testAutoincrementDetectionMulticolumns() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsIdentityColumns()) { $this->markTestSkipped('This test is only supported on platforms that have autoincrement'); @@ -725,7 +725,7 @@ public function testAutoincrementDetectionMulticolumns() /** * @group DDC-887 */ - public function testUpdateSchemaWithForeignKeyRenaming() + public function testUpdateSchemaWithForeignKeyRenaming() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('This test is only supported on platforms that have foreign keys.'); @@ -770,7 +770,7 @@ public function testUpdateSchemaWithForeignKeyRenaming() /** * @group DBAL-1062 */ - public function testRenameIndexUsedInForeignKeyConstraint() + public function testRenameIndexUsedInForeignKeyConstraint() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('This test is only supported on platforms that have foreign keys.'); @@ -811,7 +811,7 @@ public function testRenameIndexUsedInForeignKeyConstraint() /** * @group DBAL-42 */ - public function testGetColumnComment() + public function testGetColumnComment() : void { if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && @@ -855,7 +855,7 @@ public function testGetColumnComment() /** * @group DBAL-42 */ - public function testAutomaticallyAppendCommentOnMarkedColumns() + public function testAutomaticallyAppendCommentOnMarkedColumns() : void { if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && @@ -883,7 +883,7 @@ public function testAutomaticallyAppendCommentOnMarkedColumns() /** * @group DBAL-1228 */ - public function testCommentHintOnDateIntervalTypeColumn() + public function testCommentHintOnDateIntervalTypeColumn() : void { if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && @@ -908,7 +908,7 @@ public function testCommentHintOnDateIntervalTypeColumn() /** * @group DBAL-825 */ - public function testChangeColumnsTypeWithDefaultValue() + public function testChangeColumnsTypeWithDefaultValue() : void { $tableName = 'column_def_change_type'; $table = new Table($tableName); @@ -948,7 +948,7 @@ public function testChangeColumnsTypeWithDefaultValue() /** * @group DBAL-197 */ - public function testListTableWithBlob() + public function testListTableWithBlob() : void { $table = new Table('test_blob_table'); $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); @@ -965,12 +965,9 @@ public function testListTableWithBlob() } /** - * @param string $name * @param mixed[] $data - * - * @return Table */ - protected function createTestTable($name = 'test_table', array $data = []) + protected function createTestTable(string $name = 'test_table', array $data = []) : Table { $options = $data['options'] ?? []; @@ -981,7 +978,10 @@ protected function createTestTable($name = 'test_table', array $data = []) return $table; } - protected function getTestTable($name, $options = []) + /** + * @param mixed[] $options + */ + protected function getTestTable(string $name, array $options = []) : Table { $table = new Table($name, [], [], [], false, $options); $table->setSchemaConfig($this->schemaManager->createSchemaConfig()); @@ -993,7 +993,7 @@ protected function getTestTable($name, $options = []) return $table; } - protected function getTestCompositeTable($name) + protected function getTestCompositeTable(string $name) : Table { $table = new Table($name, [], [], [], false, []); $table->setSchemaConfig($this->schemaManager->createSchemaConfig()); @@ -1005,7 +1005,10 @@ protected function getTestCompositeTable($name) return $table; } - protected function assertHasTable($tables, $tableName) + /** + * @param Table[] $tables + */ + protected function assertHasTable(array $tables) : void { $foundTable = false; foreach ($tables as $table) { @@ -1019,7 +1022,7 @@ protected function assertHasTable($tables, $tableName) self::assertTrue($foundTable, 'Could not find new table'); } - public function testListForeignKeysComposite() + public function testListForeignKeysComposite() : void { if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Does not support foreign key constraints.'); @@ -1049,7 +1052,7 @@ public function testListForeignKeysComposite() /** * @group DBAL-44 */ - public function testColumnDefaultLifecycle() + public function testColumnDefaultLifecycle() : void { $table = new Table('col_def_lifecycle'); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -1100,7 +1103,7 @@ public function testColumnDefaultLifecycle() self::assertNull($columns['column7']->getDefault()); } - public function testListTableWithBinary() + public function testListTableWithBinary() : void { $tableName = 'test_binary_table'; @@ -1121,7 +1124,7 @@ public function testListTableWithBinary() self::assertTrue($table->getColumn('column_binary')->getFixed()); } - public function testListTableDetailsWithFullQualifiedTableName() + public function testListTableDetailsWithFullQualifiedTableName() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) { $this->markTestSkipped('Test only works on platforms that support schemas.'); @@ -1161,7 +1164,7 @@ public function testListTableDetailsWithFullQualifiedTableName() ); } - public function testCommentStringsAreQuoted() + public function testCommentStringsAreQuoted() : void { if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && @@ -1179,7 +1182,7 @@ public function testCommentStringsAreQuoted() self::assertEquals("It's a comment with a quote", $columns['id']->getComment()); } - public function testCommentNotDuplicated() + public function testCommentNotDuplicated() : void { if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments()) { $this->markTestSkipped('Database does not support column comments.'); @@ -1205,8 +1208,12 @@ public function testCommentNotDuplicated() * @group DBAL-1009 * @dataProvider getAlterColumnComment */ - public function testAlterColumnComment($comment1, $expectedComment1, $comment2, $expectedComment2) - { + public function testAlterColumnComment( + ?string $comment1, + ?string $expectedComment1, + ?string $comment2, + ?string $expectedComment2 + ) : void { if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && $this->connection->getDatabasePlatform()->getName() !== 'mssql') { @@ -1248,7 +1255,10 @@ public function testAlterColumnComment($comment1, $expectedComment1, $comment2, self::assertSame($expectedComment2, $onlineTable->getColumn('no_comment2')->getComment()); } - public function getAlterColumnComment() + /** + * @return mixed[][] + */ + public static function getAlterColumnComment() : iterable { return [ [null, null, ' ', ' '], @@ -1269,7 +1279,7 @@ public function getAlterColumnComment() /** * @group DBAL-1095 */ - public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys() + public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('This test is only supported on platforms that have foreign keys.'); @@ -1540,7 +1550,7 @@ static function (Sequence $sequence) use ($sequenceName) : bool { /** * @group DBAL-2921 */ - public function testPrimaryKeyAutoIncrement() + public function testPrimaryKeyAutoIncrement() : void { $table = new Table('test_pk_auto_increment'); $table->addColumn('id', 'integer', ['autoincrement' => true]); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index dc4e01c5ade..cce8f92f72d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -20,14 +20,14 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase /** * SQLITE does not support databases. */ - public function testListDatabases() + public function testListDatabases() : void { $this->expectException(DBALException::class); $this->schemaManager->listDatabases(); } - public function testCreateAndDropDatabase() + public function testCreateAndDropDatabase() : void { $path = dirname(__FILE__) . '/test_create_and_drop_sqlite_database.sqlite'; @@ -40,7 +40,7 @@ public function testCreateAndDropDatabase() /** * @group DBAL-1220 */ - public function testDropsDatabaseWithActiveConnections() + public function testDropsDatabaseWithActiveConnections() : void { $this->schemaManager->dropAndCreateDatabase('test_drop_database'); @@ -63,7 +63,7 @@ public function testDropsDatabaseWithActiveConnections() unset($connection); } - public function testRenameTable() + public function testRenameTable() : void { $this->createTestTable('oldname'); $this->schemaManager->renameTable('oldname', 'newname'); @@ -73,7 +73,7 @@ public function testRenameTable() self::assertNotContains('oldname', $tables); } - public function createListTableColumns() + public function createListTableColumns() : Table { $table = parent::createListTableColumns(); $table->getColumn('id')->setAutoincrement(true); @@ -81,7 +81,7 @@ public function createListTableColumns() return $table; } - public function testListForeignKeysFromExistingDatabase() + public function testListForeignKeysFromExistingDatabase() : void { $this->connection->exec(<<schemaManager->listTableForeignKeys('user')); } - public function testColumnCollation() + public function testColumnCollation() : void { $table = new Schema\Table('test_collation'); $table->addColumn('id', 'integer'); @@ -138,7 +138,7 @@ public function testColumnCollation() self::assertEquals('NOCASE', $columns['bar']->getPlatformOption('collation')); } - public function testListTableWithBinary() + public function testListTableWithBinary() : void { $tableName = 'test_binary_table'; @@ -159,7 +159,7 @@ public function testListTableWithBinary() self::assertFalse($table->getColumn('column_binary')->getFixed()); } - public function testNonDefaultPKOrder() + public function testNonDefaultPKOrder() : void { if (! extension_loaded('sqlite3')) { $this->markTestSkipped('This test requires the SQLite3 extension.'); @@ -189,7 +189,7 @@ public function testNonDefaultPKOrder() /** * @group DBAL-1779 */ - public function testListTableColumnsWithWhitespacesInTypeDeclarations() + public function testListTableColumnsWithWhitespacesInTypeDeclarations() : void { $sql = <<addColumn('id', 'integer'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php index 66b4a93a207..392e6d756bc 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php @@ -24,7 +24,7 @@ protected function setUp() : void $this->connection->getSchemaManager()->dropAndCreateTable($table); } - public function testStatementIsReusableAfterClosingCursor() + public function testStatementIsReusableAfterClosingCursor() : void { if ($this->connection->getDriver() instanceof PDOOracleDriver) { $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=77181'); @@ -49,7 +49,7 @@ public function testStatementIsReusableAfterClosingCursor() self::assertEquals(2, $id); } - public function testReuseStatementWithLongerResults() + public function testReuseStatementWithLongerResults() : void { if ($this->connection->getDriver() instanceof PDOOracleDriver) { $this->markTestIncomplete('PDO_OCI doesn\'t support fetching blobs via PDOStatement::fetchAll()'); @@ -86,7 +86,7 @@ public function testReuseStatementWithLongerResults() ], $stmt->fetchAll(FetchMode::NUMERIC)); } - public function testFetchLongBlob() + public function testFetchLongBlob() : void { if ($this->connection->getDriver() instanceof PDOOracleDriver) { // inserting BLOBs as streams on Oracle requires Oracle-specific SQL syntax which is currently not supported @@ -134,7 +134,7 @@ public function testFetchLongBlob() self::assertSame($contents, stream_get_contents($stream)); } - public function testIncompletelyFetchedStatementDoesNotBlockConnection() + public function testIncompletelyFetchedStatementDoesNotBlockConnection() : void { $this->connection->insert('stmt_test', ['id' => 1]); $this->connection->insert('stmt_test', ['id' => 2]); @@ -151,7 +151,7 @@ public function testIncompletelyFetchedStatementDoesNotBlockConnection() self::assertEquals(1, $stmt2->fetchColumn()); } - public function testReuseStatementAfterClosingCursor() + public function testReuseStatementAfterClosingCursor() : void { if ($this->connection->getDriver() instanceof PDOOracleDriver) { $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=77181'); @@ -173,7 +173,7 @@ public function testReuseStatementAfterClosingCursor() self::assertEquals(2, $id); } - public function testReuseStatementWithParameterBoundByReference() + public function testReuseStatementWithParameterBoundByReference() : void { $this->connection->insert('stmt_test', ['id' => 1]); $this->connection->insert('stmt_test', ['id' => 2]); @@ -190,7 +190,7 @@ public function testReuseStatementWithParameterBoundByReference() self::assertEquals(2, $stmt->fetchColumn()); } - public function testReuseStatementWithReboundValue() + public function testReuseStatementWithReboundValue() : void { $this->connection->insert('stmt_test', ['id' => 1]); $this->connection->insert('stmt_test', ['id' => 2]); @@ -206,7 +206,7 @@ public function testReuseStatementWithReboundValue() self::assertEquals(2, $stmt->fetchColumn()); } - public function testReuseStatementWithReboundParam() + public function testReuseStatementWithReboundParam() : void { $this->connection->insert('stmt_test', ['id' => 1]); $this->connection->insert('stmt_test', ['id' => 2]); @@ -225,26 +225,27 @@ public function testReuseStatementWithReboundParam() } /** + * @param mixed $expected + * * @dataProvider emptyFetchProvider */ - public function testFetchFromNonExecutedStatement(callable $fetch, $expected) + public function testFetchFromNonExecutedStatement(callable $fetch, $expected) : void { $stmt = $this->connection->prepare('SELECT id FROM stmt_test'); self::assertSame($expected, $fetch($stmt)); } - public function testCloseCursorOnNonExecutedStatement() + public function testCloseCursorOnNonExecutedStatement() : void { $stmt = $this->connection->prepare('SELECT id FROM stmt_test'); - self::assertTrue($stmt->closeCursor()); } /** * @group DBAL-2637 */ - public function testCloseCursorAfterCursorEnd() + public function testCloseCursorAfterCursorEnd() : void { $stmt = $this->connection->prepare('SELECT name FROM stmt_test'); @@ -255,9 +256,11 @@ public function testCloseCursorAfterCursorEnd() } /** + * @param mixed $expected + * * @dataProvider emptyFetchProvider */ - public function testFetchFromNonExecutedStatementWithClosedCursor(callable $fetch, $expected) + public function testFetchFromNonExecutedStatementWithClosedCursor(callable $fetch, $expected) : void { $stmt = $this->connection->prepare('SELECT id FROM stmt_test'); $stmt->closeCursor(); @@ -266,9 +269,11 @@ public function testFetchFromNonExecutedStatementWithClosedCursor(callable $fetc } /** + * @param mixed $expected + * * @dataProvider emptyFetchProvider */ - public function testFetchFromExecutedStatementWithClosedCursor(callable $fetch, $expected) + public function testFetchFromExecutedStatementWithClosedCursor(callable $fetch, $expected) : void { $this->connection->insert('stmt_test', ['id' => 1]); @@ -279,7 +284,10 @@ public function testFetchFromExecutedStatementWithClosedCursor(callable $fetch, self::assertSame($expected, $fetch($stmt)); } - public static function emptyFetchProvider() + /** + * @return mixed[][] + */ + public static function emptyFetchProvider() : iterable { return [ 'fetch' => [ diff --git a/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php b/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php index a6721b88f8d..9846bf70fa1 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php @@ -38,7 +38,7 @@ protected function setUp() : void $this->generator = new TableGenerator($this->connection); } - public function testNextVal() + public function testNextVal() : void { $id1 = $this->generator->nextValue('tbl1'); $id2 = $this->generator->nextValue('tbl1'); @@ -49,7 +49,7 @@ public function testNextVal() self::assertEquals($id1, $id3, 'First ids from different tables are equal.'); } - public function testNextValNotAffectedByOuterTransactions() + public function testNextValNotAffectedByOuterTransactions() : void { $this->connection->beginTransaction(); $id1 = $this->generator->nextValue('tbl1'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php b/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php index 8dae876dc0c..e96fd426b3a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php @@ -32,11 +32,9 @@ protected function tearDown() : void } /** - * @return void - * * @group DDC-1337 */ - public function testDropTemporaryTableNotAutoCommitTransaction() + public function testDropTemporaryTableNotAutoCommitTransaction() : void { if ($this->connection->getDatabasePlatform()->getName() === 'sqlanywhere' || $this->connection->getDatabasePlatform()->getName() === 'oracle') { @@ -69,11 +67,9 @@ public function testDropTemporaryTableNotAutoCommitTransaction() } /** - * @return void - * * @group DDC-1337 */ - public function testCreateTemporaryTableNotAutoCommitTransaction() + public function testCreateTemporaryTableNotAutoCommitTransaction() : void { if ($this->connection->getDatabasePlatform()->getName() === 'sqlanywhere' || $this->connection->getDatabasePlatform()->getName() === 'oracle') { diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php index b18b6cbdaf5..a3133635c0d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php @@ -10,7 +10,7 @@ */ class DBAL168Test extends DbalFunctionalTestCase { - public function testDomainsTable() + public function testDomainsTable() : void { if ($this->connection->getDatabasePlatform()->getName() !== 'postgresql') { $this->markTestSkipped('PostgreSQL only test'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php index eeb9b7e24ed..da1fbcbd2f1 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php @@ -29,7 +29,7 @@ protected function setUp() : void } } - public function testStatementRollback() + public function testStatementRollback() : void { $stmt = $this->connection->prepare('INSERT INTO DBAL202 VALUES (8)'); $this->connection->beginTransaction(); @@ -39,7 +39,7 @@ public function testStatementRollback() self::assertEquals(0, $this->connection->query('SELECT COUNT(1) FROM DBAL202')->fetchColumn()); } - public function testStatementCommit() + public function testStatementCommit() : void { $stmt = $this->connection->prepare('INSERT INTO DBAL202 VALUES (8)'); $this->connection->beginTransaction(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php index 6b77db02f0a..3ebd3a62f1f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php @@ -23,7 +23,7 @@ protected function setUp() : void $this->markTestSkipped('Currently restricted to MySQL and SQLite.'); } - public function testGuidShouldMatchPattern() + public function testGuidShouldMatchPattern() : void { $guid = $this->connection->query($this->getSelectGuidSql())->fetchColumn(); $pattern = '/[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[8-9A-B][0-9A-F]{3}\-[0-9A-F]{12}/i'; @@ -34,7 +34,7 @@ public function testGuidShouldMatchPattern() * This test does (of course) not proof that all generated GUIDs are * random, it should however provide some basic confidence. */ - public function testGuidShouldBeRandom() + public function testGuidShouldBeRandom() : void { $statement = $this->connection->prepare($this->getSelectGuidSql()); $guids = []; @@ -49,7 +49,7 @@ public function testGuidShouldBeRandom() $statement->closeCursor(); } - private function getSelectGuidSql() + private function getSelectGuidSql() : string { return 'SELECT ' . $this->connection->getDatabasePlatform()->getGuidExpression(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php index a9dbdb1e109..e1c0927d852 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php @@ -14,7 +14,7 @@ */ class DBAL461Test extends TestCase { - public function testIssue() + public function testIssue() : void { $conn = $this->createMock(Connection::class); $platform = $this->getMockForAbstractClass(AbstractPlatform::class); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php index 620b0a66249..1b3008db65d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php @@ -22,7 +22,7 @@ protected function setUp() : void $this->markTestSkipped('PostgreSQL Only test'); } - public function testSearchPathSchemaChanges() + public function testSearchPathSchemaChanges() : void { $table = new Table('dbal510tbl'); $table->addColumn('id', 'integer'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php index 21c6e492622..687e6e834a0 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php @@ -43,7 +43,7 @@ protected function tearDown() : void parent::tearDown(); } - public function testBooleanConversionSqlLiteral() + public function testBooleanConversionSqlLiteral() : void { $this->connection->executeUpdate('INSERT INTO dbal630 (bool_col) VALUES(false)'); $id = $this->connection->lastInsertId('dbal630_id_seq'); @@ -54,7 +54,7 @@ public function testBooleanConversionSqlLiteral() self::assertFalse($row['bool_col']); } - public function testBooleanConversionBoolParamRealPrepares() + public function testBooleanConversionBoolParamRealPrepares() : void { $this->connection->executeUpdate( 'INSERT INTO dbal630 (bool_col) VALUES(?)', @@ -69,7 +69,7 @@ public function testBooleanConversionBoolParamRealPrepares() self::assertFalse($row['bool_col']); } - public function testBooleanConversionBoolParamEmulatedPrepares() + public function testBooleanConversionBoolParamEmulatedPrepares() : void { $this->connection->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); @@ -92,9 +92,9 @@ public function testBooleanConversionBoolParamEmulatedPrepares() * @dataProvider booleanTypeConversionWithoutPdoTypeProvider */ public function testBooleanConversionNullParamEmulatedPrepares( - $statementValue, - $databaseConvertedValue - ) { + ?bool $statementValue, + ?bool $databaseConvertedValue + ) : void { $this->connection->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $platform = $this->connection->getDatabasePlatform(); @@ -116,9 +116,9 @@ public function testBooleanConversionNullParamEmulatedPrepares( * @dataProvider booleanTypeConversionUsingBooleanTypeProvider */ public function testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInBindValue( - $statementValue, - $databaseConvertedValue - ) { + ?bool $statementValue, + bool $databaseConvertedValue + ) : void { $this->connection->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $platform = $this->connection->getDatabasePlatform(); @@ -145,7 +145,7 @@ public function testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInB * * @return mixed[][] */ - public function booleanTypeConversionUsingBooleanTypeProvider() + public static function booleanTypeConversionUsingBooleanTypeProvider() : iterable { return [ // statement value, database converted value result @@ -160,7 +160,7 @@ public function booleanTypeConversionUsingBooleanTypeProvider() * * @return mixed[][] */ - public function booleanTypeConversionWithoutPdoTypeProvider() + public static function booleanTypeConversionWithoutPdoTypeProvider() : iterable { return [ // statement value, database converted value result diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php index 3e087b21b36..47bc1c3e762 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php @@ -23,7 +23,7 @@ protected function setUp() : void $this->markTestSkipped('Related to SQLite only'); } - public function testUnsignedIntegerDetection() + public function testUnsignedIntegerDetection() : void { $this->connection->exec(<<dropAndCreateTable($table); } - public function testInsertAndSelect() + public function testInsertAndSelect() : void { $id1 = random_bytes(16); $id2 = random_bytes(16); @@ -70,6 +70,9 @@ private function insert(string $id, string $value) : void self::assertSame(1, $result); } + /** + * @return mixed + */ private function select(string $id) { $value = $this->connection->fetchColumn( diff --git a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php index 52cef4d9fc2..b08751d5ec3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php @@ -35,7 +35,7 @@ protected function setUp() : void /** * @group DBAL-80 */ - public function testExecuteUpdateFirstTypeIsNull() + public function testExecuteUpdateFirstTypeIsNull() : void { $sql = 'INSERT INTO write_table (test_string, test_int) VALUES (?, ?)'; $this->connection->executeUpdate($sql, ['text', 1111], [null, ParameterType::INTEGER]); @@ -44,7 +44,7 @@ public function testExecuteUpdateFirstTypeIsNull() self::assertTrue((bool) $this->connection->fetchColumn($sql, ['text', 1111])); } - public function testExecuteUpdate() + public function testExecuteUpdate() : void { $sql = 'INSERT INTO write_table (test_int) VALUES ( ' . $this->connection->quote(1) . ')'; $affected = $this->connection->executeUpdate($sql); @@ -52,7 +52,7 @@ public function testExecuteUpdate() self::assertEquals(1, $affected, 'executeUpdate() should return the number of affected rows!'); } - public function testExecuteUpdateWithTypes() + public function testExecuteUpdateWithTypes() : void { $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $affected = $this->connection->executeUpdate( @@ -64,7 +64,7 @@ public function testExecuteUpdateWithTypes() self::assertEquals(1, $affected, 'executeUpdate() should return the number of affected rows!'); } - public function testPrepareRowCountReturnsAffectedRows() + public function testPrepareRowCountReturnsAffectedRows() : void { $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->connection->prepare($sql); @@ -76,7 +76,7 @@ public function testPrepareRowCountReturnsAffectedRows() self::assertEquals(1, $stmt->rowCount()); } - public function testPrepareWithPdoTypes() + public function testPrepareWithPdoTypes() : void { $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->connection->prepare($sql); @@ -88,7 +88,7 @@ public function testPrepareWithPdoTypes() self::assertEquals(1, $stmt->rowCount()); } - public function testPrepareWithDbalTypes() + public function testPrepareWithDbalTypes() : void { $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->connection->prepare($sql); @@ -100,7 +100,7 @@ public function testPrepareWithDbalTypes() self::assertEquals(1, $stmt->rowCount()); } - public function testPrepareWithDbalTypeNames() + public function testPrepareWithDbalTypeNames() : void { $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->connection->prepare($sql); @@ -112,18 +112,18 @@ public function testPrepareWithDbalTypeNames() self::assertEquals(1, $stmt->rowCount()); } - public function insertRows() + public function insertRows() : void { self::assertEquals(1, $this->connection->insert('write_table', ['test_int' => 1, 'test_string' => 'foo'])); self::assertEquals(1, $this->connection->insert('write_table', ['test_int' => 2, 'test_string' => 'bar'])); } - public function testInsert() + public function testInsert() : void { $this->insertRows(); } - public function testDelete() + public function testDelete() : void { $this->insertRows(); @@ -134,7 +134,7 @@ public function testDelete() self::assertCount(0, $this->connection->fetchAll('SELECT * FROM write_table')); } - public function testUpdate() + public function testUpdate() : void { $this->insertRows(); @@ -143,7 +143,7 @@ public function testUpdate() self::assertEquals(0, $this->connection->update('write_table', ['test_string' => 'baz'], ['test_string' => 'bar'])); } - public function testLastInsertId() + public function testLastInsertId() : void { if (! $this->connection->getDatabasePlatform()->prefersIdentityColumns()) { $this->markTestSkipped('Test only works on platforms with identity columns.'); @@ -156,7 +156,7 @@ public function testLastInsertId() self::assertGreaterThan(0, $num, 'LastInsertId() should be non-negative number.'); } - public function testLastInsertIdSequence() + public function testLastInsertIdSequence() : void { if (! $this->connection->getDatabasePlatform()->supportsSequences()) { $this->markTestSkipped('Test only works on platforms with sequences.'); @@ -182,7 +182,7 @@ public function testLastInsertIdSequence() self::assertEquals($nextSequenceVal, $lastInsertId); } - public function testLastInsertIdNoSequenceGiven() + public function testLastInsertIdNoSequenceGiven() : void { if (! $this->connection->getDatabasePlatform()->supportsSequences() || $this->connection->getDatabasePlatform()->supportsIdentityColumns()) { $this->markTestSkipped("Test only works consistently on platforms that support sequences and don't support identity columns."); @@ -194,7 +194,7 @@ public function testLastInsertIdNoSequenceGiven() /** * @group DBAL-445 */ - public function testInsertWithKeyValueTypes() + public function testInsertWithKeyValueTypes() : void { $testString = new DateTime('2013-04-14 10:10:10'); @@ -212,7 +212,7 @@ public function testInsertWithKeyValueTypes() /** * @group DBAL-445 */ - public function testUpdateWithKeyValueTypes() + public function testUpdateWithKeyValueTypes() : void { $testString = new DateTime('2013-04-14 10:10:10'); @@ -239,7 +239,7 @@ public function testUpdateWithKeyValueTypes() /** * @group DBAL-445 */ - public function testDeleteWithKeyValueTypes() + public function testDeleteWithKeyValueTypes() : void { $val = new DateTime('2013-04-14 10:10:10'); $this->connection->insert( @@ -255,7 +255,7 @@ public function testDeleteWithKeyValueTypes() self::assertFalse($data); } - public function testEmptyIdentityInsert() + public function testEmptyIdentityInsert() : void { $platform = $this->connection->getDatabasePlatform(); @@ -298,7 +298,7 @@ public function testEmptyIdentityInsert() /** * @group DBAL-2688 */ - public function testUpdateWhereIsNull() + public function testUpdateWhereIsNull() : void { $this->connection->insert( 'write_table', @@ -317,7 +317,7 @@ public function testUpdateWhereIsNull() self::assertCount(0, $data); } - public function testDeleteWhereIsNull() + public function testDeleteWhereIsNull() : void { $this->connection->insert( 'write_table', @@ -340,7 +340,7 @@ public function testDeleteWhereIsNull() * Returns the ID of the last inserted row or skips the test if the currently used driver * doesn't support this feature * - * @return string + * @return string|false * * @throws DriverException */ diff --git a/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php b/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php index c2239639f26..26b5a959350 100644 --- a/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php +++ b/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php @@ -20,7 +20,7 @@ protected function tearDown() : void unset($this->logger); } - public function testLoggedQuery() + public function testLoggedQuery() : void { $this->logger->startQuery('SELECT column FROM table'); self::assertEquals( @@ -39,7 +39,7 @@ public function testLoggedQuery() self::assertGreaterThan(0, $this->logger->queries[1]['executionMS']); } - public function testLoggedQueryDisabled() + public function testLoggedQueryDisabled() : void { $this->logger->enabled = false; $this->logger->startQuery('SELECT column FROM table'); diff --git a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php index a0bf8936f50..6a76e90f897 100644 --- a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php +++ b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php @@ -17,7 +17,7 @@ class TypeConversionPerformanceTest extends DbalPerformanceTestCase * * @dataProvider itemCountProvider */ - public function testDateTimeTypeConversionPerformance($count) + public function testDateTimeTypeConversionPerformance(int $count) : void { $value = new DateTime(); $type = Type::getType('datetime'); @@ -29,7 +29,10 @@ public function testDateTimeTypeConversionPerformance($count) $this->stopTiming(); } - public function itemCountProvider() + /** + * @return mixed[][] + */ + public static function itemCountProvider() : iterable { return [ '100 items' => [100], diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index ea6a6ffe59e..bc71767a766 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -3,7 +3,6 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Index; @@ -17,13 +16,13 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase /** @var MySqlPlatform */ protected $platform; - public function testModifyLimitQueryWitoutLimit() + public function testModifyLimitQueryWitoutLimit() : void { $sql = $this->platform->modifyLimitQuery('SELECT n FROM Foo', null, 10); self::assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10', $sql); } - public function testGenerateMixedCaseTableCreate() + public function testGenerateMixedCaseTableCreate() : void { $table = new Table('Foo'); $table->addColumn('Bar', 'integer'); @@ -32,29 +31,35 @@ public function testGenerateMixedCaseTableCreate() self::assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', array_shift($sql)); } - public function getGenerateTableSql() + public function getGenerateTableSql() : string { return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'; } - public function getGenerateTableWithMultiColumnUniqueIndexSql() + /** + * @return string[] + */ + public function getGenerateTableWithMultiColumnUniqueIndexSql() : array { return ['CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA (foo, bar)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; } - public function getGenerateAlterTableSql() + /** + * {@inheritDoc} + */ + public function getGenerateAlterTableSql() : array { return ["ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL, CHANGE bloo bloo TINYINT(1) DEFAULT '0' NOT NULL"]; } - public function testGeneratesSqlSnippets() + public function testGeneratesSqlSnippets() : void { self::assertEquals('RLIKE', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct'); self::assertEquals('`', $this->platform->getIdentifierQuoteCharacter(), 'Quote character is not correct'); self::assertEquals('CONCAT(column1, column2, column3)', $this->platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation function is not correct'); } - public function testGeneratesTransactionsCommands() + public function testGeneratesTransactionsCommands() : void { self::assertEquals( 'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', @@ -75,7 +80,7 @@ public function testGeneratesTransactionsCommands() ); } - public function testGeneratesDDLSnippets() + public function testGeneratesDDLSnippets() : void { self::assertEquals('SHOW DATABASES', $this->platform->getListDatabasesSQL()); self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); @@ -83,7 +88,7 @@ public function testGeneratesDDLSnippets() self::assertEquals('DROP TABLE foobar', $this->platform->getDropTableSQL('foobar')); } - public function testGeneratesTypeDeclarationForIntegers() + public function testGeneratesTypeDeclarationForIntegers() : void { self::assertEquals( 'INT', @@ -101,7 +106,7 @@ public function testGeneratesTypeDeclarationForIntegers() ); } - public function testGeneratesTypeDeclarationForStrings() + public function testGeneratesTypeDeclarationForStrings() : void { self::assertEquals( 'CHAR(10)', @@ -121,32 +126,32 @@ public function testGeneratesTypeDeclarationForStrings() ); } - public function testPrefersIdentityColumns() + public function testPrefersIdentityColumns() : void { self::assertTrue($this->platform->prefersIdentityColumns()); } - public function testSupportsIdentityColumns() + public function testSupportsIdentityColumns() : void { self::assertTrue($this->platform->supportsIdentityColumns()); } - public function testDoesSupportSavePoints() + public function testDoesSupportSavePoints() : void { self::assertTrue($this->platform->supportsSavepoints()); } - public function getGenerateIndexSql() + public function getGenerateIndexSql() : string { return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; } - public function getGenerateUniqueIndexSql() + public function getGenerateUniqueIndexSql() : string { return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; } - public function getGenerateForeignKeySql() + public function getGenerateForeignKeySql() : string { return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; } @@ -154,7 +159,7 @@ public function getGenerateForeignKeySql() /** * @group DBAL-126 */ - public function testUniquePrimaryKey() + public function testUniquePrimaryKey() : void { $keyTable = new Table('foo'); $keyTable->addColumn('bar', 'integer'); @@ -177,13 +182,13 @@ public function testUniquePrimaryKey() ], $sql); } - public function testModifyLimitQuery() + public function testModifyLimitQuery() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); self::assertEquals('SELECT * FROM user LIMIT 10', $sql); } - public function testModifyLimitQueryWithEmptyOffset() + public function testModifyLimitQueryWithEmptyOffset() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); self::assertEquals('SELECT * FROM user LIMIT 10', $sql); @@ -192,24 +197,33 @@ public function testModifyLimitQueryWithEmptyOffset() /** * @group DDC-118 */ - public function testGetDateTimeTypeDeclarationSql() + public function testGetDateTimeTypeDeclarationSql() : void { self::assertEquals('DATETIME', $this->platform->getDateTimeTypeDeclarationSQL(['version' => false])); self::assertEquals('TIMESTAMP', $this->platform->getDateTimeTypeDeclarationSQL(['version' => true])); self::assertEquals('DATETIME', $this->platform->getDateTimeTypeDeclarationSQL([])); } - public function getCreateTableColumnCommentsSQL() + /** + * {@inheritDoc} + */ + public function getCreateTableColumnCommentsSQL() : array { return ["CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"]; } - public function getAlterTableColumnCommentsSQL() + /** + * {@inheritDoc} + */ + public function getAlterTableColumnCommentsSQL() : array { return ["ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE foo foo VARCHAR(255) NOT NULL, CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'"]; } - public function getCreateTableColumnTypeCommentsSQL() + /** + * {@inheritDoc} + */ + public function getCreateTableColumnTypeCommentsSQL() : array { return ["CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"]; } @@ -217,7 +231,7 @@ public function getCreateTableColumnTypeCommentsSQL() /** * @group DBAL-237 */ - public function testChangeIndexWithForeignKeys() + public function testChangeIndexWithForeignKeys() : void { $index = new Index('idx', ['col'], false); $unique = new Index('uniq', ['col'], true); @@ -231,22 +245,34 @@ public function testChangeIndexWithForeignKeys() self::assertEquals(['ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)'], $sql); } - protected function getQuotedColumnInPrimaryKeySQL() + /** + * @return string[] + */ + protected function getQuotedColumnInPrimaryKeySQL() : array { return ['CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, PRIMARY KEY(`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; } - protected function getQuotedColumnInIndexSQL() + /** + * @return string[] + */ + protected function getQuotedColumnInIndexSQL() : array { return ['CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, INDEX IDX_22660D028FD6E0FB (`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; } - protected function getQuotedNameInIndexSQL() + /** + * @return string[] + */ + protected function getQuotedNameInIndexSQL() : array { return ['CREATE TABLE test (column1 VARCHAR(255) NOT NULL, INDEX `key` (column1)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; } - protected function getQuotedColumnInForeignKeySQL() + /** + * @return string[] + */ + protected function getQuotedColumnInForeignKeySQL() : array { return [ 'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, `bar` VARCHAR(255) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', @@ -256,7 +282,7 @@ protected function getQuotedColumnInForeignKeySQL() ]; } - public function testCreateTableWithFulltextIndex() + public function testCreateTableWithFulltextIndex() : void { $table = new Table('fulltext_table'); $table->addOption('engine', 'MyISAM'); @@ -270,7 +296,7 @@ public function testCreateTableWithFulltextIndex() self::assertEquals(['CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'], $sql); } - public function testCreateTableWithSpatialIndex() + public function testCreateTableWithSpatialIndex() : void { $table = new Table('spatial_table'); $table->addOption('engine', 'MyISAM'); @@ -284,7 +310,7 @@ public function testCreateTableWithSpatialIndex() self::assertEquals(['CREATE TABLE spatial_table (point LONGTEXT NOT NULL, SPATIAL INDEX spatial_text (point)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'], $sql); } - public function testClobTypeDeclarationSQL() + public function testClobTypeDeclarationSQL() : void { self::assertEquals('TINYTEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 1])); self::assertEquals('TINYTEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 255])); @@ -296,7 +322,7 @@ public function testClobTypeDeclarationSQL() self::assertEquals('LONGTEXT', $this->platform->getClobTypeDeclarationSQL([])); } - public function testBlobTypeDeclarationSQL() + public function testBlobTypeDeclarationSQL() : void { self::assertEquals('TINYBLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 1])); self::assertEquals('TINYBLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 255])); @@ -311,7 +337,7 @@ public function testBlobTypeDeclarationSQL() /** * @group DBAL-400 */ - public function testAlterTableAddPrimaryKey() + public function testAlterTableAddPrimaryKey() : void { $table = new Table('alter_table_add_pk'); $table->addColumn('id', 'integer'); @@ -333,7 +359,7 @@ public function testAlterTableAddPrimaryKey() /** * @group DBAL-1132 */ - public function testAlterPrimaryKeyWithAutoincrementColumn() + public function testAlterPrimaryKeyWithAutoincrementColumn() : void { $table = new Table('alter_primary_key'); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -359,7 +385,7 @@ public function testAlterPrimaryKeyWithAutoincrementColumn() /** * @group DBAL-464 */ - public function testDropPrimaryKeyWithAutoincrementColumn() + public function testDropPrimaryKeyWithAutoincrementColumn() : void { $table = new Table('drop_primary_key'); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -384,7 +410,7 @@ public function testDropPrimaryKeyWithAutoincrementColumn() /** * @group DBAL-2302 */ - public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoincrementColumn() + public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoincrementColumn() : void { $table = new Table('tbl'); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -411,7 +437,7 @@ public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoinc /** * @group DBAL-2302 */ - public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn() + public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn() : void { $table = new Table('tbl'); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -438,7 +464,7 @@ public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn /** * @group DBAL-586 */ - public function testAddAutoIncrementPrimaryKey() + public function testAddAutoIncrementPrimaryKey() : void { $keyTable = new Table('foo'); $keyTable->addColumn('id', 'integer', ['autoincrement' => true]); @@ -456,7 +482,7 @@ public function testAddAutoIncrementPrimaryKey() self::assertEquals(['ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)'], $sql); } - public function testNamedPrimaryKey() + public function testNamedPrimaryKey() : void { $diff = new TableDiff('mytable'); $diff->changedIndexes['foo_index'] = new Index('foo_index', ['foo'], true, true); @@ -469,7 +495,7 @@ public function testNamedPrimaryKey() ], $sql); } - public function testAlterPrimaryKeyWithNewColumn() + public function testAlterPrimaryKeyWithNewColumn() : void { $table = new Table('yolo'); $table->addColumn('pkc1', 'integer'); @@ -493,7 +519,7 @@ public function testAlterPrimaryKeyWithNewColumn() ); } - public function testInitializesDoctrineTypeMappings() + public function testInitializesDoctrineTypeMappings() : void { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('binary')); self::assertSame('binary', $this->platform->getDoctrineTypeMapping('binary')); @@ -502,12 +528,12 @@ public function testInitializesDoctrineTypeMappings() self::assertSame('binary', $this->platform->getDoctrineTypeMapping('varbinary')); } - protected function getBinaryMaxLength() + protected function getBinaryMaxLength() : int { return 65535; } - public function testReturnsBinaryTypeDeclarationSQL() + public function testReturnsBinaryTypeDeclarationSQL() : void { self::assertSame('VARBINARY(255)', $this->platform->getBinaryTypeDeclarationSQL([])); self::assertSame('VARBINARY(255)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); @@ -524,7 +550,7 @@ public function testReturnsBinaryTypeDeclarationSQL() * @expectedDeprecation Binary field length 16777215 is greater than supported by the platform (65535). Reduce the field length or use a BLOB field instead. * @expectedDeprecation Binary field length 16777216 is greater than supported by the platform (65535). Reduce the field length or use a BLOB field instead. */ - public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() + public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() : void { self::assertSame('MEDIUMBLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 65536])); self::assertSame('MEDIUMBLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 16777215])); @@ -535,7 +561,7 @@ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() self::assertSame('LONGBLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 16777216])); } - public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() + public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() : void { $table = new Table('foreign_table'); $table->addColumn('id', 'integer'); @@ -567,7 +593,7 @@ public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() ); } - public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines() + public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines() : void { $table = new Table('foreign_table'); $table->addColumn('id', 'integer'); @@ -608,9 +634,11 @@ public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines( } /** + * @return string[] + * * @group DBAL-234 */ - protected function getAlterTableRenameIndexSQL() + protected function getAlterTableRenameIndexSQL() : array { return [ 'DROP INDEX idx_foo ON mytable', @@ -619,9 +647,11 @@ protected function getAlterTableRenameIndexSQL() } /** + * @return string[] + * * @group DBAL-234 */ - protected function getQuotedAlterTableRenameIndexSQL() + protected function getQuotedAlterTableRenameIndexSQL() : array { return [ 'DROP INDEX `create` ON `table`', @@ -632,9 +662,11 @@ protected function getQuotedAlterTableRenameIndexSQL() } /** + * @return string[] + * * @group DBAL-807 */ - protected function getAlterTableRenameIndexInSchemaSQL() + protected function getAlterTableRenameIndexInSchemaSQL() : array { return [ 'DROP INDEX idx_foo ON myschema.mytable', @@ -643,9 +675,11 @@ protected function getAlterTableRenameIndexInSchemaSQL() } /** + * @return string[] + * * @group DBAL-807 */ - protected function getQuotedAlterTableRenameIndexInSchemaSQL() + protected function getQuotedAlterTableRenameIndexInSchemaSQL() : array { return [ 'DROP INDEX `create` ON `schema`.`table`', @@ -655,17 +689,17 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() ]; } - protected function getQuotesDropForeignKeySQL() + protected function getQuotesDropForeignKeySQL() : string { return 'ALTER TABLE `table` DROP FOREIGN KEY `select`'; } - protected function getQuotesDropConstraintSQL() + protected function getQuotesDropConstraintSQL() : string { return 'ALTER TABLE `table` DROP CONSTRAINT `select`'; } - public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() + public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() : void { $table = new Table('text_blob_default_value'); $table->addColumn('def_text', 'text', ['default' => 'def']); @@ -692,7 +726,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() /** * {@inheritdoc} */ - protected function getQuotedAlterTableRenameColumnSQL() + protected function getQuotedAlterTableRenameColumnSQL() : array { return ['ALTER TABLE mytable ' . "CHANGE unquoted1 unquoted INT NOT NULL COMMENT 'Unquoted 1', " . @@ -710,7 +744,7 @@ protected function getQuotedAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotedAlterTableChangeColumnLengthSQL() + protected function getQuotedAlterTableChangeColumnLengthSQL() : array { return ['ALTER TABLE mytable ' . "CHANGE unquoted1 unquoted1 VARCHAR(255) NOT NULL COMMENT 'Unquoted 1', " . @@ -725,7 +759,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() /** * @group DBAL-423 */ - public function testReturnsGuidTypeDeclarationSQL() + public function testReturnsGuidTypeDeclarationSQL() : void { self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); } @@ -733,7 +767,7 @@ public function testReturnsGuidTypeDeclarationSQL() /** * {@inheritdoc} */ - public function getAlterTableRenameColumnSQL() + public function getAlterTableRenameColumnSQL() : array { return ["ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'"]; } @@ -741,7 +775,7 @@ public function getAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotesTableIdentifiersInAlterTableSQL() + protected function getQuotesTableIdentifiersInAlterTableSQL() : array { return [ 'ALTER TABLE `foo` DROP FOREIGN KEY fk1', @@ -756,7 +790,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() /** * {@inheritdoc} */ - protected function getCommentOnColumnSQL() + protected function getCommentOnColumnSQL() : array { return [ "COMMENT ON COLUMN foo.bar IS 'comment'", @@ -768,7 +802,7 @@ protected function getCommentOnColumnSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() + protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string { return 'CONSTRAINT `select` UNIQUE (foo)'; } @@ -776,7 +810,7 @@ protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInIndexDeclarationSQL() + protected function getQuotesReservedKeywordInIndexDeclarationSQL() : string { return 'INDEX `select` (foo)'; } @@ -784,7 +818,7 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInTruncateTableSQL() + protected function getQuotesReservedKeywordInTruncateTableSQL() : string { return 'TRUNCATE `select`'; } @@ -792,7 +826,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() /** * {@inheritdoc} */ - protected function getAlterStringToFixedStringSQL() + protected function getAlterStringToFixedStringSQL() : array { return ['ALTER TABLE mytable CHANGE name name CHAR(2) NOT NULL']; } @@ -800,7 +834,7 @@ protected function getAlterStringToFixedStringSQL() /** * {@inheritdoc} */ - protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() + protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array { return [ 'ALTER TABLE mytable DROP FOREIGN KEY fk_foo', @@ -813,7 +847,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() /** * {@inheritdoc} */ - public function getGeneratesDecimalTypeDeclarationSQL() + public static function getGeneratesDecimalTypeDeclarationSQL() : iterable { return [ [[], 'NUMERIC(10, 0)'], @@ -828,7 +862,7 @@ public function getGeneratesDecimalTypeDeclarationSQL() /** * {@inheritdoc} */ - public function getGeneratesFloatDeclarationSQL() + public static function getGeneratesFloatDeclarationSQL() : iterable { return [ [[], 'DOUBLE PRECISION'], @@ -843,7 +877,7 @@ public function getGeneratesFloatDeclarationSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableIndexesSQL() + public function testQuotesTableNameInListTableIndexesSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\\\'", @@ -854,7 +888,7 @@ public function testQuotesTableNameInListTableIndexesSQL() /** * @group DBAL-2436 */ - public function testQuotesDatabaseNameInListTableIndexesSQL() + public function testQuotesDatabaseNameInListTableIndexesSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\\\'", @@ -865,7 +899,7 @@ public function testQuotesDatabaseNameInListTableIndexesSQL() /** * @group DBAL-2436 */ - public function testQuotesDatabaseNameInListViewsSQL() + public function testQuotesDatabaseNameInListViewsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\\\'", @@ -876,7 +910,7 @@ public function testQuotesDatabaseNameInListViewsSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableForeignKeysSQL() + public function testQuotesTableNameInListTableForeignKeysSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\\\'", @@ -887,7 +921,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() /** * @group DBAL-2436 */ - public function testQuotesDatabaseNameInListTableForeignKeysSQL() + public function testQuotesDatabaseNameInListTableForeignKeysSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\\\'", @@ -898,7 +932,7 @@ public function testQuotesDatabaseNameInListTableForeignKeysSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableColumnsSQL() + public function testQuotesTableNameInListTableColumnsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\\\'", @@ -909,7 +943,7 @@ public function testQuotesTableNameInListTableColumnsSQL() /** * @group DBAL-2436 */ - public function testQuotesDatabaseNameInListTableColumnsSQL() + public function testQuotesDatabaseNameInListTableColumnsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\\\'", @@ -917,7 +951,7 @@ public function testQuotesDatabaseNameInListTableColumnsSQL() ); } - public function testListTableForeignKeysSQLEvaluatesDatabase() + public function testListTableForeignKeysSQLEvaluatesDatabase() : void { $sql = $this->platform->getListTableForeignKeysSQL('foo'); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 910f2daa2c1..0c44d42a7b4 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -27,7 +27,7 @@ abstract class AbstractPlatformTestCase extends DbalTestCase /** @var AbstractPlatform */ protected $platform; - abstract public function createPlatform(); + abstract public function createPlatform() : AbstractPlatform; protected function setUp() : void { @@ -37,7 +37,7 @@ protected function setUp() : void /** * @group DDC-1360 */ - public function testQuoteIdentifier() + public function testQuoteIdentifier() : void { if ($this->platform->getName() === 'mssql') { $this->markTestSkipped('Not working this way on mssql.'); @@ -52,7 +52,7 @@ public function testQuoteIdentifier() /** * @group DDC-1360 */ - public function testQuoteSingleIdentifier() + public function testQuoteSingleIdentifier() : void { if ($this->platform->getName() === 'mssql') { $this->markTestSkipped('Not working this way on mssql.'); @@ -68,15 +68,15 @@ public function testQuoteSingleIdentifier() * @group DBAL-1029 * @dataProvider getReturnsForeignKeyReferentialActionSQL */ - public function testReturnsForeignKeyReferentialActionSQL($action, $expectedSQL) + public function testReturnsForeignKeyReferentialActionSQL(string $action, string $expectedSQL) : void { self::assertSame($expectedSQL, $this->platform->getForeignKeyReferentialActionSQL($action)); } /** - * @return string[][] + * @return mixed[][] */ - public function getReturnsForeignKeyReferentialActionSQL() + public static function getReturnsForeignKeyReferentialActionSQL() : iterable { return [ ['CASCADE', 'CASCADE'], @@ -88,25 +88,25 @@ public function getReturnsForeignKeyReferentialActionSQL() ]; } - public function testGetInvalidForeignKeyReferentialActionSQL() + public function testGetInvalidForeignKeyReferentialActionSQL() : void { $this->expectException('InvalidArgumentException'); $this->platform->getForeignKeyReferentialActionSQL('unknown'); } - public function testGetUnknownDoctrineMappingType() + public function testGetUnknownDoctrineMappingType() : void { $this->expectException(DBALException::class); $this->platform->getDoctrineTypeMapping('foobar'); } - public function testRegisterDoctrineMappingType() + public function testRegisterDoctrineMappingType() : void { $this->platform->registerDoctrineTypeMapping('foo', 'integer'); self::assertEquals('integer', $this->platform->getDoctrineTypeMapping('foo')); } - public function testRegisterUnknownDoctrineMappingType() + public function testRegisterUnknownDoctrineMappingType() : void { $this->expectException(DBALException::class); $this->platform->registerDoctrineTypeMapping('foo', 'bar'); @@ -115,7 +115,7 @@ public function testRegisterUnknownDoctrineMappingType() /** * @group DBAL-2594 */ - public function testRegistersCommentedDoctrineMappingTypeImplicitly() + public function testRegistersCommentedDoctrineMappingTypeImplicitly() : void { if (! Type::hasType('my_commented')) { Type::addType('my_commented', CommentedType::class); @@ -131,12 +131,15 @@ public function testRegistersCommentedDoctrineMappingTypeImplicitly() * @group DBAL-939 * @dataProvider getIsCommentedDoctrineType */ - public function testIsCommentedDoctrineType(Type $type, $commented) + public function testIsCommentedDoctrineType(Type $type, bool $commented) : void { self::assertSame($commented, $this->platform->isCommentedDoctrineType($type)); } - public function getIsCommentedDoctrineType() + /** + * @return mixed[] + */ + public function getIsCommentedDoctrineType() : iterable { $this->setUp(); @@ -154,7 +157,7 @@ public function getIsCommentedDoctrineType() return $data; } - public function testCreateWithNoColumns() + public function testCreateWithNoColumns() : void { $table = new Table('test'); @@ -162,7 +165,7 @@ public function testCreateWithNoColumns() $sql = $this->platform->getCreateTableSQL($table); } - public function testGeneratesTableCreationSql() + public function testGeneratesTableCreationSql() : void { $table = new Table('test'); $table->addColumn('id', 'integer', ['notnull' => true, 'autoincrement' => true]); @@ -173,9 +176,9 @@ public function testGeneratesTableCreationSql() self::assertEquals($this->getGenerateTableSql(), $sql[0]); } - abstract public function getGenerateTableSql(); + abstract public function getGenerateTableSql() : string; - public function testGenerateTableWithMultiColumnUniqueIndex() + public function testGenerateTableWithMultiColumnUniqueIndex() : void { $table = new Table('test'); $table->addColumn('foo', 'string', ['notnull' => false, 'length' => 255]); @@ -186,9 +189,12 @@ public function testGenerateTableWithMultiColumnUniqueIndex() self::assertEquals($this->getGenerateTableWithMultiColumnUniqueIndexSql(), $sql); } - abstract public function getGenerateTableWithMultiColumnUniqueIndexSql(); + /** + * @return string[] + */ + abstract public function getGenerateTableWithMultiColumnUniqueIndexSql() : array; - public function testGeneratesIndexCreationSql() + public function testGeneratesIndexCreationSql() : void { $indexDef = new Index('my_idx', ['user_name', 'last_login']); @@ -198,9 +204,9 @@ public function testGeneratesIndexCreationSql() ); } - abstract public function getGenerateIndexSql(); + abstract public function getGenerateIndexSql() : string; - public function testGeneratesUniqueIndexCreationSql() + public function testGeneratesUniqueIndexCreationSql() : void { $indexDef = new Index('index_name', ['test', 'test2'], true); @@ -208,9 +214,9 @@ public function testGeneratesUniqueIndexCreationSql() self::assertEquals($this->getGenerateUniqueIndexSql(), $sql); } - abstract public function getGenerateUniqueIndexSql(); + abstract public function getGenerateUniqueIndexSql() : string; - public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes() + public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes() : void { $where = 'test IS NULL AND test2 IS NOT NULL'; $indexDef = new Index('name', ['test', 'test2'], false, false, [], ['where' => $where]); @@ -236,7 +242,7 @@ public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes() } } - public function testGeneratesForeignKeyCreationSql() + public function testGeneratesForeignKeyCreationSql() : void { $fk = new ForeignKeyConstraint(['fk_name_id'], 'other_table', ['id'], ''); @@ -244,9 +250,9 @@ public function testGeneratesForeignKeyCreationSql() self::assertEquals($sql, $this->getGenerateForeignKeySql()); } - abstract public function getGenerateForeignKeySql(); + abstract public function getGenerateForeignKeySql() : string; - public function testGeneratesConstraintCreationSql() + public function testGeneratesConstraintCreationSql() : void { $idx = new Index('constraint_name', ['test'], true, false); $sql = $this->platform->getCreateConstraintSQL($idx, 'test'); @@ -261,7 +267,7 @@ public function testGeneratesConstraintCreationSql() self::assertEquals($this->getGenerateConstraintForeignKeySql($fk), $sql); } - public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys() + public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys() : void { $fk = new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk'); @@ -273,7 +279,7 @@ public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys() } } - protected function getBitAndComparisonExpressionSql($value1, $value2) + protected function getBitAndComparisonExpressionSql(string $value1, string $value2) : string { return '(' . $value1 . ' & ' . $value2 . ')'; } @@ -281,13 +287,13 @@ protected function getBitAndComparisonExpressionSql($value1, $value2) /** * @group DDC-1213 */ - public function testGeneratesBitAndComparisonExpressionSql() + public function testGeneratesBitAndComparisonExpressionSql() : void { $sql = $this->platform->getBitAndComparisonExpression(2, 4); self::assertEquals($this->getBitAndComparisonExpressionSql(2, 4), $sql); } - protected function getBitOrComparisonExpressionSql($value1, $value2) + protected function getBitOrComparisonExpressionSql(string $value1, string $value2) : string { return '(' . $value1 . ' | ' . $value2 . ')'; } @@ -295,23 +301,23 @@ protected function getBitOrComparisonExpressionSql($value1, $value2) /** * @group DDC-1213 */ - public function testGeneratesBitOrComparisonExpressionSql() + public function testGeneratesBitOrComparisonExpressionSql() : void { $sql = $this->platform->getBitOrComparisonExpression(2, 4); self::assertEquals($this->getBitOrComparisonExpressionSql(2, 4), $sql); } - public function getGenerateConstraintUniqueIndexSql() + public function getGenerateConstraintUniqueIndexSql() : string { return 'ALTER TABLE test ADD CONSTRAINT constraint_name UNIQUE (test)'; } - public function getGenerateConstraintPrimaryIndexSql() + public function getGenerateConstraintPrimaryIndexSql() : string { return 'ALTER TABLE test ADD CONSTRAINT constraint_name PRIMARY KEY (test)'; } - public function getGenerateConstraintForeignKeySql(ForeignKeyConstraint $fk) + public function getGenerateConstraintForeignKeySql(ForeignKeyConstraint $fk) : string { $quotedForeignTable = $fk->getQuotedForeignTableName($this->platform); @@ -321,9 +327,12 @@ public function getGenerateConstraintForeignKeySql(ForeignKeyConstraint $fk) ); } - abstract public function getGenerateAlterTableSql(); + /** + * @return string[] + */ + abstract public function getGenerateAlterTableSql() : array; - public function testGeneratesTableAlterationSql() + public function testGeneratesTableAlterationSql() : void { $expectedSql = $this->getGenerateAlterTableSql(); @@ -363,13 +372,13 @@ public function testGeneratesTableAlterationSql() self::assertEquals($expectedSql, $sql); } - public function testGetCustomColumnDeclarationSql() + public function testGetCustomColumnDeclarationSql() : void { $field = ['columnDefinition' => 'MEDIUMINT(6) UNSIGNED']; self::assertEquals('foo MEDIUMINT(6) UNSIGNED', $this->platform->getColumnDeclarationSQL('foo', $field)); } - public function testGetCreateTableSqlDispatchEvent() + public function testGetCreateTableSqlDispatchEvent() : void { $listenerMock = $this->getMockBuilder('GetCreateTableSqlDispatchEvenListener') ->setMethods(['onSchemaCreateTable', 'onSchemaCreateTableColumn']) @@ -393,7 +402,7 @@ public function testGetCreateTableSqlDispatchEvent() $this->platform->getCreateTableSQL($table); } - public function testGetDropTableSqlDispatchEvent() + public function testGetDropTableSqlDispatchEvent() : void { $listenerMock = $this->getMockBuilder('GetDropTableSqlDispatchEventListener') ->setMethods(['onSchemaDropTable']) @@ -410,7 +419,7 @@ public function testGetDropTableSqlDispatchEvent() $this->platform->getDropTableSQL('TABLE'); } - public function testGetAlterTableSqlDispatchEvent() + public function testGetAlterTableSqlDispatchEvent() : void { $events = [ 'onSchemaAlterTable', @@ -477,7 +486,7 @@ public function testGetAlterTableSqlDispatchEvent() /** * @group DBAL-42 */ - public function testCreateTableColumnComments() + public function testCreateTableColumnComments() : void { $table = new Table('test'); $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); @@ -489,7 +498,7 @@ public function testCreateTableColumnComments() /** * @group DBAL-42 */ - public function testAlterTableColumnComments() + public function testAlterTableColumnComments() : void { $tableDiff = new TableDiff('mytable'); $tableDiff->addedColumns['quota'] = new Column('quota', Type::getType('integer'), ['comment' => 'A comment']); @@ -514,7 +523,7 @@ public function testAlterTableColumnComments() self::assertEquals($this->getAlterTableColumnCommentsSQL(), $this->platform->getAlterTableSQL($tableDiff)); } - public function testCreateTableColumnTypeComments() + public function testCreateTableColumnTypeComments() : void { $table = new Table('test'); $table->addColumn('id', 'integer'); @@ -524,22 +533,31 @@ public function testCreateTableColumnTypeComments() self::assertEquals($this->getCreateTableColumnTypeCommentsSQL(), $this->platform->getCreateTableSQL($table)); } - public function getCreateTableColumnCommentsSQL() + /** + * @return string[] + */ + public function getCreateTableColumnCommentsSQL() : array { $this->markTestSkipped('Platform does not support Column comments.'); } - public function getAlterTableColumnCommentsSQL() + /** + * @return string[] + */ + public function getAlterTableColumnCommentsSQL() : array { $this->markTestSkipped('Platform does not support Column comments.'); } - public function getCreateTableColumnTypeCommentsSQL() + /** + * @return string[] + */ + public function getCreateTableColumnTypeCommentsSQL() : array { $this->markTestSkipped('Platform does not support Column comments.'); } - public function testGetDefaultValueDeclarationSQL() + public function testGetDefaultValueDeclarationSQL() : void { // non-timestamp value will get single quotes $field = [ @@ -569,7 +587,7 @@ public function testGetDefaultValueDeclarationSQLDateTime() : void } } - public function testGetDefaultValueDeclarationSQLForIntegerTypes() + public function testGetDefaultValueDeclarationSQLForIntegerTypes() : void { foreach (['bigint', 'integer', 'smallint'] as $type) { $field = [ @@ -606,7 +624,7 @@ public function testGetDefaultValueDeclarationSQLForDateType() : void /** * @group DBAL-45 */ - public function testKeywordList() + public function testKeywordList() : void { $keywordList = $this->platform->getReservedKeywordsList(); self::assertInstanceOf(KeywordList::class, $keywordList); @@ -617,7 +635,7 @@ public function testKeywordList() /** * @group DBAL-374 */ - public function testQuotedColumnInPrimaryKeyPropagation() + public function testQuotedColumnInPrimaryKeyPropagation() : void { $table = new Table('`quoted`'); $table->addColumn('create', 'string'); @@ -627,18 +645,30 @@ public function testQuotedColumnInPrimaryKeyPropagation() self::assertEquals($this->getQuotedColumnInPrimaryKeySQL(), $sql); } - abstract protected function getQuotedColumnInPrimaryKeySQL(); + /** + * @return string[] + */ + abstract protected function getQuotedColumnInPrimaryKeySQL() : array; - abstract protected function getQuotedColumnInIndexSQL(); + /** + * @return string[] + */ + abstract protected function getQuotedColumnInIndexSQL() : array; - abstract protected function getQuotedNameInIndexSQL(); + /** + * @return string[] + */ + abstract protected function getQuotedNameInIndexSQL() : array; - abstract protected function getQuotedColumnInForeignKeySQL(); + /** + * @return string[] + */ + abstract protected function getQuotedColumnInForeignKeySQL() : array; /** * @group DBAL-374 */ - public function testQuotedColumnInIndexPropagation() + public function testQuotedColumnInIndexPropagation() : void { $table = new Table('`quoted`'); $table->addColumn('create', 'string'); @@ -648,7 +678,7 @@ public function testQuotedColumnInIndexPropagation() self::assertEquals($this->getQuotedColumnInIndexSQL(), $sql); } - public function testQuotedNameInIndexSQL() + public function testQuotedNameInIndexSQL() : void { $table = new Table('test'); $table->addColumn('column1', 'string'); @@ -661,7 +691,7 @@ public function testQuotedNameInIndexSQL() /** * @group DBAL-374 */ - public function testQuotedColumnInForeignKeyPropagation() + public function testQuotedColumnInForeignKeyPropagation() : void { $table = new Table('`quoted`'); $table->addColumn('create', 'string'); @@ -699,7 +729,7 @@ public function testQuotedColumnInForeignKeyPropagation() /** * @group DBAL-1051 */ - public function testQuotesReservedKeywordInUniqueConstraintDeclarationSQL() + public function testQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : void { $index = new Index('select', ['foo'], true); @@ -709,15 +739,12 @@ public function testQuotesReservedKeywordInUniqueConstraintDeclarationSQL() ); } - /** - * @return string - */ - abstract protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(); + abstract protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string; /** * @group DBAL-2270 */ - public function testQuotesReservedKeywordInTruncateTableSQL() + public function testQuotesReservedKeywordInTruncateTableSQL() : void { self::assertSame( $this->getQuotesReservedKeywordInTruncateTableSQL(), @@ -725,15 +752,12 @@ public function testQuotesReservedKeywordInTruncateTableSQL() ); } - /** - * @return string - */ - abstract protected function getQuotesReservedKeywordInTruncateTableSQL(); + abstract protected function getQuotesReservedKeywordInTruncateTableSQL() : string; /** * @group DBAL-1051 */ - public function testQuotesReservedKeywordInIndexDeclarationSQL() + public function testQuotesReservedKeywordInIndexDeclarationSQL() : void { $index = new Index('select', ['foo']); @@ -747,33 +771,24 @@ public function testQuotesReservedKeywordInIndexDeclarationSQL() ); } - /** - * @return string - */ - abstract protected function getQuotesReservedKeywordInIndexDeclarationSQL(); + abstract protected function getQuotesReservedKeywordInIndexDeclarationSQL() : string; - /** - * @return bool - */ - protected function supportsInlineIndexDeclaration() + protected function supportsInlineIndexDeclaration() : bool { return true; } - public function testSupportsCommentOnStatement() + public function testSupportsCommentOnStatement() : void { self::assertSame($this->supportsCommentOnStatement(), $this->platform->supportsCommentOnStatement()); } - /** - * @return bool - */ - protected function supportsCommentOnStatement() + protected function supportsCommentOnStatement() : bool { return false; } - public function testGetCreateSchemaSQL() + public function testGetCreateSchemaSQL() : void { $this->expectException(DBALException::class); @@ -783,7 +798,7 @@ public function testGetCreateSchemaSQL() /** * @group DBAL-585 */ - public function testAlterTableChangeQuotedColumn() + public function testAlterTableChangeQuotedColumn() : void { $tableDiff = new TableDiff('mytable'); $tableDiff->fromTable = new Table('mytable'); @@ -805,7 +820,7 @@ public function testAlterTableChangeQuotedColumn() /** * @group DBAL-563 */ - public function testUsesSequenceEmulatedIdentityColumns() + public function testUsesSequenceEmulatedIdentityColumns() : void { self::assertFalse($this->platform->usesSequenceEmulatedIdentityColumns()); } @@ -813,41 +828,41 @@ public function testUsesSequenceEmulatedIdentityColumns() /** * @group DBAL-563 */ - public function testReturnsIdentitySequenceName() + public function testReturnsIdentitySequenceName() : void { $this->expectException(DBALException::class); $this->platform->getIdentitySequenceName('mytable', 'mycolumn'); } - public function testReturnsBinaryDefaultLength() + public function testReturnsBinaryDefaultLength() : void { self::assertSame($this->getBinaryDefaultLength(), $this->platform->getBinaryDefaultLength()); } - protected function getBinaryDefaultLength() + protected function getBinaryDefaultLength() : int { return 255; } - public function testReturnsBinaryMaxLength() + public function testReturnsBinaryMaxLength() : void { self::assertSame($this->getBinaryMaxLength(), $this->platform->getBinaryMaxLength()); } - protected function getBinaryMaxLength() + protected function getBinaryMaxLength() : int { return 4000; } - public function testReturnsBinaryTypeDeclarationSQL() + public function testReturnsBinaryTypeDeclarationSQL() : void { $this->expectException(DBALException::class); $this->platform->getBinaryTypeDeclarationSQL([]); } - public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() + public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() : void { $this->markTestSkipped('Not applicable to the platform'); } @@ -855,7 +870,7 @@ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() /** * @group DBAL-553 */ - public function hasNativeJsonType() + public function hasNativeJsonType() : void { self::assertFalse($this->platform->hasNativeJsonType()); } @@ -863,7 +878,7 @@ public function hasNativeJsonType() /** * @group DBAL-553 */ - public function testReturnsJsonTypeDeclarationSQL() + public function testReturnsJsonTypeDeclarationSQL() : void { $column = [ 'length' => 666, @@ -880,7 +895,7 @@ public function testReturnsJsonTypeDeclarationSQL() /** * @group DBAL-234 */ - public function testAlterTableRenameIndex() + public function testAlterTableRenameIndex() : void { $tableDiff = new TableDiff('mytable'); $tableDiff->fromTable = new Table('mytable'); @@ -897,9 +912,11 @@ public function testAlterTableRenameIndex() } /** + * @return string[] + * * @group DBAL-234 */ - protected function getAlterTableRenameIndexSQL() + protected function getAlterTableRenameIndexSQL() : array { return [ 'DROP INDEX idx_foo', @@ -910,7 +927,7 @@ protected function getAlterTableRenameIndexSQL() /** * @group DBAL-234 */ - public function testQuotesAlterTableRenameIndex() + public function testQuotesAlterTableRenameIndex() : void { $tableDiff = new TableDiff('table'); $tableDiff->fromTable = new Table('table'); @@ -928,9 +945,11 @@ public function testQuotesAlterTableRenameIndex() } /** + * @return string[] + * * @group DBAL-234 */ - protected function getQuotedAlterTableRenameIndexSQL() + protected function getQuotedAlterTableRenameIndexSQL() : array { return [ 'DROP INDEX "create"', @@ -943,7 +962,7 @@ protected function getQuotedAlterTableRenameIndexSQL() /** * @group DBAL-835 */ - public function testQuotesAlterTableRenameColumn() + public function testQuotesAlterTableRenameColumn() : void { $fromTable = new Table('mytable'); @@ -988,12 +1007,12 @@ public function testQuotesAlterTableRenameColumn() * * @group DBAL-835 */ - abstract protected function getQuotedAlterTableRenameColumnSQL(); + abstract protected function getQuotedAlterTableRenameColumnSQL() : array; /** * @group DBAL-835 */ - public function testQuotesAlterTableChangeColumnLength() + public function testQuotesAlterTableChangeColumnLength() : void { $fromTable = new Table('mytable'); @@ -1030,12 +1049,12 @@ public function testQuotesAlterTableChangeColumnLength() * * @group DBAL-835 */ - abstract protected function getQuotedAlterTableChangeColumnLengthSQL(); + abstract protected function getQuotedAlterTableChangeColumnLengthSQL() : array; /** * @group DBAL-807 */ - public function testAlterTableRenameIndexInSchema() + public function testAlterTableRenameIndexInSchema() : void { $tableDiff = new TableDiff('myschema.mytable'); $tableDiff->fromTable = new Table('myschema.mytable'); @@ -1052,9 +1071,11 @@ public function testAlterTableRenameIndexInSchema() } /** + * @return string[] + * * @group DBAL-807 */ - protected function getAlterTableRenameIndexInSchemaSQL() + protected function getAlterTableRenameIndexInSchemaSQL() : array { return [ 'DROP INDEX idx_foo', @@ -1065,7 +1086,7 @@ protected function getAlterTableRenameIndexInSchemaSQL() /** * @group DBAL-807 */ - public function testQuotesAlterTableRenameIndexInSchema() + public function testQuotesAlterTableRenameIndexInSchema() : void { $tableDiff = new TableDiff('`schema`.table'); $tableDiff->fromTable = new Table('`schema`.table'); @@ -1083,9 +1104,11 @@ public function testQuotesAlterTableRenameIndexInSchema() } /** + * @return string[] + * * @group DBAL-234 */ - protected function getQuotedAlterTableRenameIndexInSchemaSQL() + protected function getQuotedAlterTableRenameIndexInSchemaSQL() : array { return [ 'DROP INDEX "schema"."create"', @@ -1098,7 +1121,7 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() /** * @group DBAL-1237 */ - public function testQuotesDropForeignKeySQL() + public function testQuotesDropForeignKeySQL() : void { if (! $this->platform->supportsForeignKeyConstraints()) { $this->markTestSkipped( @@ -1116,7 +1139,7 @@ public function testQuotesDropForeignKeySQL() self::assertSame($expectedSql, $this->platform->getDropForeignKeySQL($foreignKey, $table)); } - protected function getQuotesDropForeignKeySQL() + protected function getQuotesDropForeignKeySQL() : string { return 'ALTER TABLE "table" DROP FOREIGN KEY "select"'; } @@ -1124,7 +1147,7 @@ protected function getQuotesDropForeignKeySQL() /** * @group DBAL-1237 */ - public function testQuotesDropConstraintSQL() + public function testQuotesDropConstraintSQL() : void { $tableName = 'table'; $table = new Table($tableName); @@ -1136,27 +1159,27 @@ public function testQuotesDropConstraintSQL() self::assertSame($expectedSql, $this->platform->getDropConstraintSQL($constraint, $table)); } - protected function getQuotesDropConstraintSQL() + protected function getQuotesDropConstraintSQL() : string { return 'ALTER TABLE "table" DROP CONSTRAINT "select"'; } - protected function getStringLiteralQuoteCharacter() + protected function getStringLiteralQuoteCharacter() : string { return "'"; } - public function testGetStringLiteralQuoteCharacter() + public function testGetStringLiteralQuoteCharacter() : void { self::assertSame($this->getStringLiteralQuoteCharacter(), $this->platform->getStringLiteralQuoteCharacter()); } - protected function getQuotedCommentOnColumnSQLWithoutQuoteCharacter() + protected function getQuotedCommentOnColumnSQLWithoutQuoteCharacter() : string { return "COMMENT ON COLUMN mytable.id IS 'This is a comment'"; } - public function testGetCommentOnColumnSQLWithoutQuoteCharacter() + public function testGetCommentOnColumnSQLWithoutQuoteCharacter() : void { self::assertEquals( $this->getQuotedCommentOnColumnSQLWithoutQuoteCharacter(), @@ -1164,12 +1187,12 @@ public function testGetCommentOnColumnSQLWithoutQuoteCharacter() ); } - protected function getQuotedCommentOnColumnSQLWithQuoteCharacter() + protected function getQuotedCommentOnColumnSQLWithQuoteCharacter() : string { return "COMMENT ON COLUMN mytable.id IS 'It''s a quote !'"; } - public function testGetCommentOnColumnSQLWithQuoteCharacter() + public function testGetCommentOnColumnSQLWithQuoteCharacter() : void { $c = $this->getStringLiteralQuoteCharacter(); @@ -1184,12 +1207,12 @@ public function testGetCommentOnColumnSQLWithQuoteCharacter() * * @return string[] */ - abstract protected function getCommentOnColumnSQL(); + abstract protected function getCommentOnColumnSQL() : array; /** * @group DBAL-1004 */ - public function testGetCommentOnColumnSQL() + public function testGetCommentOnColumnSQL() : void { self::assertSame( $this->getCommentOnColumnSQL(), @@ -1205,7 +1228,7 @@ public function testGetCommentOnColumnSQL() * @group DBAL-1176 * @dataProvider getGeneratesInlineColumnCommentSQL */ - public function testGeneratesInlineColumnCommentSQL($comment, $expectedSql) + public function testGeneratesInlineColumnCommentSQL(?string $comment, string $expectedSql) : void { if (! $this->platform->supportsInlineColumnComments()) { $this->markTestSkipped(sprintf('%s does not support inline column comments.', get_class($this->platform))); @@ -1214,52 +1237,55 @@ public function testGeneratesInlineColumnCommentSQL($comment, $expectedSql) self::assertSame($expectedSql, $this->platform->getInlineColumnCommentSQL($comment)); } - public function getGeneratesInlineColumnCommentSQL() + /** + * @return mixed[][] + */ + public static function getGeneratesInlineColumnCommentSQL() : iterable { return [ - 'regular comment' => ['Regular comment', $this->getInlineColumnRegularCommentSQL()], + 'regular comment' => ['Regular comment', static::getInlineColumnRegularCommentSQL()], 'comment requiring escaping' => [ sprintf( 'Using inline comment delimiter %s works', - $this->getInlineColumnCommentDelimiter() + static::getInlineColumnCommentDelimiter() ), - $this->getInlineColumnCommentRequiringEscapingSQL(), + static::getInlineColumnCommentRequiringEscapingSQL(), ], - 'empty comment' => ['', $this->getInlineColumnEmptyCommentSQL()], + 'empty comment' => ['', static::getInlineColumnEmptyCommentSQL()], ]; } - protected function getInlineColumnCommentDelimiter() + protected static function getInlineColumnCommentDelimiter() : string { return "'"; } - protected function getInlineColumnRegularCommentSQL() + protected static function getInlineColumnRegularCommentSQL() : string { return "COMMENT 'Regular comment'"; } - protected function getInlineColumnCommentRequiringEscapingSQL() + protected static function getInlineColumnCommentRequiringEscapingSQL() : string { return "COMMENT 'Using inline comment delimiter '' works'"; } - protected function getInlineColumnEmptyCommentSQL() + protected static function getInlineColumnEmptyCommentSQL() : string { return "COMMENT ''"; } - protected function getQuotedStringLiteralWithoutQuoteCharacter() + protected function getQuotedStringLiteralWithoutQuoteCharacter() : string { return "'No quote'"; } - protected function getQuotedStringLiteralWithQuoteCharacter() + protected function getQuotedStringLiteralWithQuoteCharacter() : string { return "'It''s a quote'"; } - protected function getQuotedStringLiteralQuoteCharacter() + protected function getQuotedStringLiteralQuoteCharacter() : string { return "''''"; } @@ -1267,7 +1293,7 @@ protected function getQuotedStringLiteralQuoteCharacter() /** * @group DBAL-1176 */ - public function testThrowsExceptionOnGeneratingInlineColumnCommentSQLIfUnsupported() + public function testThrowsExceptionOnGeneratingInlineColumnCommentSQLIfUnsupported() : void { if ($this->platform->supportsInlineColumnComments()) { $this->markTestSkipped(sprintf('%s supports inline column comments.', get_class($this->platform))); @@ -1280,7 +1306,7 @@ public function testThrowsExceptionOnGeneratingInlineColumnCommentSQLIfUnsupport $this->platform->getInlineColumnCommentSQL('unsupported'); } - public function testQuoteStringLiteral() + public function testQuoteStringLiteral() : void { $c = $this->getStringLiteralQuoteCharacter(); @@ -1301,7 +1327,7 @@ public function testQuoteStringLiteral() /** * @group DBAL-423 */ - public function testReturnsGuidTypeDeclarationSQL() + public function testReturnsGuidTypeDeclarationSQL() : void { $this->expectException(DBALException::class); @@ -1311,7 +1337,7 @@ public function testReturnsGuidTypeDeclarationSQL() /** * @group DBAL-1010 */ - public function testGeneratesAlterTableRenameColumnSQL() + public function testGeneratesAlterTableRenameColumnSQL() : void { $table = new Table('foo'); $table->addColumn( @@ -1334,12 +1360,12 @@ public function testGeneratesAlterTableRenameColumnSQL() /** * @return string[] */ - abstract public function getAlterTableRenameColumnSQL(); + abstract public function getAlterTableRenameColumnSQL() : array; /** * @group DBAL-1016 */ - public function testQuotesTableIdentifiersInAlterTableSQL() + public function testQuotesTableIdentifiersInAlterTableSQL() : void { $table = new Table('"foo"'); $table->addColumn('id', 'integer'); @@ -1376,12 +1402,12 @@ public function testQuotesTableIdentifiersInAlterTableSQL() /** * @return string[] */ - abstract protected function getQuotesTableIdentifiersInAlterTableSQL(); + abstract protected function getQuotesTableIdentifiersInAlterTableSQL() : array; /** * @group DBAL-1090 */ - public function testAlterStringToFixedString() + public function testAlterStringToFixedString() : void { $table = new Table('mytable'); $table->addColumn('name', 'string', ['length' => 2]); @@ -1409,12 +1435,12 @@ public function testAlterStringToFixedString() /** * @return string[] */ - abstract protected function getAlterStringToFixedStringSQL(); + abstract protected function getAlterStringToFixedStringSQL() : array; /** * @group DBAL-1062 */ - public function testGeneratesAlterTableRenameIndexUsedByForeignKeySQL() + public function testGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : void { $foreignTable = new Table('foreign_table'); $foreignTable->addColumn('id', 'integer'); @@ -1442,7 +1468,7 @@ public function testGeneratesAlterTableRenameIndexUsedByForeignKeySQL() /** * @return string[] */ - abstract protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL(); + abstract protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array; /** * @param mixed[] $column @@ -1450,15 +1476,15 @@ abstract protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL * @group DBAL-1082 * @dataProvider getGeneratesDecimalTypeDeclarationSQL */ - public function testGeneratesDecimalTypeDeclarationSQL(array $column, $expectedSql) + public function testGeneratesDecimalTypeDeclarationSQL(array $column, string $expectedSql) : void { self::assertSame($expectedSql, $this->platform->getDecimalTypeDeclarationSQL($column)); } /** - * @return mixed[] + * @return mixed[][] */ - public function getGeneratesDecimalTypeDeclarationSQL() + public static function getGeneratesDecimalTypeDeclarationSQL() : iterable { return [ [[], 'NUMERIC(10, 0)'], @@ -1476,15 +1502,15 @@ public function getGeneratesDecimalTypeDeclarationSQL() * @group DBAL-1082 * @dataProvider getGeneratesFloatDeclarationSQL */ - public function testGeneratesFloatDeclarationSQL(array $column, $expectedSql) + public function testGeneratesFloatDeclarationSQL(array $column, string $expectedSql) : void { self::assertSame($expectedSql, $this->platform->getFloatDeclarationSQL($column)); } /** - * @return mixed[] + * @return mixed[][] */ - public function getGeneratesFloatDeclarationSQL() + public static function getGeneratesFloatDeclarationSQL() : iterable { return [ [[], 'DOUBLE PRECISION'], diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 81d760e30b6..44c28018849 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -16,12 +16,15 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCase { - public function getGenerateTableSql() + public function getGenerateTableSql() : string { return 'CREATE TABLE test (id SERIAL NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'; } - public function getGenerateTableWithMultiColumnUniqueIndexSql() + /** + * {@inheritDoc} + */ + public function getGenerateTableWithMultiColumnUniqueIndexSql() : array { return [ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', @@ -29,7 +32,10 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql() ]; } - public function getGenerateAlterTableSql() + /** + * {@inheritDoc} + */ + public function getGenerateAlterTableSql() : array { return [ 'ALTER TABLE mytable ADD quota INT DEFAULT NULL', @@ -44,17 +50,17 @@ public function getGenerateAlterTableSql() ]; } - public function getGenerateIndexSql() + public function getGenerateIndexSql() : string { return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; } - public function getGenerateForeignKeySql() + public function getGenerateForeignKeySql() : string { return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE'; } - public function testGeneratesForeignKeySqlForNonStandardOptions() + public function testGeneratesForeignKeySqlForNonStandardOptions() : void { $foreignKey = new ForeignKeyConstraint( ['foreign_id'], @@ -129,7 +135,7 @@ public function testGeneratesForeignKeySqlForNonStandardOptions() ); } - public function testGeneratesSqlSnippets() + public function testGeneratesSqlSnippets() : void { self::assertEquals('SIMILAR TO', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct'); self::assertEquals('"', $this->platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct'); @@ -138,7 +144,7 @@ public function testGeneratesSqlSnippets() self::assertEquals('SUBSTRING(column FROM 1 FOR 5)', $this->platform->getSubstringExpression('column', 1, 5), 'Substring expression with length is not correct'); } - public function testGeneratesTransactionCommands() + public function testGeneratesTransactionCommands() : void { self::assertEquals( 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', @@ -158,14 +164,14 @@ public function testGeneratesTransactionCommands() ); } - public function testGeneratesDDLSnippets() + public function testGeneratesDDLSnippets() : void { self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); self::assertEquals('DROP DATABASE foobar', $this->platform->getDropDatabaseSQL('foobar')); self::assertEquals('DROP TABLE foobar', $this->platform->getDropTableSQL('foobar')); } - public function testGenerateTableWithAutoincrement() + public function testGenerateTableWithAutoincrement() : void { $table = new Table('autoinc_table'); $column = $table->addColumn('id', 'integer'); @@ -175,9 +181,9 @@ public function testGenerateTableWithAutoincrement() } /** - * @return string[][] + * @return mixed[][] */ - public static function serialTypes() : array + public static function serialTypes() : iterable { return [ ['integer', 'SERIAL'], @@ -234,7 +240,7 @@ public function testGetDefaultValueDeclarationSQLIgnoresTheDefaultKeyWhenTheFiel self::assertSame('', $sql); } - public function testGeneratesTypeDeclarationForIntegers() + public function testGeneratesTypeDeclarationForIntegers() : void { self::assertEquals( 'INT', @@ -252,7 +258,7 @@ public function testGeneratesTypeDeclarationForIntegers() ); } - public function testGeneratesTypeDeclarationForStrings() + public function testGeneratesTypeDeclarationForStrings() : void { self::assertEquals( 'CHAR(10)', @@ -272,12 +278,12 @@ public function testGeneratesTypeDeclarationForStrings() ); } - public function getGenerateUniqueIndexSql() + public function getGenerateUniqueIndexSql() : string { return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; } - public function testGeneratesSequenceSqlCommands() + public function testGeneratesSequenceSqlCommands() : void { $sequence = new Sequence('myseq', 20, 1); self::assertEquals( @@ -294,27 +300,27 @@ public function testGeneratesSequenceSqlCommands() ); } - public function testDoesNotPreferIdentityColumns() + public function testDoesNotPreferIdentityColumns() : void { self::assertFalse($this->platform->prefersIdentityColumns()); } - public function testPrefersSequences() + public function testPrefersSequences() : void { self::assertTrue($this->platform->prefersSequences()); } - public function testSupportsIdentityColumns() + public function testSupportsIdentityColumns() : void { self::assertTrue($this->platform->supportsIdentityColumns()); } - public function testSupportsSavePoints() + public function testSupportsSavePoints() : void { self::assertTrue($this->platform->supportsSavepoints()); } - public function testSupportsSequences() + public function testSupportsSequences() : void { self::assertTrue($this->platform->supportsSequences()); } @@ -322,24 +328,27 @@ public function testSupportsSequences() /** * {@inheritdoc} */ - protected function supportsCommentOnStatement() + protected function supportsCommentOnStatement() : bool { return true; } - public function testModifyLimitQuery() + public function testModifyLimitQuery() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); self::assertEquals('SELECT * FROM user LIMIT 10', $sql); } - public function testModifyLimitQueryWithEmptyOffset() + public function testModifyLimitQueryWithEmptyOffset() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); self::assertEquals('SELECT * FROM user LIMIT 10', $sql); } - public function getCreateTableColumnCommentsSQL() + /** + * {@inheritDoc} + */ + public function getCreateTableColumnCommentsSQL() : array { return [ 'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))', @@ -347,7 +356,10 @@ public function getCreateTableColumnCommentsSQL() ]; } - public function getAlterTableColumnCommentsSQL() + /** + * {@inheritDoc} + */ + public function getAlterTableColumnCommentsSQL() : array { return [ 'ALTER TABLE mytable ADD quota INT NOT NULL', @@ -357,7 +369,10 @@ public function getAlterTableColumnCommentsSQL() ]; } - public function getCreateTableColumnTypeCommentsSQL() + /** + * {@inheritDoc} + */ + public function getCreateTableColumnTypeCommentsSQL() : array { return [ 'CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))', @@ -365,12 +380,18 @@ public function getCreateTableColumnTypeCommentsSQL() ]; } - protected function getQuotedColumnInPrimaryKeySQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInPrimaryKeySQL() : array { return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))']; } - protected function getQuotedColumnInIndexSQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInIndexSQL() : array { return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', @@ -378,7 +399,10 @@ protected function getQuotedColumnInIndexSQL() ]; } - protected function getQuotedNameInIndexSQL() + /** + * {@inheritDoc} + */ + protected function getQuotedNameInIndexSQL() : array { return [ 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', @@ -386,7 +410,10 @@ protected function getQuotedNameInIndexSQL() ]; } - protected function getQuotedColumnInForeignKeySQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInForeignKeySQL() : array { return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL)', @@ -397,20 +424,17 @@ protected function getQuotedColumnInForeignKeySQL() } /** - * @param string $databaseValue - * @param string $preparedStatementValue - * @param int $integerValue - * @param bool $booleanValue + * @param string|bool $databaseValue * * @group DBAL-457 * @dataProvider pgBooleanProvider */ public function testConvertBooleanAsLiteralStrings( $databaseValue, - $preparedStatementValue, - $integerValue, - $booleanValue - ) { + string $preparedStatementValue, + ?int $integerValue, + ?bool $booleanValue + ) : void { $platform = $this->createPlatform(); self::assertEquals($preparedStatementValue, $platform->convertBooleans($databaseValue)); @@ -419,7 +443,7 @@ public function testConvertBooleanAsLiteralStrings( /** * @group DBAL-457 */ - public function testConvertBooleanAsLiteralIntegers() + public function testConvertBooleanAsLiteralIntegers() : void { $platform = $this->createPlatform(); $platform->setUseBooleanTrueFalseStrings(false); @@ -432,20 +456,17 @@ public function testConvertBooleanAsLiteralIntegers() } /** - * @param string $databaseValue - * @param string $preparedStatementValue - * @param int $integerValue - * @param bool $booleanValue + * @param string|bool $databaseValue * * @group DBAL-630 * @dataProvider pgBooleanProvider */ public function testConvertBooleanAsDatabaseValueStrings( $databaseValue, - $preparedStatementValue, - $integerValue, - $booleanValue - ) { + string $preparedStatementValue, + ?int $integerValue, + ?bool $booleanValue + ) : void { $platform = $this->createPlatform(); self::assertSame($integerValue, $platform->convertBooleansToDatabaseValue($booleanValue)); @@ -454,7 +475,7 @@ public function testConvertBooleanAsDatabaseValueStrings( /** * @group DBAL-630 */ - public function testConvertBooleanAsDatabaseValueIntegers() + public function testConvertBooleanAsDatabaseValueIntegers() : void { $platform = $this->createPlatform(); $platform->setUseBooleanTrueFalseStrings(false); @@ -464,21 +485,18 @@ public function testConvertBooleanAsDatabaseValueIntegers() } /** - * @param string $databaseValue - * @param string $prepareStatementValue - * @param int $integerValue - * @param bool $booleanValue + * @param string|bool $databaseValue * * @dataProvider pgBooleanProvider */ - public function testConvertFromBoolean($databaseValue, $prepareStatementValue, $integerValue, $booleanValue) + public function testConvertFromBoolean($databaseValue, string $prepareStatementValue, ?int $integerValue, ?bool $booleanValue) : void { $platform = $this->createPlatform(); self::assertSame($booleanValue, $platform->convertFromBoolean($databaseValue)); } - public function testThrowsExceptionWithInvalidBooleanLiteral() + public function testThrowsExceptionWithInvalidBooleanLiteral() : void { $platform = $this->createPlatform(); @@ -488,14 +506,14 @@ public function testThrowsExceptionWithInvalidBooleanLiteral() $platform->convertBooleansToDatabaseValue('my-bool'); } - public function testGetCreateSchemaSQL() + public function testGetCreateSchemaSQL() : void { $schemaName = 'schema'; $sql = $this->platform->getCreateSchemaSQL($schemaName); self::assertEquals('CREATE SCHEMA ' . $schemaName, $sql); } - public function testAlterDecimalPrecisionScale() + public function testAlterDecimalPrecisionScale() : void { $table = new Table('mytable'); $table->addColumn('dfoo1', 'decimal'); @@ -557,7 +575,7 @@ public function testAlterDecimalPrecisionScale() /** * @group DBAL-365 */ - public function testDroppingConstraintsBeforeColumns() + public function testDroppingConstraintsBeforeColumns() : void { $newTable = new Table('mytable'); $newTable->addColumn('id', 'integer'); @@ -584,7 +602,7 @@ public function testDroppingConstraintsBeforeColumns() /** * @group DBAL-563 */ - public function testUsesSequenceEmulatedIdentityColumns() + public function testUsesSequenceEmulatedIdentityColumns() : void { self::assertTrue($this->platform->usesSequenceEmulatedIdentityColumns()); } @@ -592,7 +610,7 @@ public function testUsesSequenceEmulatedIdentityColumns() /** * @group DBAL-563 */ - public function testReturnsIdentitySequenceName() + public function testReturnsIdentitySequenceName() : void { self::assertSame('mytable_mycolumn_seq', $this->platform->getIdentitySequenceName('mytable', 'mycolumn')); } @@ -601,30 +619,33 @@ public function testReturnsIdentitySequenceName() * @dataProvider dataCreateSequenceWithCache * @group DBAL-139 */ - public function testCreateSequenceWithCache($cacheSize, $expectedSql) + public function testCreateSequenceWithCache(int $cacheSize, string $expectedSql) : void { $sequence = new Sequence('foo', 1, 1, $cacheSize); self::assertStringContainsString($expectedSql, $this->platform->getCreateSequenceSQL($sequence)); } - public function dataCreateSequenceWithCache() + /** + * @return mixed[][] + */ + public static function dataCreateSequenceWithCache() : iterable { return [ [3, 'CACHE 3'], ]; } - protected function getBinaryDefaultLength() + protected function getBinaryDefaultLength() : int { return 0; } - protected function getBinaryMaxLength() + protected function getBinaryMaxLength() : int { return 0; } - public function testReturnsBinaryTypeDeclarationSQL() + public function testReturnsBinaryTypeDeclarationSQL() : void { self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL([])); self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); @@ -635,7 +656,7 @@ public function testReturnsBinaryTypeDeclarationSQL() self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 9999999])); } - public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() + public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() : void { $table1 = new Table('mytable'); $table1->addColumn('column_varbinary', 'binary'); @@ -676,17 +697,21 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() } /** + * {@inheritDoc} + * * @group DBAL-234 */ - protected function getAlterTableRenameIndexSQL() + protected function getAlterTableRenameIndexSQL() : array { return ['ALTER INDEX idx_foo RENAME TO idx_bar']; } /** + * {@inheritDoc} + * * @group DBAL-234 */ - protected function getQuotedAlterTableRenameIndexSQL() + protected function getQuotedAlterTableRenameIndexSQL() : array { return [ 'ALTER INDEX "create" RENAME TO "select"', @@ -697,9 +722,9 @@ protected function getQuotedAlterTableRenameIndexSQL() /** * PostgreSQL boolean strings provider * - * @return mixed[] + * @return mixed[][] */ - public function pgBooleanProvider() + public static function pgBooleanProvider() : iterable { return [ // Database value, prepared statement value, boolean integer value, boolean value. @@ -726,7 +751,7 @@ public function pgBooleanProvider() /** * {@inheritdoc} */ - protected function getQuotedAlterTableRenameColumnSQL() + protected function getQuotedAlterTableRenameColumnSQL() : array { return [ 'ALTER TABLE mytable RENAME COLUMN unquoted1 TO unquoted', @@ -744,7 +769,7 @@ protected function getQuotedAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotedAlterTableChangeColumnLengthSQL() + protected function getQuotedAlterTableChangeColumnLengthSQL() : array { return [ 'ALTER TABLE mytable ALTER unquoted1 TYPE VARCHAR(255)', @@ -757,17 +782,21 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() } /** + * {@inheritDoc} + * * @group DBAL-807 */ - protected function getAlterTableRenameIndexInSchemaSQL() + protected function getAlterTableRenameIndexInSchemaSQL() : array { return ['ALTER INDEX myschema.idx_foo RENAME TO idx_bar']; } /** + * {@inheritDoc} + * * @group DBAL-807 */ - protected function getQuotedAlterTableRenameIndexInSchemaSQL() + protected function getQuotedAlterTableRenameIndexInSchemaSQL() : array { return [ 'ALTER INDEX "schema"."create" RENAME TO "select"', @@ -775,12 +804,12 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() ]; } - protected function getQuotesDropForeignKeySQL() + protected function getQuotesDropForeignKeySQL() : string { return 'ALTER TABLE "table" DROP CONSTRAINT "select"'; } - public function testGetNullCommentOnColumnSQL() + public function testGetNullCommentOnColumnSQL() : void { self::assertEquals( 'COMMENT ON COLUMN mytable.id IS NULL', @@ -791,7 +820,7 @@ public function testGetNullCommentOnColumnSQL() /** * @group DBAL-423 */ - public function testReturnsGuidTypeDeclarationSQL() + public function testReturnsGuidTypeDeclarationSQL() : void { self::assertSame('UUID', $this->platform->getGuidTypeDeclarationSQL([])); } @@ -799,7 +828,7 @@ public function testReturnsGuidTypeDeclarationSQL() /** * {@inheritdoc} */ - public function getAlterTableRenameColumnSQL() + public function getAlterTableRenameColumnSQL() : array { return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; } @@ -807,7 +836,7 @@ public function getAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotesTableIdentifiersInAlterTableSQL() + protected function getQuotesTableIdentifiersInAlterTableSQL() : array { return [ 'ALTER TABLE "foo" DROP CONSTRAINT fk1', @@ -827,7 +856,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() /** * {@inheritdoc} */ - protected function getCommentOnColumnSQL() + protected function getCommentOnColumnSQL() : array { return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', @@ -839,7 +868,7 @@ protected function getCommentOnColumnSQL() /** * @group DBAL-1004 */ - public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() + public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() : void { $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]); $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]); @@ -858,7 +887,7 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() /** * @group 3158 */ - public function testAltersTableColumnCommentIfRequiredByType() + public function testAltersTableColumnCommentIfRequiredByType() : void { $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('datetime'))]); $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('datetime_immutable'))]); @@ -881,7 +910,7 @@ public function testAltersTableColumnCommentIfRequiredByType() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() + protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string { return 'CONSTRAINT "select" UNIQUE (foo)'; } @@ -889,7 +918,7 @@ protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInIndexDeclarationSQL() + protected function getQuotesReservedKeywordInIndexDeclarationSQL() : string { return 'INDEX "select" (foo)'; } @@ -897,7 +926,7 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInTruncateTableSQL() + protected function getQuotesReservedKeywordInTruncateTableSQL() : string { return 'TRUNCATE "select"'; } @@ -905,7 +934,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() /** * {@inheritdoc} */ - protected function getAlterStringToFixedStringSQL() + protected function getAlterStringToFixedStringSQL() : array { return ['ALTER TABLE mytable ALTER name TYPE CHAR(2)']; } @@ -913,7 +942,7 @@ protected function getAlterStringToFixedStringSQL() /** * {@inheritdoc} */ - protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() + protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array { return ['ALTER INDEX idx_foo RENAME TO idx_foo_renamed']; } @@ -921,7 +950,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() /** * @group DBAL-1142 */ - public function testInitializesTsvectorTypeMapping() + public function testInitializesTsvectorTypeMapping() : void { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('tsvector')); self::assertEquals('text', $this->platform->getDoctrineTypeMapping('tsvector')); @@ -930,7 +959,7 @@ public function testInitializesTsvectorTypeMapping() /** * @group DBAL-1220 */ - public function testReturnsDisallowDatabaseConnectionsSQL() + public function testReturnsDisallowDatabaseConnectionsSQL() : void { self::assertSame( "UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'foo'", @@ -941,7 +970,7 @@ public function testReturnsDisallowDatabaseConnectionsSQL() /** * @group DBAL-1220 */ - public function testReturnsCloseActiveDatabaseConnectionsSQL() + public function testReturnsCloseActiveDatabaseConnectionsSQL() : void { self::assertSame( "SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = 'foo'", @@ -952,7 +981,7 @@ public function testReturnsCloseActiveDatabaseConnectionsSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableForeignKeysSQL() + public function testQuotesTableNameInListTableForeignKeysSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -963,7 +992,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() /** * @group DBAL-2436 */ - public function testQuotesSchemaNameInListTableForeignKeysSQL() + public function testQuotesSchemaNameInListTableForeignKeysSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -974,7 +1003,7 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableConstraintsSQL() + public function testQuotesTableNameInListTableConstraintsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -985,7 +1014,7 @@ public function testQuotesTableNameInListTableConstraintsSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableIndexesSQL() + public function testQuotesTableNameInListTableIndexesSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -996,7 +1025,7 @@ public function testQuotesTableNameInListTableIndexesSQL() /** * @group DBAL-2436 */ - public function testQuotesSchemaNameInListTableIndexesSQL() + public function testQuotesSchemaNameInListTableIndexesSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1007,7 +1036,7 @@ public function testQuotesSchemaNameInListTableIndexesSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableColumnsSQL() + public function testQuotesTableNameInListTableColumnsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1018,7 +1047,7 @@ public function testQuotesTableNameInListTableColumnsSQL() /** * @group DBAL-2436 */ - public function testQuotesSchemaNameInListTableColumnsSQL() + public function testQuotesSchemaNameInListTableColumnsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1029,7 +1058,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL() /** * @group DBAL-2436 */ - public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() + public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index db36f8c7ca6..46627bd8cf2 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -14,12 +14,15 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCase { - public function getGenerateTableSql() + public function getGenerateTableSql() : string { return 'CREATE TABLE test (id INT IDENTITY NOT NULL, test NVARCHAR(255), PRIMARY KEY (id))'; } - public function getGenerateTableWithMultiColumnUniqueIndexSql() + /** + * {@inheritDoc} + */ + public function getGenerateTableWithMultiColumnUniqueIndexSql() : array { return [ 'CREATE TABLE test (foo NVARCHAR(255), bar NVARCHAR(255))', @@ -27,7 +30,10 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql() ]; } - public function getGenerateAlterTableSql() + /** + * {@inheritDoc} + */ + public function getGenerateAlterTableSql() : array { return [ 'ALTER TABLE mytable ADD quota INT', @@ -47,14 +53,14 @@ public function getGenerateAlterTableSql() ]; } - public function testDoesNotSupportRegexp() + public function testDoesNotSupportRegexp() : void { $this->expectException(DBALException::class); $this->platform->getRegexpExpression(); } - public function testGeneratesSqlSnippets() + public function testGeneratesSqlSnippets() : void { self::assertEquals('CONVERT(date, GETDATE())', $this->platform->getCurrentDateSQL()); self::assertEquals('CONVERT(time, GETDATE())', $this->platform->getCurrentTimeSQL()); @@ -63,7 +69,7 @@ public function testGeneratesSqlSnippets() self::assertEquals('(column1 + column2 + column3)', $this->platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct'); } - public function testGeneratesTransactionsCommands() + public function testGeneratesTransactionsCommands() : void { self::assertEquals( 'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', @@ -83,7 +89,7 @@ public function testGeneratesTransactionsCommands() ); } - public function testGeneratesDDLSnippets() + public function testGeneratesDDLSnippets() : void { $dropDatabaseExpectation = 'DROP DATABASE foobar'; @@ -93,7 +99,7 @@ public function testGeneratesDDLSnippets() self::assertEquals('DROP TABLE foobar', $this->platform->getDropTableSQL('foobar')); } - public function testGeneratesTypeDeclarationForIntegers() + public function testGeneratesTypeDeclarationForIntegers() : void { self::assertEquals( 'INT', @@ -111,7 +117,7 @@ public function testGeneratesTypeDeclarationForIntegers() ); } - public function testGeneratesTypeDeclarationsForStrings() + public function testGeneratesTypeDeclarationsForStrings() : void { self::assertEquals( 'NCHAR(10)', @@ -136,47 +142,47 @@ public function testGeneratesTypeDeclarationsForStrings() ); } - public function testPrefersIdentityColumns() + public function testPrefersIdentityColumns() : void { self::assertTrue($this->platform->prefersIdentityColumns()); } - public function testSupportsIdentityColumns() + public function testSupportsIdentityColumns() : void { self::assertTrue($this->platform->supportsIdentityColumns()); } - public function testSupportsCreateDropDatabase() + public function testSupportsCreateDropDatabase() : void { self::assertTrue($this->platform->supportsCreateDropDatabase()); } - public function testSupportsSchemas() + public function testSupportsSchemas() : void { self::assertTrue($this->platform->supportsSchemas()); } - public function testDoesNotSupportSavePoints() + public function testDoesNotSupportSavePoints() : void { self::assertTrue($this->platform->supportsSavepoints()); } - public function getGenerateIndexSql() + public function getGenerateIndexSql() : string { return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; } - public function getGenerateUniqueIndexSql() + public function getGenerateUniqueIndexSql() : string { return 'CREATE UNIQUE INDEX index_name ON test (test, test2) WHERE test IS NOT NULL AND test2 IS NOT NULL'; } - public function getGenerateForeignKeySql() + public function getGenerateForeignKeySql() : string { return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; } - public function testModifyLimitQuery() + public function testModifyLimitQuery() : void { $querySql = 'SELECT * FROM user'; $alteredSql = 'SELECT TOP 10 * FROM user'; @@ -184,7 +190,7 @@ public function testModifyLimitQuery() $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } - public function testModifyLimitQueryWithEmptyOffset() + public function testModifyLimitQueryWithEmptyOffset() : void { $querySql = 'SELECT * FROM user'; $alteredSql = 'SELECT TOP 10 * FROM user'; @@ -192,7 +198,7 @@ public function testModifyLimitQueryWithEmptyOffset() $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } - public function testModifyLimitQueryWithOffset() + public function testModifyLimitQueryWithOffset() : void { if (! $this->platform->supportsLimitOffset()) { $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->platform->getName())); @@ -205,7 +211,7 @@ public function testModifyLimitQueryWithOffset() $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); } - public function testModifyLimitQueryWithAscOrderBy() + public function testModifyLimitQueryWithAscOrderBy() : void { $querySql = 'SELECT * FROM user ORDER BY username ASC'; $alteredSql = 'SELECT TOP 10 * FROM user ORDER BY username ASC'; @@ -214,7 +220,7 @@ public function testModifyLimitQueryWithAscOrderBy() $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } - public function testModifyLimitQueryWithLowercaseOrderBy() + public function testModifyLimitQueryWithLowercaseOrderBy() : void { $querySql = 'SELECT * FROM user order by username'; $alteredSql = 'SELECT TOP 10 * FROM user order by username'; @@ -222,7 +228,7 @@ public function testModifyLimitQueryWithLowercaseOrderBy() $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } - public function testModifyLimitQueryWithDescOrderBy() + public function testModifyLimitQueryWithDescOrderBy() : void { $querySql = 'SELECT * FROM user ORDER BY username DESC'; $alteredSql = 'SELECT TOP 10 * FROM user ORDER BY username DESC'; @@ -230,7 +236,7 @@ public function testModifyLimitQueryWithDescOrderBy() $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } - public function testModifyLimitQueryWithMultipleOrderBy() + public function testModifyLimitQueryWithMultipleOrderBy() : void { $querySql = 'SELECT * FROM user ORDER BY username DESC, usereamil ASC'; $alteredSql = 'SELECT TOP 10 * FROM user ORDER BY username DESC, usereamil ASC'; @@ -238,7 +244,7 @@ public function testModifyLimitQueryWithMultipleOrderBy() $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } - public function testModifyLimitQueryWithSubSelect() + public function testModifyLimitQueryWithSubSelect() : void { $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result'; $alteredSql = 'SELECT TOP 10 * FROM (SELECT u.id as uid, u.name as uname) dctrn_result'; @@ -246,7 +252,7 @@ public function testModifyLimitQueryWithSubSelect() $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } - public function testModifyLimitQueryWithSubSelectAndOrder() + public function testModifyLimitQueryWithSubSelectAndOrder() : void { $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC) dctrn_result'; $alteredSql = 'SELECT TOP 10 * FROM (SELECT u.id as uid, u.name as uname) dctrn_result'; @@ -259,7 +265,7 @@ public function testModifyLimitQueryWithSubSelectAndOrder() $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } - public function testModifyLimitQueryWithSubSelectAndMultipleOrder() + public function testModifyLimitQueryWithSubSelectAndMultipleOrder() : void { if (! $this->platform->supportsLimitOffset()) { $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->platform->getName())); @@ -281,7 +287,7 @@ public function testModifyLimitQueryWithSubSelectAndMultipleOrder() $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); } - public function testModifyLimitQueryWithFromColumnNames() + public function testModifyLimitQueryWithFromColumnNames() : void { $querySql = 'SELECT a.fromFoo, fromBar FROM foo'; $alteredSql = 'SELECT TOP 10 a.fromFoo, fromBar FROM foo'; @@ -292,7 +298,7 @@ public function testModifyLimitQueryWithFromColumnNames() /** * @group DBAL-927 */ - public function testModifyLimitQueryWithExtraLongQuery() + public function testModifyLimitQueryWithExtraLongQuery() : void { $query = 'SELECT table1.column1, table2.column2, table3.column3, table4.column4, table5.column5, table6.column6, table7.column7, table8.column8 FROM table1, table2, table3, table4, table5, table6, table7, table8 '; $query .= 'WHERE (table1.column1 = table2.column2) AND (table1.column1 = table3.column3) AND (table1.column1 = table4.column4) AND (table1.column1 = table5.column5) AND (table1.column1 = table6.column6) AND (table1.column1 = table7.column7) AND (table1.column1 = table8.column8) AND (table2.column2 = table3.column3) AND (table2.column2 = table4.column4) AND (table2.column2 = table5.column5) AND (table2.column2 = table6.column6) '; @@ -311,7 +317,7 @@ public function testModifyLimitQueryWithExtraLongQuery() /** * @group DDC-2470 */ - public function testModifyLimitQueryWithOrderByClause() + public function testModifyLimitQueryWithOrderByClause() : void { if (! $this->platform->supportsLimitOffset()) { $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->platform->getName())); @@ -327,7 +333,7 @@ public function testModifyLimitQueryWithOrderByClause() /** * @group DBAL-713 */ - public function testModifyLimitQueryWithSubSelectInSelectList() + public function testModifyLimitQueryWithSubSelectInSelectList() : void { $querySql = 'SELECT ' . 'u.id, ' . @@ -351,7 +357,7 @@ public function testModifyLimitQueryWithSubSelectInSelectList() /** * @group DBAL-713 */ - public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() + public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() : void { if (! $this->platform->supportsLimitOffset()) { $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->platform->getName())); @@ -380,7 +386,7 @@ public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() /** * @group DBAL-834 */ - public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() + public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() : void { $querySql = 'SELECT ' . 'MAX(heading_id) aliased, ' . @@ -401,7 +407,7 @@ public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() /** * @throws DBALException */ - public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBaseTable() + public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBaseTable() : void { $querySql = 'SELECT DISTINCT id_0, name_1 ' . 'FROM (' @@ -425,7 +431,7 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBas /** * @throws DBALException */ - public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoinTable() + public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoinTable() : void { $querySql = 'SELECT DISTINCT id_0, name_1 ' . 'FROM (' @@ -449,7 +455,7 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoi /** * @throws DBALException */ - public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBothTables() + public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBothTables() : void { $querySql = 'SELECT DISTINCT id_0, name_1, foo_2 ' . 'FROM (' @@ -470,7 +476,7 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBo $this->expectCteWithMaxRowNum($alteredSql, 5, $sql); } - public function testModifyLimitSubquerySimple() + public function testModifyLimitSubquerySimple() : void { $querySql = 'SELECT DISTINCT id_0 FROM ' . '(SELECT k0_.id AS id_0, k0_.field AS field_1 ' @@ -484,7 +490,7 @@ public function testModifyLimitSubquerySimple() /** * @group DDC-1360 */ - public function testQuoteIdentifier() + public function testQuoteIdentifier() : void { self::assertEquals('[fo][o]', $this->platform->quoteIdentifier('fo]o')); self::assertEquals('[test]', $this->platform->quoteIdentifier('test')); @@ -494,7 +500,7 @@ public function testQuoteIdentifier() /** * @group DDC-1360 */ - public function testQuoteSingleIdentifier() + public function testQuoteSingleIdentifier() : void { self::assertEquals('[fo][o]', $this->platform->quoteSingleIdentifier('fo]o')); self::assertEquals('[test]', $this->platform->quoteSingleIdentifier('test')); @@ -504,7 +510,7 @@ public function testQuoteSingleIdentifier() /** * @group DBAL-220 */ - public function testCreateClusteredIndex() + public function testCreateClusteredIndex() : void { $idx = new Index('idx', ['id']); $idx->addFlag('clustered'); @@ -514,7 +520,7 @@ public function testCreateClusteredIndex() /** * @group DBAL-220 */ - public function testCreateNonClusteredPrimaryKeyInTable() + public function testCreateNonClusteredPrimaryKeyInTable() : void { $table = new Table('tbl'); $table->addColumn('id', 'integer'); @@ -527,25 +533,31 @@ public function testCreateNonClusteredPrimaryKeyInTable() /** * @group DBAL-220 */ - public function testCreateNonClusteredPrimaryKey() + public function testCreateNonClusteredPrimaryKey() : void { $idx = new Index('idx', ['id'], false, true); $idx->addFlag('nonclustered'); self::assertEquals('ALTER TABLE tbl ADD PRIMARY KEY NONCLUSTERED (id)', $this->platform->getCreatePrimaryKeySQL($idx, 'tbl')); } - public function testAlterAddPrimaryKey() + public function testAlterAddPrimaryKey() : void { $idx = new Index('idx', ['id'], false, true); self::assertEquals('ALTER TABLE tbl ADD PRIMARY KEY (id)', $this->platform->getCreateIndexSQL($idx, 'tbl')); } - protected function getQuotedColumnInPrimaryKeySQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInPrimaryKeySQL() : array { return ['CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, PRIMARY KEY ([create]))']; } - protected function getQuotedColumnInIndexSQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInIndexSQL() : array { return [ 'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL)', @@ -553,7 +565,10 @@ protected function getQuotedColumnInIndexSQL() ]; } - protected function getQuotedNameInIndexSQL() + /** + * {@inheritDoc} + */ + protected function getQuotedNameInIndexSQL() : array { return [ 'CREATE TABLE test (column1 NVARCHAR(255) NOT NULL)', @@ -561,7 +576,10 @@ protected function getQuotedNameInIndexSQL() ]; } - protected function getQuotedColumnInForeignKeySQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInForeignKeySQL() : array { return [ 'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, foo NVARCHAR(255) NOT NULL, [bar] NVARCHAR(255) NOT NULL)', @@ -571,14 +589,14 @@ protected function getQuotedColumnInForeignKeySQL() ]; } - public function testGetCreateSchemaSQL() + public function testGetCreateSchemaSQL() : void { $schemaName = 'schema'; $sql = $this->platform->getCreateSchemaSQL($schemaName); self::assertEquals('CREATE SCHEMA ' . $schemaName, $sql); } - public function testCreateTableWithSchemaColumnComments() + public function testCreateTableWithSchemaColumnComments() : void { $table = new Table('testschema.test'); $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); @@ -592,7 +610,7 @@ public function testCreateTableWithSchemaColumnComments() self::assertEquals($expectedSql, $this->platform->getCreateTableSQL($table)); } - public function testAlterTableWithSchemaColumnComments() + public function testAlterTableWithSchemaColumnComments() : void { $tableDiff = new TableDiff('testschema.mytable'); $tableDiff->addedColumns['quota'] = new Column('quota', Type::getType('integer'), ['comment' => 'A comment']); @@ -605,7 +623,7 @@ public function testAlterTableWithSchemaColumnComments() self::assertEquals($expectedSql, $this->platform->getAlterTableSQL($tableDiff)); } - public function testAlterTableWithSchemaDropColumnComments() + public function testAlterTableWithSchemaDropColumnComments() : void { $tableDiff = new TableDiff('testschema.mytable'); $tableDiff->changedColumns['quota'] = new ColumnDiff( @@ -620,7 +638,7 @@ public function testAlterTableWithSchemaDropColumnComments() self::assertEquals($expectedSql, $this->platform->getAlterTableSQL($tableDiff)); } - public function testAlterTableWithSchemaUpdateColumnComments() + public function testAlterTableWithSchemaUpdateColumnComments() : void { $tableDiff = new TableDiff('testschema.mytable'); $tableDiff->changedColumns['quota'] = new ColumnDiff( @@ -636,9 +654,11 @@ public function testAlterTableWithSchemaUpdateColumnComments() } /** + * {@inheritDoc} + * * @group DBAL-543 */ - public function getCreateTableColumnCommentsSQL() + public function getCreateTableColumnCommentsSQL() : array { return [ 'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))', @@ -647,9 +667,11 @@ public function getCreateTableColumnCommentsSQL() } /** + * {@inheritDoc} + * * @group DBAL-543 */ - public function getAlterTableColumnCommentsSQL() + public function getAlterTableColumnCommentsSQL() : array { return [ 'ALTER TABLE mytable ADD quota INT NOT NULL', @@ -660,9 +682,11 @@ public function getAlterTableColumnCommentsSQL() } /** + * {@inheritDoc} + * * @group DBAL-543 */ - public function getCreateTableColumnTypeCommentsSQL() + public function getCreateTableColumnTypeCommentsSQL() : array { return [ 'CREATE TABLE test (id INT NOT NULL, data VARCHAR(MAX) NOT NULL, PRIMARY KEY (id))', @@ -673,7 +697,7 @@ public function getCreateTableColumnTypeCommentsSQL() /** * @group DBAL-543 */ - public function testGeneratesCreateTableSQLWithColumnComments() + public function testGeneratesCreateTableSQLWithColumnComments() : void { $table = new Table('mytable'); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -712,7 +736,7 @@ public function testGeneratesCreateTableSQLWithColumnComments() * @group DBAL-543 * @group DBAL-1011 */ - public function testGeneratesAlterTableSQLWithColumnComments() + public function testGeneratesAlterTableSQLWithColumnComments() : void { $table = new Table('mytable'); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -894,7 +918,7 @@ public function testGeneratesAlterTableSQLWithColumnComments() /** * @group DBAL-122 */ - public function testInitializesDoctrineTypeMappings() + public function testInitializesDoctrineTypeMappings() : void { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('bigint')); self::assertSame('bigint', $this->platform->getDoctrineTypeMapping('bigint')); @@ -972,12 +996,12 @@ public function testInitializesDoctrineTypeMappings() self::assertSame('guid', $this->platform->getDoctrineTypeMapping('uniqueidentifier')); } - protected function getBinaryMaxLength() + protected function getBinaryMaxLength() : int { return 8000; } - public function testReturnsBinaryTypeDeclarationSQL() + public function testReturnsBinaryTypeDeclarationSQL() : void { self::assertSame('VARBINARY(255)', $this->platform->getBinaryTypeDeclarationSQL([])); self::assertSame('VARBINARY(255)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); @@ -992,24 +1016,28 @@ public function testReturnsBinaryTypeDeclarationSQL() * @group legacy * @expectedDeprecation Binary field length 8001 is greater than supported by the platform (8000). Reduce the field length or use a BLOB field instead. */ - public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() + public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() : void { self::assertSame('VARBINARY(MAX)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 8001])); self::assertSame('VARBINARY(MAX)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 8001])); } /** + * {@inheritDoc} + * * @group DBAL-234 */ - protected function getAlterTableRenameIndexSQL() + protected function getAlterTableRenameIndexSQL() : array { return ["EXEC sp_RENAME N'mytable.idx_foo', N'idx_bar', N'INDEX'"]; } /** + * {@inheritDoc} + * * @group DBAL-234 */ - protected function getQuotedAlterTableRenameIndexSQL() + protected function getQuotedAlterTableRenameIndexSQL() : array { return [ "EXEC sp_RENAME N'[table].[create]', N'[select]', N'INDEX'", @@ -1020,7 +1048,7 @@ protected function getQuotedAlterTableRenameIndexSQL() /** * @group DBAL-825 */ - public function testChangeColumnsTypeWithDefaultValue() + public function testChangeColumnsTypeWithDefaultValue() : void { $tableName = 'column_def_change_type'; $table = new Table($tableName); @@ -1062,7 +1090,7 @@ public function testChangeColumnsTypeWithDefaultValue() /** * {@inheritdoc} */ - protected function getQuotedAlterTableRenameColumnSQL() + protected function getQuotedAlterTableRenameColumnSQL() : array { return [ "sp_RENAME 'mytable.unquoted1', 'unquoted', 'COLUMN'", @@ -1080,23 +1108,27 @@ protected function getQuotedAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotedAlterTableChangeColumnLengthSQL() + protected function getQuotedAlterTableChangeColumnLengthSQL() : array { $this->markTestIncomplete('Not implemented yet'); } /** + * {@inheritDoc} + * * @group DBAL-807 */ - protected function getAlterTableRenameIndexInSchemaSQL() + protected function getAlterTableRenameIndexInSchemaSQL() : array { return ["EXEC sp_RENAME N'myschema.mytable.idx_foo', N'idx_bar', N'INDEX'"]; } /** + * {@inheritDoc} + * * @group DBAL-807 */ - protected function getQuotedAlterTableRenameIndexInSchemaSQL() + protected function getQuotedAlterTableRenameIndexInSchemaSQL() : array { return [ "EXEC sp_RENAME N'[schema].[table].[create]', N'[select]', N'INDEX'", @@ -1104,26 +1136,31 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() ]; } - protected function getQuotesDropForeignKeySQL() + protected function getQuotesDropForeignKeySQL() : string { return 'ALTER TABLE [table] DROP CONSTRAINT [select]'; } - protected function getQuotesDropConstraintSQL() + protected function getQuotesDropConstraintSQL() : string { return 'ALTER TABLE [table] DROP CONSTRAINT [select]'; } /** + * @param mixed[] $column + * * @dataProvider getGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL * @group DBAL-830 */ - public function testGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL($table, $column, $expectedSql) + public function testGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL(string $table, array $column, string $expectedSql) : void { self::assertSame($expectedSql, $this->platform->getDefaultConstraintDeclarationSQL($table, $column)); } - public function getGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL() + /** + * @return mixed[][] + */ + public static function getGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL() : iterable { return [ // Unquoted identifiers non-reserved keywords. @@ -1138,15 +1175,20 @@ public function getGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL() } /** + * @param string[] $expectedSql + * * @dataProvider getGeneratesIdentifierNamesInCreateTableSQL * @group DBAL-830 */ - public function testGeneratesIdentifierNamesInCreateTableSQL($table, $expectedSql) + public function testGeneratesIdentifierNamesInCreateTableSQL(Table $table, array $expectedSql) : void { self::assertSame($expectedSql, $this->platform->getCreateTableSQL($table)); } - public function getGeneratesIdentifierNamesInCreateTableSQL() + /** + * @return mixed[][] + */ + public static function getGeneratesIdentifierNamesInCreateTableSQL() : iterable { return [ // Unquoted identifiers non-reserved keywords. @@ -1185,15 +1227,20 @@ public function getGeneratesIdentifierNamesInCreateTableSQL() } /** + * @param string[] $expectedSql + * * @dataProvider getGeneratesIdentifierNamesInAlterTableSQL * @group DBAL-830 */ - public function testGeneratesIdentifierNamesInAlterTableSQL($tableDiff, $expectedSql) + public function testGeneratesIdentifierNamesInAlterTableSQL(TableDiff $tableDiff, array $expectedSql) : void { self::assertSame($expectedSql, $this->platform->getAlterTableSQL($tableDiff)); } - public function getGeneratesIdentifierNamesInAlterTableSQL() + /** + * @return mixed[][] + */ + public static function getGeneratesIdentifierNamesInAlterTableSQL() : iterable { return [ // Unquoted identifiers non-reserved keywords. @@ -1298,7 +1345,7 @@ public function getGeneratesIdentifierNamesInAlterTableSQL() /** * @group DBAL-423 */ - public function testReturnsGuidTypeDeclarationSQL() + public function testReturnsGuidTypeDeclarationSQL() : void { self::assertSame('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL([])); } @@ -1306,7 +1353,7 @@ public function testReturnsGuidTypeDeclarationSQL() /** * {@inheritdoc} */ - public function getAlterTableRenameColumnSQL() + public function getAlterTableRenameColumnSQL() : array { return [ "sp_RENAME 'foo.bar', 'baz', 'COLUMN'", @@ -1318,7 +1365,7 @@ public function getAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotesTableIdentifiersInAlterTableSQL() + protected function getQuotesTableIdentifiersInAlterTableSQL() : array { return [ 'ALTER TABLE [foo] DROP CONSTRAINT fk1', @@ -1340,7 +1387,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() /** * {@inheritdoc} */ - protected function getCommentOnColumnSQL() + protected function getCommentOnColumnSQL() : array { return [ "COMMENT ON COLUMN foo.bar IS 'comment'", @@ -1352,7 +1399,7 @@ protected function getCommentOnColumnSQL() /** * {@inheritdoc} */ - public function getReturnsForeignKeyReferentialActionSQL() + public static function getReturnsForeignKeyReferentialActionSQL() : iterable { return [ ['CASCADE', 'CASCADE'], @@ -1367,7 +1414,7 @@ public function getReturnsForeignKeyReferentialActionSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() + protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string { return 'CONSTRAINT [select] UNIQUE (foo) WHERE foo IS NOT NULL'; } @@ -1375,7 +1422,7 @@ protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInIndexDeclarationSQL() + protected function getQuotesReservedKeywordInIndexDeclarationSQL() : string { return 'INDEX [select] (foo)'; } @@ -1383,7 +1430,7 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInTruncateTableSQL() + protected function getQuotesReservedKeywordInTruncateTableSQL() : string { return 'TRUNCATE TABLE [select]'; } @@ -1391,7 +1438,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() /** * {@inheritdoc} */ - protected function getAlterStringToFixedStringSQL() + protected function getAlterStringToFixedStringSQL() : array { return ['ALTER TABLE mytable ALTER COLUMN name NCHAR(2) NOT NULL']; } @@ -1399,12 +1446,12 @@ protected function getAlterStringToFixedStringSQL() /** * {@inheritdoc} */ - protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() + protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array { return ["EXEC sp_RENAME N'mytable.idx_foo', N'idx_foo_renamed', N'INDEX'"]; } - public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() + public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() : void { $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC)'; $alteredSql = 'SELECT TOP 10 * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC)'; @@ -1420,7 +1467,7 @@ public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableColumnsSQL() + public function testQuotesTableNameInListTableColumnsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1431,7 +1478,7 @@ public function testQuotesTableNameInListTableColumnsSQL() /** * @group DBAL-2436 */ - public function testQuotesSchemaNameInListTableColumnsSQL() + public function testQuotesSchemaNameInListTableColumnsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1442,7 +1489,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableForeignKeysSQL() + public function testQuotesTableNameInListTableForeignKeysSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1453,7 +1500,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() /** * @group DBAL-2436 */ - public function testQuotesSchemaNameInListTableForeignKeysSQL() + public function testQuotesSchemaNameInListTableForeignKeysSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1464,7 +1511,7 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableIndexesSQL() + public function testQuotesTableNameInListTableIndexesSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1475,7 +1522,7 @@ public function testQuotesTableNameInListTableIndexesSQL() /** * @group DBAL-2436 */ - public function testQuotesSchemaNameInListTableIndexesSQL() + public function testQuotesSchemaNameInListTableIndexesSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", diff --git a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php index f1260b2d5c1..a0c1f1f4b4b 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php @@ -17,12 +17,15 @@ class DB2PlatformTest extends AbstractPlatformTestCase /** @var DB2Platform */ protected $platform; - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new DB2Platform(); } - public function getGenerateAlterTableSql() + /** + * {@inheritDoc} + */ + public function getGenerateAlterTableSql() : array { return [ 'ALTER TABLE mytable ALTER COLUMN baz SET DATA TYPE VARCHAR(255)', @@ -39,22 +42,25 @@ public function getGenerateAlterTableSql() ]; } - public function getGenerateForeignKeySql() + public function getGenerateForeignKeySql() : string { return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; } - public function getGenerateIndexSql() + public function getGenerateIndexSql() : string { return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; } - public function getGenerateTableSql() + public function getGenerateTableSql() : string { return 'CREATE TABLE test (id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'; } - public function getGenerateTableWithMultiColumnUniqueIndexSql() + /** + * {@inheritDoc} + */ + public function getGenerateTableWithMultiColumnUniqueIndexSql() : array { return [ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', @@ -62,12 +68,15 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql() ]; } - public function getGenerateUniqueIndexSql() + public function getGenerateUniqueIndexSql() : string { return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; } - protected function getQuotedColumnInForeignKeySQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInForeignKeySQL() : array { return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL)', @@ -77,7 +86,10 @@ protected function getQuotedColumnInForeignKeySQL() ]; } - protected function getQuotedColumnInIndexSQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInIndexSQL() : array { return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', @@ -85,7 +97,10 @@ protected function getQuotedColumnInIndexSQL() ]; } - protected function getQuotedNameInIndexSQL() + /** + * {@inheritDoc} + */ + protected function getQuotedNameInIndexSQL() : array { return [ 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', @@ -93,22 +108,28 @@ protected function getQuotedNameInIndexSQL() ]; } - protected function getQuotedColumnInPrimaryKeySQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInPrimaryKeySQL() : array { return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))']; } - protected function getBitAndComparisonExpressionSql($value1, $value2) + protected function getBitAndComparisonExpressionSql(string $value1, string $value2) : string { return 'BITAND(' . $value1 . ', ' . $value2 . ')'; } - protected function getBitOrComparisonExpressionSql($value1, $value2) + protected function getBitOrComparisonExpressionSql(string $value1, string $value2) : string { return 'BITOR(' . $value1 . ', ' . $value2 . ')'; } - public function getCreateTableColumnCommentsSQL() + /** + * {@inheritDoc} + */ + public function getCreateTableColumnCommentsSQL() : array { return [ 'CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))', @@ -116,7 +137,10 @@ public function getCreateTableColumnCommentsSQL() ]; } - public function getAlterTableColumnCommentsSQL() + /** + * {@inheritDoc} + */ + public function getAlterTableColumnCommentsSQL() : array { return [ 'ALTER TABLE mytable ' . @@ -128,7 +152,10 @@ public function getAlterTableColumnCommentsSQL() ]; } - public function getCreateTableColumnTypeCommentsSQL() + /** + * {@inheritDoc} + */ + public function getCreateTableColumnTypeCommentsSQL() : array { return [ 'CREATE TABLE test (id INTEGER NOT NULL, "data" CLOB(1M) NOT NULL, PRIMARY KEY(id))', @@ -136,12 +163,12 @@ public function getCreateTableColumnTypeCommentsSQL() ]; } - public function testHasCorrectPlatformName() + public function testHasCorrectPlatformName() : void { self::assertEquals('db2', $this->platform->getName()); } - public function testGeneratesCreateTableSQLWithCommonIndexes() + public function testGeneratesCreateTableSQLWithCommonIndexes() : void { $table = new Table('test'); $table->addColumn('id', 'integer'); @@ -160,7 +187,7 @@ public function testGeneratesCreateTableSQLWithCommonIndexes() ); } - public function testGeneratesCreateTableSQLWithForeignKeyConstraints() + public function testGeneratesCreateTableSQLWithForeignKeyConstraints() : void { $table = new Table('test'); $table->addColumn('id', 'integer'); @@ -186,7 +213,7 @@ public function testGeneratesCreateTableSQLWithForeignKeyConstraints() ); } - public function testGeneratesCreateTableSQLWithCheckConstraints() + public function testGeneratesCreateTableSQLWithCheckConstraints() : void { $table = new Table('test'); $table->addColumn('id', 'integer'); @@ -200,7 +227,7 @@ public function testGeneratesCreateTableSQLWithCheckConstraints() ); } - public function testGeneratesColumnTypesDeclarationSQL() + public function testGeneratesColumnTypesDeclarationSQL() : void { $fullColumnDef = [ 'length' => 10, @@ -232,7 +259,7 @@ public function testGeneratesColumnTypesDeclarationSQL() self::assertEquals('TIME', $this->platform->getTimeTypeDeclarationSQL($fullColumnDef)); } - public function testInitializesDoctrineTypeMappings() + public function testInitializesDoctrineTypeMappings() : void { $this->platform->initializeDoctrineTypeMappings(); @@ -276,7 +303,10 @@ public function testInitializesDoctrineTypeMappings() self::assertSame('datetime', $this->platform->getDoctrineTypeMapping('timestamp')); } - public function getIsCommentedDoctrineType() + /** + * {@inheritDoc} + */ + public function getIsCommentedDoctrineType() : array { $data = parent::getIsCommentedDoctrineType(); @@ -285,7 +315,7 @@ public function getIsCommentedDoctrineType() return $data; } - public function testGeneratesDDLSnippets() + public function testGeneratesDDLSnippets() : void { self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); self::assertEquals('DROP DATABASE foobar', $this->platform->getDropDatabaseSQL('foobar')); @@ -298,7 +328,7 @@ public function testGeneratesDDLSnippets() self::assertEquals('DROP VIEW fooview', $this->platform->getDropViewSQL('fooview')); } - public function testGeneratesCreateUnnamedPrimaryKeySQL() + public function testGeneratesCreateUnnamedPrimaryKeySQL() : void { self::assertEquals( 'ALTER TABLE foo ADD PRIMARY KEY (a, b)', @@ -309,7 +339,7 @@ public function testGeneratesCreateUnnamedPrimaryKeySQL() ); } - public function testGeneratesSQLSnippets() + public function testGeneratesSQLSnippets() : void { self::assertEquals('CURRENT DATE', $this->platform->getCurrentDateSQL()); self::assertEquals('CURRENT TIME', $this->platform->getCurrentTimeSQL()); @@ -339,7 +369,7 @@ public function testGeneratesSQLSnippets() self::assertEquals('SUBSTR(column, 5, 2)', $this->platform->getSubstringExpression('column', 5, 2)); } - public function testModifiesLimitQuery() + public function testModifiesLimitQuery() : void { self::assertEquals( 'SELECT * FROM user', @@ -366,47 +396,47 @@ public function testModifiesLimitQuery() ); } - public function testPrefersIdentityColumns() + public function testPrefersIdentityColumns() : void { self::assertTrue($this->platform->prefersIdentityColumns()); } - public function testSupportsIdentityColumns() + public function testSupportsIdentityColumns() : void { self::assertTrue($this->platform->supportsIdentityColumns()); } - public function testDoesNotSupportSavePoints() + public function testDoesNotSupportSavePoints() : void { self::assertFalse($this->platform->supportsSavepoints()); } - public function testDoesNotSupportReleasePoints() + public function testDoesNotSupportReleasePoints() : void { self::assertFalse($this->platform->supportsReleaseSavepoints()); } - public function testDoesNotSupportCreateDropDatabase() + public function testDoesNotSupportCreateDropDatabase() : void { self::assertFalse($this->platform->supportsCreateDropDatabase()); } - public function testReturnsSQLResultCasing() + public function testReturnsSQLResultCasing() : void { self::assertSame('COL', $this->platform->getSQLResultCasing('cOl')); } - protected function getBinaryDefaultLength() + protected function getBinaryDefaultLength() : int { return 1; } - protected function getBinaryMaxLength() + protected function getBinaryMaxLength() : int { return 32704; } - public function testReturnsBinaryTypeDeclarationSQL() + public function testReturnsBinaryTypeDeclarationSQL() : void { self::assertSame('VARCHAR(1) FOR BIT DATA', $this->platform->getBinaryTypeDeclarationSQL([])); self::assertSame('VARCHAR(255) FOR BIT DATA', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); @@ -420,24 +450,28 @@ public function testReturnsBinaryTypeDeclarationSQL() * @group legacy * @expectedDeprecation Binary field length 32705 is greater than supported by the platform (32704). Reduce the field length or use a BLOB field instead. */ - public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() + public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() : void { self::assertSame('BLOB(1M)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 32705])); self::assertSame('BLOB(1M)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 32705])); } /** + * {@inheritDoc} + * * @group DBAL-234 */ - protected function getAlterTableRenameIndexSQL() + protected function getAlterTableRenameIndexSQL() : array { return ['RENAME INDEX idx_foo TO idx_bar']; } /** + * {@inheritDoc} + * * @group DBAL-234 */ - protected function getQuotedAlterTableRenameIndexSQL() + protected function getQuotedAlterTableRenameIndexSQL() : array { return [ 'RENAME INDEX "create" TO "select"', @@ -448,7 +482,7 @@ protected function getQuotedAlterTableRenameIndexSQL() /** * {@inheritdoc} */ - protected function getQuotedAlterTableRenameColumnSQL() + protected function getQuotedAlterTableRenameColumnSQL() : array { return ['ALTER TABLE mytable ' . 'RENAME COLUMN unquoted1 TO unquoted ' . @@ -466,23 +500,27 @@ protected function getQuotedAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotedAlterTableChangeColumnLengthSQL() + protected function getQuotedAlterTableChangeColumnLengthSQL() : array { $this->markTestIncomplete('Not implemented yet'); } /** + * {@inheritDoc} + * * @group DBAL-807 */ - protected function getAlterTableRenameIndexInSchemaSQL() + protected function getAlterTableRenameIndexInSchemaSQL() : array { return ['RENAME INDEX myschema.idx_foo TO idx_bar']; } /** + * {@inheritDoc} + * * @group DBAL-807 */ - protected function getQuotedAlterTableRenameIndexInSchemaSQL() + protected function getQuotedAlterTableRenameIndexInSchemaSQL() : array { return [ 'RENAME INDEX "schema"."create" TO "select"', @@ -493,7 +531,7 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() /** * @group DBAL-423 */ - public function testReturnsGuidTypeDeclarationSQL() + public function testReturnsGuidTypeDeclarationSQL() : void { self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); } @@ -501,7 +539,7 @@ public function testReturnsGuidTypeDeclarationSQL() /** * {@inheritdoc} */ - public function getAlterTableRenameColumnSQL() + public function getAlterTableRenameColumnSQL() : array { return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; } @@ -509,7 +547,7 @@ public function getAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotesTableIdentifiersInAlterTableSQL() + protected function getQuotesTableIdentifiersInAlterTableSQL() : array { return [ 'ALTER TABLE "foo" DROP FOREIGN KEY fk1', @@ -529,7 +567,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() /** * {@inheritdoc} */ - protected function getCommentOnColumnSQL() + protected function getCommentOnColumnSQL() : array { return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', @@ -542,7 +580,7 @@ protected function getCommentOnColumnSQL() * @group DBAL-944 * @dataProvider getGeneratesAlterColumnSQL */ - public function testGeneratesAlterColumnSQL($changedProperty, Column $column, $expectedSQLClause = null) + public function testGeneratesAlterColumnSQL(string $changedProperty, Column $column, ?string $expectedSQLClause = null) : void { $tableDiff = new TableDiff('foo'); $tableDiff->fromTable = new Table('foo'); @@ -560,9 +598,9 @@ public function testGeneratesAlterColumnSQL($changedProperty, Column $column, $e } /** - * @return mixed[] + * @return mixed[][] */ - public function getGeneratesAlterColumnSQL() + public static function getGeneratesAlterColumnSQL() : iterable { return [ [ @@ -626,7 +664,7 @@ public function getGeneratesAlterColumnSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() + protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string { return 'CONSTRAINT "select" UNIQUE (foo)'; } @@ -634,7 +672,7 @@ protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInIndexDeclarationSQL() + protected function getQuotesReservedKeywordInIndexDeclarationSQL() : string { return ''; // not supported by this platform } @@ -642,7 +680,7 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInTruncateTableSQL() + protected function getQuotesReservedKeywordInTruncateTableSQL() : string { return 'TRUNCATE "select" IMMEDIATE'; } @@ -650,7 +688,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() /** * {@inheritdoc} */ - protected function supportsInlineIndexDeclaration() + protected function supportsInlineIndexDeclaration() : bool { return false; } @@ -658,7 +696,7 @@ protected function supportsInlineIndexDeclaration() /** * {@inheritdoc} */ - protected function supportsCommentOnStatement() + protected function supportsCommentOnStatement() : bool { return true; } @@ -666,7 +704,7 @@ protected function supportsCommentOnStatement() /** * {@inheritdoc} */ - protected function getAlterStringToFixedStringSQL() + protected function getAlterStringToFixedStringSQL() : array { return [ 'ALTER TABLE mytable ALTER COLUMN name SET DATA TYPE CHAR(2)', @@ -677,7 +715,7 @@ protected function getAlterStringToFixedStringSQL() /** * {@inheritdoc} */ - protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() + protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array { return ['RENAME INDEX idx_foo TO idx_foo_renamed']; } @@ -685,7 +723,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableColumnsSQL() + public function testQuotesTableNameInListTableColumnsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -696,7 +734,7 @@ public function testQuotesTableNameInListTableColumnsSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableIndexesSQL() + public function testQuotesTableNameInListTableIndexesSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -707,7 +745,7 @@ public function testQuotesTableNameInListTableIndexesSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableForeignKeysSQL() + public function testQuotesTableNameInListTableForeignKeysSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php index 0903a511612..00b86088ad5 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Types\Types; @@ -10,7 +11,7 @@ class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase /** * {@inheritdoc} */ - public function createPlatform() : MariaDb1027Platform + public function createPlatform() : AbstractPlatform { return new MariaDb1027Platform(); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php index 90e3827566c..2557562ab95 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MySQL57Platform; use Doctrine\DBAL\Types\Types; @@ -10,39 +11,43 @@ class MySQL57PlatformTest extends AbstractMySQLPlatformTestCase /** * {@inheritdoc} */ - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new MySQL57Platform(); } - public function testHasNativeJsonType() + public function testHasNativeJsonType() : void { self::assertTrue($this->platform->hasNativeJsonType()); } - public function testReturnsJsonTypeDeclarationSQL() + public function testReturnsJsonTypeDeclarationSQL() : void { self::assertSame('JSON', $this->platform->getJsonTypeDeclarationSQL([])); } - public function testInitializesJsonTypeMapping() + public function testInitializesJsonTypeMapping() : void { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('json')); self::assertSame(Types::JSON, $this->platform->getDoctrineTypeMapping('json')); } /** + * @return string[] + * * @group DBAL-234 */ - protected function getAlterTableRenameIndexSQL() + protected function getAlterTableRenameIndexSQL() : array { return ['ALTER TABLE mytable RENAME INDEX idx_foo TO idx_bar']; } /** + * @return string[] + * * @group DBAL-234 */ - protected function getQuotedAlterTableRenameIndexSQL() + protected function getQuotedAlterTableRenameIndexSQL() : array { return [ 'ALTER TABLE `table` RENAME INDEX `create` TO `select`', @@ -51,17 +56,21 @@ protected function getQuotedAlterTableRenameIndexSQL() } /** + * @return string[] + * * @group DBAL-807 */ - protected function getAlterTableRenameIndexInSchemaSQL() + protected function getAlterTableRenameIndexInSchemaSQL() : array { return ['ALTER TABLE myschema.mytable RENAME INDEX idx_foo TO idx_bar']; } /** + * @return string[] + * * @group DBAL-807 */ - protected function getQuotedAlterTableRenameIndexInSchemaSQL() + protected function getQuotedAlterTableRenameIndexInSchemaSQL() : array { return [ 'ALTER TABLE `schema`.`table` RENAME INDEX `create` TO `select`', @@ -72,7 +81,7 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() /** * {@inheritdoc} */ - protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() + protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array { return ['ALTER TABLE mytable RENAME INDEX idx_foo TO idx_foo_renamed']; } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php index ec1f3181581..e8007baf55f 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php @@ -2,17 +2,18 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\TransactionIsolationLevel; class MySqlPlatformTest extends AbstractMySQLPlatformTestCase { - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new MySqlPlatform(); } - public function testHasCorrectDefaultTransactionIsolationLevel() + public function testHasCorrectDefaultTransactionIsolationLevel() : void { self::assertEquals( TransactionIsolationLevel::REPEATABLE_READ, diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 439c413d1a0..0dd4b304739 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; @@ -21,7 +22,10 @@ class OraclePlatformTest extends AbstractPlatformTestCase { - public static function dataValidIdentifiers() + /** + * @return mixed[][] + */ + public static function dataValidIdentifiers() : iterable { return [ ['a'], @@ -39,7 +43,7 @@ public static function dataValidIdentifiers() /** * @dataProvider dataValidIdentifiers */ - public function testValidIdentifiers($identifier) + public function testValidIdentifiers(string $identifier) : void { $platform = $this->createPlatform(); $platform->assertValidIdentifier($identifier); @@ -47,7 +51,10 @@ public function testValidIdentifiers($identifier) $this->addToAssertionCount(1); } - public static function dataInvalidIdentifiers() + /** + * @return mixed[][] + */ + public static function dataInvalidIdentifiers() : iterable { return [ ['1'], @@ -61,7 +68,7 @@ public static function dataInvalidIdentifiers() /** * @dataProvider dataInvalidIdentifiers */ - public function testInvalidIdentifiers($identifier) + public function testInvalidIdentifiers(string $identifier) : void { $this->expectException(DBALException::class); @@ -69,17 +76,20 @@ public function testInvalidIdentifiers($identifier) $platform->assertValidIdentifier($identifier); } - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new OraclePlatform(); } - public function getGenerateTableSql() + public function getGenerateTableSql() : string { return 'CREATE TABLE test (id NUMBER(10) NOT NULL, test VARCHAR2(255) DEFAULT NULL NULL, PRIMARY KEY(id))'; } - public function getGenerateTableWithMultiColumnUniqueIndexSql() + /** + * @return mixed[] + */ + public function getGenerateTableWithMultiColumnUniqueIndexSql() : array { return [ 'CREATE TABLE test (foo VARCHAR2(255) DEFAULT NULL NULL, bar VARCHAR2(255) DEFAULT NULL NULL)', @@ -87,7 +97,10 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql() ]; } - public function getGenerateAlterTableSql() + /** + * {@inheritDoc} + */ + public function getGenerateAlterTableSql() : array { return [ 'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL NULL)', @@ -97,20 +110,20 @@ public function getGenerateAlterTableSql() ]; } - public function testRLike() + public function testRLike() : void { $this->expectException(DBALException::class); self::assertEquals('RLIKE', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct'); } - public function testGeneratesSqlSnippets() + public function testGeneratesSqlSnippets() : void { self::assertEquals('"', $this->platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct'); self::assertEquals('column1 || column2 || column3', $this->platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct'); } - public function testGeneratesTransactionsCommands() + public function testGeneratesTransactionsCommands() : void { self::assertEquals( 'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', @@ -130,24 +143,24 @@ public function testGeneratesTransactionsCommands() ); } - public function testCreateDatabaseThrowsException() + public function testCreateDatabaseThrowsException() : void { $this->expectException(DBALException::class); self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); } - public function testDropDatabaseThrowsException() + public function testDropDatabaseThrowsException() : void { self::assertEquals('DROP USER foobar CASCADE', $this->platform->getDropDatabaseSQL('foobar')); } - public function testDropTable() + public function testDropTable() : void { self::assertEquals('DROP TABLE foobar', $this->platform->getDropTableSQL('foobar')); } - public function testGeneratesTypeDeclarationForIntegers() + public function testGeneratesTypeDeclarationForIntegers() : void { self::assertEquals( 'NUMBER(10)', @@ -165,7 +178,7 @@ public function testGeneratesTypeDeclarationForIntegers() ); } - public function testGeneratesTypeDeclarationsForStrings() + public function testGeneratesTypeDeclarationsForStrings() : void { self::assertEquals( 'CHAR(10)', @@ -185,17 +198,17 @@ public function testGeneratesTypeDeclarationsForStrings() ); } - public function testPrefersIdentityColumns() + public function testPrefersIdentityColumns() : void { self::assertFalse($this->platform->prefersIdentityColumns()); } - public function testSupportsIdentityColumns() + public function testSupportsIdentityColumns() : void { self::assertFalse($this->platform->supportsIdentityColumns()); } - public function testSupportsSavePoints() + public function testSupportsSavePoints() : void { self::assertTrue($this->platform->supportsSavepoints()); } @@ -203,22 +216,22 @@ public function testSupportsSavePoints() /** * {@inheritdoc} */ - protected function supportsCommentOnStatement() + protected function supportsCommentOnStatement() : bool { return true; } - public function getGenerateIndexSql() + public function getGenerateIndexSql() : string { return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; } - public function getGenerateUniqueIndexSql() + public function getGenerateUniqueIndexSql() : string { return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; } - public function getGenerateForeignKeySql() + public function getGenerateForeignKeySql() : string { return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; } @@ -229,7 +242,7 @@ public function getGenerateForeignKeySql() * @group DBAL-1097 * @dataProvider getGeneratesAdvancedForeignKeyOptionsSQLData */ - public function testGeneratesAdvancedForeignKeyOptionsSQL(array $options, $expectedSql) + public function testGeneratesAdvancedForeignKeyOptionsSQL(array $options, string $expectedSql) : void { $foreignKey = new ForeignKeyConstraint(['foo'], 'foreign_table', ['bar'], null, $options); @@ -237,9 +250,9 @@ public function testGeneratesAdvancedForeignKeyOptionsSQL(array $options, $expec } /** - * @return mixed[] + * @return mixed[][] */ - public function getGeneratesAdvancedForeignKeyOptionsSQLData() + public static function getGeneratesAdvancedForeignKeyOptionsSQLData() : iterable { return [ [[], ''], @@ -254,7 +267,7 @@ public function getGeneratesAdvancedForeignKeyOptionsSQLData() /** * {@inheritdoc} */ - public function getReturnsForeignKeyReferentialActionSQL() + public static function getReturnsForeignKeyReferentialActionSQL() : iterable { return [ ['CASCADE', 'CASCADE'], @@ -265,43 +278,43 @@ public function getReturnsForeignKeyReferentialActionSQL() ]; } - public function testModifyLimitQuery() + public function testModifyLimitQuery() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); self::assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql); } - public function testModifyLimitQueryWithEmptyOffset() + public function testModifyLimitQueryWithEmptyOffset() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); self::assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql); } - public function testModifyLimitQueryWithNonEmptyOffset() + public function testModifyLimitQueryWithNonEmptyOffset() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 10); self::assertEquals('SELECT * FROM (SELECT a.*, ROWNUM AS doctrine_rownum FROM (SELECT * FROM user) a WHERE ROWNUM <= 20) WHERE doctrine_rownum >= 11', $sql); } - public function testModifyLimitQueryWithEmptyLimit() + public function testModifyLimitQueryWithEmptyLimit() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', null, 10); self::assertEquals('SELECT * FROM (SELECT a.*, ROWNUM AS doctrine_rownum FROM (SELECT * FROM user) a) WHERE doctrine_rownum >= 11', $sql); } - public function testModifyLimitQueryWithAscOrderBy() + public function testModifyLimitQueryWithAscOrderBy() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user ORDER BY username ASC', 10); self::assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username ASC) a WHERE ROWNUM <= 10', $sql); } - public function testModifyLimitQueryWithDescOrderBy() + public function testModifyLimitQueryWithDescOrderBy() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10); self::assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username DESC) a WHERE ROWNUM <= 10', $sql); } - public function testGenerateTableWithAutoincrement() + public function testGenerateTableWithAutoincrement() : void { $columnName = strtoupper('id' . uniqid()); $tableName = strtoupper('table' . uniqid()); @@ -335,7 +348,7 @@ public function testGenerateTableWithAutoincrement() ]; $statements = $this->platform->getCreateTableSQL($table); //strip all the whitespace from the statements - array_walk($statements, static function (&$value) { + array_walk($statements, static function (&$value) : void { $value = preg_replace('/\s+/', ' ', $value); }); foreach ($targets as $key => $sql) { @@ -344,7 +357,10 @@ public function testGenerateTableWithAutoincrement() } } - public function getCreateTableColumnCommentsSQL() + /** + * {@inheritDoc} + */ + public function getCreateTableColumnCommentsSQL() : array { return [ 'CREATE TABLE test (id NUMBER(10) NOT NULL, PRIMARY KEY(id))', @@ -352,7 +368,10 @@ public function getCreateTableColumnCommentsSQL() ]; } - public function getCreateTableColumnTypeCommentsSQL() + /** + * {@inheritDoc} + */ + public function getCreateTableColumnTypeCommentsSQL() : array { return [ 'CREATE TABLE test (id NUMBER(10) NOT NULL, data CLOB NOT NULL, PRIMARY KEY(id))', @@ -360,7 +379,10 @@ public function getCreateTableColumnTypeCommentsSQL() ]; } - public function getAlterTableColumnCommentsSQL() + /** + * {@inheritDoc} + */ + public function getAlterTableColumnCommentsSQL() : array { return [ 'ALTER TABLE mytable ADD (quota NUMBER(10) NOT NULL)', @@ -370,24 +392,30 @@ public function getAlterTableColumnCommentsSQL() ]; } - public function getBitAndComparisonExpressionSql($value1, $value2) + public function getBitAndComparisonExpressionSql(string $value1, string $value2) : string { return 'BITAND(' . $value1 . ', ' . $value2 . ')'; } - public function getBitOrComparisonExpressionSql($value1, $value2) + public function getBitOrComparisonExpressionSql(string $value1, string $value2) : string { return '(' . $value1 . '-' . $this->getBitAndComparisonExpressionSql($value1, $value2) . '+' . $value2 . ')'; } - protected function getQuotedColumnInPrimaryKeySQL() + /** + * @return mixed[] + */ + protected function getQuotedColumnInPrimaryKeySQL() : array { return ['CREATE TABLE "quoted" ("create" VARCHAR2(255) NOT NULL, PRIMARY KEY("create"))']; } - protected function getQuotedColumnInIndexSQL() + /** + * @return mixed[] + */ + protected function getQuotedColumnInIndexSQL() : array { return [ 'CREATE TABLE "quoted" ("create" VARCHAR2(255) NOT NULL)', @@ -395,7 +423,10 @@ protected function getQuotedColumnInIndexSQL() ]; } - protected function getQuotedNameInIndexSQL() + /** + * @return mixed[] + */ + protected function getQuotedNameInIndexSQL() : array { return [ 'CREATE TABLE test (column1 VARCHAR2(255) NOT NULL)', @@ -403,7 +434,10 @@ protected function getQuotedNameInIndexSQL() ]; } - protected function getQuotedColumnInForeignKeySQL() + /** + * @return mixed[] + */ + protected function getQuotedColumnInForeignKeySQL() : array { return [ 'CREATE TABLE "quoted" ("create" VARCHAR2(255) NOT NULL, foo VARCHAR2(255) NOT NULL, "bar" VARCHAR2(255) NOT NULL)', @@ -417,7 +451,7 @@ protected function getQuotedColumnInForeignKeySQL() * @group DBAL-472 * @group DBAL-1001 */ - public function testAlterTableNotNULL() + public function testAlterTableNotNULL() : void { $tableDiff = new TableDiff('mytable'); $tableDiff->changedColumns['foo'] = new ColumnDiff( @@ -455,7 +489,7 @@ public function testAlterTableNotNULL() /** * @group DBAL-2555 */ - public function testInitializesDoctrineTypeMappings() + public function testInitializesDoctrineTypeMappings() : void { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('long raw')); self::assertSame('blob', $this->platform->getDoctrineTypeMapping('long raw')); @@ -467,12 +501,12 @@ public function testInitializesDoctrineTypeMappings() self::assertSame('date', $this->platform->getDoctrineTypeMapping('date')); } - protected function getBinaryMaxLength() + protected function getBinaryMaxLength() : int { return 2000; } - public function testReturnsBinaryTypeDeclarationSQL() + public function testReturnsBinaryTypeDeclarationSQL() : void { self::assertSame('RAW(255)', $this->platform->getBinaryTypeDeclarationSQL([])); self::assertSame('RAW(2000)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); @@ -487,13 +521,13 @@ public function testReturnsBinaryTypeDeclarationSQL() * @group legacy * @expectedDeprecation Binary field length 2001 is greater than supported by the platform (2000). Reduce the field length or use a BLOB field instead. */ - public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() + public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() : void { self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 2001])); self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 2001])); } - public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() + public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() : void { $table1 = new Table('mytable'); $table1->addColumn('column_varbinary', 'binary'); @@ -513,7 +547,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() /** * @group DBAL-563 */ - public function testUsesSequenceEmulatedIdentityColumns() + public function testUsesSequenceEmulatedIdentityColumns() : void { self::assertTrue($this->platform->usesSequenceEmulatedIdentityColumns()); } @@ -522,7 +556,7 @@ public function testUsesSequenceEmulatedIdentityColumns() * @group DBAL-563 * @group DBAL-831 */ - public function testReturnsIdentitySequenceName() + public function testReturnsIdentitySequenceName() : void { self::assertSame('MYTABLE_SEQ', $this->platform->getIdentitySequenceName('mytable', 'mycolumn')); self::assertSame('"mytable_SEQ"', $this->platform->getIdentitySequenceName('"mytable"', 'mycolumn')); @@ -534,13 +568,16 @@ public function testReturnsIdentitySequenceName() * @dataProvider dataCreateSequenceWithCache * @group DBAL-139 */ - public function testCreateSequenceWithCache($cacheSize, $expectedSql) + public function testCreateSequenceWithCache(int $cacheSize, string $expectedSql) : void { $sequence = new Sequence('foo', 1, 1, $cacheSize); self::assertStringContainsString($expectedSql, $this->platform->getCreateSequenceSQL($sequence)); } - public function dataCreateSequenceWithCache() + /** + * @return mixed[][] + */ + public static function dataCreateSequenceWithCache() : iterable { return [ [1, 'NOCACHE'], @@ -550,17 +587,21 @@ public function dataCreateSequenceWithCache() } /** + * {@inheritDoc} + * * @group DBAL-234 */ - protected function getAlterTableRenameIndexSQL() + protected function getAlterTableRenameIndexSQL() : array { return ['ALTER INDEX idx_foo RENAME TO idx_bar']; } /** + * {@inheritDoc} + * * @group DBAL-234 */ - protected function getQuotedAlterTableRenameIndexSQL() + protected function getQuotedAlterTableRenameIndexSQL() : array { return [ 'ALTER INDEX "create" RENAME TO "select"', @@ -571,7 +612,7 @@ protected function getQuotedAlterTableRenameIndexSQL() /** * {@inheritdoc} */ - protected function getQuotedAlterTableRenameColumnSQL() + protected function getQuotedAlterTableRenameColumnSQL() : array { return [ 'ALTER TABLE mytable RENAME COLUMN unquoted1 TO unquoted', @@ -589,23 +630,27 @@ protected function getQuotedAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotedAlterTableChangeColumnLengthSQL() + protected function getQuotedAlterTableChangeColumnLengthSQL() : array { $this->markTestIncomplete('Not implemented yet'); } /** + * {@inheritDoc} + * * @group DBAL-807 */ - protected function getAlterTableRenameIndexInSchemaSQL() + protected function getAlterTableRenameIndexInSchemaSQL() : array { return ['ALTER INDEX myschema.idx_foo RENAME TO idx_bar']; } /** + * {@inheritDoc} + * * @group DBAL-807 */ - protected function getQuotedAlterTableRenameIndexInSchemaSQL() + protected function getQuotedAlterTableRenameIndexInSchemaSQL() : array { return [ 'ALTER INDEX "schema"."create" RENAME TO "select"', @@ -613,7 +658,7 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() ]; } - protected function getQuotesDropForeignKeySQL() + protected function getQuotesDropForeignKeySQL() : string { return 'ALTER TABLE "table" DROP CONSTRAINT "select"'; } @@ -621,7 +666,7 @@ protected function getQuotesDropForeignKeySQL() /** * @group DBAL-423 */ - public function testReturnsGuidTypeDeclarationSQL() + public function testReturnsGuidTypeDeclarationSQL() : void { self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); } @@ -629,21 +674,26 @@ public function testReturnsGuidTypeDeclarationSQL() /** * {@inheritdoc} */ - public function getAlterTableRenameColumnSQL() + public function getAlterTableRenameColumnSQL() : array { return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; } /** + * @param string[] $expectedSql + * * @dataProvider getReturnsDropAutoincrementSQL * @group DBAL-831 */ - public function testReturnsDropAutoincrementSQL($table, $expectedSql) + public function testReturnsDropAutoincrementSQL(string $table, array $expectedSql) : void { self::assertSame($expectedSql, $this->platform->getDropAutoincrementSql($table)); } - public function getReturnsDropAutoincrementSQL() + /** + * @return mixed[][] + */ + public static function getReturnsDropAutoincrementSQL() : iterable { return [ [ @@ -676,7 +726,7 @@ public function getReturnsDropAutoincrementSQL() /** * {@inheritdoc} */ - protected function getQuotesTableIdentifiersInAlterTableSQL() + protected function getQuotesTableIdentifiersInAlterTableSQL() : array { return [ 'ALTER TABLE "foo" DROP CONSTRAINT fk1', @@ -694,7 +744,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() /** * {@inheritdoc} */ - protected function getCommentOnColumnSQL() + protected function getCommentOnColumnSQL() : array { return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', @@ -706,7 +756,7 @@ protected function getCommentOnColumnSQL() /** * @group DBAL-1004 */ - public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() + public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() : void { $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]); $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]); @@ -722,7 +772,7 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() ); } - public function testQuotedTableNames() + public function testQuotedTableNames() : void { $table = new Table('"test"'); $table->addColumn('"id"', 'integer', ['autoincrement' => true]); @@ -766,7 +816,7 @@ public function testQuotedTableNames() * @dataProvider getReturnsGetListTableColumnsSQL * @group DBAL-831 */ - public function testReturnsGetListTableColumnsSQL($database, $expectedSql) + public function testReturnsGetListTableColumnsSQL(?string $database, string $expectedSql) : void { // note: this assertion is a bit strict, as it compares a full SQL string. // Should this break in future, then please try to reduce the matching to substring matching while reworking @@ -774,7 +824,10 @@ public function testReturnsGetListTableColumnsSQL($database, $expectedSql) self::assertEquals($expectedSql, $this->platform->getListTableColumnsSQL('"test"', $database)); } - public function getReturnsGetListTableColumnsSQL() + /** + * @return mixed[][] + */ + public static function getReturnsGetListTableColumnsSQL() : iterable { return [ [ @@ -831,7 +884,7 @@ public function getReturnsGetListTableColumnsSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() + protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string { return 'CONSTRAINT "select" UNIQUE (foo)'; } @@ -839,7 +892,7 @@ protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInIndexDeclarationSQL() + protected function getQuotesReservedKeywordInIndexDeclarationSQL() : string { return 'INDEX "select" (foo)'; } @@ -847,7 +900,7 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInTruncateTableSQL() + protected function getQuotesReservedKeywordInTruncateTableSQL() : string { return 'TRUNCATE TABLE "select"'; } @@ -855,7 +908,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() /** * {@inheritdoc} */ - protected function getAlterStringToFixedStringSQL() + protected function getAlterStringToFixedStringSQL() : array { return ['ALTER TABLE mytable MODIFY (name CHAR(2) DEFAULT NULL)']; } @@ -863,7 +916,7 @@ protected function getAlterStringToFixedStringSQL() /** * {@inheritdoc} */ - protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() + protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array { return ['ALTER INDEX idx_foo RENAME TO idx_foo_renamed']; } @@ -871,7 +924,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() /** * @group DBAL-2436 */ - public function testQuotesDatabaseNameInListSequencesSQL() + public function testQuotesDatabaseNameInListSequencesSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -882,7 +935,7 @@ public function testQuotesDatabaseNameInListSequencesSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableIndexesSQL() + public function testQuotesTableNameInListTableIndexesSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -893,7 +946,7 @@ public function testQuotesTableNameInListTableIndexesSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableForeignKeysSQL() + public function testQuotesTableNameInListTableForeignKeysSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -904,7 +957,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableConstraintsSQL() + public function testQuotesTableNameInListTableConstraintsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -915,7 +968,7 @@ public function testQuotesTableNameInListTableConstraintsSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableColumnsSQL() + public function testQuotesTableNameInListTableColumnsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -926,7 +979,7 @@ public function testQuotesTableNameInListTableColumnsSQL() /** * @group DBAL-2436 */ - public function testQuotesDatabaseNameInListTableColumnsSQL() + public function testQuotesDatabaseNameInListTableColumnsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL100PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL100PlatformTest.php index df30fc471f0..8eb58c98e72 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL100PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL100PlatformTest.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSQL100Platform; class PostgreSQL100PlatformTest extends PostgreSQL94PlatformTest @@ -11,7 +12,7 @@ class PostgreSQL100PlatformTest extends PostgreSQL94PlatformTest /** * {@inheritdoc} */ - public function createPlatform() : PostgreSQL100Platform + public function createPlatform() : AbstractPlatform { return new PostgreSQL100Platform(); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL91PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL91PlatformTest.php index ec62ac8b026..3ed82529e08 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL91PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL91PlatformTest.php @@ -2,12 +2,13 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSQL91Platform; use Doctrine\DBAL\Schema\Table; class PostgreSQL91PlatformTest extends PostgreSqlPlatformTest { - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new PostgreSQL91Platform(); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php index 123425b3879..7fbedd494be 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSQL92Platform; use Doctrine\DBAL\Types\Types; @@ -10,7 +11,7 @@ class PostgreSQL92PlatformTest extends AbstractPostgreSqlPlatformTestCase /** * {@inheritdoc} */ - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new PostgreSQL92Platform(); } @@ -18,7 +19,7 @@ public function createPlatform() /** * @group DBAL-553 */ - public function testHasNativeJsonType() + public function testHasNativeJsonType() : void { self::assertTrue($this->platform->hasNativeJsonType()); } @@ -26,12 +27,12 @@ public function testHasNativeJsonType() /** * @group DBAL-553 */ - public function testReturnsJsonTypeDeclarationSQL() + public function testReturnsJsonTypeDeclarationSQL() : void { self::assertSame('JSON', $this->platform->getJsonTypeDeclarationSQL([])); } - public function testReturnsSmallIntTypeDeclarationSQL() + public function testReturnsSmallIntTypeDeclarationSQL() : void { self::assertSame( 'SMALLSERIAL', @@ -52,7 +53,7 @@ public function testReturnsSmallIntTypeDeclarationSQL() /** * @group DBAL-553 */ - public function testInitializesJsonTypeMapping() + public function testInitializesJsonTypeMapping() : void { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('json')); self::assertEquals(Types::JSON, $this->platform->getDoctrineTypeMapping('json')); @@ -61,7 +62,7 @@ public function testInitializesJsonTypeMapping() /** * @group DBAL-1220 */ - public function testReturnsCloseActiveDatabaseConnectionsSQL() + public function testReturnsCloseActiveDatabaseConnectionsSQL() : void { self::assertSame( "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'foo'", diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php index 9643bdb5fd7..179e005b2f9 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Types\Types; @@ -10,19 +11,19 @@ class PostgreSQL94PlatformTest extends PostgreSQL92PlatformTest /** * {@inheritdoc} */ - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new PostgreSQL94Platform(); } - public function testReturnsJsonTypeDeclarationSQL() + public function testReturnsJsonTypeDeclarationSQL() : void { parent::testReturnsJsonTypeDeclarationSQL(); self::assertSame('JSON', $this->platform->getJsonTypeDeclarationSQL(['jsonb' => false])); self::assertSame('JSONB', $this->platform->getJsonTypeDeclarationSQL(['jsonb' => true])); } - public function testInitializesJsonTypeMapping() + public function testInitializesJsonTypeMapping() : void { parent::testInitializesJsonTypeMapping(); self::assertTrue($this->platform->hasDoctrineTypeMappingFor('jsonb')); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php index b45a152ab0a..41fb1564ec8 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php @@ -2,16 +2,17 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; class PostgreSqlPlatformTest extends AbstractPostgreSqlPlatformTestCase { - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new PostgreSqlPlatform(); } - public function testSupportsPartialIndexes() + public function testSupportsPartialIndexes() : void { self::assertTrue($this->platform->supportsPartialIndexes()); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php b/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php index b0c49ae6bb9..8d07f62274d 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php @@ -17,7 +17,7 @@ protected function setUp() : void $this->validator = new ReservedKeywordsValidator([new MySQLKeywords()]); } - public function testReservedTableName() + public function testReservedTableName() : void { $table = new Table('TABLE'); $this->validator->acceptTable($table); @@ -28,7 +28,7 @@ public function testReservedTableName() ); } - public function testReservedColumnName() + public function testReservedColumnName() : void { $table = new Table('TABLE'); $column = $table->addColumn('table', 'string'); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php index 7e91777d6ef..bf3f7372df3 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLAnywhere11Platform; class SQLAnywhere11PlatformTest extends SQLAnywherePlatformTest @@ -9,17 +10,17 @@ class SQLAnywhere11PlatformTest extends SQLAnywherePlatformTest /** @var SQLAnywhere11Platform */ protected $platform; - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new SQLAnywhere11Platform(); } - public function testDoesNotSupportRegexp() + public function testDoesNotSupportRegexp() : void { $this->markTestSkipped('This version of the platform now supports regular expressions.'); } - public function testGeneratesRegularExpressionSQLSnippet() + public function testGeneratesRegularExpressionSQLSnippet() : void { self::assertEquals('REGEXP', $this->platform->getRegexpExpression()); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php index 7cbb2c69bb8..e60f6b1c7f1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLAnywhere12Platform; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Sequence; @@ -11,22 +12,22 @@ class SQLAnywhere12PlatformTest extends SQLAnywhere11PlatformTest /** @var SQLAnywhere12Platform */ protected $platform; - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new SQLAnywhere12Platform(); } - public function testDoesNotSupportSequences() + public function testDoesNotSupportSequences() : void { $this->markTestSkipped('This version of the platform now supports sequences.'); } - public function testSupportsSequences() + public function testSupportsSequences() : void { self::assertTrue($this->platform->supportsSequences()); } - public function testGeneratesSequenceSqlCommands() + public function testGeneratesSequenceSqlCommands() : void { $sequence = new Sequence('myseq', 20, 1); self::assertEquals( @@ -55,7 +56,7 @@ public function testGeneratesSequenceSqlCommands() ); } - public function testGeneratesDateTimeTzColumnTypeDeclarationSQL() + public function testGeneratesDateTimeTzColumnTypeDeclarationSQL() : void { self::assertEquals( 'TIMESTAMP WITH TIME ZONE', @@ -68,18 +69,18 @@ public function testGeneratesDateTimeTzColumnTypeDeclarationSQL() ); } - public function testHasCorrectDateTimeTzFormatString() + public function testHasCorrectDateTimeTzFormatString() : void { self::assertEquals('Y-m-d H:i:s.uP', $this->platform->getDateTimeTzFormatString()); } - public function testInitializesDateTimeTzTypeMapping() + public function testInitializesDateTimeTzTypeMapping() : void { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('timestamp with time zone')); self::assertEquals('datetime', $this->platform->getDoctrineTypeMapping('timestamp with time zone')); } - public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() + public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() : void { self::assertEquals( 'CREATE VIRTUAL UNIQUE CLUSTERED INDEX fooindex ON footable (a, b) WITH NULLS NOT DISTINCT FOR OLAP WORKLOAD', diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php index 9692ffb1f76..a6a0018a06e 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php @@ -2,17 +2,18 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLAnywhere16Platform; use Doctrine\DBAL\Schema\Index; class SQLAnywhere16PlatformTest extends SQLAnywhere12PlatformTest { - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new SQLAnywhere16Platform(); } - public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() + public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() : void { self::assertEquals( 'CREATE UNIQUE INDEX fooindex ON footable (a, b) WITH NULLS DISTINCT', @@ -61,7 +62,7 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() parent::testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL(); } - public function testThrowsExceptionOnInvalidWithNullsNotDistinctIndexOptions() + public function testThrowsExceptionOnInvalidWithNullsNotDistinctIndexOptions() : void { $this->expectException('UnexpectedValueException'); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 767fb268408..0efa23b19c6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -27,12 +27,15 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase /** @var SQLAnywherePlatform */ protected $platform; - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new SQLAnywherePlatform(); } - public function getGenerateAlterTableSql() + /** + * {@inheritDoc} + */ + public function getGenerateAlterTableSql() : array { return [ "ALTER TABLE mytable ADD quota INT DEFAULT NULL, DROP foo, ALTER baz VARCHAR(1) DEFAULT 'def' NOT NULL, ALTER bloo BIT DEFAULT '0' NOT NULL", @@ -40,22 +43,25 @@ public function getGenerateAlterTableSql() ]; } - public function getGenerateForeignKeySql() + public function getGenerateForeignKeySql() : string { return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; } - public function getGenerateIndexSql() + public function getGenerateIndexSql() : string { return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; } - public function getGenerateTableSql() + public function getGenerateTableSql() : string { return 'CREATE TABLE test (id INT IDENTITY NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY (id))'; } - public function getGenerateTableWithMultiColumnUniqueIndexSql() + /** + * {@inheritDoc} + */ + public function getGenerateTableWithMultiColumnUniqueIndexSql() : array { return [ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', @@ -63,17 +69,23 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql() ]; } - public function getGenerateUniqueIndexSql() + public function getGenerateUniqueIndexSql() : string { return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; } - protected function getQuotedColumnInForeignKeySQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInForeignKeySQL() : array { return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL, CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar"), CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar"), CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar"))']; } - protected function getQuotedColumnInIndexSQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInIndexSQL() : array { return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', @@ -81,7 +93,10 @@ protected function getQuotedColumnInIndexSQL() ]; } - protected function getQuotedNameInIndexSQL() + /** + * {@inheritDoc} + */ + protected function getQuotedNameInIndexSQL() : array { return [ 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', @@ -89,12 +104,18 @@ protected function getQuotedNameInIndexSQL() ]; } - protected function getQuotedColumnInPrimaryKeySQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInPrimaryKeySQL() : array { return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY ("create"))']; } - public function getCreateTableColumnCommentsSQL() + /** + * {@inheritDoc} + */ + public function getCreateTableColumnCommentsSQL() : array { return [ 'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))', @@ -102,7 +123,10 @@ public function getCreateTableColumnCommentsSQL() ]; } - public function getAlterTableColumnCommentsSQL() + /** + * {@inheritDoc} + */ + public function getAlterTableColumnCommentsSQL() : array { return [ 'ALTER TABLE mytable ADD quota INT NOT NULL', @@ -112,7 +136,10 @@ public function getAlterTableColumnCommentsSQL() ]; } - public function getCreateTableColumnTypeCommentsSQL() + /** + * {@inheritDoc} + */ + public function getCreateTableColumnTypeCommentsSQL() : array { return [ 'CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY (id))', @@ -120,12 +147,12 @@ public function getCreateTableColumnTypeCommentsSQL() ]; } - public function testHasCorrectPlatformName() + public function testHasCorrectPlatformName() : void { self::assertEquals('sqlanywhere', $this->platform->getName()); } - public function testGeneratesCreateTableSQLWithCommonIndexes() + public function testGeneratesCreateTableSQLWithCommonIndexes() : void { $table = new Table('test'); $table->addColumn('id', 'integer'); @@ -144,7 +171,7 @@ public function testGeneratesCreateTableSQLWithCommonIndexes() ); } - public function testGeneratesCreateTableSQLWithForeignKeyConstraints() + public function testGeneratesCreateTableSQLWithForeignKeyConstraints() : void { $table = new Table('test'); $table->addColumn('id', 'integer'); @@ -169,7 +196,7 @@ public function testGeneratesCreateTableSQLWithForeignKeyConstraints() ); } - public function testGeneratesCreateTableSQLWithCheckConstraints() + public function testGeneratesCreateTableSQLWithCheckConstraints() : void { $table = new Table('test'); $table->addColumn('id', 'integer'); @@ -183,7 +210,7 @@ public function testGeneratesCreateTableSQLWithCheckConstraints() ); } - public function testGeneratesTableAlterationWithRemovedColumnCommentSql() + public function testGeneratesTableAlterationWithRemovedColumnCommentSql() : void { $table = new Table('mytable'); $table->addColumn('foo', 'string', ['comment' => 'foo comment']); @@ -203,9 +230,11 @@ public function testGeneratesTableAlterationWithRemovedColumnCommentSql() } /** + * @param int|bool|null $lockMode + * * @dataProvider getLockHints */ - public function testAppendsLockHint($lockMode, $lockHint) + public function testAppendsLockHint($lockMode, string $lockHint) : void { $fromClause = 'FROM users'; $expectedResult = $fromClause . $lockHint; @@ -213,7 +242,10 @@ public function testAppendsLockHint($lockMode, $lockHint) self::assertSame($expectedResult, $this->platform->appendLockHint($fromClause, $lockMode)); } - public function getLockHints() + /** + * @return mixed[][] + */ + public static function getLockHints() : iterable { return [ [null, ''], @@ -226,12 +258,12 @@ public function getLockHints() ]; } - public function testHasCorrectMaxIdentifierLength() + public function testHasCorrectMaxIdentifierLength() : void { self::assertEquals(128, $this->platform->getMaxIdentifierLength()); } - public function testFixesSchemaElementNames() + public function testFixesSchemaElementNames() : void { $maxIdentifierLength = $this->platform->getMaxIdentifierLength(); $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; @@ -253,7 +285,7 @@ public function testFixesSchemaElementNames() ); } - public function testGeneratesColumnTypesDeclarationSQL() + public function testGeneratesColumnTypesDeclarationSQL() : void { $fullColumnDef = [ 'length' => 10, @@ -283,12 +315,12 @@ public function testGeneratesColumnTypesDeclarationSQL() self::assertEquals(32767, $this->platform->getVarcharMaxLength()); } - public function testHasNativeGuidType() + public function testHasNativeGuidType() : void { self::assertTrue($this->platform->hasNativeGuidType()); } - public function testGeneratesDDLSnippets() + public function testGeneratesDDLSnippets() : void { self::assertEquals("CREATE DATABASE 'foobar'", $this->platform->getCreateDatabaseSQL('foobar')); self::assertEquals("CREATE DATABASE 'foobar'", $this->platform->getCreateDatabaseSQL('"foobar"')); @@ -311,7 +343,7 @@ public function testGeneratesDDLSnippets() self::assertEquals('DROP VIEW fooview', $this->platform->getDropViewSQL('fooview')); } - public function testGeneratesPrimaryKeyDeclarationSQL() + public function testGeneratesPrimaryKeyDeclarationSQL() : void { self::assertEquals( 'CONSTRAINT pk PRIMARY KEY CLUSTERED (a, b)', @@ -328,14 +360,14 @@ public function testGeneratesPrimaryKeyDeclarationSQL() ); } - public function testCannotGeneratePrimaryKeyDeclarationSQLWithEmptyColumns() + public function testCannotGeneratePrimaryKeyDeclarationSQLWithEmptyColumns() : void { $this->expectException(InvalidArgumentException::class); $this->platform->getPrimaryKeyDeclarationSQL(new Index('pk', [], true, true)); } - public function testGeneratesCreateUnnamedPrimaryKeySQL() + public function testGeneratesCreateUnnamedPrimaryKeySQL() : void { self::assertEquals( 'ALTER TABLE foo ADD PRIMARY KEY CLUSTERED (a, b)', @@ -353,7 +385,7 @@ public function testGeneratesCreateUnnamedPrimaryKeySQL() ); } - public function testGeneratesUniqueConstraintDeclarationSQL() + public function testGeneratesUniqueConstraintDeclarationSQL() : void { self::assertEquals( 'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)', @@ -368,14 +400,14 @@ public function testGeneratesUniqueConstraintDeclarationSQL() ); } - public function testCannotGenerateUniqueConstraintDeclarationSQLWithEmptyColumns() + public function testCannotGenerateUniqueConstraintDeclarationSQLWithEmptyColumns() : void { $this->expectException(InvalidArgumentException::class); $this->platform->getUniqueConstraintDeclarationSQL('constr', new Index('constr', [], true)); } - public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL() + public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL() : void { self::assertEquals( 'CONSTRAINT fk ' . @@ -402,7 +434,7 @@ public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL ); } - public function testGeneratesForeignKeyMatchClausesSQL() + public function testGeneratesForeignKeyMatchClausesSQL() : void { self::assertEquals('SIMPLE', $this->platform->getForeignKeyMatchClauseSQL(1)); self::assertEquals('FULL', $this->platform->getForeignKeyMatchClauseSQL(2)); @@ -410,46 +442,46 @@ public function testGeneratesForeignKeyMatchClausesSQL() self::assertEquals('UNIQUE FULL', $this->platform->getForeignKeyMatchClauseSQL(130)); } - public function testCannotGenerateInvalidForeignKeyMatchClauseSQL() + public function testCannotGenerateInvalidForeignKeyMatchClauseSQL() : void { $this->expectException(InvalidArgumentException::class); $this->platform->getForeignKeyMatchCLauseSQL(3); } - public function testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns() + public function testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns() : void { $this->expectException(InvalidArgumentException::class); $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint([], 'foreign_tbl', ['c', 'd'])); } - public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignColumns() + public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignColumns() : void { $this->expectException(InvalidArgumentException::class); $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], 'foreign_tbl', [])); } - public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignTableName() + public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignTableName() : void { $this->expectException(InvalidArgumentException::class); $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], '', ['c', 'd'])); } - public function testCannotGenerateCommonIndexWithCreateConstraintSQL() + public function testCannotGenerateCommonIndexWithCreateConstraintSQL() : void { $this->expectException(InvalidArgumentException::class); $this->platform->getCreateConstraintSQL(new Index('fooindex', []), new Table('footable')); } - public function testCannotGenerateCustomConstraintWithCreateConstraintSQL() + public function testCannotGenerateCustomConstraintWithCreateConstraintSQL() : void { $this->expectException(InvalidArgumentException::class); $this->platform->getCreateConstraintSQL($this->createMock(Constraint::class), 'footable'); } - public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() + public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() : void { self::assertEquals( 'CREATE VIRTUAL UNIQUE CLUSTERED INDEX fooindex ON footable (a, b) FOR OLAP WORKLOAD', @@ -466,14 +498,14 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() ); } - public function testDoesNotSupportIndexDeclarationInCreateAlterTableStatements() + public function testDoesNotSupportIndexDeclarationInCreateAlterTableStatements() : void { $this->expectException(DBALException::class); $this->platform->getIndexDeclarationSQL('index', new Index('index', [])); } - public function testGeneratesDropIndexSQL() + public function testGeneratesDropIndexSQL() : void { $index = new Index('fooindex', []); @@ -485,21 +517,21 @@ public function testGeneratesDropIndexSQL() )); } - public function testCannotGenerateDropIndexSQLWithInvalidIndexParameter() + public function testCannotGenerateDropIndexSQLWithInvalidIndexParameter() : void { $this->expectException(InvalidArgumentException::class); $this->platform->getDropIndexSQL(['index'], 'table'); } - public function testCannotGenerateDropIndexSQLWithInvalidTableParameter() + public function testCannotGenerateDropIndexSQLWithInvalidTableParameter() : void { $this->expectException(InvalidArgumentException::class); $this->platform->getDropIndexSQL('index', ['table']); } - public function testGeneratesSQLSnippets() + public function testGeneratesSQLSnippets() : void { self::assertEquals('STRING(column1, "string1", column2, "string2")', $this->platform->getConcatExpression( 'column1', @@ -573,14 +605,14 @@ public function testGeneratesSQLSnippets() ); } - public function testDoesNotSupportRegexp() + public function testDoesNotSupportRegexp() : void { $this->expectException(DBALException::class); $this->platform->getRegexpExpression(); } - public function testHasCorrectDateTimeTzFormatString() + public function testHasCorrectDateTimeTzFormatString() : void { // Date time type with timezone is not supported before version 12. // For versions before we have to ensure that the date time with timezone format @@ -588,7 +620,7 @@ public function testHasCorrectDateTimeTzFormatString() self::assertEquals($this->platform->getDateTimeFormatString(), $this->platform->getDateTimeTzFormatString()); } - public function testHasCorrectDefaultTransactionIsolationLevel() + public function testHasCorrectDefaultTransactionIsolationLevel() : void { self::assertEquals( TransactionIsolationLevel::READ_UNCOMMITTED, @@ -596,7 +628,7 @@ public function testHasCorrectDefaultTransactionIsolationLevel() ); } - public function testGeneratesTransactionsCommands() + public function testGeneratesTransactionsCommands() : void { self::assertEquals( 'SET TEMPORARY OPTION isolation_level = 0', @@ -616,14 +648,14 @@ public function testGeneratesTransactionsCommands() ); } - public function testCannotGenerateTransactionCommandWithInvalidIsolationLevel() + public function testCannotGenerateTransactionCommandWithInvalidIsolationLevel() : void { $this->expectException(InvalidArgumentException::class); $this->platform->getSetTransactionIsolationSQL('invalid_transaction_isolation_level'); } - public function testModifiesLimitQuery() + public function testModifiesLimitQuery() : void { self::assertEquals( 'SELECT TOP 10 * FROM user', @@ -631,7 +663,7 @@ public function testModifiesLimitQuery() ); } - public function testModifiesLimitQueryWithEmptyOffset() + public function testModifiesLimitQueryWithEmptyOffset() : void { self::assertEquals( 'SELECT TOP 10 * FROM user', @@ -639,7 +671,7 @@ public function testModifiesLimitQueryWithEmptyOffset() ); } - public function testModifiesLimitQueryWithOffset() + public function testModifiesLimitQueryWithOffset() : void { self::assertEquals( 'SELECT TOP 10 START AT 6 * FROM user', @@ -651,7 +683,7 @@ public function testModifiesLimitQueryWithOffset() ); } - public function testModifiesLimitQueryWithSubSelect() + public function testModifiesLimitQueryWithSubSelect() : void { self::assertEquals( 'SELECT TOP 10 * FROM (SELECT u.id as uid, u.name as uname FROM user) AS doctrine_tbl', @@ -659,7 +691,7 @@ public function testModifiesLimitQueryWithSubSelect() ); } - public function testModifiesLimitQueryWithoutLimit() + public function testModifiesLimitQueryWithoutLimit() : void { self::assertEquals( 'SELECT TOP ALL START AT 11 n FROM Foo', @@ -667,97 +699,97 @@ public function testModifiesLimitQueryWithoutLimit() ); } - public function testPrefersIdentityColumns() + public function testPrefersIdentityColumns() : void { self::assertTrue($this->platform->prefersIdentityColumns()); } - public function testDoesNotPreferSequences() + public function testDoesNotPreferSequences() : void { self::assertFalse($this->platform->prefersSequences()); } - public function testSupportsIdentityColumns() + public function testSupportsIdentityColumns() : void { self::assertTrue($this->platform->supportsIdentityColumns()); } - public function testSupportsPrimaryConstraints() + public function testSupportsPrimaryConstraints() : void { self::assertTrue($this->platform->supportsPrimaryConstraints()); } - public function testSupportsForeignKeyConstraints() + public function testSupportsForeignKeyConstraints() : void { self::assertTrue($this->platform->supportsForeignKeyConstraints()); } - public function testSupportsForeignKeyOnUpdate() + public function testSupportsForeignKeyOnUpdate() : void { self::assertTrue($this->platform->supportsForeignKeyOnUpdate()); } - public function testSupportsAlterTable() + public function testSupportsAlterTable() : void { self::assertTrue($this->platform->supportsAlterTable()); } - public function testSupportsTransactions() + public function testSupportsTransactions() : void { self::assertTrue($this->platform->supportsTransactions()); } - public function testSupportsSchemas() + public function testSupportsSchemas() : void { self::assertFalse($this->platform->supportsSchemas()); } - public function testSupportsIndexes() + public function testSupportsIndexes() : void { self::assertTrue($this->platform->supportsIndexes()); } - public function testSupportsCommentOnStatement() + public function testSupportsCommentOnStatement() : void { self::assertTrue($this->platform->supportsCommentOnStatement()); } - public function testSupportsSavePoints() + public function testSupportsSavePoints() : void { self::assertTrue($this->platform->supportsSavepoints()); } - public function testSupportsReleasePoints() + public function testSupportsReleasePoints() : void { self::assertTrue($this->platform->supportsReleaseSavepoints()); } - public function testSupportsCreateDropDatabase() + public function testSupportsCreateDropDatabase() : void { self::assertTrue($this->platform->supportsCreateDropDatabase()); } - public function testSupportsGettingAffectedRows() + public function testSupportsGettingAffectedRows() : void { self::assertTrue($this->platform->supportsGettingAffectedRows()); } - public function testDoesNotSupportSequences() + public function testDoesNotSupportSequences() : void { self::assertFalse($this->platform->supportsSequences()); } - public function testDoesNotSupportInlineColumnComments() + public function testDoesNotSupportInlineColumnComments() : void { self::assertFalse($this->platform->supportsInlineColumnComments()); } - public function testCannotEmulateSchemas() + public function testCannotEmulateSchemas() : void { self::assertFalse($this->platform->canEmulateSchemas()); } - public function testInitializesDoctrineTypeMappings() + public function testInitializesDoctrineTypeMappings() : void { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('integer')); self::assertSame('integer', $this->platform->getDoctrineTypeMapping('integer')); @@ -769,17 +801,17 @@ public function testInitializesDoctrineTypeMappings() self::assertSame('binary', $this->platform->getDoctrineTypeMapping('varbinary')); } - protected function getBinaryDefaultLength() + protected function getBinaryDefaultLength() : int { return 1; } - protected function getBinaryMaxLength() + protected function getBinaryMaxLength() : int { return 32767; } - public function testReturnsBinaryTypeDeclarationSQL() + public function testReturnsBinaryTypeDeclarationSQL() : void { self::assertSame('VARBINARY(1)', $this->platform->getBinaryTypeDeclarationSQL([])); self::assertSame('VARBINARY(1)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); @@ -794,24 +826,28 @@ public function testReturnsBinaryTypeDeclarationSQL() * @group legacy * @expectedDeprecation Binary field length 32768 is greater than supported by the platform (32767). Reduce the field length or use a BLOB field instead. */ - public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() + public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() : void { self::assertSame('LONG BINARY', $this->platform->getBinaryTypeDeclarationSQL(['length' => 32768])); self::assertSame('LONG BINARY', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 32768])); } /** + * {@inheritDoc} + * * @group DBAL-234 */ - protected function getAlterTableRenameIndexSQL() + protected function getAlterTableRenameIndexSQL() : array { return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_bar']; } /** + * {@inheritDoc} + * * @group DBAL-234 */ - protected function getQuotedAlterTableRenameIndexSQL() + protected function getQuotedAlterTableRenameIndexSQL() : array { return [ 'ALTER INDEX "create" ON "table" RENAME TO "select"', @@ -822,7 +858,7 @@ protected function getQuotedAlterTableRenameIndexSQL() /** * {@inheritdoc} */ - protected function getQuotedAlterTableRenameColumnSQL() + protected function getQuotedAlterTableRenameColumnSQL() : array { return [ 'ALTER TABLE mytable RENAME unquoted1 TO unquoted', @@ -840,23 +876,27 @@ protected function getQuotedAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotedAlterTableChangeColumnLengthSQL() + protected function getQuotedAlterTableChangeColumnLengthSQL() : array { $this->markTestIncomplete('Not implemented yet'); } /** + * {@inheritDoc} + * * @group DBAL-807 */ - protected function getAlterTableRenameIndexInSchemaSQL() + protected function getAlterTableRenameIndexInSchemaSQL() : array { return ['ALTER INDEX idx_foo ON myschema.mytable RENAME TO idx_bar']; } /** + * {@inheritDoc} + * * @group DBAL-807 */ - protected function getQuotedAlterTableRenameIndexInSchemaSQL() + protected function getQuotedAlterTableRenameIndexInSchemaSQL() : array { return [ 'ALTER INDEX "create" ON "schema"."table" RENAME TO "select"', @@ -867,7 +907,7 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() /** * @group DBAL-423 */ - public function testReturnsGuidTypeDeclarationSQL() + public function testReturnsGuidTypeDeclarationSQL() : void { self::assertSame('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL([])); } @@ -875,7 +915,7 @@ public function testReturnsGuidTypeDeclarationSQL() /** * {@inheritdoc} */ - public function getAlterTableRenameColumnSQL() + public function getAlterTableRenameColumnSQL() : array { return ['ALTER TABLE foo RENAME bar TO baz']; } @@ -883,7 +923,7 @@ public function getAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotesTableIdentifiersInAlterTableSQL() + protected function getQuotesTableIdentifiersInAlterTableSQL() : array { return [ 'ALTER TABLE "foo" DROP FOREIGN KEY fk1', @@ -899,7 +939,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() /** * {@inheritdoc} */ - protected function getCommentOnColumnSQL() + protected function getCommentOnColumnSQL() : array { return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', @@ -911,7 +951,7 @@ protected function getCommentOnColumnSQL() /** * @group DBAL-1004 */ - public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() + public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() : void { $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]); $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]); @@ -930,7 +970,7 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() /** * {@inheritdoc} */ - public function getReturnsForeignKeyReferentialActionSQL() + public static function getReturnsForeignKeyReferentialActionSQL() : iterable { return [ ['CASCADE', 'CASCADE'], @@ -945,7 +985,7 @@ public function getReturnsForeignKeyReferentialActionSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() + protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string { return 'CONSTRAINT "select" UNIQUE (foo)'; } @@ -953,7 +993,7 @@ protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInIndexDeclarationSQL() + protected function getQuotesReservedKeywordInIndexDeclarationSQL() : string { return ''; // not supported by this platform } @@ -961,7 +1001,7 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInTruncateTableSQL() + protected function getQuotesReservedKeywordInTruncateTableSQL() : string { return 'TRUNCATE TABLE "select"'; } @@ -969,7 +1009,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() /** * {@inheritdoc} */ - protected function supportsInlineIndexDeclaration() + protected function supportsInlineIndexDeclaration() : bool { return false; } @@ -977,7 +1017,7 @@ protected function supportsInlineIndexDeclaration() /** * {@inheritdoc} */ - protected function getAlterStringToFixedStringSQL() + protected function getAlterStringToFixedStringSQL() : array { return ['ALTER TABLE mytable ALTER name CHAR(2) NOT NULL']; } @@ -985,7 +1025,7 @@ protected function getAlterStringToFixedStringSQL() /** * {@inheritdoc} */ - protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() + protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array { return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_foo_renamed']; } @@ -993,7 +1033,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() /** * @group DBAL-2436 */ - public function testQuotesSchemaNameInListTableColumnsSQL() + public function testQuotesSchemaNameInListTableColumnsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1004,7 +1044,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableConstraintsSQL() + public function testQuotesTableNameInListTableConstraintsSQL() : void { self::assertStringContainsStringIgnoringCase("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); } @@ -1012,7 +1052,7 @@ public function testQuotesTableNameInListTableConstraintsSQL() /** * @group DBAL-2436 */ - public function testQuotesSchemaNameInListTableConstraintsSQL() + public function testQuotesSchemaNameInListTableConstraintsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1023,7 +1063,7 @@ public function testQuotesSchemaNameInListTableConstraintsSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableForeignKeysSQL() + public function testQuotesTableNameInListTableForeignKeysSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1034,7 +1074,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() /** * @group DBAL-2436 */ - public function testQuotesSchemaNameInListTableForeignKeysSQL() + public function testQuotesSchemaNameInListTableForeignKeysSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1045,7 +1085,7 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableIndexesSQL() + public function testQuotesTableNameInListTableIndexesSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -1056,7 +1096,7 @@ public function testQuotesTableNameInListTableIndexesSQL() /** * @group DBAL-2436 */ - public function testQuotesSchemaNameInListTableIndexesSQL() + public function testQuotesSchemaNameInListTableIndexesSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php index 8aa6bc0cda3..65b5e85f219 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php @@ -19,7 +19,7 @@ protected function setUp() : void $this->platform = new SQLAzurePlatform(); } - public function testCreateFederatedOnTable() + public function testCreateFederatedOnTable() : void { $table = new Table('tbl'); $table->addColumn('id', 'integer'); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php index 3083ab7b606..60abcad7c06 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php @@ -2,16 +2,17 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLServer2008Platform; class SQLServer2008PlatformTest extends AbstractSQLServerPlatformTestCase { - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new SQLServer2008Platform(); } - public function testGeneratesTypeDeclarationForDateTimeTz() + public function testGeneratesTypeDeclarationForDateTimeTz() : void { self::assertEquals('DATETIMEOFFSET(6)', $this->platform->getDateTimeTzTypeDeclarationSQL([])); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php index 91f8cfe2dc2..18a8a0ef1d2 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php @@ -3,27 +3,28 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Schema\Sequence; class SQLServer2012PlatformTest extends AbstractSQLServerPlatformTestCase { - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new SQLServer2012Platform(); } - public function testSupportsSequences() + public function testSupportsSequences() : void { self::assertTrue($this->platform->supportsSequences()); } - public function testDoesNotPreferSequences() + public function testDoesNotPreferSequences() : void { self::assertFalse($this->platform->prefersSequences()); } - public function testGeneratesSequenceSqlCommands() + public function testGeneratesSequenceSqlCommands() : void { $sequence = new Sequence('myseq', 20, 1); self::assertEquals( @@ -44,55 +45,55 @@ public function testGeneratesSequenceSqlCommands() ); } - public function testModifyLimitQuery() + public function testModifyLimitQuery() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); self::assertEquals('SELECT * FROM user ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $sql); } - public function testModifyLimitQueryWithEmptyOffset() + public function testModifyLimitQueryWithEmptyOffset() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); self::assertEquals('SELECT * FROM user ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $sql); } - public function testModifyLimitQueryWithOffset() + public function testModifyLimitQueryWithOffset() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10, 5); self::assertEquals('SELECT * FROM user ORDER BY username DESC OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY', $sql); } - public function testModifyLimitQueryWithAscOrderBy() + public function testModifyLimitQueryWithAscOrderBy() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user ORDER BY username ASC', 10); self::assertEquals('SELECT * FROM user ORDER BY username ASC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $sql); } - public function testModifyLimitQueryWithLowercaseOrderBy() + public function testModifyLimitQueryWithLowercaseOrderBy() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user order by username', 10); self::assertEquals('SELECT * FROM user order by username OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $sql); } - public function testModifyLimitQueryWithDescOrderBy() + public function testModifyLimitQueryWithDescOrderBy() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10); self::assertEquals('SELECT * FROM user ORDER BY username DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $sql); } - public function testModifyLimitQueryWithMultipleOrderBy() + public function testModifyLimitQueryWithMultipleOrderBy() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC, usereamil ASC', 10); self::assertEquals('SELECT * FROM user ORDER BY username DESC, usereamil ASC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $sql); } - public function testModifyLimitQueryWithSubSelect() + public function testModifyLimitQueryWithSubSelect() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result', 10); self::assertEquals('SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $sql); } - public function testModifyLimitQueryWithSubSelectAndOrder() + public function testModifyLimitQueryWithSubSelectAndOrder() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result ORDER BY uname DESC', 10); self::assertEquals('SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result ORDER BY uname DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $sql); @@ -101,7 +102,7 @@ public function testModifyLimitQueryWithSubSelectAndOrder() self::assertEquals('SELECT * FROM (SELECT u.id, u.name) dctrn_result ORDER BY name DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $sql); } - public function testModifyLimitQueryWithSubSelectAndMultipleOrder() + public function testModifyLimitQueryWithSubSelectAndMultipleOrder() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result ORDER BY uname DESC, uid ASC', 10, 5); self::assertEquals('SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result ORDER BY uname DESC, uid ASC OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY', $sql); @@ -113,7 +114,7 @@ public function testModifyLimitQueryWithSubSelectAndMultipleOrder() self::assertEquals('SELECT * FROM (SELECT u.id, u.name) dctrn_result ORDER BY name DESC, id ASC OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY', $sql); } - public function testModifyLimitQueryWithFromColumnNames() + public function testModifyLimitQueryWithFromColumnNames() : void { $sql = $this->platform->modifyLimitQuery('SELECT a.fromFoo, fromBar FROM foo', 10); self::assertEquals('SELECT a.fromFoo, fromBar FROM foo ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $sql); @@ -122,7 +123,7 @@ public function testModifyLimitQueryWithFromColumnNames() /** * @group DBAL-927 */ - public function testModifyLimitQueryWithExtraLongQuery() + public function testModifyLimitQueryWithExtraLongQuery() : void { $query = 'SELECT table1.column1, table2.column2, table3.column3, table4.column4, table5.column5, table6.column6, table7.column7, table8.column8 FROM table1, table2, table3, table4, table5, table6, table7, table8 '; $query .= 'WHERE (table1.column1 = table2.column2) AND (table1.column1 = table3.column3) AND (table1.column1 = table4.column4) AND (table1.column1 = table5.column5) AND (table1.column1 = table6.column6) AND (table1.column1 = table7.column7) AND (table1.column1 = table8.column8) AND (table2.column2 = table3.column3) AND (table2.column2 = table4.column4) AND (table2.column2 = table5.column5) AND (table2.column2 = table6.column6) '; @@ -143,7 +144,7 @@ public function testModifyLimitQueryWithExtraLongQuery() /** * @group DDC-2470 */ - public function testModifyLimitQueryWithOrderByClause() + public function testModifyLimitQueryWithOrderByClause() : void { $sql = 'SELECT m0_.NOMBRE AS NOMBRE0, m0_.FECHAINICIO AS FECHAINICIO1, m0_.FECHAFIN AS FECHAFIN2 FROM MEDICION m0_ WITH (NOLOCK) INNER JOIN ESTUDIO e1_ ON m0_.ESTUDIO_ID = e1_.ID INNER JOIN CLIENTE c2_ ON e1_.CLIENTE_ID = c2_.ID INNER JOIN USUARIO u3_ ON c2_.ID = u3_.CLIENTE_ID WHERE u3_.ID = ? ORDER BY m0_.FECHAINICIO DESC'; $expected = 'SELECT m0_.NOMBRE AS NOMBRE0, m0_.FECHAINICIO AS FECHAINICIO1, m0_.FECHAFIN AS FECHAFIN2 FROM MEDICION m0_ WITH (NOLOCK) INNER JOIN ESTUDIO e1_ ON m0_.ESTUDIO_ID = e1_.ID INNER JOIN CLIENTE c2_ ON e1_.CLIENTE_ID = c2_.ID INNER JOIN USUARIO u3_ ON c2_.ID = u3_.CLIENTE_ID WHERE u3_.ID = ? ORDER BY m0_.FECHAINICIO DESC OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY'; @@ -155,7 +156,7 @@ public function testModifyLimitQueryWithOrderByClause() /** * @group DBAL-713 */ - public function testModifyLimitQueryWithSubSelectInSelectList() + public function testModifyLimitQueryWithSubSelectInSelectList() : void { $sql = $this->platform->modifyLimitQuery( 'SELECT ' . @@ -185,7 +186,7 @@ public function testModifyLimitQueryWithSubSelectInSelectList() /** * @group DBAL-713 */ - public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() + public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() : void { $sql = $this->platform->modifyLimitQuery( 'SELECT ' . @@ -217,7 +218,7 @@ public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() /** * @group DBAL-834 */ - public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() + public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() : void { $sql = $this->platform->modifyLimitQuery( 'SELECT ' . @@ -242,7 +243,7 @@ public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() ); } - public function testModifyLimitQueryWithFromSubquery() + public function testModifyLimitQueryWithFromSubquery() : void { $sql = $this->platform->modifyLimitQuery('SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result', 10); @@ -251,7 +252,7 @@ public function testModifyLimitQueryWithFromSubquery() self::assertEquals($sql, $expected); } - public function testModifyLimitQueryWithFromSubqueryAndOrder() + public function testModifyLimitQueryWithFromSubqueryAndOrder() : void { $sql = $this->platform->modifyLimitQuery('SELECT DISTINCT id_0, value_1 FROM (SELECT k0_.id AS id_0, k0_.value AS value_1 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result ORDER BY value_1 DESC', 10); @@ -260,7 +261,7 @@ public function testModifyLimitQueryWithFromSubqueryAndOrder() self::assertEquals($sql, $expected); } - public function testModifyLimitQueryWithComplexOrderByExpression() + public function testModifyLimitQueryWithComplexOrderByExpression() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM table ORDER BY (table.x * table.y) DESC', 10); @@ -272,7 +273,7 @@ public function testModifyLimitQueryWithComplexOrderByExpression() /** * @throws DBALException */ - public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBaseTable() + public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBaseTable() : void { $querySql = 'SELECT DISTINCT id_0, name_1 ' . 'FROM (' @@ -295,7 +296,7 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBas /** * @throws DBALException */ - public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoinTable() + public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoinTable() : void { $querySql = 'SELECT DISTINCT id_0, name_1 ' . 'FROM (' @@ -318,7 +319,7 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoi /** * @throws DBALException */ - public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBothTables() + public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBothTables() : void { $querySql = 'SELECT DISTINCT id_0, name_1, foo_2 ' . 'FROM (' @@ -338,7 +339,7 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBo self::assertEquals($alteredSql, $sql); } - public function testModifyLimitSubquerySimple() + public function testModifyLimitSubquerySimple() : void { $querySql = 'SELECT DISTINCT id_0 FROM ' . '(SELECT k0_.id AS id_0, k0_.field AS field_1 ' @@ -349,7 +350,7 @@ public function testModifyLimitSubquerySimple() self::assertEquals($alteredSql, $sql); } - public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() + public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() : void { $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC)'; $expectedSql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; @@ -362,7 +363,7 @@ public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() self::assertEquals($expectedSql, $sql); } - public function testModifyLimitQueryWithNewlineBeforeOrderBy() + public function testModifyLimitQueryWithNewlineBeforeOrderBy() : void { $querySql = "SELECT * FROM test\nORDER BY col DESC"; $expectedSql = "SELECT * FROM test\nORDER BY col DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"; diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php index ed2842813aa..77cf7b17b41 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php @@ -3,20 +3,23 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\LockMode; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLServerPlatform; class SQLServerPlatformTest extends AbstractSQLServerPlatformTestCase { - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new SQLServerPlatform(); } /** + * @param int|bool|null $lockMode + * * @group DDC-2310 * @dataProvider getLockHints */ - public function testAppendsLockHint($lockMode, $lockHint) + public function testAppendsLockHint($lockMode, string $lockHint) : void { $fromClause = 'FROM users'; $expectedResult = $fromClause . $lockHint; @@ -28,12 +31,15 @@ public function testAppendsLockHint($lockMode, $lockHint) * @group DBAL-2408 * @dataProvider getModifyLimitQueries */ - public function testScrubInnerOrderBy($query, $limit, $offset, $expectedResult) + public function testScrubInnerOrderBy(string $query, int $limit, ?int $offset, string $expectedResult) : void { self::assertSame($expectedResult, $this->platform->modifyLimitQuery($query, $limit, $offset)); } - public function getLockHints() + /** + * @return mixed[][] + */ + public static function getLockHints() : iterable { return [ [null, ''], @@ -46,7 +52,10 @@ public function getLockHints() ]; } - public function getModifyLimitQueries() + /** + * @return mixed[][] + */ + public static function getModifyLimitQueries() : iterable { return [ // Test re-ordered query with correctly-scrubbed ORDER BY clause diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index 26cc4d304eb..d645b218cb8 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table; @@ -12,17 +13,20 @@ class SqlitePlatformTest extends AbstractPlatformTestCase { - public function createPlatform() + public function createPlatform() : AbstractPlatform { return new SqlitePlatform(); } - public function getGenerateTableSql() + public function getGenerateTableSql() : string { return 'CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL)'; } - public function getGenerateTableWithMultiColumnUniqueIndexSql() + /** + * {@inheritDoc} + */ + public function getGenerateTableWithMultiColumnUniqueIndexSql() : array { return [ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', @@ -30,14 +34,14 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql() ]; } - public function testGeneratesSqlSnippets() + public function testGeneratesSqlSnippets() : void { self::assertEquals('REGEXP', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct'); self::assertEquals('SUBSTR(column, 5, LENGTH(column))', $this->platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct'); self::assertEquals('SUBSTR(column, 0, 5)', $this->platform->getSubstringExpression('column', 0, 5), 'Substring expression with length is not correct'); } - public function testGeneratesTransactionCommands() + public function testGeneratesTransactionCommands() : void { self::assertEquals( 'PRAGMA read_uncommitted = 0', @@ -57,12 +61,12 @@ public function testGeneratesTransactionCommands() ); } - public function testPrefersIdentityColumns() + public function testPrefersIdentityColumns() : void { self::assertTrue($this->platform->prefersIdentityColumns()); } - public function testIgnoresUnsignedIntegerDeclarationForAutoIncrementalIntegers() + public function testIgnoresUnsignedIntegerDeclarationForAutoIncrementalIntegers() : void { self::assertSame( 'INTEGER PRIMARY KEY AUTOINCREMENT', @@ -74,7 +78,7 @@ public function testIgnoresUnsignedIntegerDeclarationForAutoIncrementalIntegers( * @group DBAL-752 * @group DBAL-924 */ - public function testGeneratesTypeDeclarationForTinyIntegers() + public function testGeneratesTypeDeclarationForTinyIntegers() : void { self::assertEquals( 'TINYINT', @@ -104,7 +108,7 @@ public function testGeneratesTypeDeclarationForTinyIntegers() * @group DBAL-752 * @group DBAL-924 */ - public function testGeneratesTypeDeclarationForSmallIntegers() + public function testGeneratesTypeDeclarationForSmallIntegers() : void { self::assertEquals( 'SMALLINT', @@ -138,7 +142,7 @@ public function testGeneratesTypeDeclarationForSmallIntegers() * @group DBAL-752 * @group DBAL-924 */ - public function testGeneratesTypeDeclarationForMediumIntegers() + public function testGeneratesTypeDeclarationForMediumIntegers() : void { self::assertEquals( 'MEDIUMINT', @@ -168,7 +172,7 @@ public function testGeneratesTypeDeclarationForMediumIntegers() ); } - public function testGeneratesTypeDeclarationForIntegers() + public function testGeneratesTypeDeclarationForIntegers() : void { self::assertEquals( 'INTEGER', @@ -202,7 +206,7 @@ public function testGeneratesTypeDeclarationForIntegers() * @group DBAL-752 * @group DBAL-924 */ - public function testGeneratesTypeDeclarationForBigIntegers() + public function testGeneratesTypeDeclarationForBigIntegers() : void { self::assertEquals( 'BIGINT', @@ -232,7 +236,7 @@ public function testGeneratesTypeDeclarationForBigIntegers() ); } - public function testGeneratesTypeDeclarationForStrings() + public function testGeneratesTypeDeclarationForStrings() : void { self::assertEquals( 'CHAR(10)', @@ -252,54 +256,57 @@ public function testGeneratesTypeDeclarationForStrings() ); } - public function getGenerateIndexSql() + public function getGenerateIndexSql() : string { return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; } - public function getGenerateUniqueIndexSql() + public function getGenerateUniqueIndexSql() : string { return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; } - public function testGeneratesForeignKeyCreationSql() + public function testGeneratesForeignKeyCreationSql() : void { $this->expectException(DBALException::class); parent::testGeneratesForeignKeyCreationSql(); } - public function testGeneratesConstraintCreationSql() + public function testGeneratesConstraintCreationSql() : void { $this->expectException(DBALException::class); parent::testGeneratesConstraintCreationSql(); } - public function getGenerateForeignKeySql() + public function getGenerateForeignKeySql() : string { return null; } - public function testModifyLimitQuery() + public function testModifyLimitQuery() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); self::assertEquals('SELECT * FROM user LIMIT 10', $sql); } - public function testModifyLimitQueryWithEmptyOffset() + public function testModifyLimitQueryWithEmptyOffset() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); self::assertEquals('SELECT * FROM user LIMIT 10', $sql); } - public function testModifyLimitQueryWithOffsetAndEmptyLimit() + public function testModifyLimitQueryWithOffsetAndEmptyLimit() : void { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', null, 10); self::assertEquals('SELECT * FROM user LIMIT -1 OFFSET 10', $sql); } - public function getGenerateAlterTableSql() + /** + * {@inheritDoc} + */ + public function getGenerateAlterTableSql() : array { return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT id, bar, bloo FROM mytable', @@ -314,7 +321,7 @@ public function getGenerateAlterTableSql() /** * @group DDC-1845 */ - public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey() + public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey() : void { $table = new Table('test'); $table->addColumn('"like"', 'integer', ['notnull' => true, 'autoincrement' => true]); @@ -327,7 +334,7 @@ public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey() ); } - public function testAlterTableAddColumns() + public function testAlterTableAddColumns() : void { $diff = new TableDiff('user'); $diff->addedColumns['foo'] = new Column('foo', Type::getType('string')); @@ -351,8 +358,10 @@ public function testAlterTableAddComplexColumns(TableDiff $diff) : void $this->platform->getAlterTableSQL($diff); } - /** @return mixed[] */ - public function complexDiffProvider() : array + /** + * @return mixed[][] + */ + public static function complexDiffProvider() : iterable { $date = new TableDiff('user'); $date->addedColumns['time'] = new Column('time', Type::getType('date'), ['default' => 'CURRENT_DATE']); @@ -366,7 +375,7 @@ public function complexDiffProvider() : array ]; } - public function testCreateTableWithDeferredForeignKeys() + public function testCreateTableWithDeferredForeignKeys() : void { $table = new Table('user'); $table->addColumn('id', 'integer'); @@ -394,7 +403,7 @@ public function testCreateTableWithDeferredForeignKeys() self::assertEquals($sql, $this->platform->getCreateTableSQL($table)); } - public function testAlterTable() + public function testAlterTable() : void { $table = new Table('user'); $table->addColumn('id', 'integer'); @@ -438,12 +447,18 @@ public function testAlterTable() self::assertEquals($sql, $this->platform->getAlterTableSQL($diff)); } - protected function getQuotedColumnInPrimaryKeySQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInPrimaryKeySQL() : array { return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))']; } - protected function getQuotedColumnInIndexSQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInIndexSQL() : array { return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', @@ -451,7 +466,10 @@ protected function getQuotedColumnInIndexSQL() ]; } - protected function getQuotedNameInIndexSQL() + /** + * {@inheritDoc} + */ + protected function getQuotedNameInIndexSQL() : array { return [ 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', @@ -459,7 +477,10 @@ protected function getQuotedNameInIndexSQL() ]; } - protected function getQuotedColumnInForeignKeySQL() + /** + * {@inheritDoc} + */ + protected function getQuotedColumnInForeignKeySQL() : array { return [ 'CREATE TABLE "quoted" (' . @@ -470,17 +491,17 @@ protected function getQuotedColumnInForeignKeySQL() ]; } - protected function getBinaryDefaultLength() + protected function getBinaryDefaultLength() : int { return 0; } - protected function getBinaryMaxLength() + protected function getBinaryMaxLength() : int { return 0; } - public function testReturnsBinaryTypeDeclarationSQL() + public function testReturnsBinaryTypeDeclarationSQL() : void { self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL([])); self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); @@ -492,9 +513,11 @@ public function testReturnsBinaryTypeDeclarationSQL() } /** + * {@inheritDoc} + * * @group DBAL-234 */ - protected function getAlterTableRenameIndexSQL() + protected function getAlterTableRenameIndexSQL() : array { return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT id FROM mytable', @@ -507,9 +530,11 @@ protected function getAlterTableRenameIndexSQL() } /** + * {@inheritDoc} + * * @group DBAL-234 */ - protected function getQuotedAlterTableRenameIndexSQL() + protected function getQuotedAlterTableRenameIndexSQL() : array { return [ 'CREATE TEMPORARY TABLE __temp__table AS SELECT id FROM "table"', @@ -525,7 +550,7 @@ protected function getQuotedAlterTableRenameIndexSQL() /** * {@inheritdoc} */ - protected function getQuotedAlterTableRenameColumnSQL() + protected function getQuotedAlterTableRenameColumnSQL() : array { return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", "quoted1", "quoted2", "quoted3" FROM mytable', @@ -548,7 +573,7 @@ protected function getQuotedAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotedAlterTableChangeColumnLengthSQL() + protected function getQuotedAlterTableChangeColumnLengthSQL() : array { return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM mytable', @@ -568,7 +593,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() /** * @group DBAL-807 */ - public function testAlterTableRenameIndexInSchema() + public function testAlterTableRenameIndexInSchema() : void { $this->markTestIncomplete( 'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' . @@ -579,7 +604,7 @@ public function testAlterTableRenameIndexInSchema() /** * @group DBAL-807 */ - public function testQuotesAlterTableRenameIndexInSchema() + public function testQuotesAlterTableRenameIndexInSchema() : void { $this->markTestIncomplete( 'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' . @@ -590,7 +615,7 @@ public function testQuotesAlterTableRenameIndexInSchema() /** * @group DBAL-423 */ - public function testReturnsGuidTypeDeclarationSQL() + public function testReturnsGuidTypeDeclarationSQL() : void { self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); } @@ -598,7 +623,7 @@ public function testReturnsGuidTypeDeclarationSQL() /** * {@inheritdoc} */ - public function getAlterTableRenameColumnSQL() + public function getAlterTableRenameColumnSQL() : array { return [ 'CREATE TEMPORARY TABLE __temp__foo AS SELECT bar FROM foo', @@ -613,7 +638,7 @@ public function getAlterTableRenameColumnSQL() /** * {@inheritdoc} */ - protected function getQuotesTableIdentifiersInAlterTableSQL() + protected function getQuotesTableIdentifiersInAlterTableSQL() : array { return [ 'DROP INDEX IDX_8C736521A81E660E', @@ -635,7 +660,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() /** * {@inheritdoc} */ - protected function getCommentOnColumnSQL() + protected function getCommentOnColumnSQL() : array { return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', @@ -644,22 +669,22 @@ protected function getCommentOnColumnSQL() ]; } - protected function getInlineColumnCommentDelimiter() + protected static function getInlineColumnCommentDelimiter() : string { return "\n"; } - protected function getInlineColumnRegularCommentSQL() + protected static function getInlineColumnRegularCommentSQL() : string { return "--Regular comment\n"; } - protected function getInlineColumnCommentRequiringEscapingSQL() + protected static function getInlineColumnCommentRequiringEscapingSQL() : string { return "--Using inline comment delimiter \n-- works\n"; } - protected function getInlineColumnEmptyCommentSQL() + protected static function getInlineColumnEmptyCommentSQL() : string { return "--\n"; } @@ -667,7 +692,7 @@ protected function getInlineColumnEmptyCommentSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() + protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string { return 'CONSTRAINT "select" UNIQUE (foo)'; } @@ -675,7 +700,7 @@ protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInIndexDeclarationSQL() + protected function getQuotesReservedKeywordInIndexDeclarationSQL() : string { return 'INDEX "select" (foo)'; } @@ -683,7 +708,7 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() /** * {@inheritdoc} */ - protected function getQuotesReservedKeywordInTruncateTableSQL() + protected function getQuotesReservedKeywordInTruncateTableSQL() : string { return 'DELETE FROM "select"'; } @@ -691,7 +716,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() /** * {@inheritdoc} */ - protected function getAlterStringToFixedStringSQL() + protected function getAlterStringToFixedStringSQL() : array { return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT name FROM mytable', @@ -705,7 +730,7 @@ protected function getAlterStringToFixedStringSQL() /** * {@inheritdoc} */ - protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() + protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array { return [ 'DROP INDEX idx_foo', @@ -723,7 +748,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableConstraintsSQL() + public function testQuotesTableNameInListTableConstraintsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -734,7 +759,7 @@ public function testQuotesTableNameInListTableConstraintsSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableColumnsSQL() + public function testQuotesTableNameInListTableColumnsSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -745,7 +770,7 @@ public function testQuotesTableNameInListTableColumnsSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableIndexesSQL() + public function testQuotesTableNameInListTableIndexesSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -756,7 +781,7 @@ public function testQuotesTableNameInListTableIndexesSQL() /** * @group DBAL-2436 */ - public function testQuotesTableNameInListTableForeignKeysSQL() + public function testQuotesTableNameInListTableForeignKeysSQL() : void { self::assertStringContainsStringIgnoringCase( "'Foo''Bar\\'", @@ -764,12 +789,12 @@ public function testQuotesTableNameInListTableForeignKeysSQL() ); } - public function testDateAddStaticNumberOfDays() + public function testDateAddStaticNumberOfDays() : void { self::assertSame("DATE(rentalBeginsOn,'+12 DAY')", $this->platform->getDateAddDaysExpression('rentalBeginsOn', 12)); } - public function testDateAddNumberOfDaysFromColumn() + public function testDateAddNumberOfDaysFromColumn() : void { self::assertSame("DATE(rentalBeginsOn,'+' || duration || ' DAY')", $this->platform->getDateAddDaysExpression('rentalBeginsOn', 'duration')); } diff --git a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php index 4d0c066d618..c8e40214eb0 100644 --- a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php @@ -36,7 +36,7 @@ protected function setUp() : void /** * @group DBAL-726 */ - public function testBindParam() + public function testBindParam() : void { $column = 'mycolumn'; $variable = 'myvalue'; @@ -51,7 +51,7 @@ public function testBindParam() self::assertTrue($this->stmt->bindParam($column, $variable, $type, $length)); } - public function testBindValue() + public function testBindValue() : void { $param = 'myparam'; $value = 'myvalue'; @@ -65,7 +65,7 @@ public function testBindValue() self::assertTrue($this->stmt->bindValue($param, $value, $type)); } - public function testCloseCursor() + public function testCloseCursor() : void { $this->wrappedStmt->expects($this->once()) ->method('closeCursor') @@ -74,7 +74,7 @@ public function testCloseCursor() self::assertTrue($this->stmt->closeCursor()); } - public function testColumnCount() + public function testColumnCount() : void { $columnCount = 666; @@ -85,7 +85,7 @@ public function testColumnCount() self::assertSame($columnCount, $this->stmt->columnCount()); } - public function testErrorCode() + public function testErrorCode() : void { $errorCode = '666'; @@ -96,7 +96,7 @@ public function testErrorCode() self::assertSame($errorCode, $this->stmt->errorCode()); } - public function testErrorInfo() + public function testErrorInfo() : void { $errorInfo = ['666', 'Evil error.']; @@ -107,7 +107,7 @@ public function testErrorInfo() self::assertSame($errorInfo, $this->stmt->errorInfo()); } - public function testExecute() + public function testExecute() : void { $params = [ 'foo', @@ -122,7 +122,7 @@ public function testExecute() self::assertTrue($this->stmt->execute($params)); } - public function testSetFetchMode() + public function testSetFetchMode() : void { $fetchMode = FetchMode::CUSTOM_OBJECT; $arg1 = 'MyClass'; @@ -141,7 +141,7 @@ public function testSetFetchMode() self::assertSame($fetchMode, $re->getValue($this->stmt)); } - public function testGetIterator() + public function testGetIterator() : void { $this->wrappedStmt->expects($this->exactly(3)) ->method('fetch') @@ -150,7 +150,7 @@ public function testGetIterator() self::assertSame(['foo', 'bar'], iterator_to_array($this->stmt->getIterator())); } - public function testRowCount() + public function testRowCount() : void { $rowCount = 666; @@ -171,10 +171,7 @@ protected function createConnection() ->getMock(); } - /** - * @return Statement - */ - protected function createStatement(DriverStatement $wrappedStatement, Connection $connection) + protected function createStatement(DriverStatement $wrappedStatement, Connection $connection) : Statement { return new Statement($wrappedStatement, $connection); } diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php index 512dfb08224..0a8492f795f 100644 --- a/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php @@ -10,7 +10,7 @@ */ class CompositeExpressionTest extends DbalTestCase { - public function testCount() + public function testCount() : void { $expr = new CompositeExpression(CompositeExpression::TYPE_OR, ['u.group_id = 1']); @@ -21,7 +21,7 @@ public function testCount() self::assertCount(2, $expr); } - public function testAdd() + public function testAdd() : void { $expr = new CompositeExpression(CompositeExpression::TYPE_OR, ['u.group_id = 1']); @@ -45,16 +45,21 @@ public function testAdd() } /** + * @param string[]|CompositeExpression[] $parts + * * @dataProvider provideDataForConvertToString */ - public function testCompositeUsageAndGeneration($type, $parts, $expects) + public function testCompositeUsageAndGeneration(string $type, array $parts, string $expects) : void { $expr = new CompositeExpression($type, $parts); self::assertEquals($expects, (string) $expr); } - public function provideDataForConvertToString() + /** + * @return mixed[][] + */ + public static function provideDataForConvertToString() : iterable { return [ [ diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php index d419f8d5fd4..817007d67d6 100644 --- a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php @@ -27,9 +27,11 @@ protected function setUp() : void } /** + * @param string[]|CompositeExpression[] $parts + * * @dataProvider provideDataForAndX */ - public function testAndX($parts, $expected) + public function testAndX(array $parts, string $expected) : void { $composite = $this->expr->andX(); @@ -40,7 +42,10 @@ public function testAndX($parts, $expected) self::assertEquals($expected, (string) $composite); } - public function provideDataForAndX() + /** + * @return mixed[][] + */ + public static function provideDataForAndX() : iterable { return [ [ @@ -83,9 +88,11 @@ public function provideDataForAndX() } /** + * @param string[]|CompositeExpression[] $parts + * * @dataProvider provideDataForOrX */ - public function testOrX($parts, $expected) + public function testOrX(array $parts, string $expected) : void { $composite = $this->expr->orX(); @@ -96,7 +103,10 @@ public function testOrX($parts, $expected) self::assertEquals($expected, (string) $composite); } - public function provideDataForOrX() + /** + * @return mixed[][] + */ + public static function provideDataForOrX() : iterable { return [ [ @@ -141,14 +151,17 @@ public function provideDataForOrX() /** * @dataProvider provideDataForComparison */ - public function testComparison($leftExpr, $operator, $rightExpr, $expected) + public function testComparison(string $leftExpr, string $operator, string $rightExpr, string $expected) : void { $part = $this->expr->comparison($leftExpr, $operator, $rightExpr); self::assertEquals($expected, (string) $part); } - public function provideDataForComparison() + /** + * @return mixed[][] + */ + public static function provideDataForComparison() : iterable { return [ ['u.user_id', ExpressionBuilder::EQ, '1', 'u.user_id = 1'], @@ -160,72 +173,72 @@ public function provideDataForComparison() ]; } - public function testEq() + public function testEq() : void { self::assertEquals('u.user_id = 1', $this->expr->eq('u.user_id', '1')); } - public function testNeq() + public function testNeq() : void { self::assertEquals('u.user_id <> 1', $this->expr->neq('u.user_id', '1')); } - public function testLt() + public function testLt() : void { self::assertEquals('u.salary < 10000', $this->expr->lt('u.salary', '10000')); } - public function testLte() + public function testLte() : void { self::assertEquals('u.salary <= 10000', $this->expr->lte('u.salary', '10000')); } - public function testGt() + public function testGt() : void { self::assertEquals('u.salary > 10000', $this->expr->gt('u.salary', '10000')); } - public function testGte() + public function testGte() : void { self::assertEquals('u.salary >= 10000', $this->expr->gte('u.salary', '10000')); } - public function testIsNull() + public function testIsNull() : void { self::assertEquals('u.deleted IS NULL', $this->expr->isNull('u.deleted')); } - public function testIsNotNull() + public function testIsNotNull() : void { self::assertEquals('u.updated IS NOT NULL', $this->expr->isNotNull('u.updated')); } - public function testIn() + public function testIn() : void { self::assertEquals('u.groups IN (1, 3, 4, 7)', $this->expr->in('u.groups', [1, 3, 4, 7])); } - public function testInWithPlaceholder() + public function testInWithPlaceholder() : void { self::assertEquals('u.groups IN (?)', $this->expr->in('u.groups', '?')); } - public function testNotIn() + public function testNotIn() : void { self::assertEquals('u.groups NOT IN (1, 3, 4, 7)', $this->expr->notIn('u.groups', [1, 3, 4, 7])); } - public function testNotInWithPlaceholder() + public function testNotInWithPlaceholder() : void { self::assertEquals('u.groups NOT IN (:values)', $this->expr->notIn('u.groups', ':values')); } - public function testLikeWithoutEscape() + public function testLikeWithoutEscape() : void { self::assertEquals("a.song LIKE 'a virgin'", $this->expr->like('a.song', "'a virgin'")); } - public function testLikeWithEscape() + public function testLikeWithEscape() : void { self::assertEquals( "a.song LIKE 'a virgin' ESCAPE '💩'", @@ -233,7 +246,7 @@ public function testLikeWithEscape() ); } - public function testNotLikeWithoutEscape() + public function testNotLikeWithoutEscape() : void { self::assertEquals( "s.last_words NOT LIKE 'this'", @@ -241,7 +254,7 @@ public function testNotLikeWithoutEscape() ); } - public function testNotLikeWithEscape() + public function testNotLikeWithEscape() : void { self::assertEquals( "p.description NOT LIKE '20💩%' ESCAPE '💩'", diff --git a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php index b6d4d090374..610abc319a9 100644 --- a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php @@ -31,7 +31,7 @@ protected function setUp() : void /** * @group DBAL-2291 */ - public function testSimpleSelectWithoutFrom() + public function testSimpleSelectWithoutFrom() : void { $qb = new QueryBuilder($this->conn); @@ -40,7 +40,7 @@ public function testSimpleSelectWithoutFrom() self::assertEquals('SELECT some_function()', (string) $qb); } - public function testSimpleSelect() + public function testSimpleSelect() : void { $qb = new QueryBuilder($this->conn); @@ -50,7 +50,7 @@ public function testSimpleSelect() self::assertEquals('SELECT u.id FROM users u', (string) $qb); } - public function testSelectWithSimpleWhere() + public function testSelectWithSimpleWhere() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -62,7 +62,7 @@ public function testSelectWithSimpleWhere() self::assertEquals('SELECT u.id FROM users u WHERE u.nickname = ?', (string) $qb); } - public function testSelectWithLeftJoin() + public function testSelectWithLeftJoin() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -74,7 +74,7 @@ public function testSelectWithLeftJoin() self::assertEquals('SELECT u.*, p.* FROM users u LEFT JOIN phones p ON p.user_id = u.id', (string) $qb); } - public function testSelectWithJoin() + public function testSelectWithJoin() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -86,7 +86,7 @@ public function testSelectWithJoin() self::assertEquals('SELECT u.*, p.* FROM users u INNER JOIN phones p ON p.user_id = u.id', (string) $qb); } - public function testSelectWithInnerJoin() + public function testSelectWithInnerJoin() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -98,7 +98,7 @@ public function testSelectWithInnerJoin() self::assertEquals('SELECT u.*, p.* FROM users u INNER JOIN phones p ON p.user_id = u.id', (string) $qb); } - public function testSelectWithRightJoin() + public function testSelectWithRightJoin() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -110,7 +110,7 @@ public function testSelectWithRightJoin() self::assertEquals('SELECT u.*, p.* FROM users u RIGHT JOIN phones p ON p.user_id = u.id', (string) $qb); } - public function testSelectWithAndWhereConditions() + public function testSelectWithAndWhereConditions() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -123,7 +123,7 @@ public function testSelectWithAndWhereConditions() self::assertEquals('SELECT u.*, p.* FROM users u WHERE (u.username = ?) AND (u.name = ?)', (string) $qb); } - public function testSelectWithOrWhereConditions() + public function testSelectWithOrWhereConditions() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -136,7 +136,7 @@ public function testSelectWithOrWhereConditions() self::assertEquals('SELECT u.*, p.* FROM users u WHERE (u.username = ?) OR (u.name = ?)', (string) $qb); } - public function testSelectWithOrOrWhereConditions() + public function testSelectWithOrOrWhereConditions() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -149,7 +149,7 @@ public function testSelectWithOrOrWhereConditions() self::assertEquals('SELECT u.*, p.* FROM users u WHERE (u.username = ?) OR (u.name = ?)', (string) $qb); } - public function testSelectWithAndOrWhereConditions() + public function testSelectWithAndOrWhereConditions() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -164,7 +164,7 @@ public function testSelectWithAndOrWhereConditions() self::assertEquals('SELECT u.*, p.* FROM users u WHERE (((u.username = ?) AND (u.username = ?)) OR (u.name = ?)) AND (u.name = ?)', (string) $qb); } - public function testSelectGroupBy() + public function testSelectGroupBy() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -176,7 +176,7 @@ public function testSelectGroupBy() self::assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id', (string) $qb); } - public function testSelectEmptyGroupBy() + public function testSelectEmptyGroupBy() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -188,7 +188,7 @@ public function testSelectEmptyGroupBy() self::assertEquals('SELECT u.*, p.* FROM users u', (string) $qb); } - public function testSelectEmptyAddGroupBy() + public function testSelectEmptyAddGroupBy() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -200,7 +200,7 @@ public function testSelectEmptyAddGroupBy() self::assertEquals('SELECT u.*, p.* FROM users u', (string) $qb); } - public function testSelectAddGroupBy() + public function testSelectAddGroupBy() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -213,7 +213,7 @@ public function testSelectAddGroupBy() self::assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id, u.foo', (string) $qb); } - public function testSelectAddGroupBys() + public function testSelectAddGroupBys() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -226,7 +226,7 @@ public function testSelectAddGroupBys() self::assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id, u.foo, u.bar', (string) $qb); } - public function testSelectHaving() + public function testSelectHaving() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -239,7 +239,7 @@ public function testSelectHaving() self::assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id HAVING u.name = ?', (string) $qb); } - public function testSelectAndHaving() + public function testSelectAndHaving() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -252,7 +252,7 @@ public function testSelectAndHaving() self::assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id HAVING u.name = ?', (string) $qb); } - public function testSelectHavingAndHaving() + public function testSelectHavingAndHaving() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -266,7 +266,7 @@ public function testSelectHavingAndHaving() self::assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id HAVING (u.name = ?) AND (u.username = ?)', (string) $qb); } - public function testSelectHavingOrHaving() + public function testSelectHavingOrHaving() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -280,7 +280,7 @@ public function testSelectHavingOrHaving() self::assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id HAVING (u.name = ?) OR (u.username = ?)', (string) $qb); } - public function testSelectOrHavingOrHaving() + public function testSelectOrHavingOrHaving() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -294,7 +294,7 @@ public function testSelectOrHavingOrHaving() self::assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id HAVING (u.name = ?) OR (u.username = ?)', (string) $qb); } - public function testSelectHavingAndOrHaving() + public function testSelectHavingAndOrHaving() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -309,7 +309,7 @@ public function testSelectHavingAndOrHaving() self::assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id HAVING ((u.name = ?) OR (u.username = ?)) AND (u.username = ?)', (string) $qb); } - public function testSelectOrderBy() + public function testSelectOrderBy() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -321,7 +321,7 @@ public function testSelectOrderBy() self::assertEquals('SELECT u.*, p.* FROM users u ORDER BY u.name ASC', (string) $qb); } - public function testSelectAddOrderBy() + public function testSelectAddOrderBy() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -334,7 +334,7 @@ public function testSelectAddOrderBy() self::assertEquals('SELECT u.*, p.* FROM users u ORDER BY u.name ASC, u.username DESC', (string) $qb); } - public function testSelectAddAddOrderBy() + public function testSelectAddAddOrderBy() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -347,7 +347,7 @@ public function testSelectAddAddOrderBy() self::assertEquals('SELECT u.*, p.* FROM users u ORDER BY u.name ASC, u.username DESC', (string) $qb); } - public function testEmptySelect() + public function testEmptySelect() : void { $qb = new QueryBuilder($this->conn); $qb2 = $qb->select(); @@ -356,7 +356,7 @@ public function testEmptySelect() self::assertEquals(QueryBuilder::SELECT, $qb->getType()); } - public function testSelectAddSelect() + public function testSelectAddSelect() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -368,7 +368,7 @@ public function testSelectAddSelect() self::assertEquals('SELECT u.*, p.* FROM users u', (string) $qb); } - public function testEmptyAddSelect() + public function testEmptyAddSelect() : void { $qb = new QueryBuilder($this->conn); $qb2 = $qb->addSelect(); @@ -377,7 +377,7 @@ public function testEmptyAddSelect() self::assertEquals(QueryBuilder::SELECT, $qb->getType()); } - public function testSelectMultipleFrom() + public function testSelectMultipleFrom() : void { $qb = new QueryBuilder($this->conn); $expr = $qb->expr(); @@ -390,7 +390,7 @@ public function testSelectMultipleFrom() self::assertEquals('SELECT u.*, p.* FROM users u, phonenumbers p', (string) $qb); } - public function testUpdate() + public function testUpdate() : void { $qb = new QueryBuilder($this->conn); $qb->update('users', 'u') @@ -401,7 +401,7 @@ public function testUpdate() self::assertEquals('UPDATE users u SET u.foo = ?, u.bar = ?', (string) $qb); } - public function testUpdateWithoutAlias() + public function testUpdateWithoutAlias() : void { $qb = new QueryBuilder($this->conn); $qb->update('users') @@ -411,7 +411,7 @@ public function testUpdateWithoutAlias() self::assertEquals('UPDATE users SET foo = ?, bar = ?', (string) $qb); } - public function testUpdateWhere() + public function testUpdateWhere() : void { $qb = new QueryBuilder($this->conn); $qb->update('users', 'u') @@ -421,7 +421,7 @@ public function testUpdateWhere() self::assertEquals('UPDATE users u SET u.foo = ? WHERE u.foo = ?', (string) $qb); } - public function testEmptyUpdate() + public function testEmptyUpdate() : void { $qb = new QueryBuilder($this->conn); $qb2 = $qb->update(); @@ -430,7 +430,7 @@ public function testEmptyUpdate() self::assertSame($qb2, $qb); } - public function testDelete() + public function testDelete() : void { $qb = new QueryBuilder($this->conn); $qb->delete('users', 'u'); @@ -439,7 +439,7 @@ public function testDelete() self::assertEquals('DELETE FROM users u', (string) $qb); } - public function testDeleteWithoutAlias() + public function testDeleteWithoutAlias() : void { $qb = new QueryBuilder($this->conn); $qb->delete('users'); @@ -448,7 +448,7 @@ public function testDeleteWithoutAlias() self::assertEquals('DELETE FROM users', (string) $qb); } - public function testDeleteWhere() + public function testDeleteWhere() : void { $qb = new QueryBuilder($this->conn); $qb->delete('users', 'u') @@ -457,7 +457,7 @@ public function testDeleteWhere() self::assertEquals('DELETE FROM users u WHERE u.foo = ?', (string) $qb); } - public function testEmptyDelete() + public function testEmptyDelete() : void { $qb = new QueryBuilder($this->conn); $qb2 = $qb->delete(); @@ -466,7 +466,7 @@ public function testEmptyDelete() self::assertSame($qb2, $qb); } - public function testInsertValues() + public function testInsertValues() : void { $qb = new QueryBuilder($this->conn); $qb->insert('users') @@ -481,7 +481,7 @@ public function testInsertValues() self::assertEquals('INSERT INTO users (foo, bar) VALUES(?, ?)', (string) $qb); } - public function testInsertReplaceValues() + public function testInsertReplaceValues() : void { $qb = new QueryBuilder($this->conn); $qb->insert('users') @@ -502,7 +502,7 @@ public function testInsertReplaceValues() self::assertEquals('INSERT INTO users (bar, foo) VALUES(?, ?)', (string) $qb); } - public function testInsertSetValue() + public function testInsertSetValue() : void { $qb = new QueryBuilder($this->conn); $qb->insert('users') @@ -514,7 +514,7 @@ public function testInsertSetValue() self::assertEquals('INSERT INTO users (foo, bar) VALUES(?, ?)', (string) $qb); } - public function testInsertValuesSetValue() + public function testInsertValuesSetValue() : void { $qb = new QueryBuilder($this->conn); $qb->insert('users') @@ -527,7 +527,7 @@ public function testInsertValuesSetValue() self::assertEquals('INSERT INTO users (foo, bar) VALUES(?, ?)', (string) $qb); } - public function testEmptyInsert() + public function testEmptyInsert() : void { $qb = new QueryBuilder($this->conn); $qb2 = $qb->insert(); @@ -536,13 +536,13 @@ public function testEmptyInsert() self::assertSame($qb2, $qb); } - public function testGetConnection() + public function testGetConnection() : void { $qb = new QueryBuilder($this->conn); self::assertSame($this->conn, $qb->getConnection()); } - public function testGetState() + public function testGetState() : void { $qb = new QueryBuilder($this->conn); @@ -558,7 +558,7 @@ public function testGetState() self::assertEquals($sql1, $qb->getSQL()); } - public function testSetMaxResults() + public function testSetMaxResults() : void { $qb = new QueryBuilder($this->conn); $qb->setMaxResults(10); @@ -567,7 +567,7 @@ public function testSetMaxResults() self::assertEquals(10, $qb->getMaxResults()); } - public function testSetFirstResult() + public function testSetFirstResult() : void { $qb = new QueryBuilder($this->conn); $qb->setFirstResult(10); @@ -576,7 +576,7 @@ public function testSetFirstResult() self::assertEquals(10, $qb->getFirstResult()); } - public function testResetQueryPart() + public function testResetQueryPart() : void { $qb = new QueryBuilder($this->conn); @@ -587,7 +587,7 @@ public function testResetQueryPart() self::assertEquals('SELECT u.* FROM users u', (string) $qb); } - public function testResetQueryParts() + public function testResetQueryParts() : void { $qb = new QueryBuilder($this->conn); @@ -598,7 +598,7 @@ public function testResetQueryParts() self::assertEquals('SELECT u.* FROM users u', (string) $qb); } - public function testCreateNamedParameter() + public function testCreateNamedParameter() : void { $qb = new QueryBuilder($this->conn); @@ -611,7 +611,7 @@ public function testCreateNamedParameter() self::assertEquals(ParameterType::INTEGER, $qb->getParameterType('dcValue1')); } - public function testCreateNamedParameterCustomPlaceholder() + public function testCreateNamedParameterCustomPlaceholder() : void { $qb = new QueryBuilder($this->conn); @@ -624,7 +624,7 @@ public function testCreateNamedParameterCustomPlaceholder() self::assertEquals(ParameterType::INTEGER, $qb->getParameterType('test')); } - public function testCreatePositionalParameter() + public function testCreatePositionalParameter() : void { $qb = new QueryBuilder($this->conn); @@ -640,7 +640,7 @@ public function testCreatePositionalParameter() /** * @group DBAL-172 */ - public function testReferenceJoinFromJoin() + public function testReferenceJoinFromJoin() : void { $qb = new QueryBuilder($this->conn); @@ -659,7 +659,7 @@ public function testReferenceJoinFromJoin() /** * @group DBAL-172 */ - public function testSelectFromMasterWithWhereOnJoinedTables() + public function testSelectFromMasterWithWhereOnJoinedTables() : void { $qb = new QueryBuilder($this->conn); @@ -677,7 +677,7 @@ public function testSelectFromMasterWithWhereOnJoinedTables() /** * @group DBAL-442 */ - public function testSelectWithMultipleFromAndJoins() + public function testSelectWithMultipleFromAndJoins() : void { $qb = new QueryBuilder($this->conn); @@ -695,7 +695,7 @@ public function testSelectWithMultipleFromAndJoins() /** * @group DBAL-774 */ - public function testSelectWithJoinsWithMultipleOnConditionsParseOrder() + public function testSelectWithJoinsWithMultipleOnConditionsParseOrder() : void { $qb = new QueryBuilder($this->conn); @@ -720,7 +720,7 @@ public function testSelectWithJoinsWithMultipleOnConditionsParseOrder() /** * @group DBAL-774 */ - public function testSelectWithMultipleFromsAndJoinsWithMultipleOnConditionsParseOrder() + public function testSelectWithMultipleFromsAndJoinsWithMultipleOnConditionsParseOrder() : void { $qb = new QueryBuilder($this->conn); @@ -746,7 +746,7 @@ public function testSelectWithMultipleFromsAndJoinsWithMultipleOnConditionsParse ); } - public function testClone() + public function testClone() : void { $qb = new QueryBuilder($this->conn); @@ -766,7 +766,7 @@ public function testClone() self::assertNotSame($qb->getParameters(), $qb_clone->getParameters()); } - public function testSimpleSelectWithoutTableAlias() + public function testSimpleSelectWithoutTableAlias() : void { $qb = new QueryBuilder($this->conn); @@ -776,7 +776,7 @@ public function testSimpleSelectWithoutTableAlias() self::assertEquals('SELECT id FROM users', (string) $qb); } - public function testSelectWithSimpleWhereWithoutTableAlias() + public function testSelectWithSimpleWhereWithoutTableAlias() : void { $qb = new QueryBuilder($this->conn); @@ -787,7 +787,7 @@ public function testSelectWithSimpleWhereWithoutTableAlias() self::assertEquals('SELECT id, name FROM users WHERE awesome=9001', (string) $qb); } - public function testComplexSelectWithoutTableAliases() + public function testComplexSelectWithoutTableAliases() : void { $qb = new QueryBuilder($this->conn); @@ -802,7 +802,7 @@ public function testComplexSelectWithoutTableAliases() self::assertEquals('SELECT DISTINCT users.id FROM users INNER JOIN permissions p ON p.user_id = users.id, articles INNER JOIN comments c ON c.article_id = articles.id WHERE (users.id = articles.user_id) AND (p.read = 1)', $qb->getSQL()); } - public function testComplexSelectWithSomeTableAliases() + public function testComplexSelectWithSomeTableAliases() : void { $qb = new QueryBuilder($this->conn); @@ -815,7 +815,7 @@ public function testComplexSelectWithSomeTableAliases() self::assertEquals('SELECT u.id FROM users u INNER JOIN permissions p ON p.user_id = u.id, articles INNER JOIN comments c ON c.article_id = articles.id', $qb->getSQL()); } - public function testSelectAllFromTableWithoutTableAlias() + public function testSelectAllFromTableWithoutTableAlias() : void { $qb = new QueryBuilder($this->conn); @@ -825,7 +825,7 @@ public function testSelectAllFromTableWithoutTableAlias() self::assertEquals('SELECT users.* FROM users', (string) $qb); } - public function testSelectAllWithoutTableAlias() + public function testSelectAllWithoutTableAlias() : void { $qb = new QueryBuilder($this->conn); @@ -838,7 +838,7 @@ public function testSelectAllWithoutTableAlias() /** * @group DBAL-959 */ - public function testGetParameterType() + public function testGetParameterType() : void { $qb = new QueryBuilder($this->conn); @@ -859,7 +859,7 @@ public function testGetParameterType() /** * @group DBAL-959 */ - public function testGetParameterTypes() + public function testGetParameterTypes() : void { $qb = new QueryBuilder($this->conn); @@ -886,7 +886,7 @@ public function testGetParameterTypes() /** * @group DBAL-1137 */ - public function testJoinWithNonUniqueAliasThrowsException() + public function testJoinWithNonUniqueAliasThrowsException() : void { $qb = new QueryBuilder($this->conn); diff --git a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php index 414f909f870..ea8d4dc0752 100644 --- a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php +++ b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php @@ -14,7 +14,10 @@ */ class SQLParserUtilsTest extends DbalTestCase { - public function dataGetPlaceholderPositions() + /** + * @return mixed[][] + */ + public static function dataGetPlaceholderPositions() : iterable { return [ // none @@ -91,15 +94,20 @@ public function dataGetPlaceholderPositions() } /** + * @param int[] $expectedParamPos + * * @dataProvider dataGetPlaceholderPositions */ - public function testGetPlaceholderPositions($query, $isPositional, $expectedParamPos) + public function testGetPlaceholderPositions(string $query, bool $isPositional, array $expectedParamPos) : void { $actualParamPos = SQLParserUtils::getPlaceholderPositions($query, $isPositional); self::assertEquals($expectedParamPos, $actualParamPos); } - public function dataExpandListParameters() + /** + * @return mixed[][] + */ + public static function dataExpandListParameters() : iterable { return [ // Positional: Very simple with one needle @@ -413,18 +421,32 @@ public function dataExpandListParameters() } /** + * @param mixed[] $params + * @param mixed[] $types + * @param mixed[] $expectedParams + * @param mixed[] $expectedTypes + * * @dataProvider dataExpandListParameters */ - public function testExpandListParameters($q, $p, $t, $expectedQuery, $expectedParams, $expectedTypes) - { - [$query, $params, $types] = SQLParserUtils::expandListParameters($q, $p, $t); + public function testExpandListParameters( + string $query, + array $params, + array $types, + string $expectedQuery, + array $expectedParams, + array $expectedTypes + ) : void { + [$query, $params, $types] = SQLParserUtils::expandListParameters($query, $params, $types); self::assertEquals($expectedQuery, $query, 'Query was not rewritten correctly.'); self::assertEquals($expectedParams, $params, 'Params dont match'); self::assertEquals($expectedTypes, $types, 'Types dont match'); } - public function dataQueryWithMissingParameters() + /** + * @return mixed[][] + */ + public static function dataQueryWithMissingParameters() : iterable { return [ [ @@ -461,9 +483,12 @@ public function dataQueryWithMissingParameters() } /** + * @param mixed[] $params + * @param mixed[] $types + * * @dataProvider dataQueryWithMissingParameters */ - public function testExceptionIsThrownForMissingParam($query, $params, $types = []) + public function testExceptionIsThrownForMissingParam(string $query, array $params, array $types = []) : void { $this->expectException(SQLParserUtilsException::class); $this->expectExceptionMessage('Value for :param not found in params array. Params array key should be "param"'); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php index 099fb788b55..0bdaa85ef6d 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php @@ -13,7 +13,7 @@ class ColumnDiffTest extends TestCase /** * @group DBAL-1255 */ - public function testPreservesOldColumnNameQuotation() + public function testPreservesOldColumnNameQuotation() : void { $fromColumn = new Column('"foo"', Type::getType(Types::INTEGER)); $toColumn = new Column('bar', Type::getType(Types::INTEGER)); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php index 150e5263f93..0997ce26319 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php @@ -12,7 +12,7 @@ class ColumnTest extends TestCase { - public function testGet() + public function testGet() : void { $column = $this->createColumn(); @@ -38,7 +38,7 @@ public function testGet() self::assertFalse($column->hasCustomSchemaOption('foo')); } - public function testToArray() + public function testToArray() : void { $expected = [ 'name' => 'foo', @@ -82,10 +82,7 @@ public function testOptionsShouldNotBeIgnored() : void self::assertFalse($col2->getNotnull()); } - /** - * @return Column - */ - public function createColumn() + public function createColumn() : Column { $options = [ 'length' => 200, @@ -108,7 +105,7 @@ public function createColumn() * @group DBAL-64 * @group DBAL-830 */ - public function testQuotedColumnName() + public function testQuotedColumnName() : void { $string = Type::getType('string'); $column = new Column('`bar`', $string, []); @@ -132,7 +129,7 @@ public function testQuotedColumnName() * @dataProvider getIsQuoted * @group DBAL-830 */ - public function testIsQuoted($columnName, $isQuoted) + public function testIsQuoted(string $columnName, bool $isQuoted) : void { $type = Type::getType('string'); $column = new Column($columnName, $type); @@ -140,7 +137,10 @@ public function testIsQuoted($columnName, $isQuoted) self::assertSame($isQuoted, $column->isQuoted()); } - public function getIsQuoted() + /** + * @return mixed[][] + */ + public static function getIsQuoted() : iterable { return [ ['bar', false], @@ -153,7 +153,7 @@ public function getIsQuoted() /** * @group DBAL-42 */ - public function testColumnComment() + public function testColumnComment() : void { $column = new Column('bar', Type::getType('string')); self::assertNull($column->getComment()); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index 5222a1ee548..a98f477ac4c 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -19,7 +19,7 @@ class ComparatorTest extends TestCase { - public function testCompareSame1() + public function testCompareSame1() : void { $schema1 = new Schema([ 'bugdb' => new Table( @@ -43,7 +43,7 @@ public function testCompareSame1() self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } - public function testCompareSame2() + public function testCompareSame2() : void { $schema1 = new Schema([ 'bugdb' => new Table( @@ -69,7 +69,7 @@ public function testCompareSame2() self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } - public function testCompareMissingTable() + public function testCompareMissingTable() : void { $schemaConfig = new SchemaConfig(); $table = new Table('bugdb', ['integerfield1' => new Column('integerfield1', Type::getType('integer'))]); @@ -83,7 +83,7 @@ public function testCompareMissingTable() self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } - public function testCompareNewTable() + public function testCompareNewTable() : void { $schemaConfig = new SchemaConfig(); $table = new Table('bugdb', ['integerfield1' => new Column('integerfield1', Type::getType('integer'))]); @@ -97,7 +97,7 @@ public function testCompareNewTable() self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } - public function testCompareOnlyAutoincrementChanged() + public function testCompareOnlyAutoincrementChanged() : void { $column1 = new Column('foo', Type::getType('integer'), ['autoincrement' => true]); $column2 = new Column('foo', Type::getType('integer'), ['autoincrement' => false]); @@ -108,7 +108,7 @@ public function testCompareOnlyAutoincrementChanged() self::assertEquals(['autoincrement'], $changedProperties); } - public function testCompareMissingField() + public function testCompareMissingField() : void { $missingColumn = new Column('integerfield1', Type::getType('integer')); $schema1 = new Schema([ @@ -146,7 +146,7 @@ public function testCompareMissingField() self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } - public function testCompareNewField() + public function testCompareNewField() : void { $schema1 = new Schema([ 'bugdb' => new Table( @@ -183,7 +183,7 @@ public function testCompareNewField() self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } - public function testCompareChangedColumnsChangeType() + public function testCompareChangedColumnsChangeType() : void { $column1 = new Column('charfield1', Type::getType('string')); $column2 = new Column('charfield1', Type::getType('integer')); @@ -193,7 +193,7 @@ public function testCompareChangedColumnsChangeType() self::assertEquals([], $c->diffColumn($column1, $column1)); } - public function testCompareChangedColumnsChangeCustomSchemaOption() + public function testCompareChangedColumnsChangeCustomSchemaOption() : void { $column1 = new Column('charfield1', Type::getType('string')); $column2 = new Column('charfield1', Type::getType('string')); @@ -209,7 +209,7 @@ public function testCompareChangedColumnsChangeCustomSchemaOption() self::assertEquals([], $c->diffColumn($column1, $column1)); } - public function testCompareChangeColumnsMultipleNewColumnsRename() + public function testCompareChangeColumnsMultipleNewColumnsRename() : void { $tableA = new Table('foo'); $tableA->addColumn('datefield1', 'datetime'); @@ -229,7 +229,7 @@ public function testCompareChangeColumnsMultipleNewColumnsRename() self::assertCount(0, $tableDiff->changedColumns, 'Nothing should be changed as all fields old & new have diff names.'); } - public function testCompareRemovedIndex() + public function testCompareRemovedIndex() : void { $schema1 = new Schema([ 'bugdb' => new Table( @@ -283,7 +283,7 @@ public function testCompareRemovedIndex() self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } - public function testCompareNewIndex() + public function testCompareNewIndex() : void { $schema1 = new Schema([ 'bugdb' => new Table( @@ -335,7 +335,7 @@ public function testCompareNewIndex() self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } - public function testCompareChangedIndex() + public function testCompareChangedIndex() : void { $schema1 = new Schema([ 'bugdb' => new Table( @@ -398,7 +398,7 @@ public function testCompareChangedIndex() self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } - public function testCompareChangedIndexFieldPositions() + public function testCompareChangedIndexFieldPositions() : void { $schema1 = new Schema([ 'bugdb' => new Table( @@ -446,7 +446,7 @@ public function testCompareChangedIndexFieldPositions() self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } - public function testCompareSequences() + public function testCompareSequences() : void { $seq1 = new Sequence('foo', 1, 1); $seq2 = new Sequence('foo', 1, 2); @@ -460,7 +460,7 @@ public function testCompareSequences() self::assertFalse($c->diffSequence($seq1, $seq4)); } - public function testRemovedSequence() + public function testRemovedSequence() : void { $schema1 = new Schema(); $seq = $schema1->createSequence('foo'); @@ -474,7 +474,7 @@ public function testRemovedSequence() self::assertSame($seq, $diffSchema->removedSequences[0]); } - public function testAddedSequence() + public function testAddedSequence() : void { $schema1 = new Schema(); @@ -488,7 +488,7 @@ public function testAddedSequence() self::assertSame($seq, $diffSchema->newSequences[0]); } - public function testTableAddForeignKey() + public function testTableAddForeignKey() : void { $tableForeign = new Table('bar'); $tableForeign->addColumn('id', 'integer'); @@ -507,7 +507,7 @@ public function testTableAddForeignKey() self::assertCount(1, $tableDiff->addedForeignKeys); } - public function testTableRemoveForeignKey() + public function testTableRemoveForeignKey() : void { $tableForeign = new Table('bar'); $tableForeign->addColumn('id', 'integer'); @@ -526,7 +526,7 @@ public function testTableRemoveForeignKey() self::assertCount(1, $tableDiff->removedForeignKeys); } - public function testTableUpdateForeignKey() + public function testTableUpdateForeignKey() : void { $tableForeign = new Table('bar'); $tableForeign->addColumn('id', 'integer'); @@ -546,7 +546,7 @@ public function testTableUpdateForeignKey() self::assertCount(1, $tableDiff->changedForeignKeys); } - public function testMovedForeignKeyForeignTable() + public function testMovedForeignKeyForeignTable() : void { $tableForeign = new Table('bar'); $tableForeign->addColumn('id', 'integer'); @@ -569,7 +569,7 @@ public function testMovedForeignKeyForeignTable() self::assertCount(1, $tableDiff->changedForeignKeys); } - public function testTablesCaseInsensitive() + public function testTablesCaseInsensitive() : void { $schemaA = new Schema(); $schemaA->createTable('foo'); @@ -589,7 +589,7 @@ public function testTablesCaseInsensitive() self::assertSchemaTableChangeCount($diff, 1, 0, 1); } - public function testSequencesCaseInsensitive() + public function testSequencesCaseInsensitive() : void { $schemaA = new Schema(); $schemaA->createSequence('foo'); @@ -609,7 +609,7 @@ public function testSequencesCaseInsensitive() self::assertSchemaSequenceChangeCount($diff, 1, 0, 1); } - public function testCompareColumnCompareCaseInsensitive() + public function testCompareColumnCompareCaseInsensitive() : void { $tableA = new Table('foo'); $tableA->addColumn('id', 'integer'); @@ -623,7 +623,7 @@ public function testCompareColumnCompareCaseInsensitive() self::assertFalse($tableDiff); } - public function testCompareIndexBasedOnPropertiesNotName() + public function testCompareIndexBasedOnPropertiesNotName() : void { $tableA = new Table('foo'); $tableA->addColumn('id', 'integer'); @@ -644,7 +644,7 @@ public function testCompareIndexBasedOnPropertiesNotName() ); } - public function testCompareForeignKeyBasedOnPropertiesNotName() + public function testCompareForeignKeyBasedOnPropertiesNotName() : void { $tableA = new Table('foo'); $tableA->addColumn('id', 'integer'); @@ -660,7 +660,7 @@ public function testCompareForeignKeyBasedOnPropertiesNotName() self::assertFalse($tableDiff); } - public function testCompareForeignKeyRestrictNoActionAreTheSame() + public function testCompareForeignKeyRestrictNoActionAreTheSame() : void { $fk1 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'NO ACTION']); $fk2 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'RESTRICT']); @@ -672,7 +672,7 @@ public function testCompareForeignKeyRestrictNoActionAreTheSame() /** * @group DBAL-492 */ - public function testCompareForeignKeyNamesUnqualifiedAsNoSchemaInformationIsAvailable() + public function testCompareForeignKeyNamesUnqualifiedAsNoSchemaInformationIsAvailable() : void { $fk1 = new ForeignKeyConstraint(['foo'], 'foo.bar', ['baz'], 'fk1'); $fk2 = new ForeignKeyConstraint(['foo'], 'baz.bar', ['baz'], 'fk1'); @@ -681,7 +681,7 @@ public function testCompareForeignKeyNamesUnqualifiedAsNoSchemaInformationIsAvai self::assertFalse($c->diffForeignKey($fk1, $fk2)); } - public function testDetectRenameColumn() + public function testDetectRenameColumn() : void { $tableA = new Table('foo'); $tableA->addColumn('foo', 'integer'); @@ -705,7 +705,7 @@ public function testDetectRenameColumn() * * @group DBAL-24 */ - public function testDetectRenameColumnAmbiguous() + public function testDetectRenameColumnAmbiguous() : void { $tableA = new Table('foo'); $tableA->addColumn('foo', 'integer'); @@ -728,7 +728,7 @@ public function testDetectRenameColumnAmbiguous() /** * @group DBAL-1063 */ - public function testDetectRenameIndex() + public function testDetectRenameIndex() : void { $table1 = new Table('foo'); $table1->addColumn('foo', 'integer'); @@ -755,7 +755,7 @@ public function testDetectRenameIndex() * * @group DBAL-1063 */ - public function testDetectRenameIndexAmbiguous() + public function testDetectRenameIndexAmbiguous() : void { $table1 = new Table('foo'); $table1->addColumn('foo', 'integer'); @@ -778,7 +778,7 @@ public function testDetectRenameIndexAmbiguous() self::assertCount(0, $tableDiff->renamedIndexes); } - public function testDetectChangeIdentifierType() + public function testDetectChangeIdentifierType() : void { $this->markTestSkipped('DBAL-2 was reopened, this test cannot work anymore.'); @@ -798,7 +798,7 @@ public function testDetectChangeIdentifierType() /** * @group DBAL-105 */ - public function testDiff() + public function testDiff() : void { $table = new Table('twitter_users'); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -825,7 +825,7 @@ public function testDiff() /** * @group DBAL-112 */ - public function testChangedSequence() + public function testChangedSequence() : void { $schema = new Schema(); $sequence = $schema->createSequence('baz'); @@ -842,7 +842,7 @@ public function testChangedSequence() /** * @group DBAL-106 */ - public function testDiffDecimalWithNullPrecision() + public function testDiffDecimalWithNullPrecision() : void { $column = new Column('foo', Type::getType('decimal')); $column->setPrecision(null); @@ -856,7 +856,7 @@ public function testDiffDecimalWithNullPrecision() /** * @group DBAL-204 */ - public function testFqnSchemaComparison() + public function testFqnSchemaComparison() : void { $config = new SchemaConfig(); $config->setName('foo'); @@ -876,7 +876,7 @@ public function testFqnSchemaComparison() /** * @group DBAL-669 */ - public function testNamespacesComparison() + public function testNamespacesComparison() : void { $config = new SchemaConfig(); $config->setName('schemaName'); @@ -903,7 +903,7 @@ public function testNamespacesComparison() /** * @group DBAL-204 */ - public function testFqnSchemaComparisonDifferentSchemaNameButSameTableNoDiff() + public function testFqnSchemaComparisonDifferentSchemaNameButSameTableNoDiff() : void { $config = new SchemaConfig(); $config->setName('foo'); @@ -923,7 +923,7 @@ public function testFqnSchemaComparisonDifferentSchemaNameButSameTableNoDiff() /** * @group DBAL-204 */ - public function testFqnSchemaComparisonNoSchemaSame() + public function testFqnSchemaComparisonNoSchemaSame() : void { $config = new SchemaConfig(); $config->setName('foo'); @@ -942,7 +942,7 @@ public function testFqnSchemaComparisonNoSchemaSame() /** * @group DDC-1657 */ - public function testAutoIncrementSequences() + public function testAutoIncrementSequences() : void { $oldSchema = new Schema(); $table = $oldSchema->createTable('foo'); @@ -966,7 +966,7 @@ public function testAutoIncrementSequences() * * @group DBAL-562 */ - public function testAutoIncrementNoSequences() + public function testAutoIncrementNoSequences() : void { $oldSchema = new Schema(); $table = $oldSchema->createTable('foo'); @@ -991,7 +991,7 @@ public function testAutoIncrementNoSequences() * array because of the dropped table, and once on changedTables array. We * now check that the key is present once. */ - public function testAvoidMultipleDropForeignKey() + public function testAvoidMultipleDropForeignKey() : void { $oldSchema = new Schema(); @@ -1024,7 +1024,7 @@ public function testAvoidMultipleDropForeignKey() self::assertCount(1, $schemaDiff->orphanedForeignKeys); } - public function testCompareChangedColumn() + public function testCompareChangedColumn() : void { $oldSchema = new Schema(); @@ -1046,7 +1046,7 @@ public function testCompareChangedColumn() self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema)); } - public function testCompareChangedBinaryColumn() + public function testCompareChangedBinaryColumn() : void { $oldSchema = new Schema(); @@ -1071,7 +1071,7 @@ public function testCompareChangedBinaryColumn() /** * @group DBAL-617 */ - public function testCompareQuotedAndUnquotedForeignKeyColumns() + public function testCompareQuotedAndUnquotedForeignKeyColumns() : void { $fk1 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'NO ACTION']); $fk2 = new ForeignKeyConstraint(['`foo`'], 'bar', ['`baz`'], 'fk1', ['onDelete' => 'NO ACTION']); @@ -1082,33 +1082,25 @@ public function testCompareQuotedAndUnquotedForeignKeyColumns() self::assertFalse($diff); } - /** - * @param SchemaDiff $diff - * @param int $newTableCount - * @param int $changeTableCount - * @param int $removeTableCount - */ - public function assertSchemaTableChangeCount($diff, $newTableCount = 0, $changeTableCount = 0, $removeTableCount = 0) + public function assertSchemaTableChangeCount(SchemaDiff $diff, int $newTableCount = 0, int $changeTableCount = 0, int $removeTableCount = 0) : void { self::assertCount($newTableCount, $diff->newTables); self::assertCount($changeTableCount, $diff->changedTables); self::assertCount($removeTableCount, $diff->removedTables); } - /** - * @param SchemaDiff $diff - * @param int $newSequenceCount - * @param int $changeSequenceCount - * @param int $changeSequenceCount - */ - public function assertSchemaSequenceChangeCount($diff, $newSequenceCount = 0, $changeSequenceCount = 0, $removeSequenceCount = 0) - { + public function assertSchemaSequenceChangeCount( + SchemaDiff $diff, + int $newSequenceCount = 0, + int $changeSequenceCount = 0, + int $removeSequenceCount = 0 + ) : void { self::assertCount($newSequenceCount, $diff->newSequences, 'Expected number of new sequences is wrong.'); self::assertCount($changeSequenceCount, $diff->changedSequences, 'Expected number of changed sequences is wrong.'); self::assertCount($removeSequenceCount, $diff->removedSequences, 'Expected number of removed sequences is wrong.'); } - public function testDiffColumnPlatformOptions() + public function testDiffColumnPlatformOptions() : void { $column1 = new Column('foo', Type::getType('string'), ['platformOptions' => ['foo' => 'foo', 'bar' => 'bar']]); $column2 = new Column('foo', Type::getType('string'), ['platformOptions' => ['foo' => 'foo', 'foobar' => 'foobar']]); @@ -1125,7 +1117,7 @@ public function testDiffColumnPlatformOptions() self::assertEquals([], $comparator->diffColumn($column4, $column1)); } - public function testComplexDiffColumn() + public function testComplexDiffColumn() : void { $column1 = new Column('foo', Type::getType('string'), [ 'platformOptions' => ['foo' => 'foo'], @@ -1145,7 +1137,7 @@ public function testComplexDiffColumn() /** * @group DBAL-669 */ - public function testComparesNamespaces() + public function testComparesNamespaces() : void { $comparator = new Comparator(); $fromSchema = $this->getMockBuilder(Schema::class) @@ -1191,7 +1183,7 @@ public function testComparesNamespaces() self::assertEquals($expected, $comparator->compare($fromSchema, $toSchema)); } - public function testCompareGuidColumns() + public function testCompareGuidColumns() : void { $comparator = new Comparator(); @@ -1210,7 +1202,7 @@ public function testCompareGuidColumns() * @group DBAL-1009 * @dataProvider getCompareColumnComments */ - public function testCompareColumnComments($comment1, $comment2, $equals) + public function testCompareColumnComments(?string $comment1, ?string $comment2, bool $equals) : void { $column1 = new Column('foo', Type::getType('integer'), ['comment' => $comment1]); $column2 = new Column('foo', Type::getType('integer'), ['comment' => $comment2]); @@ -1228,7 +1220,10 @@ public function testCompareColumnComments($comment1, $comment2, $equals) self::assertSame($expectedDiff, $actualDiff); } - public function getCompareColumnComments() + /** + * @return mixed[][] + */ + public static function getCompareColumnComments() : iterable { return [ [null, null, true], @@ -1253,7 +1248,7 @@ public function getCompareColumnComments() ]; } - public function testForeignKeyRemovalWithRenamedLocalColumn() + public function testForeignKeyRemovalWithRenamedLocalColumn() : void { $fromSchema = new Schema([ 'table1' => new Table( diff --git a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php index b3f91149b32..b5744fd672d 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php @@ -39,11 +39,9 @@ protected function setUp() : void /** * @see https://github.com/doctrine/dbal/issues/2701 * - * @return void - * * @group DBAL-2701 */ - public function testListTableNamesFiltersAssetNamesCorrectly() + public function testListTableNamesFiltersAssetNamesCorrectly() : void { $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/'); $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ @@ -63,11 +61,9 @@ public function testListTableNamesFiltersAssetNamesCorrectly() } /** - * @return void - * * @group DBAL-2701 */ - public function testAssetFilteringSetsACallable() + public function testAssetFilteringSetsACallable() : void { $filterExpression = '/^(?!T_)/'; $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); @@ -93,10 +89,7 @@ public function testAssetFilteringSetsACallable() $this->assertEquals($filterExpression, $this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); } - /** - * @return void - */ - public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() + public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() : void { $accepted = ['T_FOO', 'T_BAR']; $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { @@ -121,10 +114,7 @@ public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() $this->assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); } - /** - * @return void - */ - public function testSettingNullExpressionWillResetCallable() + public function testSettingNullExpressionWillResetCallable() : void { $accepted = ['T_FOO', 'T_BAR']; $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { @@ -161,10 +151,7 @@ public function testSettingNullExpressionWillResetCallable() $this->assertNull($this->conn->getConfiguration()->getSchemaAssetsFilter()); } - /** - * @return void - */ - public function testSettingNullAsCallableClearsExpression() + public function testSettingNullAsCallableClearsExpression() : void { $filterExpression = '/^(?!T_)/'; $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php b/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php index 2c317fc5dea..f0b115ddc4f 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php @@ -14,7 +14,7 @@ class ForeignKeyConstraintTest extends TestCase * @group DBAL-1062 * @dataProvider getIntersectsIndexColumnsData */ - public function testIntersectsIndexColumns(array $indexColumns, $expectedResult) + public function testIntersectsIndexColumns(array $indexColumns, bool $expectedResult) : void { $foreignKey = new ForeignKeyConstraint(['foo', 'bar'], 'foreign_table', ['fk_foo', 'fk_bar']); @@ -29,9 +29,9 @@ public function testIntersectsIndexColumns(array $indexColumns, $expectedResult) } /** - * @return mixed[] + * @return mixed[][] */ - public function getIntersectsIndexColumnsData() + public static function getIntersectsIndexColumnsData() : iterable { return [ [['baz'], false], diff --git a/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php b/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php index ad9e2bbbdb7..d21e676b273 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php @@ -7,12 +7,15 @@ class IndexTest extends TestCase { - public function createIndex($unique = false, $primary = false, $options = []) + /** + * @param mixed[] $options + */ + private function createIndex(bool $unique = false, bool $primary = false, array $options = []) : Index { return new Index('foo', ['bar', 'baz'], $unique, $primary, [], $options); } - public function testCreateIndex() + public function testCreateIndex() : void { $idx = $this->createIndex(); self::assertEquals('foo', $idx->getName()); @@ -23,14 +26,14 @@ public function testCreateIndex() self::assertFalse($idx->isPrimary()); } - public function testCreatePrimary() + public function testCreatePrimary() : void { $idx = $this->createIndex(false, true); self::assertTrue($idx->isUnique()); self::assertTrue($idx->isPrimary()); } - public function testCreateUnique() + public function testCreateUnique() : void { $idx = $this->createIndex(true, false); self::assertTrue($idx->isUnique()); @@ -40,7 +43,7 @@ public function testCreateUnique() /** * @group DBAL-50 */ - public function testFulfilledByUnique() + public function testFulfilledByUnique() : void { $idx1 = $this->createIndex(true, false); $idx2 = $this->createIndex(true, false); @@ -53,7 +56,7 @@ public function testFulfilledByUnique() /** * @group DBAL-50 */ - public function testFulfilledByPrimary() + public function testFulfilledByPrimary() : void { $idx1 = $this->createIndex(true, true); $idx2 = $this->createIndex(true, true); @@ -66,7 +69,7 @@ public function testFulfilledByPrimary() /** * @group DBAL-50 */ - public function testFulfilledByIndex() + public function testFulfilledByIndex() : void { $idx1 = $this->createIndex(); $idx2 = $this->createIndex(); @@ -78,7 +81,7 @@ public function testFulfilledByIndex() self::assertTrue($idx1->isFullfilledBy($uniq)); } - public function testFulfilledWithPartial() + public function testFulfilledWithPartial() : void { $without = new Index('without', ['col1', 'col2'], true, false, [], []); $partial = new Index('partial', ['col1', 'col2'], true, false, [], ['where' => 'col1 IS NULL']); @@ -93,7 +96,7 @@ public function testFulfilledWithPartial() self::assertTrue($another->isFullfilledBy($partial)); } - public function testOverrulesWithPartial() + public function testOverrulesWithPartial() : void { $without = new Index('without', ['col1', 'col2'], true, false, [], []); $partial = new Index('partial', ['col1', 'col2'], true, false, [], ['where' => 'col1 IS NULL']); @@ -141,7 +144,7 @@ public static function indexLengthProvider() : iterable /** * @group DBAL-220 */ - public function testFlags() + public function testFlags() : void { $idx1 = $this->createIndex(); self::assertFalse($idx1->hasFlag('clustered')); @@ -160,7 +163,7 @@ public function testFlags() /** * @group DBAL-285 */ - public function testIndexQuotes() + public function testIndexQuotes() : void { $index = new Index('foo', ['`bar`', '`baz`']); @@ -172,7 +175,7 @@ public function testIndexQuotes() self::assertFalse($index->hasColumnAtPosition('baz', 0)); } - public function testOptions() + public function testOptions() : void { $idx1 = $this->createIndex(); self::assertFalse($idx1->hasOption('where')); diff --git a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php index 4646700e0e7..5c8881decb4 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php @@ -33,7 +33,7 @@ protected function setUp() : void $this->manager = new MySqlSchemaManager($this->conn); } - public function testCompositeForeignKeys() + public function testCompositeForeignKeys() : void { $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue($this->getFKDefinition())); $fkeys = $this->manager->listTableForeignKeys('dummy'); @@ -44,7 +44,10 @@ public function testCompositeForeignKeys() self::assertEquals(['column_1', 'column_2', 'column_3'], array_map('strtolower', $fkeys[0]->getForeignColumns())); } - public function getFKDefinition() + /** + * @return string[][] + */ + public function getFKDefinition() : array { return [ [ diff --git a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php index 568a4bfa79a..4cf69f28f7c 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php @@ -22,7 +22,7 @@ protected function setUp() : void $this->platform = new MySqlPlatform(); } - public function testSwitchPrimaryKeyOrder() + public function testSwitchPrimaryKeyOrder() : void { $tableOld = new Table('test'); $tableOld->addColumn('foo_id', 'integer'); @@ -47,7 +47,7 @@ public function testSwitchPrimaryKeyOrder() /** * @group DBAL-132 */ - public function testGenerateForeignKeySQL() + public function testGenerateForeignKeySQL() : void { $tableOld = new Table('test'); $tableOld->addColumn('foo_id', 'integer'); @@ -64,7 +64,7 @@ public function testGenerateForeignKeySQL() /** * @group DDC-1737 */ - public function testClobNoAlterTable() + public function testClobNoAlterTable() : void { $tableOld = new Table('test'); $tableOld->addColumn('id', 'integer'); diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php index 8400e952ef6..87146c2f001 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php @@ -13,7 +13,7 @@ class SchemaDiffTest extends TestCase { - public function testSchemaDiffToSql() + public function testSchemaDiffToSql() : void { $diff = $this->createSchemaDiff(); $platform = $this->createPlatform(true); @@ -25,7 +25,7 @@ public function testSchemaDiffToSql() self::assertEquals($expected, $sql); } - public function testSchemaDiffToSaveSql() + public function testSchemaDiffToSaveSql() : void { $diff = $this->createSchemaDiff(); $platform = $this->createPlatform(false); @@ -102,7 +102,7 @@ private function createPlatform(bool $unsafe) return $platform; } - public function createSchemaDiff() + public function createSchemaDiff() : SchemaDiff { $diff = new SchemaDiff(); $diff->newNamespaces['foo_ns'] = 'foo_ns'; diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php index 5618feeefdb..69796236235 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php @@ -16,7 +16,7 @@ class SchemaTest extends TestCase { - public function testAddTable() + public function testAddTable() : void { $tableName = 'public.foo'; $table = new Table($tableName); @@ -32,7 +32,7 @@ public function testAddTable() self::assertTrue($schema->hasTable($tableName)); } - public function testTableMatchingCaseInsensitive() + public function testTableMatchingCaseInsensitive() : void { $table = new Table('Foo'); @@ -45,7 +45,7 @@ public function testTableMatchingCaseInsensitive() self::assertSame($table, $schema->getTable('Foo')); } - public function testGetUnknownTableThrowsException() + public function testGetUnknownTableThrowsException() : void { $this->expectException(SchemaException::class); @@ -53,7 +53,7 @@ public function testGetUnknownTableThrowsException() $schema->getTable('unknown'); } - public function testCreateTableTwiceThrowsException() + public function testCreateTableTwiceThrowsException() : void { $this->expectException(SchemaException::class); @@ -64,7 +64,7 @@ public function testCreateTableTwiceThrowsException() $schema = new Schema($tables); } - public function testRenameTable() + public function testRenameTable() : void { $tableName = 'foo'; $table = new Table($tableName); @@ -77,7 +77,7 @@ public function testRenameTable() self::assertSame($table, $schema->getTable('bar')); } - public function testDropTable() + public function testDropTable() : void { $tableName = 'foo'; $table = new Table($tableName); @@ -90,7 +90,7 @@ public function testDropTable() self::assertFalse($schema->hasTable('foo')); } - public function testCreateTable() + public function testCreateTable() : void { $schema = new Schema(); @@ -103,7 +103,7 @@ public function testCreateTable() self::assertTrue($schema->hasTable('foo')); } - public function testAddSequences() + public function testAddSequences() : void { $sequence = new Sequence('a_seq', 1, 1); @@ -116,7 +116,7 @@ public function testAddSequences() self::assertArrayHasKey('public.a_seq', $sequences); } - public function testSequenceAccessCaseInsensitive() + public function testSequenceAccessCaseInsensitive() : void { $sequence = new Sequence('a_Seq'); @@ -130,7 +130,7 @@ public function testSequenceAccessCaseInsensitive() self::assertEquals($sequence, $schema->getSequence('A_SEQ')); } - public function testGetUnknownSequenceThrowsException() + public function testGetUnknownSequenceThrowsException() : void { $this->expectException(SchemaException::class); @@ -138,7 +138,7 @@ public function testGetUnknownSequenceThrowsException() $schema->getSequence('unknown'); } - public function testCreateSequence() + public function testCreateSequence() : void { $schema = new Schema(); $sequence = $schema->createSequence('a_seq', 10, 20); @@ -154,7 +154,7 @@ public function testCreateSequence() self::assertArrayHasKey('public.a_seq', $sequences); } - public function testDropSequence() + public function testDropSequence() : void { $sequence = new Sequence('a_seq', 1, 1); @@ -164,7 +164,7 @@ public function testDropSequence() self::assertFalse($schema->hasSequence('a_seq')); } - public function testAddSequenceTwiceThrowsException() + public function testAddSequenceTwiceThrowsException() : void { $this->expectException(SchemaException::class); @@ -173,7 +173,7 @@ public function testAddSequenceTwiceThrowsException() $schema = new Schema([], [$sequence, $sequence]); } - public function testConfigMaxIdentifierLength() + public function testConfigMaxIdentifierLength() : void { $schemaConfig = new SchemaConfig(); $schemaConfig->setMaxIdentifierLength(5); @@ -187,7 +187,7 @@ public function testConfigMaxIdentifierLength() self::assertEquals(5, strlen($index->getName())); } - public function testDeepClone() + public function testDeepClone() : void { $schema = new Schema(); $sequence = $schema->createSequence('baz'); @@ -222,7 +222,7 @@ public function testDeepClone() /** * @group DBAL-219 */ - public function testHasTableForQuotedAsset() + public function testHasTableForQuotedAsset() : void { $schema = new Schema(); @@ -235,7 +235,7 @@ public function testHasTableForQuotedAsset() /** * @group DBAL-669 */ - public function testHasNamespace() + public function testHasNamespace() : void { $schema = new Schema(); @@ -259,7 +259,7 @@ public function testHasNamespace() /** * @group DBAL-669 */ - public function testCreatesNamespace() + public function testCreatesNamespace() : void { $schema = new Schema(); @@ -285,7 +285,7 @@ public function testCreatesNamespace() /** * @group DBAL-669 */ - public function testThrowsExceptionOnCreatingNamespaceTwice() + public function testThrowsExceptionOnCreatingNamespaceTwice() : void { $schema = new Schema(); @@ -299,7 +299,7 @@ public function testThrowsExceptionOnCreatingNamespaceTwice() /** * @group DBAL-669 */ - public function testCreatesNamespaceThroughAddingTableImplicitly() + public function testCreatesNamespaceThroughAddingTableImplicitly() : void { $schema = new Schema(); @@ -329,7 +329,7 @@ public function testCreatesNamespaceThroughAddingTableImplicitly() /** * @group DBAL-669 */ - public function testCreatesNamespaceThroughAddingSequenceImplicitly() + public function testCreatesNamespaceThroughAddingSequenceImplicitly() : void { $schema = new Schema(); @@ -359,7 +359,7 @@ public function testCreatesNamespaceThroughAddingSequenceImplicitly() /** * @group DBAL-669 */ - public function testVisitsVisitor() + public function testVisitsVisitor() : void { $schema = new Schema(); $visitor = $this->createMock(Visitor::class); @@ -405,7 +405,7 @@ public function testVisitsVisitor() /** * @group DBAL-669 */ - public function testVisitsNamespaceVisitor() + public function testVisitsNamespaceVisitor() : void { $schema = new Schema(); $visitor = $this->createMock(AbstractVisitor::class); diff --git a/tests/Doctrine/Tests/DBAL/Schema/SequenceTest.php b/tests/Doctrine/Tests/DBAL/Schema/SequenceTest.php index b3a72017c16..d13d0a908a6 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SequenceTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SequenceTest.php @@ -11,7 +11,7 @@ class SequenceTest extends DbalTestCase /** * @group DDC-1657 */ - public function testIsAutoincrementFor() + public function testIsAutoincrementFor() : void { $table = new Table('foo'); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -26,7 +26,7 @@ public function testIsAutoincrementFor() self::assertFalse($sequence3->isAutoIncrementsFor($table)); } - public function testIsAutoincrementForCaseInsensitive() + public function testIsAutoincrementForCaseInsensitive() : void { $table = new Table('foo'); $table->addColumn('ID', 'integer', ['autoincrement' => true]); diff --git a/tests/Doctrine/Tests/DBAL/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/SqliteSchemaManagerTest.php index 7b3031624af..3677212f240 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SqliteSchemaManagerTest.php @@ -26,7 +26,10 @@ public function testParseColumnCollation(?string $collation, string $column, str self::assertSame($collation, $ref->invoke($manager, $column, $sql)); } - public function getDataColumnCollation() + /** + * @return mixed[][] + */ + public static function getDataColumnCollation() : iterable { return [ ['RTRIM', 'a', 'CREATE TABLE "a" ("a" text DEFAULT "aa" COLLATE "RTRIM" NOT NULL)'], @@ -64,7 +67,10 @@ public function testParseColumnCommentFromSQL(?string $comment, string $column, self::assertSame($comment, $ref->invoke($manager, $column, $sql)); } - public function getDataColumnComment() + /** + * @return mixed[][] + */ + public static function getDataColumnComment() : iterable { return [ 'Single column with no comment' => [ diff --git a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php index 80d43e0e1b4..ad24ca599a6 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php @@ -28,7 +28,7 @@ protected function setUp() : void $this->synchronizer = new SingleDatabaseSynchronizer($this->conn); } - public function testGetCreateSchema() + public function testGetCreateSchema() : void { $schema = new Schema(); $table = $schema->createTable('test'); @@ -39,7 +39,7 @@ public function testGetCreateSchema() self::assertEquals(['CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))'], $sql); } - public function testGetUpdateSchema() + public function testGetUpdateSchema() : void { $schema = new Schema(); $table = $schema->createTable('test'); @@ -50,7 +50,7 @@ public function testGetUpdateSchema() self::assertEquals(['CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))'], $sql); } - public function testGetDropSchema() + public function testGetDropSchema() : void { $schema = new Schema(); $table = $schema->createTable('test'); @@ -63,7 +63,7 @@ public function testGetDropSchema() self::assertEquals(['DROP TABLE test'], $sql); } - public function testGetDropAllSchema() + public function testGetDropAllSchema() : void { $schema = new Schema(); $table = $schema->createTable('test'); diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php index ae1682739c6..7ae17019f83 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php @@ -22,7 +22,7 @@ public function setUp() : void /** * @group DBAL-1013 */ - public function testReturnsName() + public function testReturnsName() : void { $tableDiff = new TableDiff('foo'); @@ -32,7 +32,7 @@ public function testReturnsName() /** * @group DBAL-1016 */ - public function testPrefersNameFromTableObject() + public function testPrefersNameFromTableObject() : void { $tableMock = $this->getMockBuilder(Table::class) ->disableOriginalConstructor() @@ -52,7 +52,7 @@ public function testPrefersNameFromTableObject() /** * @group DBAL-1013 */ - public function testReturnsNewName() + public function testReturnsNewName() : void { $tableDiff = new TableDiff('foo'); diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index 154a29ad7b0..6b5145934a8 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -17,20 +17,20 @@ class TableTest extends DbalTestCase { - public function testCreateWithInvalidTableName() + public function testCreateWithInvalidTableName() : void { $this->expectException(DBALException::class); new Table(''); } - public function testGetName() + public function testGetName() : void { $table = new Table('foo', [], [], []); self::assertEquals('foo', $table->getName()); } - public function testColumns() + public function testColumns() : void { $type = Type::getType('integer'); $columns = []; @@ -48,7 +48,7 @@ public function testColumns() self::assertCount(2, $table->getColumns()); } - public function testColumnsCaseInsensitive() + public function testColumnsCaseInsensitive() : void { $table = new Table('foo'); $column = $table->addColumn('Foo', 'integer'); @@ -62,7 +62,7 @@ public function testColumnsCaseInsensitive() self::assertSame($column, $table->getColumn('FOO')); } - public function testCreateColumn() + public function testCreateColumn() : void { $type = Type::getType('integer'); @@ -74,7 +74,7 @@ public function testCreateColumn() self::assertSame($type, $table->getColumn('bar')->getType()); } - public function testDropColumn() + public function testDropColumn() : void { $type = Type::getType('integer'); $columns = []; @@ -91,7 +91,7 @@ public function testDropColumn() self::assertFalse($table->hasColumn('bar')); } - public function testGetUnknownColumnThrowsException() + public function testGetUnknownColumnThrowsException() : void { $this->expectException(SchemaException::class); @@ -99,7 +99,7 @@ public function testGetUnknownColumnThrowsException() $table->getColumn('unknown'); } - public function testAddColumnTwiceThrowsException() + public function testAddColumnTwiceThrowsException() : void { $this->expectException(SchemaException::class); @@ -110,7 +110,7 @@ public function testAddColumnTwiceThrowsException() $table = new Table('foo', $columns, [], []); } - public function testCreateIndex() + public function testCreateIndex() : void { $type = Type::getType('integer'); $columns = [new Column('foo', $type), new Column('bar', $type), new Column('baz', $type)]; @@ -123,7 +123,7 @@ public function testCreateIndex() self::assertTrue($table->hasIndex('foo_bar_baz_uniq')); } - public function testIndexCaseInsensitive() + public function testIndexCaseInsensitive() : void { $type = Type::getType('integer'); $columns = [ @@ -140,7 +140,7 @@ public function testIndexCaseInsensitive() self::assertTrue($table->hasIndex('FOO_IDX')); } - public function testAddIndexes() + public function testAddIndexes() : void { $type = Type::getType('integer'); $columns = [ @@ -162,7 +162,7 @@ public function testAddIndexes() self::assertInstanceOf(Index::class, $table->getIndex('bar_idx')); } - public function testGetUnknownIndexThrowsException() + public function testGetUnknownIndexThrowsException() : void { $this->expectException(SchemaException::class); @@ -170,7 +170,7 @@ public function testGetUnknownIndexThrowsException() $table->getIndex('unknownIndex'); } - public function testAddTwoPrimaryThrowsException() + public function testAddTwoPrimaryThrowsException() : void { $this->expectException(SchemaException::class); @@ -183,7 +183,7 @@ public function testAddTwoPrimaryThrowsException() $table = new Table('foo', $columns, $indexes, []); } - public function testAddTwoIndexesWithSameNameThrowsException() + public function testAddTwoIndexesWithSameNameThrowsException() : void { $this->expectException(SchemaException::class); @@ -196,7 +196,7 @@ public function testAddTwoIndexesWithSameNameThrowsException() $table = new Table('foo', $columns, $indexes, []); } - public function testConstraints() + public function testConstraints() : void { $constraint = new ForeignKeyConstraint([], 'foo', []); @@ -207,7 +207,7 @@ public function testConstraints() self::assertSame($constraint, array_shift($constraints)); } - public function testOptions() + public function testOptions() : void { $table = new Table('foo', [], [], [], false, ['foo' => 'bar']); @@ -215,7 +215,7 @@ public function testOptions() self::assertEquals('bar', $table->getOption('foo')); } - public function testBuilderSetPrimaryKey() + public function testBuilderSetPrimaryKey() : void { $table = new Table('foo'); @@ -228,7 +228,7 @@ public function testBuilderSetPrimaryKey() self::assertTrue($table->getIndex('primary')->isPrimary()); } - public function testBuilderAddUniqueIndex() + public function testBuilderAddUniqueIndex() : void { $table = new Table('foo'); @@ -240,7 +240,7 @@ public function testBuilderAddUniqueIndex() self::assertFalse($table->getIndex('my_idx')->isPrimary()); } - public function testBuilderAddIndex() + public function testBuilderAddIndex() : void { $table = new Table('foo'); @@ -252,7 +252,7 @@ public function testBuilderAddIndex() self::assertFalse($table->getIndex('my_idx')->isPrimary()); } - public function testBuilderAddIndexWithInvalidNameThrowsException() + public function testBuilderAddIndexWithInvalidNameThrowsException() : void { $this->expectException(SchemaException::class); @@ -261,7 +261,7 @@ public function testBuilderAddIndexWithInvalidNameThrowsException() $table->addIndex(['bar'], 'invalid name %&/'); } - public function testBuilderAddIndexWithUnknownColumnThrowsException() + public function testBuilderAddIndexWithUnknownColumnThrowsException() : void { $this->expectException(SchemaException::class); @@ -269,7 +269,7 @@ public function testBuilderAddIndexWithUnknownColumnThrowsException() $table->addIndex(['bar'], 'invalidName'); } - public function testBuilderOptions() + public function testBuilderOptions() : void { $table = new Table('foo'); $table->addOption('foo', 'bar'); @@ -277,7 +277,7 @@ public function testBuilderOptions() self::assertEquals('bar', $table->getOption('foo')); } - public function testAddForeignKeyConstraintUnknownLocalColumnThrowsException() + public function testAddForeignKeyConstraintUnknownLocalColumnThrowsException() : void { $this->expectException(SchemaException::class); @@ -290,7 +290,7 @@ public function testAddForeignKeyConstraintUnknownLocalColumnThrowsException() $table->addForeignKeyConstraint($foreignTable, ['foo'], ['id']); } - public function testAddForeignKeyConstraintUnknownForeignColumnThrowsException() + public function testAddForeignKeyConstraintUnknownForeignColumnThrowsException() : void { $this->expectException(SchemaException::class); @@ -303,7 +303,7 @@ public function testAddForeignKeyConstraintUnknownForeignColumnThrowsException() $table->addForeignKeyConstraint($foreignTable, ['id'], ['foo']); } - public function testAddForeignKeyConstraint() + public function testAddForeignKeyConstraint() : void { $table = new Table('foo'); $table->addColumn('id', 'integer'); @@ -323,7 +323,7 @@ public function testAddForeignKeyConstraint() self::assertEquals('bar', $constraint->getOption('foo')); } - public function testAddIndexWithCaseSensitiveColumnProblem() + public function testAddIndexWithCaseSensitiveColumnProblem() : void { $table = new Table('foo'); $table->addColumn('id', 'integer'); @@ -335,7 +335,7 @@ public function testAddIndexWithCaseSensitiveColumnProblem() self::assertTrue($table->getIndex('my_idx')->spansColumns(['id'])); } - public function testAddPrimaryKeyColumnsAreExplicitlySetToNotNull() + public function testAddPrimaryKeyColumnsAreExplicitlySetToNotNull() : void { $table = new Table('foo'); $column = $table->addColumn('id', 'integer', ['notnull' => false]); @@ -350,7 +350,7 @@ public function testAddPrimaryKeyColumnsAreExplicitlySetToNotNull() /** * @group DDC-133 */ - public function testAllowImplicitSchemaTableInAutogeneratedIndexNames() + public function testAllowImplicitSchemaTableInAutogeneratedIndexNames() : void { $table = new Table('foo.bar'); $table->addColumn('baz', 'integer', []); @@ -362,7 +362,7 @@ public function testAllowImplicitSchemaTableInAutogeneratedIndexNames() /** * @group DBAL-50 */ - public function testAddForeignKeyIndexImplicitly() + public function testAddForeignKeyIndexImplicitly() : void { $table = new Table('foo'); $table->addColumn('id', 'integer'); @@ -383,7 +383,7 @@ public function testAddForeignKeyIndexImplicitly() /** * @group DBAL-1063 */ - public function testAddForeignKeyDoesNotCreateDuplicateIndex() + public function testAddForeignKeyDoesNotCreateDuplicateIndex() : void { $table = new Table('foo'); $table->addColumn('bar', 'integer'); @@ -402,7 +402,7 @@ public function testAddForeignKeyDoesNotCreateDuplicateIndex() /** * @group DBAL-1063 */ - public function testAddForeignKeyAddsImplicitIndexIfIndexColumnsDoNotSpan() + public function testAddForeignKeyAddsImplicitIndexIfIndexColumnsDoNotSpan() : void { $table = new Table('foo'); $table->addColumn('bar', 'integer'); @@ -430,7 +430,7 @@ public function testAddForeignKeyAddsImplicitIndexIfIndexColumnsDoNotSpan() * @group DBAL-50 * @group DBAL-1063 */ - public function testOverrulingIndexDoesNotDropOverruledIndex() + public function testOverrulingIndexDoesNotDropOverruledIndex() : void { $table = new Table('bar'); $table->addColumn('baz', 'integer', []); @@ -448,7 +448,7 @@ public function testOverrulingIndexDoesNotDropOverruledIndex() /** * @group DBAL-1063 */ - public function testAllowsAddingDuplicateIndexesBasedOnColumns() + public function testAllowsAddingDuplicateIndexesBasedOnColumns() : void { $table = new Table('foo'); $table->addColumn('bar', 'integer'); @@ -465,7 +465,7 @@ public function testAllowsAddingDuplicateIndexesBasedOnColumns() /** * @group DBAL-1063 */ - public function testAllowsAddingFulfillingIndexesBasedOnColumns() + public function testAllowsAddingFulfillingIndexesBasedOnColumns() : void { $table = new Table('foo'); $table->addColumn('bar', 'integer'); @@ -484,7 +484,7 @@ public function testAllowsAddingFulfillingIndexesBasedOnColumns() * @group DBAL-50 * @group DBAL-1063 */ - public function testPrimaryKeyOverrulingUniqueIndexDoesNotDropUniqueIndex() + public function testPrimaryKeyOverrulingUniqueIndexDoesNotDropUniqueIndex() : void { $table = new Table('bar'); $table->addColumn('baz', 'integer', []); @@ -499,7 +499,7 @@ public function testPrimaryKeyOverrulingUniqueIndexDoesNotDropUniqueIndex() self::assertTrue($table->hasIndex('idx_unique')); } - public function testAddingFulfillingRegularIndexOverridesImplicitForeignKeyConstraintIndex() + public function testAddingFulfillingRegularIndexOverridesImplicitForeignKeyConstraintIndex() : void { $foreignTable = new Table('foreign'); $foreignTable->addColumn('id', 'integer'); @@ -516,7 +516,7 @@ public function testAddingFulfillingRegularIndexOverridesImplicitForeignKeyConst self::assertTrue($localTable->hasIndex('explicit_idx')); } - public function testAddingFulfillingUniqueIndexOverridesImplicitForeignKeyConstraintIndex() + public function testAddingFulfillingUniqueIndexOverridesImplicitForeignKeyConstraintIndex() : void { $foreignTable = new Table('foreign'); $foreignTable->addColumn('id', 'integer'); @@ -533,7 +533,7 @@ public function testAddingFulfillingUniqueIndexOverridesImplicitForeignKeyConstr self::assertTrue($localTable->hasIndex('explicit_idx')); } - public function testAddingFulfillingPrimaryKeyOverridesImplicitForeignKeyConstraintIndex() + public function testAddingFulfillingPrimaryKeyOverridesImplicitForeignKeyConstraintIndex() : void { $foreignTable = new Table('foreign'); $foreignTable->addColumn('id', 'integer'); @@ -550,7 +550,7 @@ public function testAddingFulfillingPrimaryKeyOverridesImplicitForeignKeyConstra self::assertTrue($localTable->hasIndex('explicit_idx')); } - public function testAddingFulfillingExplicitIndexOverridingImplicitForeignKeyConstraintIndexWithSameNameDoesNotThrowException() + public function testAddingFulfillingExplicitIndexOverridingImplicitForeignKeyConstraintIndexWithSameNameDoesNotThrowException() : void { $foreignTable = new Table('foreign'); $foreignTable->addColumn('id', 'integer'); @@ -574,7 +574,7 @@ public function testAddingFulfillingExplicitIndexOverridingImplicitForeignKeyCon /** * @group DBAL-64 */ - public function testQuotedTableName() + public function testQuotedTableName() : void { $table = new Table('`bar`'); @@ -589,7 +589,7 @@ public function testQuotedTableName() /** * @group DBAL-79 */ - public function testTableHasPrimaryKey() + public function testTableHasPrimaryKey() : void { $table = new Table('test'); @@ -604,7 +604,7 @@ public function testTableHasPrimaryKey() /** * @group DBAL-91 */ - public function testAddIndexWithQuotedColumns() + public function testAddIndexWithQuotedColumns() : void { $table = new Table('test'); $table->addColumn('"foo"', 'integer'); @@ -617,7 +617,7 @@ public function testAddIndexWithQuotedColumns() /** * @group DBAL-91 */ - public function testAddForeignKeyWithQuotedColumnsAndTable() + public function testAddForeignKeyWithQuotedColumnsAndTable() : void { $table = new Table('test'); $table->addColumn('"foo"', 'integer'); @@ -630,7 +630,7 @@ public function testAddForeignKeyWithQuotedColumnsAndTable() /** * @group DBAL-177 */ - public function testQuoteSchemaPrefixed() + public function testQuoteSchemaPrefixed() : void { $table = new Table('`test`.`test`'); self::assertEquals('test.test', $table->getName()); @@ -640,7 +640,7 @@ public function testQuoteSchemaPrefixed() /** * @group DBAL-204 */ - public function testFullQualifiedTableName() + public function testFullQualifiedTableName() : void { $table = new Table('`test`.`test`'); self::assertEquals('test.test', $table->getFullQualifiedName('test')); @@ -654,7 +654,7 @@ public function testFullQualifiedTableName() /** * @group DBAL-224 */ - public function testDropIndex() + public function testDropIndex() : void { $table = new Table('test'); $table->addColumn('id', 'integer'); @@ -669,7 +669,7 @@ public function testDropIndex() /** * @group DBAL-224 */ - public function testDropPrimaryKey() + public function testDropPrimaryKey() : void { $table = new Table('test'); $table->addColumn('id', 'integer'); @@ -684,7 +684,7 @@ public function testDropPrimaryKey() /** * @group DBAL-234 */ - public function testRenameIndex() + public function testRenameIndex() : void { $table = new Table('test'); $table->addColumn('id', 'integer'); @@ -756,7 +756,7 @@ public function testRenameIndex() /** * @group DBAL-2508 */ - public function testKeepsIndexOptionsOnRenamingRegularIndex() + public function testKeepsIndexOptionsOnRenamingRegularIndex() : void { $table = new Table('foo'); $table->addColumn('id', 'integer'); @@ -770,7 +770,7 @@ public function testKeepsIndexOptionsOnRenamingRegularIndex() /** * @group DBAL-2508 */ - public function testKeepsIndexOptionsOnRenamingUniqueIndex() + public function testKeepsIndexOptionsOnRenamingUniqueIndex() : void { $table = new Table('foo'); $table->addColumn('id', 'integer'); @@ -784,7 +784,7 @@ public function testKeepsIndexOptionsOnRenamingUniqueIndex() /** * @group DBAL-234 */ - public function testThrowsExceptionOnRenamingNonExistingIndex() + public function testThrowsExceptionOnRenamingNonExistingIndex() : void { $table = new Table('test'); $table->addColumn('id', 'integer'); @@ -798,7 +798,7 @@ public function testThrowsExceptionOnRenamingNonExistingIndex() /** * @group DBAL-234 */ - public function testThrowsExceptionOnRenamingToAlreadyExistingIndex() + public function testThrowsExceptionOnRenamingToAlreadyExistingIndex() : void { $table = new Table('test'); $table->addColumn('id', 'integer'); @@ -815,7 +815,7 @@ public function testThrowsExceptionOnRenamingToAlreadyExistingIndex() * @dataProvider getNormalizesAssetNames * @group DBAL-831 */ - public function testNormalizesColumnNames($assetName) + public function testNormalizesColumnNames(string $assetName) : void { $table = new Table('test'); @@ -869,7 +869,10 @@ public function testNormalizesColumnNames($assetName) self::assertFalse($table->hasForeignKey('foo')); } - public function getNormalizesAssetNames() + /** + * @return mixed[][] + */ + public static function getNormalizesAssetNames() : iterable { return [ ['foo'], diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php index e35583182a1..b70d2193a37 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -48,7 +48,7 @@ protected function setUp() : void ->willReturn(['foo']); } - public function testAcceptsNamespace() + public function testAcceptsNamespace() : void { $this->platformMock->expects($this->at(0)) ->method('supportsSchemas') @@ -67,7 +67,7 @@ public function testAcceptsNamespace() self::assertSame(['foo'], $this->visitor->getQueries()); } - public function testAcceptsTable() + public function testAcceptsTable() : void { $table = $this->createTableMock(); @@ -76,7 +76,7 @@ public function testAcceptsTable() self::assertSame(['foo'], $this->visitor->getQueries()); } - public function testAcceptsForeignKey() + public function testAcceptsForeignKey() : void { $this->platformMock->expects($this->at(0)) ->method('supportsForeignKeyConstraints') @@ -98,7 +98,7 @@ public function testAcceptsForeignKey() self::assertSame(['foo'], $this->visitor->getQueries()); } - public function testAcceptsSequences() + public function testAcceptsSequences() : void { $sequence = $this->createSequenceMock(); @@ -107,7 +107,7 @@ public function testAcceptsSequences() self::assertSame(['foo'], $this->visitor->getQueries()); } - public function testResetsQueries() + public function testResetsQueries() : void { foreach (['supportsSchemas', 'supportsForeignKeyConstraints'] as $method) { $this->platformMock->expects($this->any()) diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php index b2aff283871..ea265396333 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php @@ -10,14 +10,14 @@ use PHPUnit\Framework\TestCase; /** - * @covers Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector + * @covers \Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector */ class DropSchemaSqlCollectorTest extends TestCase { - public function testGetQueriesUsesAcceptedForeignKeys() + public function testGetQueriesUsesAcceptedForeignKeys() : void { - $tableOne = $this->getTableMock(); - $tableTwo = $this->getTableMock(); + $tableOne = $this->createMock(Table::class); + $tableTwo = $this->createMock(Table::class); $keyConstraintOne = $this->getStubKeyConstraint('first'); $keyConstraintTwo = $this->getStubKeyConstraint('second'); @@ -45,19 +45,9 @@ public function testGetQueriesUsesAcceptedForeignKeys() $collector->getQueries(); } - private function getTableMock() + private function getStubKeyConstraint(string $name) : ForeignKeyConstraint { - return $this->getMockWithoutArguments(Table::class); - } - - private function getMockWithoutArguments($className) - { - return $this->getMockBuilder($className)->disableOriginalConstructor()->getMock(); - } - - private function getStubKeyConstraint($name) - { - $constraint = $this->getMockWithoutArguments(ForeignKeyConstraint::class); + $constraint = $this->createMock(ForeignKeyConstraint::class); $constraint->expects($this->any()) ->method('getName') @@ -74,13 +64,16 @@ private function getStubKeyConstraint($name) return $constraint; } - public function testGivenForeignKeyWithZeroLengthAcceptForeignKeyThrowsException() + public function testGivenForeignKeyWithZeroLengthAcceptForeignKeyThrowsException() : void { $collector = new DropSchemaSqlCollector( $this->getMockForAbstractClass(AbstractPlatform::class) ); $this->expectException(SchemaException::class); - $collector->acceptForeignKey($this->getTableMock(), $this->getStubKeyConstraint('')); + $collector->acceptForeignKey( + $this->createMock(Table::class), + $this->getStubKeyConstraint('') + ); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php index c3e52b0ffaf..982da52ec44 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php @@ -14,7 +14,7 @@ class RemoveNamespacedAssetsTest extends TestCase /** * @group DBAL-204 */ - public function testRemoveNamespacedAssets() + public function testRemoveNamespacedAssets() : void { $config = new SchemaConfig(); $config->setName('test'); @@ -33,7 +33,7 @@ public function testRemoveNamespacedAssets() /** * @group DBAL-204 */ - public function testCleanupForeignKeys() + public function testCleanupForeignKeys() : void { $config = new SchemaConfig(); $config->setName('test'); @@ -56,7 +56,7 @@ public function testCleanupForeignKeys() /** * @group DBAL-204 */ - public function testCleanupForeignKeysDifferentOrder() + public function testCleanupForeignKeysDifferentOrder() : void { $config = new SchemaConfig(); $config->setName('test'); diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php index 4ebfd1cac54..34e2896de29 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php @@ -8,7 +8,7 @@ class SchemaSqlCollectorTest extends TestCase { - public function testCreateSchema() + public function testCreateSchema() : void { $platformMock = $this->getMockBuilder(MySqlPlatform::class) ->setMethods(['getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql']) @@ -30,7 +30,7 @@ public function testCreateSchema() self::assertEquals(['foo', 'foo', 'bar', 'baz'], $sql); } - public function testDropSchema() + public function testDropSchema() : void { $platformMock = $this->getMockBuilder(MySqlPlatform::class) ->setMethods(['getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql']) @@ -52,10 +52,7 @@ public function testDropSchema() self::assertEquals(['fk', 'seq', 'tbl', 'tbl'], $sql); } - /** - * @return Schema - */ - public function createFixtureSchema() + public function createFixtureSchema() : Schema { $schema = new Schema(); $tableA = $schema->createTable('foo'); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php index 4985605c60d..c782b06b919 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -14,7 +14,7 @@ */ class PoolingShardConnectionTest extends TestCase { - public function testConnect() + public function testConnect() : void { $conn = DriverManager::getConnection([ 'wrapperClass' => PoolingShardConnection::class, @@ -48,7 +48,7 @@ public function testConnect() self::assertFalse($conn->isConnected(2)); } - public function testNoGlobalServerException() + public function testNoGlobalServerException() : void { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Connection Parameters require 'global' and 'shards' configurations."); @@ -64,7 +64,7 @@ public function testNoGlobalServerException() ]); } - public function testNoShardsServersException() + public function testNoShardsServersException() : void { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Connection Parameters require 'global' and 'shards' configurations."); @@ -77,7 +77,7 @@ public function testNoShardsServersException() ]); } - public function testNoShardsChoserException() + public function testNoShardsChoserException() : void { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Missing Shard Choser configuration 'shardChoser'"); @@ -93,7 +93,7 @@ public function testNoShardsChoserException() ]); } - public function testShardChoserWrongInstance() + public function testShardChoserWrongInstance() : void { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser"); @@ -110,7 +110,7 @@ public function testShardChoserWrongInstance() ]); } - public function testShardNonNumericId() + public function testShardNonNumericId() : void { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Shard Id has to be a non-negative number.'); @@ -126,7 +126,7 @@ public function testShardNonNumericId() ]); } - public function testShardMissingId() + public function testShardMissingId() : void { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Missing 'id' for one configured shard. Please specify a unique shard-id."); @@ -142,7 +142,7 @@ public function testShardMissingId() ]); } - public function testDuplicateShardId() + public function testDuplicateShardId() : void { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Shard 1 is duplicated in the configuration.'); @@ -159,7 +159,7 @@ public function testDuplicateShardId() ]); } - public function testSwitchShardWithOpenTransactionException() + public function testSwitchShardWithOpenTransactionException() : void { $conn = DriverManager::getConnection([ 'wrapperClass' => PoolingShardConnection::class, @@ -178,7 +178,7 @@ public function testSwitchShardWithOpenTransactionException() $conn->connect(1); } - public function testGetActiveShardId() + public function testGetActiveShardId() : void { $conn = DriverManager::getConnection([ 'wrapperClass' => PoolingShardConnection::class, @@ -202,7 +202,7 @@ public function testGetActiveShardId() self::assertNull($conn->getActiveShardId()); } - public function testGetParamsOverride() + public function testGetParamsOverride() : void { $conn = DriverManager::getConnection([ 'wrapperClass' => PoolingShardConnection::class, @@ -241,7 +241,7 @@ public function testGetParamsOverride() ], $conn->getParams()); } - public function testGetHostOverride() + public function testGetHostOverride() : void { $conn = DriverManager::getConnection([ 'wrapperClass' => PoolingShardConnection::class, @@ -260,7 +260,7 @@ public function testGetHostOverride() self::assertEquals('foo', $conn->getHost()); } - public function testGetPortOverride() + public function testGetPortOverride() : void { $conn = DriverManager::getConnection([ 'wrapperClass' => PoolingShardConnection::class, @@ -279,7 +279,7 @@ public function testGetPortOverride() self::assertEquals(3307, $conn->getPort()); } - public function testGetUsernameOverride() + public function testGetUsernameOverride() : void { $conn = DriverManager::getConnection([ 'wrapperClass' => PoolingShardConnection::class, @@ -298,7 +298,7 @@ public function testGetUsernameOverride() self::assertEquals('bar', $conn->getUsername()); } - public function testGetPasswordOverride() + public function testGetPasswordOverride() : void { $conn = DriverManager::getConnection([ 'wrapperClass' => PoolingShardConnection::class, diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php index f1f6cc0e2e7..01db26773f3 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php @@ -5,11 +5,15 @@ use Doctrine\DBAL\Sharding\PoolingShardConnection; use Doctrine\DBAL\Sharding\PoolingShardManager; use Doctrine\DBAL\Sharding\ShardChoser\ShardChoser; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class PoolingShardManagerTest extends TestCase { - private function createConnectionMock() + /** + * @return PoolingShardConnection|MockObject + */ + private function createConnectionMock() : PoolingShardConnection { return $this->getMockBuilder(PoolingShardConnection::class) ->setMethods(['connect', 'getParams', 'fetchAll']) @@ -17,7 +21,7 @@ private function createConnectionMock() ->getMock(); } - private function createPassthroughShardChoser() + private function createPassthroughShardChoser() : ShardChoser { $mock = $this->createMock(ShardChoser::class); $mock->expects($this->any()) @@ -29,7 +33,7 @@ private function createPassthroughShardChoser() return $mock; } - private function createStaticShardChooser() + private function createStaticShardChooser() : ShardChoser { $mock = $this->createMock(ShardChoser::class); $mock->expects($this->any()) @@ -39,7 +43,7 @@ private function createStaticShardChooser() return $mock; } - public function testSelectGlobal() + public function testSelectGlobal() : void { $conn = $this->createConnectionMock(); $conn->expects($this->once())->method('connect')->with($this->equalTo(0)); @@ -50,7 +54,7 @@ public function testSelectGlobal() self::assertNull($shardManager->getCurrentDistributionValue()); } - public function testSelectShard() + public function testSelectShard() : void { $shardId = 10; $conn = $this->createConnectionMock(); @@ -63,7 +67,7 @@ public function testSelectShard() self::assertEquals($shardId, $shardManager->getCurrentDistributionValue()); } - public function testGetShards() + public function testGetShards() : void { $conn = $this->createConnectionMock(); $conn->expects($this->any())->method('getParams')->will( @@ -78,7 +82,7 @@ public function testGetShards() self::assertEquals([['id' => 1], ['id' => 2]], $shards); } - public function testQueryAll() + public function testQueryAll() : void { $sql = 'SELECT * FROM table'; $params = [1]; @@ -108,7 +112,7 @@ public function testQueryAll() self::assertEquals([['id' => 1], ['id' => 2]], $result); } - public function testQueryAllWithStaticShardChoser() + public function testQueryAllWithStaticShardChoser() : void { $sql = 'SELECT * FROM table'; $params = [1]; diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php index 5424c7bb676..b0439d5dfe2 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php @@ -52,7 +52,7 @@ protected function setUp() : void $this->sm = new SQLAzureShardManager($this->conn); } - public function createShopSchema() + protected function createShopSchema() : Schema { $schema = new Schema(); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/FunctionalTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/FunctionalTest.php index 8a99ea70879..6e31d8716ed 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/FunctionalTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/FunctionalTest.php @@ -7,7 +7,7 @@ class FunctionalTest extends AbstractTestCase { - public function testSharding() + public function testSharding() : void { $schema = $this->createShopSchema(); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php index 94634dadb69..3549cf40b0e 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php @@ -9,7 +9,7 @@ class MultiTenantVisitorTest extends TestCase { - public function testMultiTenantPrimaryKey() + public function testMultiTenantPrimaryKey() : void { $platform = new SQLAzurePlatform(); $visitor = new MultiTenantVisitor(); @@ -24,7 +24,7 @@ public function testMultiTenantPrimaryKey() self::assertTrue($foo->hasColumn('tenant_id')); } - public function testMultiTenantNonPrimaryKey() + public function testMultiTenantNonPrimaryKey() : void { $platform = new SQLAzurePlatform(); $visitor = new MultiTenantVisitor(); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizerTest.php index 20e479a3e00..2185a9fc8d1 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizerTest.php @@ -6,7 +6,7 @@ class SQLAzureFederationsSynchronizerTest extends AbstractTestCase { - public function testCreateSchema() + public function testCreateSchema() : void { $schema = $this->createShopSchema(); @@ -23,7 +23,7 @@ public function testCreateSchema() ], $sql); } - public function testUpdateSchema() + public function testUpdateSchema() : void { $schema = $this->createShopSchema(); @@ -35,7 +35,7 @@ public function testUpdateSchema() self::assertEquals([], $sql); } - public function testDropSchema() + public function testDropSchema() : void { $schema = $this->createShopSchema(); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php index 3a0d37ab4ce..6dcbad5f356 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php @@ -9,7 +9,7 @@ class SQLAzureShardManagerTest extends TestCase { - public function testNoFederationName() + public function testNoFederationName() : void { $this->expectException(ShardingException::class); $this->expectExceptionMessage('SQLAzure requires a federation name to be set during sharding configuration.'); @@ -18,7 +18,7 @@ public function testNoFederationName() new SQLAzureShardManager($conn); } - public function testNoDistributionKey() + public function testNoDistributionKey() : void { $this->expectException(ShardingException::class); $this->expectExceptionMessage('SQLAzure requires a distribution key to be set during sharding configuration.'); @@ -27,7 +27,7 @@ public function testNoDistributionKey() new SQLAzureShardManager($conn); } - public function testNoDistributionType() + public function testNoDistributionType() : void { $this->expectException(ShardingException::class); @@ -35,7 +35,7 @@ public function testNoDistributionType() new SQLAzureShardManager($conn); } - public function testGetDefaultDistributionValue() + public function testGetDefaultDistributionValue() : void { $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); @@ -43,7 +43,7 @@ public function testGetDefaultDistributionValue() self::assertNull($sm->getCurrentDistributionValue()); } - public function testSelectGlobalTransactionActive() + public function testSelectGlobalTransactionActive() : void { $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true)); @@ -55,7 +55,7 @@ public function testSelectGlobalTransactionActive() $sm->selectGlobal(); } - public function testSelectGlobal() + public function testSelectGlobal() : void { $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false)); @@ -65,7 +65,7 @@ public function testSelectGlobal() $sm->selectGlobal(); } - public function testSelectShard() + public function testSelectShard() : void { $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true)); @@ -82,7 +82,7 @@ public function testSelectShard() /** * @param mixed[] $params */ - private function createConnection(array $params) + private function createConnection(array $params) : Connection { $conn = $this->getMockBuilder(Connection::class) ->setMethods(['getParams', 'exec', 'isTransactionActive']) diff --git a/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php b/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php index 0c78b5c1771..aa15f91d3cc 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php @@ -8,7 +8,7 @@ class MultiTenantShardChoserTest extends TestCase { - public function testPickShard() + public function testPickShard() : void { $choser = new MultiTenantShardChoser(); $conn = $this->createConnectionMock(); @@ -17,7 +17,7 @@ public function testPickShard() self::assertEquals(2, $choser->pickShard(2, $conn)); } - private function createConnectionMock() + private function createConnectionMock() : PoolingShardConnection { return $this->getMockBuilder(PoolingShardConnection::class) ->setMethods(['connect', 'getParams', 'fetchAll']) diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index 1dae44d253d..1d76e3aabe3 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -55,7 +55,7 @@ protected function setUp() : void ->will($this->returnValue($driver)); } - public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound() + public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound() : void { $name = 'foo'; $var = 'bar'; @@ -78,7 +78,7 @@ public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound() $statement->execute(); } - public function testExecuteCallsLoggerStartQueryWithParametersWhenParamsPassedToExecute() + public function testExecuteCallsLoggerStartQueryWithParametersWhenParamsPassedToExecute() : void { $name = 'foo'; $var = 'bar'; @@ -99,7 +99,7 @@ public function testExecuteCallsLoggerStartQueryWithParametersWhenParamsPassedTo $statement->execute($values); } - public function testExecuteCallsStartQueryWithTheParametersBoundViaBindParam() + public function testExecuteCallsStartQueryWithTheParametersBoundViaBindParam() : void { $name = 'foo'; $var = 'bar'; @@ -121,7 +121,7 @@ public function testExecuteCallsStartQueryWithTheParametersBoundViaBindParam() $statement->execute(); } - public function testExecuteCallsLoggerStopQueryOnException() + public function testExecuteCallsLoggerStopQueryOnException() : void { $logger = $this->createMock(SQLLogger::class); diff --git a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php index eb06ddc350b..21eab4203ba 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php @@ -39,7 +39,7 @@ protected function setUp() : void $this->command->setHelperSet($helperSet); } - public function testMissingSqlArgument() + public function testMissingSqlArgument() : void { try { $this->commandTester->execute([ @@ -52,7 +52,7 @@ public function testMissingSqlArgument() } } - public function testIncorrectDepthOption() + public function testIncorrectDepthOption() : void { try { $this->commandTester->execute([ @@ -66,7 +66,7 @@ public function testIncorrectDepthOption() } } - public function testSelectStatementsPrintsResult() + public function testSelectStatementsPrintsResult() : void { $this->expectConnectionFetchAll(); @@ -79,7 +79,7 @@ public function testSelectStatementsPrintsResult() self::assertRegExp('@array.*1.*@', $this->commandTester->getDisplay()); } - public function testUpdateStatementsPrintsAffectedLines() + public function testUpdateStatementsPrintsAffectedLines() : void { $this->expectConnectionExecuteUpdate(); @@ -92,7 +92,7 @@ public function testUpdateStatementsPrintsAffectedLines() self::assertNotRegExp('@array.*1.*@', $this->commandTester->getDisplay()); } - private function expectConnectionExecuteUpdate() + private function expectConnectionExecuteUpdate() : void { $this->connectionMock ->expects($this->exactly(1)) @@ -102,7 +102,7 @@ private function expectConnectionExecuteUpdate() ->method('fetchAll'); } - private function expectConnectionFetchAll() + private function expectConnectionFetchAll() : void { $this->connectionMock ->expects($this->exactly(0)) @@ -112,7 +112,7 @@ private function expectConnectionFetchAll() ->method('fetchAll'); } - public function testStatementsWithFetchResultPrintsResult() + public function testStatementsWithFetchResultPrintsResult() : void { $this->expectConnectionFetchAll(); diff --git a/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php b/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php index 2aae261561f..ba99024231b 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php @@ -16,7 +16,7 @@ class DumperTest extends DbalTestCase { - public function testExportObject() + public function testExportObject() : void { $obj = new stdClass(); $obj->foo = 'bar'; @@ -26,7 +26,7 @@ public function testExportObject() self::assertEquals('stdClass', $var->__CLASS__); } - public function testExportObjectWithReference() + public function testExportObjectWithReference() : void { $foo = 'bar'; $bar = ['foo' => & $foo]; @@ -39,7 +39,7 @@ public function testExportObjectWithReference() self::assertEquals('tab', $bar['foo']); } - public function testExportArray() + public function testExportArray() : void { $array = ['a' => 'b', 'b' => ['c', 'd' => ['e', 'f']]]; $var = Dumper::export($array, 2); @@ -48,7 +48,7 @@ public function testExportArray() self::assertEquals($expected, $var); } - public function testExportDateTime() + public function testExportDateTime() : void { $obj = new DateTime('2010-10-10 10:10:10', new DateTimeZone('UTC')); @@ -57,7 +57,7 @@ public function testExportDateTime() self::assertEquals('2010-10-10T10:10:10+00:00', $var->date); } - public function testExportDateTimeImmutable() + public function testExportDateTimeImmutable() : void { $obj = new DateTimeImmutable('2010-10-10 10:10:10', new DateTimeZone('UTC')); @@ -66,7 +66,7 @@ public function testExportDateTimeImmutable() self::assertEquals('2010-10-10T10:10:10+00:00', $var->date); } - public function testExportDateTimeZone() + public function testExportDateTimeZone() : void { $obj = new DateTimeImmutable('2010-10-10 12:34:56', new DateTimeZone('Europe/Rome')); @@ -75,7 +75,7 @@ public function testExportDateTimeZone() self::assertEquals('2010-10-10T12:34:56+02:00', $var->date); } - public function testExportArrayTraversable() + public function testExportArrayTraversable() : void { $obj = new ArrayObject(['foobar']); @@ -93,7 +93,7 @@ public function testExportArrayTraversable() * * @dataProvider provideAttributesCases */ - public function testExportParentAttributes(TestAsset\ParentClass $class, array $expected) + public function testExportParentAttributes(TestAsset\ParentClass $class, array $expected) : void { $print_r_class = print_r($class, true); $print_r_expected = print_r($expected, true); @@ -110,7 +110,10 @@ public function testExportParentAttributes(TestAsset\ParentClass $class, array $ self::assertSame($expected, $var); } - public function provideAttributesCases() + /** + * @return mixed[][] + */ + public static function provideAttributesCases() : iterable { return [ 'different-attributes' => [ diff --git a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php index 6f09cbf2bc0..bc6ab4d413f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php @@ -24,24 +24,24 @@ protected function setUp() : void $this->type = Type::getType('array'); } - public function testArrayConvertsToDatabaseValue() + public function testArrayConvertsToDatabaseValue() : void { self::assertIsString($this->type->convertToDatabaseValue([], $this->platform)); } - public function testArrayConvertsToPHPValue() + public function testArrayConvertsToPHPValue() : void { self::assertIsArray($this->type->convertToPHPValue(serialize([]), $this->platform)); } - public function testConversionFailure() + public function testConversionFailure() : void { $this->expectException(ConversionException::class); $this->expectExceptionMessage("Could not convert database value to 'array' as an error was triggered by the unserialization: 'unserialize(): Error at offset 0 of 7 bytes'"); $this->type->convertToPHPValue('abcdefg', $this->platform); } - public function testNullConversion() + public function testNullConversion() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } @@ -49,7 +49,7 @@ public function testNullConversion() /** * @group DBAL-73 */ - public function testFalseConversion() + public function testFalseConversion() : void { self::assertFalse($this->type->convertToPHPValue(serialize(false), $this->platform)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php index 3e73c96e7c9..5f5b412e249 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php @@ -43,7 +43,7 @@ protected function tearDown() : void date_default_timezone_set($this->currentTimezone); } - public function testDateConvertsToDatabaseValue() + public function testDateConvertsToDatabaseValue() : void { self::assertIsString($this->type->convertToDatabaseValue(new DateTime(), $this->platform)); } @@ -53,19 +53,19 @@ public function testDateConvertsToDatabaseValue() * * @dataProvider invalidPHPValuesProvider */ - public function testInvalidTypeConversionToDatabaseValue($value) + public function testInvalidTypeConversionToDatabaseValue($value) : void { $this->expectException(ConversionException::class); $this->type->convertToDatabaseValue($value, $this->platform); } - public function testNullConversion() + public function testNullConversion() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } - public function testConvertDateTimeToPHPValue() + public function testConvertDateTimeToPHPValue() : void { $date = new DateTime('now'); @@ -79,7 +79,7 @@ public function testConvertDateTimeToPHPValue() * by @see \Doctrine\DBAL\Types\DateTimeImmutableType, previous DBAL versions handled it just fine. * This test is just in place to prevent further regressions, even if the type is being misused */ - public function testConvertDateTimeImmutableToPHPValue() + public function testConvertDateTimeImmutableToPHPValue() : void { $date = new DateTimeImmutable('now'); @@ -93,7 +93,7 @@ public function testConvertDateTimeImmutableToPHPValue() * by @see \Doctrine\DBAL\Types\DateTimeImmutableType, previous DBAL versions handled it just fine. * This test is just in place to prevent further regressions, even if the type is being misused */ - public function testDateTimeImmutableConvertsToDatabaseValue() + public function testDateTimeImmutableConvertsToDatabaseValue() : void { self::assertIsString($this->type->convertToDatabaseValue(new DateTimeImmutable(), $this->platform)); } @@ -101,7 +101,7 @@ public function testDateTimeImmutableConvertsToDatabaseValue() /** * @return mixed[][] */ - public function invalidPHPValuesProvider() + public static function invalidPHPValuesProvider() : iterable { return [ [0], @@ -111,7 +111,6 @@ public function invalidPHPValuesProvider() ['2015-01-31'], ['2015-01-31 10:11:12'], [new stdClass()], - [$this], [27], [-1], [1.2], diff --git a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php index 4eed8f7e4fd..fceeee557b8 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php @@ -31,17 +31,17 @@ protected function setUp() : void $this->type = Type::getType('binary'); } - public function testReturnsBindingType() + public function testReturnsBindingType() : void { self::assertSame(ParameterType::BINARY, $this->type->getBindingType()); } - public function testReturnsName() + public function testReturnsName() : void { self::assertSame(Types::BINARY, $this->type->getName()); } - public function testReturnsSQLDeclaration() + public function testReturnsSQLDeclaration() : void { $this->platform->expects($this->once()) ->method('getBinaryTypeDeclarationSQL') @@ -50,12 +50,12 @@ public function testReturnsSQLDeclaration() self::assertSame('TEST_BINARY', $this->type->getSQLDeclaration([], $this->platform)); } - public function testBinaryNullConvertsToPHPValue() + public function testBinaryNullConvertsToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } - public function testBinaryStringConvertsToPHPValue() + public function testBinaryStringConvertsToPHPValue() : void { $databaseValue = 'binary string'; $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); @@ -64,7 +64,7 @@ public function testBinaryStringConvertsToPHPValue() self::assertEquals($databaseValue, stream_get_contents($phpValue)); } - public function testBinaryResourceConvertsToPHPValue() + public function testBinaryResourceConvertsToPHPValue() : void { $databaseValue = fopen('data://text/plain;base64,' . base64_encode('binary string'), 'r'); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); @@ -73,16 +73,21 @@ public function testBinaryResourceConvertsToPHPValue() } /** + * @param mixed $value + * * @dataProvider getInvalidDatabaseValues */ - public function testThrowsConversionExceptionOnInvalidDatabaseValue($value) + public function testThrowsConversionExceptionOnInvalidDatabaseValue($value) : void { $this->expectException(ConversionException::class); $this->type->convertToPHPValue($value, $this->platform); } - public function getInvalidDatabaseValues() + /** + * @return mixed[][] + */ + public static function getInvalidDatabaseValues() : iterable { return [ [false], diff --git a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php index 70bbcf55967..194d26af0b8 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php @@ -29,12 +29,12 @@ protected function setUp() : void $this->type = Type::getType('blob'); } - public function testBlobNullConvertsToPHPValue() + public function testBlobNullConvertsToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } - public function testBinaryStringConvertsToPHPValue() + public function testBinaryStringConvertsToPHPValue() : void { $databaseValue = $this->getBinaryString(); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); @@ -43,7 +43,7 @@ public function testBinaryStringConvertsToPHPValue() self::assertSame($databaseValue, stream_get_contents($phpValue)); } - public function testBinaryResourceConvertsToPHPValue() + public function testBinaryResourceConvertsToPHPValue() : void { $databaseValue = fopen('data://text/plain;base64,' . base64_encode($this->getBinaryString()), 'r'); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); @@ -53,10 +53,8 @@ public function testBinaryResourceConvertsToPHPValue() /** * Creates a binary string containing all possible byte values. - * - * @return string */ - private function getBinaryString() + private function getBinaryString() : string { $string = ''; diff --git a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php index af84fbf00d2..b5e25c2a77b 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php @@ -22,17 +22,17 @@ protected function setUp() : void $this->type = Type::getType('boolean'); } - public function testBooleanConvertsToDatabaseValue() + public function testBooleanConvertsToDatabaseValue() : void { self::assertIsInt($this->type->convertToDatabaseValue(1, $this->platform)); } - public function testBooleanConvertsToPHPValue() + public function testBooleanConvertsToPHPValue() : void { self::assertIsBool($this->type->convertToPHPValue(0, $this->platform)); } - public function testBooleanNullConvertsToPHPValue() + public function testBooleanNullConvertsToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php index 3030899cd51..e7fa8a4be03 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php @@ -15,7 +15,7 @@ class ConversionExceptionTest extends TestCase * * @dataProvider scalarsProvider */ - public function testConversionFailedInvalidTypeWithScalar($scalarValue) + public function testConversionFailedInvalidTypeWithScalar($scalarValue) : void { $exception = ConversionException::conversionFailedInvalidType($scalarValue, 'foo', ['bar', 'baz']); @@ -32,7 +32,7 @@ public function testConversionFailedInvalidTypeWithScalar($scalarValue) * * @dataProvider nonScalarsProvider */ - public function testConversionFailedInvalidTypeWithNonScalar($nonScalar) + public function testConversionFailedInvalidTypeWithNonScalar($nonScalar) : void { $exception = ConversionException::conversionFailedInvalidType($nonScalar, 'foo', ['bar', 'baz']); @@ -44,7 +44,7 @@ public function testConversionFailedInvalidTypeWithNonScalar($nonScalar) ); } - public function testConversionFailedFormatPreservesPreviousException() + public function testConversionFailedFormatPreservesPreviousException() : void { $previous = new Exception(); @@ -57,13 +57,12 @@ public function testConversionFailedFormatPreservesPreviousException() /** * @return mixed[][] */ - public function nonScalarsProvider() + public static function nonScalarsProvider() : iterable { return [ [[]], [['foo']], [null], - [$this], [new stdClass()], [tmpfile()], ]; @@ -72,7 +71,7 @@ public function nonScalarsProvider() /** * @return mixed[][] */ - public function scalarsProvider() + public static function scalarsProvider() : iterable { return [ [''], diff --git a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php index 38cf0a98a33..c48f9a5ee34 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php @@ -27,22 +27,22 @@ protected function setUp() : void $this->platform = $this->prophesize(AbstractPlatform::class); } - public function testFactoryCreatesCorrectType() + public function testFactoryCreatesCorrectType() : void { self::assertSame(DateImmutableType::class, get_class($this->type)); } - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('date_immutable', $this->type->getName()); } - public function testReturnsBindingType() + public function testReturnsBindingType() : void { self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } - public function testConvertsDateTimeImmutableInstanceToDatabaseValue() + public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { $date = $this->prophesize(DateTimeImmutable::class); @@ -55,31 +55,31 @@ public function testConvertsDateTimeImmutableInstanceToDatabaseValue() ); } - public function testConvertsNullToDatabaseValue() + public function testConvertsNullToDatabaseValue() : void { self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); } - public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() + public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() : void { $this->expectException(ConversionException::class); $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } - public function testConvertsDateTimeImmutableInstanceToPHPValue() + public function testConvertsDateTimeImmutableInstanceToPHPValue() : void { $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } - public function testConvertsNullToPHPValue() + public function testConvertsNullToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); } - public function testConvertsDateStringToPHPValue() + public function testConvertsDateStringToPHPValue() : void { $this->platform->getDateFormatString()->willReturn('Y-m-d')->shouldBeCalled(); @@ -89,7 +89,7 @@ public function testConvertsDateStringToPHPValue() self::assertSame('2016-01-01', $date->format('Y-m-d')); } - public function testResetTimeFractionsWhenConvertingToPHPValue() + public function testResetTimeFractionsWhenConvertingToPHPValue() : void { $this->platform->getDateFormatString()->willReturn('Y-m-d'); @@ -98,14 +98,14 @@ public function testResetTimeFractionsWhenConvertingToPHPValue() self::assertSame('2016-01-01 00:00:00.000000', $date->format('Y-m-d H:i:s.u')); } - public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateString() + public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateString() : void { $this->expectException(ConversionException::class); $this->type->convertToPHPValue('invalid date string', $this->platform->reveal()); } - public function testRequiresSQLCommentHint() + public function testRequiresSQLCommentHint() : void { self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php index 710474257af..7b2c09aca9f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php @@ -103,6 +103,8 @@ public function testRequiresSQLCommentHint() : void } /** + * @param mixed $value + * * @dataProvider invalidPHPValuesProvider */ public function testInvalidTypeConversionToDatabaseValue($value) : void @@ -115,7 +117,7 @@ public function testInvalidTypeConversionToDatabaseValue($value) : void /** * @return mixed[][] */ - public function invalidPHPValuesProvider() : array + public static function invalidPHPValuesProvider() : iterable { return [ [0], @@ -125,7 +127,6 @@ public function invalidPHPValuesProvider() : array ['2015-01-31'], ['2015-01-31 10:11:12'], [new stdClass()], - [$this], [27], [-1], [1.2], diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index e7c76ba77ff..73e426ea41c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -19,7 +19,7 @@ protected function setUp() : void parent::setUp(); } - public function testDateConvertsToPHPValue() + public function testDateConvertsToPHPValue() : void { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) self::assertInstanceOf( @@ -28,14 +28,14 @@ public function testDateConvertsToPHPValue() ); } - public function testDateResetsNonDatePartsToZeroUnixTimeValues() + public function testDateResetsNonDatePartsToZeroUnixTimeValues() : void { $date = $this->type->convertToPHPValue('1985-09-01', $this->platform); self::assertEquals('00:00:00', $date->format('H:i:s')); } - public function testDateRestsSummerTimeAffection() + public function testDateRestsSummerTimeAffection() : void { date_default_timezone_set('Europe/Berlin'); @@ -48,7 +48,7 @@ public function testDateRestsSummerTimeAffection() self::assertEquals('2009-11-01', $date->format('Y-m-d')); } - public function testInvalidDateFormatConversion() + public function testInvalidDateFormatConversion() : void { $this->expectException(ConversionException::class); $this->type->convertToPHPValue('abcdefg', $this->platform); diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php index 4c2ed8e104e..8bc957f5c6b 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php @@ -27,22 +27,22 @@ protected function setUp() : void $this->platform = $this->prophesize(AbstractPlatform::class); } - public function testFactoryCreatesCorrectType() + public function testFactoryCreatesCorrectType() : void { self::assertSame(DateTimeImmutableType::class, get_class($this->type)); } - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('datetime_immutable', $this->type->getName()); } - public function testReturnsBindingType() + public function testReturnsBindingType() : void { self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } - public function testConvertsDateTimeImmutableInstanceToDatabaseValue() + public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { $date = $this->prophesize(DateTimeImmutable::class); @@ -55,31 +55,31 @@ public function testConvertsDateTimeImmutableInstanceToDatabaseValue() ); } - public function testConvertsNullToDatabaseValue() + public function testConvertsNullToDatabaseValue() : void { self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); } - public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() + public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() : void { $this->expectException(ConversionException::class); $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } - public function testConvertsDateTimeImmutableInstanceToPHPValue() + public function testConvertsDateTimeImmutableInstanceToPHPValue() : void { $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } - public function testConvertsNullToPHPValue() + public function testConvertsNullToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); } - public function testConvertsDateTimeStringToPHPValue() + public function testConvertsDateTimeStringToPHPValue() : void { $this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s')->shouldBeCalled(); @@ -92,7 +92,7 @@ public function testConvertsDateTimeStringToPHPValue() /** * @group DBAL-415 */ - public function testConvertsDateTimeStringWithMicrosecondsToPHPValue() + public function testConvertsDateTimeStringWithMicrosecondsToPHPValue() : void { $this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s'); @@ -101,14 +101,14 @@ public function testConvertsDateTimeStringWithMicrosecondsToPHPValue() self::assertSame('2016-01-01 15:58:59', $date->format('Y-m-d H:i:s')); } - public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeString() + public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeString() : void { $this->expectException(ConversionException::class); $this->type->convertToPHPValue('invalid datetime string', $this->platform->reveal()); } - public function testRequiresSQLCommentHint() + public function testRequiresSQLCommentHint() : void { self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index 615c14d584d..ba7a661c8d9 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -18,7 +18,7 @@ protected function setUp() : void parent::setUp(); } - public function testDateTimeConvertsToDatabaseValue() + public function testDateTimeConvertsToDatabaseValue() : void { $date = new DateTime('1985-09-01 10:10:10'); @@ -28,7 +28,7 @@ public function testDateTimeConvertsToDatabaseValue() self::assertEquals($expected, $actual); } - public function testDateTimeConvertsToPHPValue() + public function testDateTimeConvertsToPHPValue() : void { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) $date = $this->type->convertToPHPValue('1985-09-01 00:00:00', $this->platform); @@ -36,13 +36,13 @@ public function testDateTimeConvertsToPHPValue() self::assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); } - public function testInvalidDateTimeFormatConversion() + public function testInvalidDateTimeFormatConversion() : void { $this->expectException(ConversionException::class); $this->type->convertToPHPValue('abcdefg', $this->platform); } - public function testConvertsNonMatchingFormatToPhpValueWithParser() + public function testConvertsNonMatchingFormatToPhpValueWithParser() : void { $date = '1985/09/01 10:10:10.12345'; diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php index aa602b629c2..ededd0e6e6c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php @@ -27,22 +27,22 @@ protected function setUp() : void $this->platform = $this->prophesize(AbstractPlatform::class); } - public function testFactoryCreatesCorrectType() + public function testFactoryCreatesCorrectType() : void { self::assertSame(DateTimeTzImmutableType::class, get_class($this->type)); } - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('datetimetz_immutable', $this->type->getName()); } - public function testReturnsBindingType() + public function testReturnsBindingType() : void { self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } - public function testConvertsDateTimeImmutableInstanceToDatabaseValue() + public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { $date = $this->prophesize(DateTimeImmutable::class); @@ -55,31 +55,31 @@ public function testConvertsDateTimeImmutableInstanceToDatabaseValue() ); } - public function testConvertsNullToDatabaseValue() + public function testConvertsNullToDatabaseValue() : void { self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); } - public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() + public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() : void { $this->expectException(ConversionException::class); $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } - public function testConvertsDateTimeImmutableInstanceToPHPValue() + public function testConvertsDateTimeImmutableInstanceToPHPValue() : void { $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } - public function testConvertsNullToPHPValue() + public function testConvertsNullToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); } - public function testConvertsDateTimeWithTimezoneStringToPHPValue() + public function testConvertsDateTimeWithTimezoneStringToPHPValue() : void { $this->platform->getDateTimeTzFormatString()->willReturn('Y-m-d H:i:s T')->shouldBeCalled(); @@ -89,14 +89,14 @@ public function testConvertsDateTimeWithTimezoneStringToPHPValue() self::assertSame('2016-01-01 15:58:59 UTC', $date->format('Y-m-d H:i:s T')); } - public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeWithTimezoneString() + public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeWithTimezoneString() : void { $this->expectException(ConversionException::class); $this->type->convertToPHPValue('invalid datetime with timezone string', $this->platform->reveal()); } - public function testRequiresSQLCommentHint() + public function testRequiresSQLCommentHint() : void { self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index 419974c6b09..72ccaf87d05 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -18,7 +18,7 @@ protected function setUp() : void parent::setUp(); } - public function testDateTimeConvertsToDatabaseValue() + public function testDateTimeConvertsToDatabaseValue() : void { $date = new DateTime('1985-09-01 10:10:10'); @@ -28,7 +28,7 @@ public function testDateTimeConvertsToDatabaseValue() self::assertEquals($expected, $actual); } - public function testDateTimeConvertsToPHPValue() + public function testDateTimeConvertsToPHPValue() : void { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) $date = $this->type->convertToPHPValue('1985-09-01 00:00:00', $this->platform); @@ -36,7 +36,7 @@ public function testDateTimeConvertsToPHPValue() self::assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); } - public function testInvalidDateFormatConversion() + public function testInvalidDateFormatConversion() : void { $this->expectException(ConversionException::class); $this->type->convertToPHPValue('abcdefg', $this->platform); diff --git a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php index 7087d2a6a49..1528dfd86d9 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php @@ -22,12 +22,12 @@ protected function setUp() : void $this->type = Type::getType('decimal'); } - public function testDecimalConvertsToPHPValue() + public function testDecimalConvertsToPHPValue() : void { self::assertIsString($this->type->convertToPHPValue('5.5', $this->platform)); } - public function testDecimalNullConvertsToPHPValue() + public function testDecimalNullConvertsToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php index 6daffd7d29b..4934f716c0f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php @@ -22,22 +22,22 @@ protected function setUp() : void $this->type = Type::getType('float'); } - public function testFloatConvertsToPHPValue() + public function testFloatConvertsToPHPValue() : void { self::assertIsFloat($this->type->convertToPHPValue('5.5', $this->platform)); } - public function testFloatNullConvertsToPHPValue() + public function testFloatNullConvertsToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } - public function testFloatConvertToDatabaseValue() + public function testFloatConvertToDatabaseValue() : void { self::assertIsFloat($this->type->convertToDatabaseValue(5.5, $this->platform)); } - public function testFloatNullConvertToDatabaseValue() + public function testFloatNullConvertToDatabaseValue() : void { self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php index bbd309bea6d..df265d8541a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php @@ -22,18 +22,18 @@ protected function setUp() : void $this->type = Type::getType('guid'); } - public function testConvertToPHPValue() + public function testConvertToPHPValue() : void { self::assertIsString($this->type->convertToPHPValue('foo', $this->platform)); self::assertIsString($this->type->convertToPHPValue('', $this->platform)); } - public function testNullConversion() + public function testNullConversion() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } - public function testNativeGuidSupport() + public function testNativeGuidSupport() : void { self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); diff --git a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php index 789de21e208..e4ac718c4ea 100644 --- a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php @@ -22,13 +22,13 @@ protected function setUp() : void $this->type = Type::getType('integer'); } - public function testIntegerConvertsToPHPValue() + public function testIntegerConvertsToPHPValue() : void { self::assertIsInt($this->type->convertToPHPValue('1', $this->platform)); self::assertIsInt($this->type->convertToPHPValue('0', $this->platform)); } - public function testIntegerNullConvertsToPHPValue() + public function testIntegerNullConvertsToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index 2f76d14b503..2ee5e9fc45e 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -30,17 +30,17 @@ protected function setUp() : void $this->type = Type::getType('json_array'); } - public function testReturnsBindingType() + public function testReturnsBindingType() : void { self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } - public function testReturnsName() + public function testReturnsName() : void { self::assertSame(Types::JSON_ARRAY, $this->type->getName()); } - public function testReturnsSQLDeclaration() + public function testReturnsSQLDeclaration() : void { $this->platform->expects($this->once()) ->method('getJsonTypeDeclarationSQL') @@ -49,17 +49,17 @@ public function testReturnsSQLDeclaration() self::assertSame('TEST_JSON', $this->type->getSQLDeclaration([], $this->platform)); } - public function testJsonNullConvertsToPHPValue() + public function testJsonNullConvertsToPHPValue() : void { self::assertSame([], $this->type->convertToPHPValue(null, $this->platform)); } - public function testJsonEmptyStringConvertsToPHPValue() + public function testJsonEmptyStringConvertsToPHPValue() : void { self::assertSame([], $this->type->convertToPHPValue('', $this->platform)); } - public function testJsonStringConvertsToPHPValue() + public function testJsonStringConvertsToPHPValue() : void { $value = ['foo' => 'bar', 'bar' => 'foo']; $databaseValue = json_encode($value); @@ -68,7 +68,7 @@ public function testJsonStringConvertsToPHPValue() self::assertEquals($value, $phpValue); } - public function testJsonResourceConvertsToPHPValue() + public function testJsonResourceConvertsToPHPValue() : void { $value = ['foo' => 'bar', 'bar' => 'foo']; $databaseValue = fopen('data://text/plain;base64,' . base64_encode(json_encode($value)), 'r'); @@ -77,7 +77,7 @@ public function testJsonResourceConvertsToPHPValue() self::assertSame($value, $phpValue); } - public function testRequiresSQLCommentHint() + public function testRequiresSQLCommentHint() : void { self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index 796f5b1464f..4a5ff3c28c0 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -31,17 +31,17 @@ protected function setUp() : void $this->type = Type::getType('json'); } - public function testReturnsBindingType() + public function testReturnsBindingType() : void { self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } - public function testReturnsName() + public function testReturnsName() : void { self::assertSame(Types::JSON, $this->type->getName()); } - public function testReturnsSQLDeclaration() + public function testReturnsSQLDeclaration() : void { $this->platform->expects($this->once()) ->method('getJsonTypeDeclarationSQL') @@ -50,17 +50,17 @@ public function testReturnsSQLDeclaration() self::assertSame('TEST_JSON', $this->type->getSQLDeclaration([], $this->platform)); } - public function testJsonNullConvertsToPHPValue() + public function testJsonNullConvertsToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } - public function testJsonEmptyStringConvertsToPHPValue() + public function testJsonEmptyStringConvertsToPHPValue() : void { self::assertNull($this->type->convertToPHPValue('', $this->platform)); } - public function testJsonStringConvertsToPHPValue() + public function testJsonStringConvertsToPHPValue() : void { $value = ['foo' => 'bar', 'bar' => 'foo']; $databaseValue = json_encode($value); @@ -70,18 +70,21 @@ public function testJsonStringConvertsToPHPValue() } /** @dataProvider providerFailure */ - public function testConversionFailure($data) + public function testConversionFailure(string $data) : void { $this->expectException(ConversionException::class); $this->type->convertToPHPValue($data, $this->platform); } - public function providerFailure() + /** + * @return mixed[][] + */ + public static function providerFailure() : iterable { return [['a'], ['{']]; } - public function testJsonResourceConvertsToPHPValue() + public function testJsonResourceConvertsToPHPValue() : void { $value = ['foo' => 'bar', 'bar' => 'foo']; $databaseValue = fopen('data://text/plain;base64,' . base64_encode(json_encode($value)), 'r'); @@ -90,7 +93,7 @@ public function testJsonResourceConvertsToPHPValue() self::assertSame($value, $phpValue); } - public function testRequiresSQLCommentHint() + public function testRequiresSQLCommentHint() : void { self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index f8852ff1640..da9481d105a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -25,24 +25,24 @@ protected function setUp() : void $this->type = Type::getType('object'); } - public function testObjectConvertsToDatabaseValue() + public function testObjectConvertsToDatabaseValue() : void { self::assertIsString($this->type->convertToDatabaseValue(new stdClass(), $this->platform)); } - public function testObjectConvertsToPHPValue() + public function testObjectConvertsToPHPValue() : void { self::assertIsObject($this->type->convertToPHPValue(serialize(new stdClass()), $this->platform)); } - public function testConversionFailure() + public function testConversionFailure() : void { $this->expectException(ConversionException::class); $this->expectExceptionMessage("Could not convert database value to 'object' as an error was triggered by the unserialization: 'unserialize(): Error at offset 0 of 7 bytes'"); $this->type->convertToPHPValue('abcdefg', $this->platform); } - public function testNullConversion() + public function testNullConversion() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } @@ -50,7 +50,7 @@ public function testNullConversion() /** * @group DBAL-73 */ - public function testFalseConversion() + public function testFalseConversion() : void { self::assertFalse($this->type->convertToPHPValue(serialize(false), $this->platform)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php index 8aecc6649fa..b1731a99578 100644 --- a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php @@ -22,13 +22,13 @@ protected function setUp() : void $this->type = Type::getType('smallint'); } - public function testSmallIntConvertsToPHPValue() + public function testSmallIntConvertsToPHPValue() : void { self::assertIsInt($this->type->convertToPHPValue('1', $this->platform)); self::assertIsInt($this->type->convertToPHPValue('0', $this->platform)); } - public function testSmallIntNullConvertsToPHPValue() + public function testSmallIntNullConvertsToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/StringTest.php b/tests/Doctrine/Tests/DBAL/Types/StringTest.php index 4ffb9af7d96..4548ff60943 100644 --- a/tests/Doctrine/Tests/DBAL/Types/StringTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/StringTest.php @@ -22,7 +22,7 @@ protected function setUp() : void $this->type = Type::getType('string'); } - public function testReturnsSqlDeclarationFromPlatformVarchar() + public function testReturnsSqlDeclarationFromPlatformVarchar() : void { $this->platform->expects($this->once()) ->method('getVarcharTypeDeclarationSQL') @@ -31,7 +31,7 @@ public function testReturnsSqlDeclarationFromPlatformVarchar() self::assertEquals('TEST_VARCHAR', $this->type->getSqlDeclaration([], $this->platform)); } - public function testReturnsDefaultLengthFromPlatformVarchar() + public function testReturnsDefaultLengthFromPlatformVarchar() : void { $this->platform->expects($this->once()) ->method('getVarcharDefaultLength') @@ -40,18 +40,18 @@ public function testReturnsDefaultLengthFromPlatformVarchar() self::assertEquals(255, $this->type->getDefaultLength($this->platform)); } - public function testConvertToPHPValue() + public function testConvertToPHPValue() : void { self::assertIsString($this->type->convertToPHPValue('foo', $this->platform)); self::assertIsString($this->type->convertToPHPValue('', $this->platform)); } - public function testNullConversion() + public function testNullConversion() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } - public function testSQLConversion() + public function testSQLConversion() : void { self::assertFalse($this->type->canRequireSQLConversion(), 'String type can never require SQL conversion to work.'); self::assertEquals('t.foo', $this->type->convertToDatabaseValueSQL('t.foo', $this->platform)); diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php index a374cf1015f..e1445bee90c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php @@ -27,22 +27,22 @@ protected function setUp() : void $this->platform = $this->prophesize(AbstractPlatform::class); } - public function testFactoryCreatesCorrectType() + public function testFactoryCreatesCorrectType() : void { self::assertSame(TimeImmutableType::class, get_class($this->type)); } - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('time_immutable', $this->type->getName()); } - public function testReturnsBindingType() + public function testReturnsBindingType() : void { self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } - public function testConvertsDateTimeImmutableInstanceToDatabaseValue() + public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { $date = $this->prophesize(DateTimeImmutable::class); @@ -55,31 +55,31 @@ public function testConvertsDateTimeImmutableInstanceToDatabaseValue() ); } - public function testConvertsNullToDatabaseValue() + public function testConvertsNullToDatabaseValue() : void { self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); } - public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() + public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() : void { $this->expectException(ConversionException::class); $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } - public function testConvertsDateTimeImmutableInstanceToPHPValue() + public function testConvertsDateTimeImmutableInstanceToPHPValue() : void { $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } - public function testConvertsNullToPHPValue() + public function testConvertsNullToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); } - public function testConvertsTimeStringToPHPValue() + public function testConvertsTimeStringToPHPValue() : void { $this->platform->getTimeFormatString()->willReturn('H:i:s')->shouldBeCalled(); @@ -89,7 +89,7 @@ public function testConvertsTimeStringToPHPValue() self::assertSame('15:58:59', $date->format('H:i:s')); } - public function testResetDateFractionsWhenConvertingToPHPValue() + public function testResetDateFractionsWhenConvertingToPHPValue() : void { $this->platform->getTimeFormatString()->willReturn('H:i:s'); @@ -98,14 +98,14 @@ public function testResetDateFractionsWhenConvertingToPHPValue() self::assertSame('1970-01-01 15:58:59', $date->format('Y-m-d H:i:s')); } - public function testThrowsExceptionDuringConversionToPHPValueWithInvalidTimeString() + public function testThrowsExceptionDuringConversionToPHPValueWithInvalidTimeString() : void { $this->expectException(ConversionException::class); $this->type->convertToPHPValue('invalid time string', $this->platform->reveal()); } - public function testRequiresSQLCommentHint() + public function testRequiresSQLCommentHint() : void { self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); } diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index 1b254730092..a75544b650e 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -17,12 +17,12 @@ protected function setUp() : void parent::setUp(); } - public function testTimeConvertsToPHPValue() + public function testTimeConvertsToPHPValue() : void { self::assertInstanceOf('DateTime', $this->type->convertToPHPValue('5:30:55', $this->platform)); } - public function testDateFieldResetInPHPValue() + public function testDateFieldResetInPHPValue() : void { $time = $this->type->convertToPHPValue('01:23:34', $this->platform); @@ -30,7 +30,7 @@ public function testDateFieldResetInPHPValue() self::assertEquals('1970-01-01', $time->format('Y-m-d')); } - public function testInvalidTimeFormatConversion() + public function testInvalidTimeFormatConversion() : void { $this->expectException(ConversionException::class); $this->type->convertToPHPValue('abcdefg', $this->platform); diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php index b948f22af77..9786c46bb1c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php @@ -30,17 +30,17 @@ protected function setUp() : void $this->platform = $this->prophesize(AbstractPlatform::class); } - public function testReturnsName() + public function testReturnsName() : void { self::assertSame('datetime_immutable', $this->type->getName()); } - public function testReturnsBindingType() + public function testReturnsBindingType() : void { self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } - public function testConvertsDateTimeImmutableInstanceToDatabaseValue() + public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { $date = $this->prophesize(DateTimeImmutable::class); @@ -53,31 +53,31 @@ public function testConvertsDateTimeImmutableInstanceToDatabaseValue() ); } - public function testConvertsNullToDatabaseValue() + public function testConvertsNullToDatabaseValue() : void { self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); } - public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() + public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() : void { $this->expectException(ConversionException::class); $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } - public function testConvertsDateTimeImmutableInstanceToPHPValue() + public function testConvertsDateTimeImmutableInstanceToPHPValue() : void { $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } - public function testConvertsNullToPHPValue() + public function testConvertsNullToPHPValue() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); } - public function testConvertsDateishStringToPHPValue() + public function testConvertsDateishStringToPHPValue() : void { $this->platform->getDateTimeFormatString()->shouldNotBeCalled(); @@ -87,14 +87,14 @@ public function testConvertsDateishStringToPHPValue() self::assertSame('2016-01-01 15:58:59.123456 UTC', $date->format('Y-m-d H:i:s.u T')); } - public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateishString() + public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateishString() : void { $this->expectException(ConversionException::class); $this->type->convertToPHPValue('invalid date-ish string', $this->platform->reveal()); } - public function testRequiresSQLCommentHint() + public function testRequiresSQLCommentHint() : void { self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); } diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index 0807b25f022..7fe10cb2ba3 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -27,7 +27,7 @@ protected function setUp() : void $this->type = Type::getType('vardatetime'); } - public function testDateTimeConvertsToDatabaseValue() + public function testDateTimeConvertsToDatabaseValue() : void { $date = new DateTime('1985-09-01 10:10:10'); @@ -37,7 +37,7 @@ public function testDateTimeConvertsToDatabaseValue() self::assertEquals($expected, $actual); } - public function testDateTimeConvertsToPHPValue() + public function testDateTimeConvertsToPHPValue() : void { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) $date = $this->type->convertToPHPValue('1985-09-01 00:00:00', $this->platform); @@ -46,13 +46,13 @@ public function testDateTimeConvertsToPHPValue() self::assertEquals('000000', $date->format('u')); } - public function testInvalidDateTimeFormatConversion() + public function testInvalidDateTimeFormatConversion() : void { $this->expectException(ConversionException::class); $this->type->convertToPHPValue('abcdefg', $this->platform); } - public function testConversionWithMicroseconds() + public function testConversionWithMicroseconds() : void { $date = $this->type->convertToPHPValue('1985-09-01 00:00:00.123456', $this->platform); self::assertInstanceOf('DateTime', $date); @@ -60,12 +60,12 @@ public function testConversionWithMicroseconds() self::assertEquals('123456', $date->format('u')); } - public function testNullConversion() + public function testNullConversion() : void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } - public function testConvertDateTimeToPHPValue() + public function testConvertDateTimeToPHPValue() : void { $date = new DateTime('now'); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); diff --git a/tests/Doctrine/Tests/DBAL/UtilTest.php b/tests/Doctrine/Tests/DBAL/UtilTest.php index e7800fceba3..92f63872f15 100644 --- a/tests/Doctrine/Tests/DBAL/UtilTest.php +++ b/tests/Doctrine/Tests/DBAL/UtilTest.php @@ -7,7 +7,10 @@ class UtilTest extends DbalTestCase { - public static function dataConvertPositionalToNamedParameters() + /** + * @return mixed[][] + */ + public static function dataConvertPositionalToNamedParameters() : iterable { return [ [ @@ -64,13 +67,11 @@ public static function dataConvertPositionalToNamedParameters() } /** - * @param string $inputSQL - * @param string $expectedOutputSQL * @param mixed[] $expectedOutputParamsMap * * @dataProvider dataConvertPositionalToNamedParameters */ - public function testConvertPositionalToNamedParameters($inputSQL, $expectedOutputSQL, $expectedOutputParamsMap) + public function testConvertPositionalToNamedParameters(string $inputSQL, string $expectedOutputSQL, array $expectedOutputParamsMap) : void { [$statement, $params] = OCI8Statement::convertPositionalToNamedPlaceholders($inputSQL); diff --git a/tests/Doctrine/Tests/DbalFunctionalTestCase.php b/tests/Doctrine/Tests/DbalFunctionalTestCase.php index 2ae17cf9165..16aa747c20e 100644 --- a/tests/Doctrine/Tests/DbalFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DbalFunctionalTestCase.php @@ -33,7 +33,7 @@ abstract class DbalFunctionalTestCase extends DbalTestCase /** @var DebugStack */ protected $sqlLoggerStack; - protected function resetSharedConn() + protected function resetSharedConn() : void { if (! self::$sharedConnection) { return; diff --git a/tests/Doctrine/Tests/DbalPerformanceTestCase.php b/tests/Doctrine/Tests/DbalPerformanceTestCase.php index f9bb40df38c..ac0beb3c5de 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestCase.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestCase.php @@ -40,7 +40,7 @@ protected function assertPostConditions() : void /** * begin timing */ - protected function startTiming() + protected function startTiming() : void { $this->startTime = microtime(true); } @@ -48,7 +48,7 @@ protected function startTiming() /** * end timing */ - protected function stopTiming() + protected function stopTiming() : void { $this->runTime = microtime(true) - $this->startTime; } @@ -56,7 +56,7 @@ protected function stopTiming() /** * @return float elapsed test execution time */ - public function getTime() + public function getTime() : float { return $this->runTime; } diff --git a/tests/Doctrine/Tests/TestUtil.php b/tests/Doctrine/Tests/TestUtil.php index 0ff5a42ce8c..b5f4dd010c2 100644 --- a/tests/Doctrine/Tests/TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -38,7 +38,7 @@ class TestUtil * * @return Connection The database connection instance. */ - public static function getConnection() + public static function getConnection() : Connection { if (self::hasRequiredConnectionParams() && ! self::$initialized) { self::initializeDatabase(); @@ -52,7 +52,10 @@ public static function getConnection() return $conn; } - public static function getConnectionParams() + /** + * @return mixed[] + */ + public static function getConnectionParams() : array { if (self::hasRequiredConnectionParams()) { return self::getParamsForMainConnection(); @@ -61,7 +64,7 @@ public static function getConnectionParams() return self::getFallbackConnectionParams(); } - private static function hasRequiredConnectionParams() + private static function hasRequiredConnectionParams() : bool { return isset( $GLOBALS['db_type'], @@ -111,7 +114,10 @@ private static function initializeDatabase() : void } } - private static function getFallbackConnectionParams() + /** + * @return mixed[] + */ + private static function getFallbackConnectionParams() : array { if (! extension_loaded('pdo_sqlite')) { Assert::markTestSkipped('PDO SQLite extension is not loaded'); @@ -130,7 +136,7 @@ private static function getFallbackConnectionParams() return $params; } - private static function addDbEventSubscribers(Connection $conn) + private static function addDbEventSubscribers(Connection $conn) : void { if (! isset($GLOBALS['db_event_subscribers'])) { return; @@ -143,7 +149,10 @@ private static function addDbEventSubscribers(Connection $conn) } } - private static function getParamsForTemporaryConnection() + /** + * @return mixed[] + */ + private static function getParamsForTemporaryConnection() : array { $connectionParams = [ 'driver' => $GLOBALS['tmpdb_type'], @@ -169,7 +178,10 @@ private static function getParamsForTemporaryConnection() return $connectionParams; } - private static function getParamsForMainConnection() + /** + * @return mixed[] + */ + private static function getParamsForMainConnection() : array { $connectionParams = [ 'driver' => $GLOBALS['db_type'], @@ -191,10 +203,7 @@ private static function getParamsForMainConnection() return $connectionParams; } - /** - * @return Connection - */ - public static function getTempConnection() + public static function getTempConnection() : Connection { return DriverManager::getConnection(self::getParamsForTemporaryConnection()); } From 32803b926a9bdb229a3ca9a01caf3152e7e5c8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Thu, 30 May 2019 18:23:13 +0200 Subject: [PATCH 073/106] Make LoggerChain use constructor to add loggers instead of adder method --- UPGRADE.md | 4 ++++ lib/Doctrine/DBAL/Logging/LoggerChain.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index ad366845ef7..a8e2b7f879e 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -42,6 +42,10 @@ The `Doctrine\DBAL\Driver\SQLSrv\SQLSrvStatement::LAST_INSERT_ID_SQL` constant The constants in `Doctrine\DBAL\SQLParserUtils` have been deprecated and will be made private in 3.0. +## Deprecated `LoggerChain::addLogger` method + +The `Doctrine\DBAL\Logging\LoggerChain::addLogger` method has been deprecated. Inject list of loggers via constructor instead. + # Upgrade to 2.9 ## Deprecated `Statement::fetchColumn()` with an invalid index diff --git a/lib/Doctrine/DBAL/Logging/LoggerChain.php b/lib/Doctrine/DBAL/Logging/LoggerChain.php index 2b5404b25c7..024afae283a 100644 --- a/lib/Doctrine/DBAL/Logging/LoggerChain.php +++ b/lib/Doctrine/DBAL/Logging/LoggerChain.php @@ -10,9 +10,19 @@ class LoggerChain implements SQLLogger /** @var SQLLogger[] */ private $loggers = []; + /** + * @param SQLLogger[] $loggers + */ + public function __construct(array $loggers = []) + { + $this->loggers = $loggers; + } + /** * Adds a logger in the chain. * + * @deprecated Inject list of loggers via constructor instead + * * @return void */ public function addLogger(SQLLogger $logger) From 9706ef975cd7f78b7a62acc428f31b8ec2799596 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 6 Jun 2019 07:03:48 -0700 Subject: [PATCH 074/106] Deprecated some unused code bits --- UPGRADE.md | 8 ++++++++ lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php | 6 +++++- lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/UPGRADE.md b/UPGRADE.md index a8e2b7f879e..b79cc16c5b5 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,13 @@ # Upgrade to 2.10 +## Deprecated `Doctrine\DBAL\Platforms::_getAlterTableIndexForeignKeySQL()` + +Method `Doctrine\DBAL\Platforms::_getAlterTableIndexForeignKeySQL()` has been deprecated as no longer used. + +## Deprecated `Doctrine\DBAL\Driver\OCI8\OCI8Statement::$_PARAM` + +Property `Doctrine\DBAL\Driver\OCI8\OCI8Statement::$_PARAM` has been deprecated as not used. + ## Deprecated `Doctrine\DBAL\Driver::getName()` Relying on the name of the driver is discouraged. For referencing the driver, use its class name. diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index f9540110263..c974bf8fc7f 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -58,7 +58,11 @@ class OCI8Statement implements IteratorAggregate, Statement /** @var OCI8Connection */ protected $_conn; - /** @var string */ + /** + * @deprecated + * + * @var string + */ protected static $_PARAM = ':param'; /** @var int[] */ diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 57664e6b8d6..ba4a6b5dbc7 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -2140,6 +2140,8 @@ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) /** * Common code for alter table statement generation that updates the changed Index and Foreign Key definitions. * + * @deprecated + * * @return string[] */ protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff) From e2ddcb1b704343413f720077792f109c19942e4e Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 7 Jun 2019 09:24:57 -0700 Subject: [PATCH 075/106] Updated Jetbrains PhpStorm stubs to 2019.1 --- composer.json | 2 +- composer.lock | 15 ++++++++------- phpstan.neon.dist | 11 ++++------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 0012752347a..c80e0a928b2 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ }, "require-dev": { "doctrine/coding-standard": "^6.0", - "jetbrains/phpstorm-stubs": "^2018.1.2", + "jetbrains/phpstorm-stubs": "^2019.1", "phpstan/phpstan": "^0.11.3", "phpunit/phpunit": "^8.1.6", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", diff --git a/composer.lock b/composer.lock index ebe32e583c5..05ec05330fa 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "20970a03470d26a047432b1e25bb4a2a", + "content-hash": "9612eb03f704eeb9e5e8099f7e096443", "packages": [ { "name": "doctrine/cache", @@ -436,20 +436,21 @@ }, { "name": "jetbrains/phpstorm-stubs", - "version": "v2018.1.2", + "version": "v2019.1", "source": { "type": "git", "url": "https://github.com/JetBrains/phpstorm-stubs.git", - "reference": "d5fd088949a717b477a08ed8e24e7e64a814ae10" + "reference": "9e309771f362e979ecfb429303ad7a402c657234" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/JetBrains/phpstorm-stubs/zipball/d5fd088949a717b477a08ed8e24e7e64a814ae10", - "reference": "d5fd088949a717b477a08ed8e24e7e64a814ae10", + "url": "https://api.github.com/repos/JetBrains/phpstorm-stubs/zipball/9e309771f362e979ecfb429303ad7a402c657234", + "reference": "9e309771f362e979ecfb429303ad7a402c657234", "shasum": "" }, "require-dev": { "nikic/php-parser": "v4.0.1", + "php": "^7.1", "phpdocumentor/reflection-docblock": "^4.3", "phpunit/phpunit": "7.1.4" }, @@ -470,7 +471,7 @@ "stubs", "type" ], - "time": "2018-04-25T12:26:46+00:00" + "time": "2019-03-25T16:59:23+00:00" }, { "name": "myclabs/deep-copy", @@ -2931,7 +2932,7 @@ }, { "name": "Gert de Pagter", - "email": "backendtea@gmail.com" + "email": "BackEndTea@gmail.com" } ], "description": "Symfony polyfill for ctype functions", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 7aca228c393..4ae1fda3f8a 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -28,12 +28,9 @@ parameters: - '~^Method Doctrine\\DBAL\\Driver\\OCI8\\OCI8Connection::lastInsertId\(\) should return string but returns (int|false)\.\z~' - '~^Method Doctrine\\DBAL\\Driver\\SQLSrv\\SQLSrvConnection::errorCode\(\) should return string\|null but returns false\.\z~' - # http://php.net/manual/en/pdo.sqlitecreatefunction.php + # https://bugs.php.net/bug.php?id=78126 - '~^Call to an undefined method Doctrine\\DBAL\\Driver\\PDOConnection::sqliteCreateFunction\(\)\.\z~' - # https://github.com/JetBrains/phpstorm-stubs/pull/488 - - '~^Parameter #1 \$byteCount of function SQLSRV_SQLTYPE_VARBINARY expects int, string given\.\z~' - # https://github.com/phpstan/phpstan/issues/1847 - '~^Parameter #2 \$registeredAliases of static method Doctrine\\DBAL\\Query\\QueryException::unknownAlias\(\) expects array, array given\.\z~' - '~^Parameter #2 \$registeredAliases of static method Doctrine\\DBAL\\Query\\QueryException::nonUniqueAlias\(\) expects array, array given\.\z~' @@ -42,7 +39,7 @@ parameters: - '~^Method Doctrine\\DBAL\\Platforms\\AbstractPlatform::escapeStringForLike\(\) should return string but returns string|null\.\z~' # legacy variadic-like signature - - '~^Method Doctrine\\DBAL\\Driver\\Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~' + - '~^Method Doctrine\\DBAL(\\.*)?Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~' # some drivers actually do accept 2nd parameter... - '~^Method Doctrine\\DBAL\\Platforms\\AbstractPlatform::getListTableForeignKeysSQL\(\) invoked with \d+ parameters, 1 required\.\z~' @@ -54,8 +51,8 @@ parameters: # inheritance variance inference issue - '~^Method Doctrine\\DBAL\\Driver\\PDOConnection::\w+\(\) should return Doctrine\\DBAL\\Driver\\Statement but returns PDOStatement\.\z~' - # may not exist when pdo_sqlsrv is not loaded + # may not exist when pdo_sqlsrv is not loaded but PDO is - '~^Access to undefined constant PDO::SQLSRV_ENCODING_BINARY\.\z~' - # weird class name, doesn't exist in stubs either + # weird class name, represented in stubs as OCI_(Lob|Collection) - '~unknown class OCI-(Lob|Collection)~' From 056cd808988f662ef2922f49c80ebbd22c5a8633 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 7 Jun 2019 07:55:22 -0700 Subject: [PATCH 076/106] Updated PHPUnit to 8.2.1 The new version contains some improvements in handling mocks (https://github.com/sebastianbergmann/phpunit/issues/3602) and will help identify some existing issues in DBAL 3.0 tests: There were 2 warnings: 1) Doctrine\Tests\DBAL\Driver\OCI8\OCI8StatementTest::testExecute with data set #0 (array('test', null, 'value')) Method bindValue may not return value of type boolean 2) Doctrine\Tests\DBAL\Driver\OCI8\OCI8StatementTest::testExecute with data set #1 (array(null, 'test', 'value')) Method bindValue may not return value of type boolean --- composer.json | 2 +- composer.lock | 111 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 80 insertions(+), 33 deletions(-) diff --git a/composer.json b/composer.json index c80e0a928b2..65d0718f7f1 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "doctrine/coding-standard": "^6.0", "jetbrains/phpstorm-stubs": "^2019.1", "phpstan/phpstan": "^0.11.3", - "phpunit/phpunit": "^8.1.6", + "phpunit/phpunit": "^8.2.1", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", "symfony/phpunit-bridge": "^3.4.5|^4.0.5|^5.0" }, diff --git a/composer.lock b/composer.lock index 05ec05330fa..579ac1b883a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9612eb03f704eeb9e5e8099f7e096443", + "content-hash": "a386165fd4eb85610333facec8026438", "packages": [ { "name": "doctrine/cache", @@ -1537,16 +1537,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "7.0.3", + "version": "7.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "0317a769a81845c390e19684d9ba25d7f6aa4707" + "reference": "aed67b57d459dcab93e84a5c9703d3deb5025dff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/0317a769a81845c390e19684d9ba25d7f6aa4707", - "reference": "0317a769a81845c390e19684d9ba25d7f6aa4707", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aed67b57d459dcab93e84a5c9703d3deb5025dff", + "reference": "aed67b57d459dcab93e84a5c9703d3deb5025dff", "shasum": "" }, "require": { @@ -1596,7 +1596,7 @@ "testing", "xunit" ], - "time": "2019-02-26T07:38:26+00:00" + "time": "2019-06-06T12:28:18+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1691,16 +1691,16 @@ }, { "name": "phpunit/php-timer", - "version": "2.1.1", + "version": "2.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059" + "reference": "1038454804406b0b5f5f520358e78c1c2f71501e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b389aebe1b8b0578430bda0c7c95a829608e059", - "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1038454804406b0b5f5f520358e78c1c2f71501e", + "reference": "1038454804406b0b5f5f520358e78c1c2f71501e", "shasum": "" }, "require": { @@ -1736,7 +1736,7 @@ "keywords": [ "timer" ], - "time": "2019-02-20T10:12:59+00:00" + "time": "2019-06-07T04:22:29+00:00" }, { "name": "phpunit/php-token-stream", @@ -1789,42 +1789,43 @@ }, { "name": "phpunit/phpunit", - "version": "8.1.6", + "version": "8.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "e3c9da6e645492c461e0a11eca117f83f4f4c840" + "reference": "047f771e34dccacb6c432a1a70e9980e087eac92" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e3c9da6e645492c461e0a11eca117f83f4f4c840", - "reference": "e3c9da6e645492c461e0a11eca117f83f4f4c840", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/047f771e34dccacb6c432a1a70e9980e087eac92", + "reference": "047f771e34dccacb6c432a1a70e9980e087eac92", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.1", + "doctrine/instantiator": "^1.2.0", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.7", - "phar-io/manifest": "^1.0.2", - "phar-io/version": "^2.0", + "myclabs/deep-copy": "^1.9.1", + "phar-io/manifest": "^1.0.3", + "phar-io/version": "^2.0.1", "php": "^7.2", - "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^7.0", - "phpunit/php-file-iterator": "^2.0.1", + "phpspec/prophecy": "^1.8.0", + "phpunit/php-code-coverage": "^7.0.5", + "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^2.1", - "sebastian/comparator": "^3.0", - "sebastian/diff": "^3.0", - "sebastian/environment": "^4.1", - "sebastian/exporter": "^3.1", - "sebastian/global-state": "^3.0", + "phpunit/php-timer": "^2.1.2", + "sebastian/comparator": "^3.0.2", + "sebastian/diff": "^3.0.2", + "sebastian/environment": "^4.2.2", + "sebastian/exporter": "^3.1.0", + "sebastian/global-state": "^3.0.0", "sebastian/object-enumerator": "^3.0.3", - "sebastian/resource-operations": "^2.0", + "sebastian/resource-operations": "^2.0.1", + "sebastian/type": "^1.1.0", "sebastian/version": "^2.0.1" }, "require-dev": { @@ -1833,7 +1834,7 @@ "suggest": { "ext-soap": "*", "ext-xdebug": "*", - "phpunit/php-invoker": "^2.0" + "phpunit/php-invoker": "^2.0.0" }, "bin": [ "phpunit" @@ -1841,7 +1842,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "8.1-dev" + "dev-master": "8.2-dev" } }, "autoload": { @@ -1867,7 +1868,7 @@ "testing", "xunit" ], - "time": "2019-05-28T11:53:42+00:00" + "time": "2019-06-07T14:04:13+00:00" }, { "name": "psr/log", @@ -2442,6 +2443,52 @@ "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "time": "2018-10-04T04:07:39+00:00" }, + { + "name": "sebastian/type", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "b2a7f9aac51ce18cd7ac8b31e37c8ce5646fc741" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b2a7f9aac51ce18cd7ac8b31e37c8ce5646fc741", + "reference": "b2a7f9aac51ce18cd7ac8b31e37c8ce5646fc741", + "shasum": "" + }, + "require": { + "php": "^7.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "time": "2019-06-08T04:53:27+00:00" + }, { "name": "sebastian/version", "version": "2.0.1", From 80cccaa9a9954f3f9f901386b75d5becd5d740e1 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 14 Jun 2019 09:55:09 -0700 Subject: [PATCH 077/106] Added a unit test for Doctrine\DBAL\Logging\LoggerChain --- .../Tests/DBAL/Logging/LoggerChainTest.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/Doctrine/Tests/DBAL/Logging/LoggerChainTest.php diff --git a/tests/Doctrine/Tests/DBAL/Logging/LoggerChainTest.php b/tests/Doctrine/Tests/DBAL/Logging/LoggerChainTest.php new file mode 100644 index 00000000000..60d9c669d13 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Logging/LoggerChainTest.php @@ -0,0 +1,56 @@ +createChain('startQuery', $sql, $params, $types); + $listener->startQuery($sql, $params, $types); + } + + public function testStopQuery() : void + { + $listener = $this->createChain('stopQuery'); + $listener->stopQuery(); + } + + /** + * @param mixed ...$args + */ + private function createChain(string $method, ...$args) : LoggerChain + { + $chain = new LoggerChain([ + $this->createLogger($method, ...$args), + ]); + + $chain->addLogger($this->createLogger($method, ...$args)); + + return $chain; + } + + /** + * @param mixed ...$args + */ + private function createLogger(string $method, ...$args) : SQLLogger + { + $logger = $this->createMock(SQLLogger::class); + $logger->expects($this->once()) + ->method($method) + ->with(...$args); + + return $logger; + } +} From 8004701a95764c0079f7a96f92dd4f5e85a8bcfe Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 14 Jun 2019 20:04:31 -0700 Subject: [PATCH 078/106] Reworked the mocks generated by Prophecy using PHPUnit --- .../DBAL/Types/DateImmutableTypeTest.php | 43 ++++++++++------- .../DBAL/Types/DateTimeImmutableTypeTest.php | 47 ++++++++++++------- .../Types/DateTimeTzImmutableTypeTest.php | 41 ++++++++++------ .../DBAL/Types/TimeImmutableTypeTest.php | 43 ++++++++++------- .../Types/VarDateTimeImmutableTypeTest.php | 32 ++++++------- 5 files changed, 124 insertions(+), 82 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php index c48f9a5ee34..d023e6bc1ba 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php @@ -9,13 +9,13 @@ use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Prophecy\ObjectProphecy; use function get_class; class DateImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|ObjectProphecy */ + /** @var AbstractPlatform|MockObject */ private $platform; /** @var DateImmutableType */ @@ -24,7 +24,7 @@ class DateImmutableTypeTest extends TestCase protected function setUp() : void { $this->type = Type::getType('date_immutable'); - $this->platform = $this->prophesize(AbstractPlatform::class); + $this->platform = $this->createMock(AbstractPlatform::class); } public function testFactoryCreatesCorrectType() : void @@ -44,46 +44,53 @@ public function testReturnsBindingType() : void public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { - $date = $this->prophesize(DateTimeImmutable::class); + $date = $this->createMock(DateTimeImmutable::class); - $this->platform->getDateFormatString()->willReturn('Y-m-d')->shouldBeCalled(); - $date->format('Y-m-d')->willReturn('2016-01-01')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateFormatString') + ->willReturn('Y-m-d'); + $date->expects($this->once()) + ->method('format') + ->with('Y-m-d') + ->willReturn('2016-01-01'); self::assertSame( '2016-01-01', - $this->type->convertToDatabaseValue($date->reveal(), $this->platform->reveal()) + $this->type->convertToDatabaseValue($date, $this->platform) ); } public function testConvertsNullToDatabaseValue() : void { - self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); } public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() : void { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform); } public function testConvertsDateTimeImmutableInstanceToPHPValue() : void { $date = new DateTimeImmutable(); - self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); + self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } public function testConvertsNullToPHPValue() : void { - self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testConvertsDateStringToPHPValue() : void { - $this->platform->getDateFormatString()->willReturn('Y-m-d')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateFormatString') + ->willReturn('Y-m-d'); - $date = $this->type->convertToPHPValue('2016-01-01', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('2016-01-01', $this->platform); self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('2016-01-01', $date->format('Y-m-d')); @@ -91,9 +98,11 @@ public function testConvertsDateStringToPHPValue() : void public function testResetTimeFractionsWhenConvertingToPHPValue() : void { - $this->platform->getDateFormatString()->willReturn('Y-m-d'); + $this->platform->expects($this->any()) + ->method('getDateFormatString') + ->willReturn('Y-m-d'); - $date = $this->type->convertToPHPValue('2016-01-01', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('2016-01-01', $this->platform); self::assertSame('2016-01-01 00:00:00.000000', $date->format('Y-m-d H:i:s.u')); } @@ -102,11 +111,11 @@ public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateStri { $this->expectException(ConversionException::class); - $this->type->convertToPHPValue('invalid date string', $this->platform->reveal()); + $this->type->convertToPHPValue('invalid date string', $this->platform); } public function testRequiresSQLCommentHint() : void { - self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); + self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php index 8bc957f5c6b..6ace4b4c4e8 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php @@ -9,13 +9,13 @@ use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Prophecy\ObjectProphecy; use function get_class; class DateTimeImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|ObjectProphecy */ + /** @var AbstractPlatform|MockObject */ private $platform; /** @var DateTimeImmutableType */ @@ -24,7 +24,7 @@ class DateTimeImmutableTypeTest extends TestCase protected function setUp() : void { $this->type = Type::getType('datetime_immutable'); - $this->platform = $this->prophesize(AbstractPlatform::class); + $this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock(); } public function testFactoryCreatesCorrectType() : void @@ -44,46 +44,53 @@ public function testReturnsBindingType() : void public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { - $date = $this->prophesize(DateTimeImmutable::class); + $date = $this->getMockBuilder(DateTimeImmutable::class)->getMock(); - $this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s')->shouldBeCalled(); - $date->format('Y-m-d H:i:s')->willReturn('2016-01-01 15:58:59')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateTimeFormatString') + ->willReturn('Y-m-d H:i:s'); + $date->expects($this->once()) + ->method('format') + ->with('Y-m-d H:i:s') + ->willReturn('2016-01-01 15:58:59'); self::assertSame( '2016-01-01 15:58:59', - $this->type->convertToDatabaseValue($date->reveal(), $this->platform->reveal()) + $this->type->convertToDatabaseValue($date, $this->platform) ); } public function testConvertsNullToDatabaseValue() : void { - self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); } public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() : void { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform); } public function testConvertsDateTimeImmutableInstanceToPHPValue() : void { $date = new DateTimeImmutable(); - self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); + self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } public function testConvertsNullToPHPValue() : void { - self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testConvertsDateTimeStringToPHPValue() : void { - $this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateTimeFormatString') + ->willReturn('Y-m-d H:i:s'); - $date = $this->type->convertToPHPValue('2016-01-01 15:58:59', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('2016-01-01 15:58:59', $this->platform); self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('2016-01-01 15:58:59', $date->format('Y-m-d H:i:s')); @@ -94,22 +101,28 @@ public function testConvertsDateTimeStringToPHPValue() : void */ public function testConvertsDateTimeStringWithMicrosecondsToPHPValue() : void { - $this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s'); + $this->platform->expects($this->any()) + ->method('getDateTimeFormatString') + ->willReturn('Y-m-d H:i:s'); - $date = $this->type->convertToPHPValue('2016-01-01 15:58:59.123456', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('2016-01-01 15:58:59.123456', $this->platform); self::assertSame('2016-01-01 15:58:59', $date->format('Y-m-d H:i:s')); } public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeString() : void { + $this->platform->expects($this->atLeastOnce()) + ->method('getDateTimeFormatString') + ->willReturn('Y-m-d H:i:s'); + $this->expectException(ConversionException::class); - $this->type->convertToPHPValue('invalid datetime string', $this->platform->reveal()); + $this->type->convertToPHPValue('invalid datetime string', $this->platform); } public function testRequiresSQLCommentHint() : void { - self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); + self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php index ededd0e6e6c..808dfaf50ed 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php @@ -9,13 +9,13 @@ use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeTzImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Prophecy\ObjectProphecy; use function get_class; class DateTimeTzImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|ObjectProphecy */ + /** @var AbstractPlatform|MockObject */ private $platform; /** @var DateTimeTzImmutableType */ @@ -24,7 +24,7 @@ class DateTimeTzImmutableTypeTest extends TestCase protected function setUp() : void { $this->type = Type::getType('datetimetz_immutable'); - $this->platform = $this->prophesize(AbstractPlatform::class); + $this->platform = $this->createMock(AbstractPlatform::class); } public function testFactoryCreatesCorrectType() : void @@ -44,46 +44,53 @@ public function testReturnsBindingType() : void public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { - $date = $this->prophesize(DateTimeImmutable::class); + $date = $this->createMock(DateTimeImmutable::class); - $this->platform->getDateTimeTzFormatString()->willReturn('Y-m-d H:i:s T')->shouldBeCalled(); - $date->format('Y-m-d H:i:s T')->willReturn('2016-01-01 15:58:59 UTC')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateTimeTzFormatString') + ->willReturn('Y-m-d H:i:s T'); + $date->expects($this->once()) + ->method('format') + ->with('Y-m-d H:i:s T') + ->willReturn('2016-01-01 15:58:59 UTC'); self::assertSame( '2016-01-01 15:58:59 UTC', - $this->type->convertToDatabaseValue($date->reveal(), $this->platform->reveal()) + $this->type->convertToDatabaseValue($date, $this->platform) ); } public function testConvertsNullToDatabaseValue() : void { - self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); } public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() : void { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform); } public function testConvertsDateTimeImmutableInstanceToPHPValue() : void { $date = new DateTimeImmutable(); - self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); + self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } public function testConvertsNullToPHPValue() : void { - self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testConvertsDateTimeWithTimezoneStringToPHPValue() : void { - $this->platform->getDateTimeTzFormatString()->willReturn('Y-m-d H:i:s T')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateTimeTzFormatString') + ->willReturn('Y-m-d H:i:s T'); - $date = $this->type->convertToPHPValue('2016-01-01 15:58:59 UTC', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('2016-01-01 15:58:59 UTC', $this->platform); self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('2016-01-01 15:58:59 UTC', $date->format('Y-m-d H:i:s T')); @@ -91,13 +98,17 @@ public function testConvertsDateTimeWithTimezoneStringToPHPValue() : void public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeWithTimezoneString() : void { + $this->platform->expects($this->atLeastOnce()) + ->method('getDateTimeTzFormatString') + ->willReturn('Y-m-d H:i:s T'); + $this->expectException(ConversionException::class); - $this->type->convertToPHPValue('invalid datetime with timezone string', $this->platform->reveal()); + $this->type->convertToPHPValue('invalid datetime with timezone string', $this->platform); } public function testRequiresSQLCommentHint() : void { - self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); + self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php index e1445bee90c..ba087f19f40 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php @@ -9,13 +9,13 @@ use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\TimeImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Prophecy\ObjectProphecy; use function get_class; class TimeImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|ObjectProphecy */ + /** @var AbstractPlatform|MockObject */ private $platform; /** @var TimeImmutableType */ @@ -24,7 +24,7 @@ class TimeImmutableTypeTest extends TestCase protected function setUp() : void { $this->type = Type::getType('time_immutable'); - $this->platform = $this->prophesize(AbstractPlatform::class); + $this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock(); } public function testFactoryCreatesCorrectType() : void @@ -44,46 +44,53 @@ public function testReturnsBindingType() : void public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { - $date = $this->prophesize(DateTimeImmutable::class); + $date = $this->getMockBuilder(DateTimeImmutable::class)->getMock(); - $this->platform->getTimeFormatString()->willReturn('H:i:s')->shouldBeCalled(); - $date->format('H:i:s')->willReturn('15:58:59')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getTimeFormatString') + ->willReturn('H:i:s'); + $date->expects($this->once()) + ->method('format') + ->with('H:i:s') + ->willReturn('15:58:59'); self::assertSame( '15:58:59', - $this->type->convertToDatabaseValue($date->reveal(), $this->platform->reveal()) + $this->type->convertToDatabaseValue($date, $this->platform) ); } public function testConvertsNullToDatabaseValue() : void { - self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); } public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() : void { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform); } public function testConvertsDateTimeImmutableInstanceToPHPValue() : void { $date = new DateTimeImmutable(); - self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); + self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } public function testConvertsNullToPHPValue() : void { - self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testConvertsTimeStringToPHPValue() : void { - $this->platform->getTimeFormatString()->willReturn('H:i:s')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getTimeFormatString') + ->willReturn('H:i:s'); - $date = $this->type->convertToPHPValue('15:58:59', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('15:58:59', $this->platform); self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('15:58:59', $date->format('H:i:s')); @@ -91,9 +98,11 @@ public function testConvertsTimeStringToPHPValue() : void public function testResetDateFractionsWhenConvertingToPHPValue() : void { - $this->platform->getTimeFormatString()->willReturn('H:i:s'); + $this->platform->expects($this->any()) + ->method('getTimeFormatString') + ->willReturn('H:i:s'); - $date = $this->type->convertToPHPValue('15:58:59', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('15:58:59', $this->platform); self::assertSame('1970-01-01 15:58:59', $date->format('Y-m-d H:i:s')); } @@ -102,11 +111,11 @@ public function testThrowsExceptionDuringConversionToPHPValueWithInvalidTimeStri { $this->expectException(ConversionException::class); - $this->type->convertToPHPValue('invalid time string', $this->platform->reveal()); + $this->type->convertToPHPValue('invalid time string', $this->platform); } public function testRequiresSQLCommentHint() : void { - self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); + self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php index 9786c46bb1c..d3609fe2bac 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php @@ -9,12 +9,12 @@ use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\VarDateTimeImmutableType; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Prophecy\ObjectProphecy; class VarDateTimeImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|ObjectProphecy */ + /** @var AbstractPlatform|MockObject */ private $platform; /** @var VarDateTimeImmutableType */ @@ -27,7 +27,7 @@ protected function setUp() : void } $this->type = Type::getType('vardatetime_immutable'); - $this->platform = $this->prophesize(AbstractPlatform::class); + $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); } public function testReturnsName() : void @@ -42,46 +42,46 @@ public function testReturnsBindingType() : void public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { - $date = $this->prophesize(DateTimeImmutable::class); + $date = $this->getMockBuilder(DateTimeImmutable::class)->getMock(); - $this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s')->shouldBeCalled(); - $date->format('Y-m-d H:i:s')->willReturn('2016-01-01 15:58:59')->shouldBeCalled(); + $date->expects($this->once()) + ->method('format') + ->with('Y-m-d H:i:s') + ->willReturn('2016-01-01 15:58:59'); self::assertSame( '2016-01-01 15:58:59', - $this->type->convertToDatabaseValue($date->reveal(), $this->platform->reveal()) + $this->type->convertToDatabaseValue($date, $this->platform) ); } public function testConvertsNullToDatabaseValue() : void { - self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); } public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() : void { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform); } public function testConvertsDateTimeImmutableInstanceToPHPValue() : void { $date = new DateTimeImmutable(); - self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); + self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } public function testConvertsNullToPHPValue() : void { - self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testConvertsDateishStringToPHPValue() : void { - $this->platform->getDateTimeFormatString()->shouldNotBeCalled(); - - $date = $this->type->convertToPHPValue('2016-01-01 15:58:59.123456 UTC', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('2016-01-01 15:58:59.123456 UTC', $this->platform); self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('2016-01-01 15:58:59.123456 UTC', $date->format('Y-m-d H:i:s.u T')); @@ -91,11 +91,11 @@ public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateishS { $this->expectException(ConversionException::class); - $this->type->convertToPHPValue('invalid date-ish string', $this->platform->reveal()); + $this->type->convertToPHPValue('invalid date-ish string', $this->platform); } public function testRequiresSQLCommentHint() : void { - self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); + self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); } } From ccde56fe060ef2362f624ecbbb23eb87819281d5 Mon Sep 17 00:00:00 2001 From: garret-gunter Date: Mon, 17 Jun 2019 12:13:23 -0600 Subject: [PATCH 079/106] Compare type class when comparing columns. --- lib/Doctrine/DBAL/Schema/Comparator.php | 7 ++++- .../Tests/DBAL/Schema/ComparatorTest.php | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index 84d7808abef..9ccaa9a1efa 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -12,6 +12,7 @@ use function array_unique; use function assert; use function count; +use function get_class; use function strtolower; /** @@ -421,7 +422,11 @@ public function diffColumn(Column $column1, Column $column2) $changedProperties = []; - foreach (['type', 'notnull', 'unsigned', 'autoincrement'] as $property) { + if (get_class($properties1['type']) !== get_class($properties2['type'])) { + $changedProperties[] = 'type'; + } + + foreach (['notnull', 'unsigned', 'autoincrement'] as $property) { if ($properties1[$property] === $properties2[$property]) { continue; } diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index a98f477ac4c..43137e28883 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -16,6 +16,7 @@ use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\TestCase; use function array_keys; +use function get_class; class ComparatorTest extends TestCase { @@ -193,6 +194,36 @@ public function testCompareChangedColumnsChangeType() : void self::assertEquals([], $c->diffColumn($column1, $column1)); } + public function testCompareColumnsMultipleTypeInstances() : void + { + $integerType1 = Type::getType('integer'); + Type::overrideType('integer', get_class($integerType1)); + $integerType2 = Type::getType('integer'); + + $column1 = new Column('integerfield1', $integerType1); + $column2 = new Column('integerfield1', $integerType2); + + $c = new Comparator(); + self::assertEquals([], $c->diffColumn($column1, $column2)); + } + + public function testCompareColumnsOverriddenType() : void + { + $oldStringInstance = Type::getType('string'); + $integerType = Type::getType('integer'); + + Type::overrideType('string', get_class($integerType)); + $overriddenStringType = Type::getType('string'); + + Type::overrideType('string', get_class($oldStringInstance)); + + $column1 = new Column('integerfield1', $integerType); + $column2 = new Column('integerfield1', $overriddenStringType); + + $c = new Comparator(); + self::assertEquals([], $c->diffColumn($column1, $column2)); + } + public function testCompareChangedColumnsChangeCustomSchemaOption() : void { $column1 = new Column('charfield1', Type::getType('string')); From d6a1237f6d16cb5b8cd57c7aca7096cd84925cce Mon Sep 17 00:00:00 2001 From: Andrej Hudec Date: Tue, 4 Jun 2019 12:46:23 +0200 Subject: [PATCH 080/106] Return result from commit() --- lib/Doctrine/DBAL/Connection.php | 8 ++-- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 30 ++++++++++++++ .../Tests/DBAL/Functional/ConnectionTest.php | 2 +- .../Tests/DBAL/Functional/TransactionTest.php | 39 +++++++++++++++++++ 4 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/TransactionTest.php diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index d514557ff79..7fef4e8628a 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1266,6 +1266,8 @@ public function commit() throw ConnectionException::commitFailedRollbackOnly(); } + $result = true; + $connection = $this->getWrappedConnection(); $logger = $this->_config->getSQLLogger(); @@ -1275,7 +1277,7 @@ public function commit() $logger->startQuery('"COMMIT"'); } - $connection->commit(); + $result = $connection->commit(); if ($logger) { $logger->stopQuery(); @@ -1293,12 +1295,12 @@ public function commit() --$this->transactionNestingLevel; if ($this->autoCommit !== false || $this->transactionNestingLevel !== 0) { - return true; + return $result; } $this->beginTransaction(); - return true; + return $result; } /** diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index dfd89f80dd6..09ee88349ec 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -297,6 +297,36 @@ public function testCommitStartsTransactionInNoAutoCommitMode() : void self::assertTrue($conn->isTransactionActive()); } + /** + * @dataProvider resultProvider + */ + public function testCommitReturn(bool $expectedResult) : void + { + $driverConnection = $this->createMock(DriverConnection::class); + $driverConnection->expects($this->once()) + ->method('commit')->willReturn($expectedResult); + + $driverMock = $this->createMock(Driver::class); + $driverMock->expects($this->any()) + ->method('connect') + ->will($this->returnValue($driverConnection)); + + $conn = new Connection([], $driverMock); + + $conn->connect(); + $conn->beginTransaction(); + + self::assertSame($expectedResult, $conn->commit()); + } + + /** + * @return bool[][] + */ + public function resultProvider() : array + { + return [[true], [false]]; + } + /** * @group DBAL-81 */ diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index 2c88a127e33..9218d35e0ab 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -88,7 +88,7 @@ public function testTransactionNestingBehaviorWithSavepoints() : void self::assertEquals(2, $this->connection->getTransactionNestingLevel()); $this->connection->beginTransaction(); self::assertEquals(3, $this->connection->getTransactionNestingLevel()); - $this->connection->commit(); + self::assertTrue($this->connection->commit()); self::assertEquals(2, $this->connection->getTransactionNestingLevel()); throw new Exception(); $this->connection->commit(); // never reached diff --git a/tests/Doctrine/Tests/DBAL/Functional/TransactionTest.php b/tests/Doctrine/Tests/DBAL/Functional/TransactionTest.php new file mode 100644 index 00000000000..4d57874671d --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/TransactionTest.php @@ -0,0 +1,39 @@ +connection->getDatabasePlatform() instanceof MySqlPlatform) { + return; + } + + $this->markTestSkipped('Restricted to MySQL.'); + } + + protected function tearDown() : void + { + $this->resetSharedConn(); + + parent::tearDown(); + } + + public function testCommitFalse() : void + { + $this->connection->query('SET SESSION wait_timeout=1'); + + $this->assertTrue($this->connection->beginTransaction()); + + sleep(2); // during the sleep mysql will close the connection + + $this->assertFalse(@$this->connection->commit()); // we will ignore `MySQL server has gone away` warnings + } +} From 0b7e39097bea247512e05109fa5b523796a93680 Mon Sep 17 00:00:00 2001 From: Robin D'Arcy Date: Thu, 27 Jun 2019 17:29:41 +0100 Subject: [PATCH 081/106] Fix typo in AbstractSchemaManager.php docblock Change "we're" to "where" in docblock for listTableColumns() method. Add comma to improve readability. --- lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 5c92c2e3f7b..259803c423f 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -146,7 +146,7 @@ public function listSequences($database = null) * this column definition does try to contain the 'primary' field for * the reason that it is not portable across different RDBMS. Use * {@see listTableIndexes($tableName)} to retrieve the primary key - * of a table. We're a RDBMS specifies more details these are held + * of a table. Where a RDBMS specifies more details, these are held * in the platformDetails array. * * @param string $table The name of the table. From c51b5c6c389c2a61ef795af31316a2196301f01b Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 7 Jul 2019 05:31:37 +0300 Subject: [PATCH 082/106] Switched from ibmcom/db2express-c to ibmcom/db2 --- tests/travis/install-db2.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/travis/install-db2.sh b/tests/travis/install-db2.sh index f5b374db2d3..79c1be98f74 100644 --- a/tests/travis/install-db2.sh +++ b/tests/travis/install-db2.sh @@ -4,19 +4,20 @@ set -ex echo Setting up IBM DB2 -sudo docker pull ibmcom/db2express-c:10.5.0.5-3.10.0 +echo "su - db2inst1 -c 'db2 CONNECT TO doctrine && db2 CREATE USER TEMPORARY TABLESPACE doctrine_tbsp PAGESIZE 4 K'" > /tmp/doctrine-init.sh +chmod +x /tmp/doctrine-init.sh + sudo docker run \ -d \ -p 50000:50000 \ -e DB2INST1_PASSWORD=Doctrine2018 \ -e LICENSE=accept \ + -e DBNAME=doctrine \ + -v /tmp/doctrine-init.sh:/var/custom/doctrine-init.sh:ro \ --name db2 \ - ibmcom/db2express-c:10.5.0.5-3.10.0 \ - db2start - -sleep 15 + --privileged=true \ + ibmcom/db2:11.5.0.0 -sudo docker exec db2 su - db2inst1 -c \ - 'db2 CREATE DB doctrine && db2 CONNECT TO doctrine && db2 CREATE USER TEMPORARY TABLESPACE doctrine_tbsp PAGESIZE 4 K' +sudo docker logs -f db2 | sed '/(*) Setup has completed./ q' echo DB2 started From 194f710b130e45b70227ca366a2005a7c90a0f4a Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 3 Aug 2019 10:05:09 -0700 Subject: [PATCH 083/106] Bumped PHPUnit requrement to ^8.3.3, removed dependency on symfony/phpunit-bridge --- composer.json | 5 +- composer.lock | 164 ++++++------------ phpunit.xml.dist | 1 - .../Doctrine/Tests/DBAL/Schema/ColumnTest.php | 2 + .../mssql.sql2008r2sp2.sqlsrv.appveyor.xml | 4 - .../mssql.sql2012sp1.sqlsrv.appveyor.xml | 4 - .../mssql.sql2017.pdo_sqlsrv.appveyor.xml | 4 - .../mssql.sql2017.sqlsrv.appveyor.xml | 4 - .../oci8.phpunit.continuousphp.xml | 4 - tests/continuousphp/pdo-oci.phpunit.xml | 4 - tests/travis/ibm_db2.travis.xml | 4 - tests/travis/mariadb.mysqli.travis.xml | 4 - tests/travis/mariadb.travis.xml | 4 - tests/travis/mysql.docker.travis.xml | 4 - tests/travis/mysql.travis.xml | 4 - tests/travis/mysqli.docker.travis.xml | 4 - tests/travis/mysqli.travis.xml | 4 - tests/travis/pdo_sqlsrv.travis.xml | 4 - tests/travis/pgsql.travis.xml | 4 - tests/travis/sqlite.travis.xml | 4 - tests/travis/sqlsrv.travis.xml | 4 - 21 files changed, 53 insertions(+), 187 deletions(-) diff --git a/composer.json b/composer.json index 65d0718f7f1..2d09887ce4c 100644 --- a/composer.json +++ b/composer.json @@ -41,9 +41,8 @@ "doctrine/coding-standard": "^6.0", "jetbrains/phpstorm-stubs": "^2019.1", "phpstan/phpstan": "^0.11.3", - "phpunit/phpunit": "^8.2.1", - "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", - "symfony/phpunit-bridge": "^3.4.5|^4.0.5|^5.0" + "phpunit/phpunit": "^8.3.3", + "symfony/console": "^2.0.5|^3.0|^4.0|^5.0" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." diff --git a/composer.lock b/composer.lock index 579ac1b883a..75dc9e0be18 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a386165fd4eb85610333facec8026438", + "content-hash": "1d397d6d064efda6d4150edce78e283a", "packages": [ { "name": "doctrine/cache", @@ -1355,16 +1355,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.8.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", "shasum": "" }, "require": { @@ -1385,8 +1385,8 @@ } }, "autoload": { - "psr-0": { - "Prophecy\\": "src/" + "psr-4": { + "Prophecy\\": "src/Prophecy" } }, "notification-url": "https://packagist.org/downloads/", @@ -1414,7 +1414,7 @@ "spy", "stub" ], - "time": "2018-08-05T17:53:17+00:00" + "time": "2019-06-13T12:50:23+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -1537,16 +1537,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "7.0.5", + "version": "7.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "aed67b57d459dcab93e84a5c9703d3deb5025dff" + "reference": "7743bbcfff2a907e9ee4a25be13d0f8ec5e73800" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aed67b57d459dcab93e84a5c9703d3deb5025dff", - "reference": "aed67b57d459dcab93e84a5c9703d3deb5025dff", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7743bbcfff2a907e9ee4a25be13d0f8ec5e73800", + "reference": "7743bbcfff2a907e9ee4a25be13d0f8ec5e73800", "shasum": "" }, "require": { @@ -1555,17 +1555,17 @@ "php": "^7.2", "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.0.1", + "phpunit/php-token-stream": "^3.1.0", "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^4.1", + "sebastian/environment": "^4.2.2", "sebastian/version": "^2.0.1", - "theseer/tokenizer": "^1.1" + "theseer/tokenizer": "^1.1.3" }, "require-dev": { - "phpunit/phpunit": "^8.0" + "phpunit/phpunit": "^8.2.2" }, "suggest": { - "ext-xdebug": "^2.6.1" + "ext-xdebug": "^2.7.2" }, "type": "library", "extra": { @@ -1585,8 +1585,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" + "role": "lead", + "email": "sebastian@phpunit.de" } ], "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", @@ -1596,7 +1596,7 @@ "testing", "xunit" ], - "time": "2019-06-06T12:28:18+00:00" + "time": "2019-07-25T05:31:54+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1740,16 +1740,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "3.0.1", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18" + "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c99e3be9d3e85f60646f152f9002d46ed7770d18", - "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e899757bb3df5ff6e95089132f32cd59aac2220a", + "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a", "shasum": "" }, "require": { @@ -1762,7 +1762,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -1785,20 +1785,20 @@ "keywords": [ "tokenizer" ], - "time": "2018-10-30T05:52:18+00:00" + "time": "2019-07-25T05:29:42+00:00" }, { "name": "phpunit/phpunit", - "version": "8.2.1", + "version": "8.3.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "047f771e34dccacb6c432a1a70e9980e087eac92" + "reference": "c319d08ebd31e137034c84ad7339054709491485" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/047f771e34dccacb6c432a1a70e9980e087eac92", - "reference": "047f771e34dccacb6c432a1a70e9980e087eac92", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c319d08ebd31e137034c84ad7339054709491485", + "reference": "c319d08ebd31e137034c84ad7339054709491485", "shasum": "" }, "require": { @@ -1813,8 +1813,8 @@ "phar-io/manifest": "^1.0.3", "phar-io/version": "^2.0.1", "php": "^7.2", - "phpspec/prophecy": "^1.8.0", - "phpunit/php-code-coverage": "^7.0.5", + "phpspec/prophecy": "^1.8.1", + "phpunit/php-code-coverage": "^7.0.7", "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", "phpunit/php-timer": "^2.1.2", @@ -1825,7 +1825,7 @@ "sebastian/global-state": "^3.0.0", "sebastian/object-enumerator": "^3.0.3", "sebastian/resource-operations": "^2.0.1", - "sebastian/type": "^1.1.0", + "sebastian/type": "^1.1.3", "sebastian/version": "^2.0.1" }, "require-dev": { @@ -1842,7 +1842,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "8.2-dev" + "dev-master": "8.3-dev" } }, "autoload": { @@ -1857,8 +1857,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" + "role": "lead", + "email": "sebastian@phpunit.de" } ], "description": "The PHP Unit Testing framework.", @@ -1868,7 +1868,7 @@ "testing", "xunit" ], - "time": "2019-06-07T14:04:13+00:00" + "time": "2019-08-03T15:41:47+00:00" }, { "name": "psr/log", @@ -2445,16 +2445,16 @@ }, { "name": "sebastian/type", - "version": "1.1.1", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "b2a7f9aac51ce18cd7ac8b31e37c8ce5646fc741" + "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b2a7f9aac51ce18cd7ac8b31e37c8ce5646fc741", - "reference": "b2a7f9aac51ce18cd7ac8b31e37c8ce5646fc741", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/3aaaa15fa71d27650d62a948be022fe3b48541a3", + "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3", "shasum": "" }, "require": { @@ -2481,13 +2481,13 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" + "role": "lead", + "email": "sebastian@phpunit.de" } ], "description": "Collection of value objects that represent the types of the PHP type system", "homepage": "https://github.com/sebastianbergmann/type", - "time": "2019-06-08T04:53:27+00:00" + "time": "2019-07-02T08:10:15+00:00" }, { "name": "sebastian/version", @@ -2868,72 +2868,6 @@ "homepage": "https://symfony.com", "time": "2019-02-23T15:42:05+00:00" }, - { - "name": "symfony/phpunit-bridge", - "version": "v4.0.6", - "source": { - "type": "git", - "url": "https://github.com/symfony/phpunit-bridge.git", - "reference": "14ffbbe2a72d0f6339b24eb830dd38cf63ba6630" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/14ffbbe2a72d0f6339b24eb830dd38cf63ba6630", - "reference": "14ffbbe2a72d0f6339b24eb830dd38cf63ba6630", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "conflict": { - "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0" - }, - "suggest": { - "ext-zip": "Zip support is required when using bin/simple-phpunit", - "symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" - }, - "bin": [ - "bin/simple-phpunit" - ], - "type": "symfony-bridge", - "extra": { - "branch-alias": { - "dev-master": "4.0-dev" - }, - "thanks": { - "name": "phpunit/phpunit", - "url": "https://github.com/sebastianbergmann/phpunit" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Bridge\\PhpUnit\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony PHPUnit Bridge", - "homepage": "https://symfony.com", - "time": "2018-02-19T16:50:22+00:00" - }, { "name": "symfony/polyfill-ctype", "version": "v1.11.0", @@ -3053,16 +2987,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.1.2", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8" + "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/1c42705be2b6c1de5904f8afacef5895cab44bf8", - "reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/11336f6f84e16a720dae9d8e6ed5019efa85a0f9", + "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9", "shasum": "" }, "require": { @@ -3089,7 +3023,7 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "time": "2019-04-04T09:56:43+00:00" + "time": "2019-06-13T22:48:21+00:00" }, { "name": "webmozart/assert", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b212ccf7e0d..f62532ed9f9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -60,7 +60,6 @@ - diff --git a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php index 0997ce26319..32e4568ed03 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php @@ -66,6 +66,8 @@ public function testToArray() : void */ public function testSettingUnknownOptionIsStillSupported() : void { + $this->expectNotToPerformAssertions(); + new Column('foo', $this->createMock(Type::class), ['unknown_option' => 'bar']); } diff --git a/tests/appveyor/mssql.sql2008r2sp2.sqlsrv.appveyor.xml b/tests/appveyor/mssql.sql2008r2sp2.sqlsrv.appveyor.xml index 712a8029ade..ef358c2d3be 100644 --- a/tests/appveyor/mssql.sql2008r2sp2.sqlsrv.appveyor.xml +++ b/tests/appveyor/mssql.sql2008r2sp2.sqlsrv.appveyor.xml @@ -37,10 +37,6 @@ - - - - performance diff --git a/tests/appveyor/mssql.sql2012sp1.sqlsrv.appveyor.xml b/tests/appveyor/mssql.sql2012sp1.sqlsrv.appveyor.xml index 9195c5aaa87..68b1f31daea 100644 --- a/tests/appveyor/mssql.sql2012sp1.sqlsrv.appveyor.xml +++ b/tests/appveyor/mssql.sql2012sp1.sqlsrv.appveyor.xml @@ -37,10 +37,6 @@ - - - - performance diff --git a/tests/appveyor/mssql.sql2017.pdo_sqlsrv.appveyor.xml b/tests/appveyor/mssql.sql2017.pdo_sqlsrv.appveyor.xml index 281955abb16..4ed53022628 100644 --- a/tests/appveyor/mssql.sql2017.pdo_sqlsrv.appveyor.xml +++ b/tests/appveyor/mssql.sql2017.pdo_sqlsrv.appveyor.xml @@ -37,10 +37,6 @@ - - - - performance diff --git a/tests/appveyor/mssql.sql2017.sqlsrv.appveyor.xml b/tests/appveyor/mssql.sql2017.sqlsrv.appveyor.xml index 6818a6320db..86702637719 100644 --- a/tests/appveyor/mssql.sql2017.sqlsrv.appveyor.xml +++ b/tests/appveyor/mssql.sql2017.sqlsrv.appveyor.xml @@ -37,10 +37,6 @@ - - - - performance diff --git a/tests/continuousphp/oci8.phpunit.continuousphp.xml b/tests/continuousphp/oci8.phpunit.continuousphp.xml index 4b3740936d0..4a2de468240 100644 --- a/tests/continuousphp/oci8.phpunit.continuousphp.xml +++ b/tests/continuousphp/oci8.phpunit.continuousphp.xml @@ -39,10 +39,6 @@ - - - - performance diff --git a/tests/continuousphp/pdo-oci.phpunit.xml b/tests/continuousphp/pdo-oci.phpunit.xml index ef145a990d5..b25e0c02745 100644 --- a/tests/continuousphp/pdo-oci.phpunit.xml +++ b/tests/continuousphp/pdo-oci.phpunit.xml @@ -37,8 +37,4 @@ - - - - diff --git a/tests/travis/ibm_db2.travis.xml b/tests/travis/ibm_db2.travis.xml index b58f3451bc3..e841a8ce252 100644 --- a/tests/travis/ibm_db2.travis.xml +++ b/tests/travis/ibm_db2.travis.xml @@ -37,10 +37,6 @@ - - - - performance diff --git a/tests/travis/mariadb.mysqli.travis.xml b/tests/travis/mariadb.mysqli.travis.xml index 46e7ea4853a..dfc62d307c5 100644 --- a/tests/travis/mariadb.mysqli.travis.xml +++ b/tests/travis/mariadb.mysqli.travis.xml @@ -37,10 +37,6 @@ - - - - performance diff --git a/tests/travis/mariadb.travis.xml b/tests/travis/mariadb.travis.xml index 132c27f3dab..0d4e2c43c9e 100644 --- a/tests/travis/mariadb.travis.xml +++ b/tests/travis/mariadb.travis.xml @@ -36,10 +36,6 @@ - - - - performance diff --git a/tests/travis/mysql.docker.travis.xml b/tests/travis/mysql.docker.travis.xml index 21fae6f35e9..fa6617c0948 100644 --- a/tests/travis/mysql.docker.travis.xml +++ b/tests/travis/mysql.docker.travis.xml @@ -36,10 +36,6 @@ - - - - performance diff --git a/tests/travis/mysql.travis.xml b/tests/travis/mysql.travis.xml index 132c27f3dab..0d4e2c43c9e 100644 --- a/tests/travis/mysql.travis.xml +++ b/tests/travis/mysql.travis.xml @@ -36,10 +36,6 @@ - - - - performance diff --git a/tests/travis/mysqli.docker.travis.xml b/tests/travis/mysqli.docker.travis.xml index 935815e9cf4..679415d7a18 100644 --- a/tests/travis/mysqli.docker.travis.xml +++ b/tests/travis/mysqli.docker.travis.xml @@ -36,10 +36,6 @@ - - - - performance diff --git a/tests/travis/mysqli.travis.xml b/tests/travis/mysqli.travis.xml index 8348cab6343..b8bd9be01cd 100644 --- a/tests/travis/mysqli.travis.xml +++ b/tests/travis/mysqli.travis.xml @@ -36,10 +36,6 @@ - - - - performance diff --git a/tests/travis/pdo_sqlsrv.travis.xml b/tests/travis/pdo_sqlsrv.travis.xml index 31de675b016..07f947600ea 100644 --- a/tests/travis/pdo_sqlsrv.travis.xml +++ b/tests/travis/pdo_sqlsrv.travis.xml @@ -36,10 +36,6 @@ - - - - performance diff --git a/tests/travis/pgsql.travis.xml b/tests/travis/pgsql.travis.xml index 27a671b8b22..5215f2e6f1b 100644 --- a/tests/travis/pgsql.travis.xml +++ b/tests/travis/pgsql.travis.xml @@ -36,10 +36,6 @@ - - - - performance diff --git a/tests/travis/sqlite.travis.xml b/tests/travis/sqlite.travis.xml index bfc18433db7..c6e3e291fce 100644 --- a/tests/travis/sqlite.travis.xml +++ b/tests/travis/sqlite.travis.xml @@ -23,10 +23,6 @@ - - - - performance diff --git a/tests/travis/sqlsrv.travis.xml b/tests/travis/sqlsrv.travis.xml index f5ca622d3a7..6c642e58e9a 100644 --- a/tests/travis/sqlsrv.travis.xml +++ b/tests/travis/sqlsrv.travis.xml @@ -36,10 +36,6 @@ - - - - performance From 860b90b8b00b8fe556038c9a6c730e0ff58adf4f Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 3 Aug 2019 09:27:57 -0700 Subject: [PATCH 084/106] Fixed test failures on PHP 7.4 The failures are caused by the changes in PHP according to https://wiki.php.net/rfc/notice-for-non-valid-array-container. --- lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php | 7 +++++++ lib/Doctrine/DBAL/Schema/Table.php | 6 ++++-- .../Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php | 5 +++++ .../Tests/DBAL/Sharding/PoolingShardManagerTest.php | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 5e0368509f7..9522faf6a73 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -309,13 +309,20 @@ public function listTableDetails($tableName) $tableOptions = $this->_conn->fetchAssoc($sql); + if ($tableOptions === false) { + return $table; + } + $table->addOption('engine', $tableOptions['ENGINE']); + if ($tableOptions['TABLE_COLLATION'] !== null) { $table->addOption('collation', $tableOptions['TABLE_COLLATION']); } + if ($tableOptions['AUTO_INCREMENT'] !== null) { $table->addOption('autoincrement', $tableOptions['AUTO_INCREMENT']); } + $table->addOption('comment', $tableOptions['TABLE_COMMENT']); $table->addOption('create_options', $this->parseCreateOptions($tableOptions['CREATE_OPTIONS'])); diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index af853c277d5..0abb3f4b863 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -34,7 +34,9 @@ class Table extends AbstractAsset protected $_fkConstraints = []; /** @var mixed[] */ - protected $_options = []; + protected $_options = [ + 'create_options' => [], + ]; /** @var SchemaConfig|null */ protected $_schemaConfig = null; @@ -69,7 +71,7 @@ public function __construct($tableName, array $columns = [], array $indexes = [] $this->_addForeignKeyConstraint($constraint); } - $this->_options = $options; + $this->_options = array_merge($this->_options, $options); } /** diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php index b28b2d83887..45d0c45264c 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php @@ -59,6 +59,11 @@ public function testExecute(array $params) : void $this->equalTo($params[2]) ); + // the return value is irrelevant to the test + // but it has to be compatible with the method signature + $statement->method('errorInfo') + ->willReturn(false); + // can't pass to constructor since we don't have a real database handle, // but execute must check the connection for the executeMode $conn = $this->getMockBuilder(OCI8Connection::class) diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php index 01db26773f3..31a308e0393 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php @@ -47,6 +47,10 @@ public function testSelectGlobal() : void { $conn = $this->createConnectionMock(); $conn->expects($this->once())->method('connect')->with($this->equalTo(0)); + $conn->method('getParams') + ->willReturn([ + 'shardChoser' => $this->createMock(ShardChoser::class), + ]); $shardManager = new PoolingShardManager($conn); $shardManager->selectGlobal(); From 22db2e383c6b6e04d7cd9c7a7184fac59e94daa7 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 3 Aug 2019 14:09:48 -0700 Subject: [PATCH 085/106] Using command line options to configure MySQL 8 instead of mounting a config file --- tests/travis/install-mysql-8.0.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/travis/install-mysql-8.0.sh b/tests/travis/install-mysql-8.0.sh index d3622777f3e..952a4300ba7 100644 --- a/tests/travis/install-mysql-8.0.sh +++ b/tests/travis/install-mysql-8.0.sh @@ -4,16 +4,14 @@ set -ex echo "Starting MySQL 8.0..." -echo -e "[mysqld]\ndefault_authentication_plugin=mysql_native_password" > /tmp/mysql-auth.cnf - sudo docker pull mysql:8.0 sudo docker run \ -d \ -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ -e MYSQL_DATABASE=doctrine_tests \ - -v /tmp/mysql-auth.cnf:/etc/mysql/conf.d/auth.cnf:ro \ -p 33306:3306 \ --name mysql80 \ - mysql:8.0 + mysql:8.0 \ + --default-authentication-plugin=mysql_native_password sudo docker exec -i mysql80 bash <<< 'until echo \\q | mysql doctrine_tests > /dev/null 2>&1 ; do sleep 1; done' From 62c2a8b90b58359b6dc0d7be84721f9e83caf3f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Wed, 27 Mar 2019 11:32:57 +0100 Subject: [PATCH 086/106] Adding support for table level comments in all DBMS --- docs/en/reference/schema-representation.rst | 1 + .../DBAL/Platforms/AbstractPlatform.php | 14 +++++++ lib/Doctrine/DBAL/Platforms/DB2Platform.php | 13 +++++++ lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 4 +- .../DBAL/Platforms/OraclePlatform.php | 21 +++++++++++ .../DBAL/Platforms/PostgreSqlPlatform.php | 15 ++++++++ .../DBAL/Platforms/SQLServerPlatform.php | 36 ++++++++++++++++++ .../DBAL/Platforms/SqlitePlatform.php | 15 +++++++- lib/Doctrine/DBAL/Schema/DB2SchemaManager.php | 15 ++++++++ .../DBAL/Schema/OracleSchemaManager.php | 14 +++++++ .../DBAL/Schema/PostgreSqlSchemaManager.php | 15 ++++++++ .../DBAL/Schema/SQLServerSchemaManager.php | 19 ++++++++++ .../DBAL/Schema/SqliteSchemaManager.php | 37 +++++++++++++++++++ lib/Doctrine/DBAL/Schema/Table.php | 13 +++++++ .../Schema/SQLAnywhereSchemaManagerTest.php | 5 +++ .../SchemaManagerFunctionalTestCase.php | 11 ++++++ .../DBAL/Platforms/PostgreSqlPlatformTest.php | 16 ++++++++ .../Doctrine/Tests/DBAL/Schema/TableTest.php | 9 +++++ 18 files changed, 269 insertions(+), 4 deletions(-) diff --git a/docs/en/reference/schema-representation.rst b/docs/en/reference/schema-representation.rst index b250a5c5109..e1beff8a0df 100644 --- a/docs/en/reference/schema-representation.rst +++ b/docs/en/reference/schema-representation.rst @@ -28,6 +28,7 @@ example shows: $myTable->addColumn("username", "string", array("length" => 32)); $myTable->setPrimaryKey(array("id")); $myTable->addUniqueIndex(array("username")); + $myTable->setComment('Some comment'); $schema->createSequence("my_table_seq"); $myForeign = $schema->createTable("my_foreign"); diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index ba4a6b5dbc7..3d833dfaaeb 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -1607,6 +1607,9 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE $sql = $this->_getCreateTableSQL($tableName, $columns, $options); if ($this->supportsCommentOnStatement()) { + if ($table->hasOption('comment')) { + $sql[] = $this->getCommentOnTableSQL($tableName, $table->getOption('comment')); + } foreach ($table->getColumns() as $column) { $comment = $this->getColumnComment($column); @@ -1621,6 +1624,17 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE return array_merge($sql, $columnSql); } + protected function getCommentOnTableSQL(string $tableName, ?string $comment) : string + { + $tableName = new Identifier($tableName); + + return sprintf( + 'COMMENT ON TABLE %s IS %s', + $tableName->getQuotedName($this), + $this->quoteStringLiteral((string) $comment) + ); + } + /** * @param string $tableName * @param string $columnName diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index fcc8c1c67f4..25d4163b6ec 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -900,4 +900,17 @@ protected function getReservedKeywordsClass() { return Keywords\DB2Keywords::class; } + + public function getListTableCommentsSQL(string $table) : string + { + return sprintf( + <<<'SQL' +SELECT REMARKS + FROM SYSIBM.SYSTABLES + WHERE NAME = UPPER( %s ) +SQL + , + $this->quoteStringLiteral($table) + ); + } } diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 9679a8447e7..30b065e79d7 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -519,9 +519,7 @@ private function buildTableOptions(array $options) // Comment if (isset($options['comment'])) { - $comment = trim($options['comment'], " '"); - - $tableOptions[] = sprintf('COMMENT = %s ', $this->quoteStringLiteral($comment)); + $tableOptions[] = sprintf('COMMENT = %s ', $this->quoteStringLiteral($options['comment'])); } // Row format diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index ced7fbf9bdc..21b13a2d691 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -1182,4 +1182,25 @@ public function getBlobTypeDeclarationSQL(array $field) { return 'BLOB'; } + + public function getListTableCommentsSQL(string $table, ?string $database = null) : string + { + $tableCommentsName = 'user_tab_comments'; + $ownerCondition = ''; + + if ($database !== null && $database !== '/') { + $tableCommentsName = 'all_tab_comments'; + $ownerCondition = ' AND owner = ' . $this->quoteStringLiteral($this->normalizeIdentifier($database)->getName()); + } + + return sprintf( + <<<'SQL' +SELECT comments FROM %s WHERE table_name = %s%s +SQL + , + $tableCommentsName, + $this->quoteStringLiteral($this->normalizeIdentifier($table)->getName()), + $ownerCondition + ); + } } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 4458ae27750..e570dc04ab0 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -1252,4 +1252,19 @@ private function getOldColumnComment(ColumnDiff $columnDiff) : ?string { return $columnDiff->fromColumn ? $this->getColumnComment($columnDiff->fromColumn) : null; } + + public function getListTableMetadataSQL(string $table, ?string $schema = null) : string + { + if ($schema !== null) { + $table = $schema . '.' . $table; + } + + return sprintf( + <<<'SQL' +SELECT obj_description(%s::regclass) AS table_comment; +SQL + , + $this->quoteStringLiteral($table) + ); + } } diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 3258a6623ad..a37f7c9394a 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -247,6 +247,11 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options $defaultConstraintsSql = []; $commentsSql = []; + $tableComment = $options['comment'] ?? null; + if ($tableComment !== null) { + $commentsSql[] = $this->getCommentOnTableSQL($tableName, $tableComment); + } + // @todo does other code breaks because of this? // force primary keys to be not null foreach ($columns as &$column) { @@ -1656,4 +1661,35 @@ private function generateIdentifierName($identifier) return strtoupper(dechex(crc32($identifier->getName()))); } + + protected function getCommentOnTableSQL(string $tableName, ?string $comment) : string + { + return sprintf( + <<<'SQL' +EXEC sys.sp_addextendedproperty @name=N'MS_Description', + @value=N%s, @level0type=N'SCHEMA', @level0name=N'dbo', + @level1type=N'TABLE', @level1name=N%s +SQL + , + $this->quoteStringLiteral((string) $comment), + $this->quoteStringLiteral($tableName) + ); + } + + public function getListTableMetadataSQL(string $table) : string + { + return sprintf( + <<<'SQL' +SELECT + p.value AS [table_comment] +FROM + sys.tables AS tbl + INNER JOIN sys.extended_properties AS p ON p.major_id=tbl.object_id AND p.minor_id=0 AND p.class=1 +WHERE + (tbl.name=N%s and SCHEMA_NAME(tbl.schema_id)=N'dbo' and p.name=N'MS_Description') +SQL + , + $this->quoteStringLiteral($table) + ); + } } diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index b7382ec08b0..02d2482c86e 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -23,6 +23,7 @@ use function strlen; use function strpos; use function strtolower; +use function trim; /** * The SqlitePlatform class describes the specifics and dialects of the SQLite @@ -332,7 +333,14 @@ protected function _getCreateTableSQL($name, array $columns, array $options = [] } } - $query = ['CREATE TABLE ' . $name . ' (' . $queryFields . ')']; + $tableComment = ''; + if (isset($options['comment'])) { + $comment = trim($options['comment'], " '"); + + $tableComment = $this->getInlineTableCommentSQL($comment); + } + + $query = ['CREATE TABLE ' . $name . ' ' . $tableComment . '(' . $queryFields . ')']; if (isset($options['alter']) && $options['alter'] === true) { return $query; @@ -605,6 +613,11 @@ public function getInlineColumnCommentSQL($comment) return '--' . str_replace("\n", "\n--", $comment) . "\n"; } + private function getInlineTableCommentSQL(string $comment) : string + { + return $this->getInlineColumnCommentSQL($comment); + } + /** * {@inheritDoc} */ diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index 201d6015b96..b1fe64afef4 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Schema; +use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Types\Type; use const CASE_LOWER; use function array_change_key_case; @@ -209,4 +210,18 @@ protected function _getPortableViewDefinition($view) return new View($view['name'], $sql); } + + public function listTableDetails($tableName) : Table + { + $table = parent::listTableDetails($tableName); + + /** @var DB2Platform $platform */ + $platform = $this->_platform; + $sql = $platform->getListTableCommentsSQL($tableName); + + $tableOptions = $this->_conn->fetchAssoc($sql); + $table->addOption('comment', $tableOptions['REMARKS']); + + return $table; + } } diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index 0e9700a616d..38889e37407 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -385,4 +385,18 @@ private function killUserSessions($user) ); } } + + public function listTableDetails($tableName) : Table + { + $table = parent::listTableDetails($tableName); + + /** @var OraclePlatform $platform */ + $platform = $this->_platform; + $sql = $platform->getListTableCommentsSQL($tableName); + + $tableOptions = $this->_conn->fetchAssoc($sql); + $table->addOption('comment', $tableOptions['COMMENTS']); + + return $table; + } } diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index d84077d5268..e9608e7c193 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -489,4 +489,19 @@ private function parseDefaultExpression(?string $default) : ?string return str_replace("''", "'", $default); } + + public function listTableDetails($tableName) : Table + { + $table = parent::listTableDetails($tableName); + + /** @var PostgreSqlPlatform $platform */ + $platform = $this->_platform; + $sql = $platform->getListTableMetadataSQL($tableName); + + $tableOptions = $this->_conn->fetchAssoc($sql); + + $table->addOption('comment', $tableOptions['table_comment']); + + return $table; + } } diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index 31ec6fffd50..d0c88f7fe76 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\DriverException; +use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Types\Type; use PDOException; use Throwable; @@ -325,4 +326,22 @@ private function closeActiveDatabaseConnections($database) ) ); } + + /** + * @param string $tableName + */ + public function listTableDetails($tableName) : Table + { + $table = parent::listTableDetails($tableName); + + /** @var SQLServerPlatform $platform */ + $platform = $this->_platform; + $sql = $platform->getListTableMetadataSQL($tableName); + + $tableOptions = $this->_conn->fetchAssoc($sql); + + $table->addOption('comment', $tableOptions['table_comment']); + + return $table; + } } diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 66d3c8503d5..605a68be187 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -470,6 +470,25 @@ private function parseColumnCollationFromSQL(string $column, string $sql) : ?str return $match[1]; } + private function parseTableCommentFromSQL(string $table, string $sql) : ?string + { + $pattern = '/\s* # Allow whitespace characters at start of line +CREATE\sTABLE # Match "CREATE TABLE" +(?:\W"' . preg_quote($this->_platform->quoteSingleIdentifier($table), '/') . '"\W|\W' . preg_quote($table, '/') + . '\W) # Match table name (quoted and unquoted) +( # Start capture + (?:\s*--[^\n]*\n?)+ # Capture anything that starts with whitespaces followed by -- until the end of the line(s) +)/ix'; + + if (preg_match($pattern, $sql, $match) !== 1) { + return null; + } + + $comment = preg_replace('{^\s*--}m', '', rtrim($match[1], "\n")); + + return $comment === '' ? null : $comment; + } + private function parseColumnCommentFromSQL(string $column, string $sql) : ?string { $pattern = '{[\s(,](?:\W' . preg_quote($this->_platform->quoteSingleIdentifier($column)) . '\W|\W' . preg_quote($column) @@ -503,4 +522,22 @@ private function getCreateTableSQL(string $table) : ?string [$table] ) ?: null; } + + /** + * @param string $tableName + */ + public function listTableDetails($tableName) : Table + { + $table = parent::listTableDetails($tableName); + + $tableCreateSql = $this->getCreateTableSQL($tableName) ?? ''; + + $comment = $this->parseTableCommentFromSQL($tableName, $tableCreateSql); + + if ($comment !== null) { + $table->addOption('comment', $comment); + } + + return $table; + } } diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 0abb3f4b863..8e613320f79 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -840,4 +840,17 @@ private function normalizeIdentifier($identifier) return $this->trimQuotes(strtolower($identifier)); } + + public function setComment(?string $comment) : self + { + // For keeping backward compatibility with MySQL in previous releases, table comments are stored as options. + $this->addOption('comment', $comment); + + return $this; + } + + public function getComment() : ?string + { + return $this->_options['comment'] ?? null; + } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php index ffb5d6cf5ec..ab5db98eff9 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php @@ -61,4 +61,9 @@ public function testListTableColumnsWithFixedStringTypeColumn() : void self::assertArrayHasKey('test', $columns); self::assertTrue($columns['test']->getFixed()); } + + public function testCommentInTable() : void + { + self::markTestSkipped('Table level comments are not supported on SQLAnywhere'); + } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 241662b56d3..e8580cba2b4 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -1594,4 +1594,15 @@ public function testGenerateAnIndexWithPartialColumnLength() : void $onlineTable = $this->schemaManager->listTableDetails('test_partial_column_index'); self::assertEquals($expected, $onlineTable->getIndexes()); } + + public function testCommentInTable() : void + { + $table = new Table('table_with_comment'); + $table->addColumn('id', 'integer'); + $table->setComment('Foo with control characters \'\\'); + $this->schemaManager->dropAndCreateTable($table); + + $table = $this->schemaManager->listTableDetails('table_with_comment'); + self::assertSame('Foo with control characters \'\\', $table->getComment()); + } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php index 41fb1564ec8..0b029d3497d 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Schema\Table; class PostgreSqlPlatformTest extends AbstractPostgreSqlPlatformTestCase { @@ -16,4 +17,19 @@ public function testSupportsPartialIndexes() : void { self::assertTrue($this->platform->supportsPartialIndexes()); } + + public function testGetCreateTableSQLWithColumnCollation() : void + { + $table = new Table('foo'); + $table->addColumn('id', 'string'); + $table->addOption('comment', 'foo'); + self::assertSame( + [ + 'CREATE TABLE foo (id VARCHAR(255) NOT NULL)', + "COMMENT ON TABLE foo IS 'foo'", + ], + $this->platform->getCreateTableSQL($table), + 'Comments are added to table.' + ); + } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index 6b5145934a8..d330e758184 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -885,4 +885,13 @@ public static function getNormalizesAssetNames() : iterable ['"FOO"'], ]; } + + public function testTableComment() : void + { + $table = new Table('bar'); + self::assertNull($table->getComment()); + + $table->setComment('foo'); + self::assertEquals('foo', $table->getComment()); + } } From 6f51d9449d429c92f2f4e8a1cb58a808beaa79d5 Mon Sep 17 00:00:00 2001 From: "Matthew J. Mucklo" Date: Fri, 16 Aug 2019 22:56:56 -0700 Subject: [PATCH 087/106] fix Appveyor builds --- .appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 63a9c0ddb73..a7fe2f1cb06 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -22,21 +22,21 @@ environment: driver: sqlsrv db_version: sql2008r2sp2 coverage: yes - php: 7.2 + php: 7.3 - db: mssql driver: sqlsrv db_version: sql2012sp1 - php: 7.2 + php: 7.3 coverage: yes - db: mssql driver: sqlsrv db_version: sql2017 coverage: no - php: 7.2 + php: 7.3 - db: mssql driver: pdo_sqlsrv db_version: sql2017 - php: 7.2 + php: 7.3 coverage: yes init: From 2c2cdd90e0bc5c2724111f3403a258e5dab8804c Mon Sep 17 00:00:00 2001 From: Bas Peeters Date: Fri, 23 Aug 2019 16:15:24 +0200 Subject: [PATCH 088/106] Call non-static functions dynamically --- tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index 43137e28883..fecff1cbcfa 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -617,7 +617,7 @@ public function testTablesCaseInsensitive() : void $c = new Comparator(); $diff = $c->compare($schemaA, $schemaB); - self::assertSchemaTableChangeCount($diff, 1, 0, 1); + $this->assertSchemaTableChangeCount($diff, 1, 0, 1); } public function testSequencesCaseInsensitive() : void @@ -637,7 +637,7 @@ public function testSequencesCaseInsensitive() : void $c = new Comparator(); $diff = $c->compare($schemaA, $schemaB); - self::assertSchemaSequenceChangeCount($diff, 1, 0, 1); + $this->assertSchemaSequenceChangeCount($diff, 1, 0, 1); } public function testCompareColumnCompareCaseInsensitive() : void From 971570325bc0798683ffb5dced22d13e7ee59d49 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 23 Aug 2019 09:10:27 -0700 Subject: [PATCH 089/106] Marked connection exception test incomplete on MySQL 8 --- .../Tests/DBAL/Functional/ExceptionTest.php | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php index 7f4a8145cfe..161a32f1111 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php @@ -3,14 +3,20 @@ namespace Doctrine\Tests\DBAL\Functional; use Doctrine\DBAL\Driver\ExceptionConverterDriver; +use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Platforms\DrizzlePlatform; +use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalFunctionalTestCase; use Throwable; use const PHP_OS; use function array_merge; +use function assert; use function chmod; use function exec; use function file_exists; @@ -20,6 +26,7 @@ use function sys_get_temp_dir; use function touch; use function unlink; +use function version_compare; class ExceptionTest extends DbalFunctionalTestCase { @@ -289,7 +296,7 @@ public function testSyntaxErrorException() : void public function testConnectionExceptionSqLite() : void { - if ($this->connection->getDatabasePlatform()->getName() !== 'sqlite') { + if ($this->connection instanceof SqlitePlatform) { $this->markTestSkipped('Only fails this way on sqlite'); } @@ -343,18 +350,29 @@ public function testConnectionExceptionSqLite() : void */ public function testConnectionException(array $params) : void { - if ($this->connection->getDatabasePlatform()->getName() === 'sqlite') { + $platform = $this->connection->getDatabasePlatform(); + + if ($platform instanceof SqlitePlatform) { $this->markTestSkipped('Only skipped if platform is not sqlite'); } - if ($this->connection->getDatabasePlatform()->getName() === 'drizzle') { + if ($platform instanceof DrizzlePlatform) { $this->markTestSkipped('Drizzle does not always support authentication'); } - if ($this->connection->getDatabasePlatform()->getName() === 'postgresql' && isset($params['password'])) { + if ($platform instanceof PostgreSqlPlatform && isset($params['password'])) { $this->markTestSkipped('Does not work on Travis'); } + if ($platform instanceof MySqlPlatform && isset($params['user'])) { + $wrappedConnection = $this->connection->getWrappedConnection(); + assert($wrappedConnection instanceof ServerInfoAwareConnection); + + if (version_compare($wrappedConnection->getServerVersion(), '8', '>=')) { + $this->markTestIncomplete('PHP currently does not completely support MySQL 8'); + } + } + $defaultParams = $this->connection->getParams(); $params = array_merge($defaultParams, $params); From c23e780ca02d973ec3db9606657a27f1b09cf945 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 24 Aug 2019 20:49:15 -0700 Subject: [PATCH 090/106] Updated PHPStan to v0.11.15 --- composer.lock | 263 +++++++++++++++---------- lib/Doctrine/DBAL/Types/ArrayType.php | 2 +- lib/Doctrine/DBAL/Types/ObjectType.php | 2 +- phpcs.xml.dist | 6 + 4 files changed, 164 insertions(+), 109 deletions(-) diff --git a/composer.lock b/composer.lock index 75dc9e0be18..5e29b96ee83 100644 --- a/composer.lock +++ b/composer.lock @@ -158,16 +158,16 @@ "packages-dev": [ { "name": "composer/xdebug-handler", - "version": "1.3.2", + "version": "1.3.3", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "d17708133b6c276d6e42ef887a877866b909d892" + "reference": "46867cbf8ca9fb8d60c506895449eb799db1184f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/d17708133b6c276d6e42ef887a877866b909d892", - "reference": "d17708133b6c276d6e42ef887a877866b909d892", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/46867cbf8ca9fb8d60c506895449eb799db1184f", + "reference": "46867cbf8ca9fb8d60c506895449eb799db1184f", "shasum": "" }, "require": { @@ -198,7 +198,7 @@ "Xdebug", "performance" ], - "time": "2019-01-28T20:25:53+00:00" + "time": "2019-05-27T17:52:04+00:00" }, { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -523,39 +523,36 @@ }, { "name": "nette/bootstrap", - "version": "v2.4.6", + "version": "v3.0.0", "source": { "type": "git", "url": "https://github.com/nette/bootstrap.git", - "reference": "268816e3f1bb7426c3a4ceec2bd38a036b532543" + "reference": "e1075af05c211915e03e0c86542f3ba5433df4a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/bootstrap/zipball/268816e3f1bb7426c3a4ceec2bd38a036b532543", - "reference": "268816e3f1bb7426c3a4ceec2bd38a036b532543", + "url": "https://api.github.com/repos/nette/bootstrap/zipball/e1075af05c211915e03e0c86542f3ba5433df4a3", + "reference": "e1075af05c211915e03e0c86542f3ba5433df4a3", "shasum": "" }, "require": { - "nette/di": "~2.4.7", - "nette/utils": "~2.4", - "php": ">=5.6.0" - }, - "conflict": { - "nette/nette": "<2.2" + "nette/di": "^3.0", + "nette/utils": "^3.0", + "php": ">=7.1" }, "require-dev": { - "latte/latte": "~2.2", - "nette/application": "~2.3", - "nette/caching": "~2.3", - "nette/database": "~2.3", - "nette/forms": "~2.3", - "nette/http": "~2.4.0", - "nette/mail": "~2.3", - "nette/robot-loader": "^2.4.2 || ^3.0", - "nette/safe-stream": "~2.2", - "nette/security": "~2.3", - "nette/tester": "~2.0", - "tracy/tracy": "^2.4.1" + "latte/latte": "^2.2", + "nette/application": "^3.0", + "nette/caching": "^3.0", + "nette/database": "^3.0", + "nette/forms": "^3.0", + "nette/http": "^3.0", + "nette/mail": "^3.0", + "nette/robot-loader": "^3.0", + "nette/safe-stream": "^2.2", + "nette/security": "^3.0", + "nette/tester": "^2.0", + "tracy/tracy": "^2.6" }, "suggest": { "nette/robot-loader": "to use Configurator::createRobotLoader()", @@ -564,7 +561,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.4-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -595,46 +592,50 @@ "configurator", "nette" ], - "time": "2018-05-17T12:52:20+00:00" + "time": "2019-03-26T12:59:07+00:00" }, { "name": "nette/di", - "version": "v2.4.15", + "version": "v3.0.1", "source": { "type": "git", "url": "https://github.com/nette/di.git", - "reference": "d0561b8f77e8ef2ed6d83328860e16c81a5a8649" + "reference": "4aff517a1c6bb5c36fa09733d4cea089f529de6d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/di/zipball/d0561b8f77e8ef2ed6d83328860e16c81a5a8649", - "reference": "d0561b8f77e8ef2ed6d83328860e16c81a5a8649", + "url": "https://api.github.com/repos/nette/di/zipball/4aff517a1c6bb5c36fa09733d4cea089f529de6d", + "reference": "4aff517a1c6bb5c36fa09733d4cea089f529de6d", "shasum": "" }, "require": { "ext-tokenizer": "*", - "nette/neon": "^2.3.3 || ~3.0.0", - "nette/php-generator": "^2.6.1 || ^3.0.0", - "nette/utils": "^2.5.0 || ~3.0.0", - "php": ">=5.6.0" + "nette/neon": "^3.0", + "nette/php-generator": "^3.2.2", + "nette/robot-loader": "^3.2", + "nette/schema": "^1.0", + "nette/utils": "^3.0", + "php": ">=7.1" }, "conflict": { - "nette/bootstrap": "<2.4", - "nette/nette": "<2.2" + "nette/bootstrap": "<3.0" }, "require-dev": { - "nette/tester": "^2.0", + "nette/tester": "^2.2", "tracy/tracy": "^2.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.4-dev" + "dev-master": "3.0-dev" } }, "autoload": { "classmap": [ "src/" + ], + "files": [ + "src/compatibility.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -664,7 +665,7 @@ "nette", "static" ], - "time": "2019-01-30T13:26:05+00:00" + "time": "2019-08-07T12:11:33+00:00" }, { "name": "nette/finder", @@ -791,25 +792,22 @@ }, { "name": "nette/php-generator", - "version": "v3.2.1", + "version": "v3.2.3", "source": { "type": "git", "url": "https://github.com/nette/php-generator.git", - "reference": "9de4e093a130f7a1bd175198799ebc0efbac6924" + "reference": "aea6e81437bb238e5f0e5b5ce06337433908e63b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/php-generator/zipball/9de4e093a130f7a1bd175198799ebc0efbac6924", - "reference": "9de4e093a130f7a1bd175198799ebc0efbac6924", + "url": "https://api.github.com/repos/nette/php-generator/zipball/aea6e81437bb238e5f0e5b5ce06337433908e63b", + "reference": "aea6e81437bb238e5f0e5b5ce06337433908e63b", "shasum": "" }, "require": { "nette/utils": "^2.4.2 || ~3.0.0", "php": ">=7.1" }, - "conflict": { - "nette/nette": "<2.2" - }, "require-dev": { "nette/tester": "^2.0", "tracy/tracy": "^2.3" @@ -849,30 +847,27 @@ "php", "scaffolding" ], - "time": "2018-11-27T19:00:14+00:00" + "time": "2019-07-05T13:01:56+00:00" }, { "name": "nette/robot-loader", - "version": "v3.1.1", + "version": "v3.2.0", "source": { "type": "git", "url": "https://github.com/nette/robot-loader.git", - "reference": "3e8d75d6d976e191bdf46752ca40a286671219d2" + "reference": "0712a0e39ae7956d6a94c0ab6ad41aa842544b5c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/robot-loader/zipball/3e8d75d6d976e191bdf46752ca40a286671219d2", - "reference": "3e8d75d6d976e191bdf46752ca40a286671219d2", + "url": "https://api.github.com/repos/nette/robot-loader/zipball/0712a0e39ae7956d6a94c0ab6ad41aa842544b5c", + "reference": "0712a0e39ae7956d6a94c0ab6ad41aa842544b5c", "shasum": "" }, "require": { "ext-tokenizer": "*", - "nette/finder": "^2.3 || ^3.0", - "nette/utils": "^2.4 || ^3.0", - "php": ">=5.6.0" - }, - "conflict": { - "nette/nette": "<2.2" + "nette/finder": "^2.5", + "nette/utils": "^3.0", + "php": ">=7.1" }, "require-dev": { "nette/tester": "^2.0", @@ -881,7 +876,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "3.2-dev" } }, "autoload": { @@ -905,7 +900,7 @@ "homepage": "https://nette.org/contributors" } ], - "description": "🍀 Nette RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.", + "description": "? Nette RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.", "homepage": "https://nette.org", "keywords": [ "autoload", @@ -914,27 +909,81 @@ "nette", "trait" ], - "time": "2019-03-01T20:23:02+00:00" + "time": "2019-03-08T21:57:24+00:00" + }, + { + "name": "nette/schema", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/nette/schema.git", + "reference": "6241d8d4da39e825dd6cb5bfbe4242912f4d7e4d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/schema/zipball/6241d8d4da39e825dd6cb5bfbe4242912f4d7e4d", + "reference": "6241d8d4da39e825dd6cb5bfbe4242912f4d7e4d", + "shasum": "" + }, + "require": { + "nette/utils": "^3.0.1", + "php": ">=7.1" + }, + "require-dev": { + "nette/tester": "^2.2", + "tracy/tracy": "^2.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0", + "GPL-3.0" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "📐 Nette Schema: validating data structures against a given Schema.", + "homepage": "https://nette.org", + "keywords": [ + "config", + "nette" + ], + "time": "2019-04-03T15:53:25+00:00" }, { "name": "nette/utils", - "version": "v2.5.3", + "version": "v3.0.1", "source": { "type": "git", "url": "https://github.com/nette/utils.git", - "reference": "17b9f76f2abd0c943adfb556e56f2165460b15ce" + "reference": "bd961f49b211997202bda1d0fbc410905be370d4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/utils/zipball/17b9f76f2abd0c943adfb556e56f2165460b15ce", - "reference": "17b9f76f2abd0c943adfb556e56f2165460b15ce", + "url": "https://api.github.com/repos/nette/utils/zipball/bd961f49b211997202bda1d0fbc410905be370d4", + "reference": "bd961f49b211997202bda1d0fbc410905be370d4", "shasum": "" }, "require": { - "php": ">=5.6.0" - }, - "conflict": { - "nette/nette": "<2.2" + "php": ">=7.1" }, "require-dev": { "nette/tester": "~2.0", @@ -943,7 +992,7 @@ "suggest": { "ext-gd": "to use Image", "ext-iconv": "to use Strings::webalize() and toAscii()", - "ext-intl": "for script transliteration in Strings::webalize() and toAscii()", + "ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()", "ext-json": "to use Nette\\Utils\\Json", "ext-mbstring": "to use Strings::lower() etc...", "ext-xml": "to use Strings::length() etc. when mbstring is not available" @@ -951,15 +1000,12 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "3.0-dev" } }, "autoload": { "classmap": [ "src/" - ], - "files": [ - "src/loader.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -996,20 +1042,20 @@ "utility", "validation" ], - "time": "2018-09-18T10:22:16+00:00" + "time": "2019-03-22T01:00:30+00:00" }, { "name": "nikic/php-parser", - "version": "v4.2.1", + "version": "v4.2.3", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "5221f49a608808c1e4d436df32884cbc1b821ac0" + "reference": "e612609022e935f3d0337c1295176505b41188c8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/5221f49a608808c1e4d436df32884cbc1b821ac0", - "reference": "5221f49a608808c1e4d436df32884cbc1b821ac0", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/e612609022e935f3d0337c1295176505b41188c8", + "reference": "e612609022e935f3d0337c1295176505b41188c8", "shasum": "" }, "require": { @@ -1017,7 +1063,7 @@ "php": ">=7.0" }, "require-dev": { - "phpunit/phpunit": "^6.5 || ^7.0" + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0" }, "bin": [ "bin/php-parse" @@ -1047,7 +1093,7 @@ "parser", "php" ], - "time": "2019-02-16T20:54:15+00:00" + "time": "2019-08-12T20:17:41+00:00" }, { "name": "ocramius/package-versions", @@ -1418,28 +1464,29 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "0.3.1", + "version": "0.3.5", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "2cc49f47c69b023eaf05b48e6529389893b13d74" + "reference": "8c4ef2aefd9788238897b678a985e1d5c8df6db4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/2cc49f47c69b023eaf05b48e6529389893b13d74", - "reference": "2cc49f47c69b023eaf05b48e6529389893b13d74", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/8c4ef2aefd9788238897b678a985e1d5c8df6db4", + "reference": "8c4ef2aefd9788238897b678a985e1d5c8df6db4", "shasum": "" }, "require": { "php": "~7.1" }, "require-dev": { - "consistence/coding-standard": "^2.0.0", + "consistence/coding-standard": "^3.5", "jakub-onderka/php-parallel-lint": "^0.9.2", "phing/phing": "^2.16.0", "phpstan/phpstan": "^0.10", "phpunit/phpunit": "^6.3", - "slevomat/coding-standard": "^3.3.0", + "slevomat/coding-standard": "^4.7.2", + "squizlabs/php_codesniffer": "^3.3.2", "symfony/process": "^3.4 || ^4.0" }, "type": "library", @@ -1460,20 +1507,20 @@ "MIT" ], "description": "PHPDoc parser with support for nullable, intersection and generic types", - "time": "2019-01-14T12:26:23+00:00" + "time": "2019-06-07T19:13:52+00:00" }, { "name": "phpstan/phpstan", - "version": "0.11.3", + "version": "0.11.15", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e4644b4a8fd393c346f1137305fb2f76a7dc20a7" + "reference": "1be5b3a706db16ac472a4c40ec03cf4c810b118d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e4644b4a8fd393c346f1137305fb2f76a7dc20a7", - "reference": "e4644b4a8fd393c346f1137305fb2f76a7dc20a7", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/1be5b3a706db16ac472a4c40ec03cf4c810b118d", + "reference": "1be5b3a706db16ac472a4c40ec03cf4c810b118d", "shasum": "" }, "require": { @@ -1482,10 +1529,11 @@ "nette/bootstrap": "^2.4 || ^3.0", "nette/di": "^2.4.7 || ^3.0", "nette/robot-loader": "^3.0.1", + "nette/schema": "^1.0", "nette/utils": "^2.4.5 || ^3.0", - "nikic/php-parser": "^4.0.2", + "nikic/php-parser": "^4.2.3", "php": "~7.1", - "phpstan/phpdoc-parser": "^0.3", + "phpstan/phpdoc-parser": "^0.3.5", "symfony/console": "~3.2 || ~4.0", "symfony/finder": "~3.2 || ~4.0" }, @@ -1493,11 +1541,12 @@ "symfony/console": "3.4.16 || 4.1.5" }, "require-dev": { - "brianium/paratest": "^2.0", + "brianium/paratest": "^2.0 || ^3.0", "consistence/coding-standard": "^3.5", "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", "ext-intl": "*", "ext-mysqli": "*", + "ext-simplexml": "*", "ext-soap": "*", "ext-zip": "*", "jakub-onderka/php-parallel-lint": "^1.0", @@ -1507,7 +1556,7 @@ "phpstan/phpstan-php-parser": "^0.11", "phpstan/phpstan-phpunit": "^0.11", "phpstan/phpstan-strict-rules": "^0.11", - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "^7.5.14 || ^8.0", "slevomat/coding-standard": "^4.7.2", "squizlabs/php_codesniffer": "^3.3.2" }, @@ -1533,7 +1582,7 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", - "time": "2019-03-10T16:25:30+00:00" + "time": "2019-08-18T20:51:53+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2821,16 +2870,16 @@ }, { "name": "symfony/finder", - "version": "v4.2.4", + "version": "v4.3.3", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "267b7002c1b70ea80db0833c3afe05f0fbde580a" + "reference": "9638d41e3729459860bb96f6247ccb61faaa45f2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/267b7002c1b70ea80db0833c3afe05f0fbde580a", - "reference": "267b7002c1b70ea80db0833c3afe05f0fbde580a", + "url": "https://api.github.com/repos/symfony/finder/zipball/9638d41e3729459860bb96f6247ccb61faaa45f2", + "reference": "9638d41e3729459860bb96f6247ccb61faaa45f2", "shasum": "" }, "require": { @@ -2839,7 +2888,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -2866,7 +2915,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2019-02-23T15:42:05+00:00" + "time": "2019-06-28T13:16:30+00:00" }, { "name": "symfony/polyfill-ctype", @@ -3018,8 +3067,8 @@ "authors": [ { "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" + "role": "Developer", + "email": "arne@blankerts.de" } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", diff --git a/lib/Doctrine/DBAL/Types/ArrayType.php b/lib/Doctrine/DBAL/Types/ArrayType.php index e981ded1eca..78325ad95c9 100644 --- a/lib/Doctrine/DBAL/Types/ArrayType.php +++ b/lib/Doctrine/DBAL/Types/ArrayType.php @@ -43,7 +43,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $value = is_resource($value) ? stream_get_contents($value) : $value; - set_error_handler(function (int $code, string $message) : void { + set_error_handler(function (int $code, string $message) : bool { throw ConversionException::conversionFailedUnserialization($this->getName(), $message); }); diff --git a/lib/Doctrine/DBAL/Types/ObjectType.php b/lib/Doctrine/DBAL/Types/ObjectType.php index 32f5f4efd02..82b1a752ee1 100644 --- a/lib/Doctrine/DBAL/Types/ObjectType.php +++ b/lib/Doctrine/DBAL/Types/ObjectType.php @@ -42,7 +42,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $value = is_resource($value) ? stream_get_contents($value) : $value; - set_error_handler(function (int $code, string $message) : void { + set_error_handler(function (int $code, string $message) : bool { throw ConversionException::conversionFailedUnserialization($this->getName(), $message); }); diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 6c4117a7c52..3a11021ffa3 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -72,4 +72,10 @@ lib/Doctrine/DBAL/Schema/Comparator.php + + + + lib/Doctrine/DBAL/Types/ArrayType.php + lib/Doctrine/DBAL/Types/ObjectType.php + From 36f7e92982cfefc21d3574f787fd9d9d07df5e33 Mon Sep 17 00:00:00 2001 From: Bas Peeters Date: Sat, 24 Aug 2019 00:41:32 +0200 Subject: [PATCH 091/106] Replace usage of deprecated MockBuilder setMethods --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 16 ++++++++-------- .../Tests/DBAL/Driver/OCI8/OCI8StatementTest.php | 4 ++-- .../Schema/SchemaManagerFunctionalTestCase.php | 11 +++++------ .../DBAL/Platforms/AbstractPlatformTestCase.php | 12 ++++++------ .../Tests/DBAL/Schema/ComparatorTest.php | 4 ++-- .../Tests/DBAL/Schema/DB2SchemaManagerTest.php | 2 +- .../Tests/DBAL/Schema/MySqlSchemaManagerTest.php | 2 +- .../Visitor/CreateSchemaSqlCollectorTest.php | 2 +- .../Visitor/DropSchemaSqlCollectorTest.php | 2 +- .../Schema/Visitor/SchemaSqlCollectorTest.php | 4 ++-- .../DBAL/Sharding/PoolingShardManagerTest.php | 2 +- .../SQLAzure/SQLAzureShardManagerTest.php | 2 +- .../ShardChoser/MultiTenantShardChoserTest.php | 2 +- tests/Doctrine/Tests/DBAL/StatementTest.php | 2 +- 14 files changed, 33 insertions(+), 34 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 09ee88349ec..fb0157314d6 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -67,7 +67,7 @@ private function getExecuteUpdateMockConnection() $platform = $this->getMockForAbstractClass(AbstractPlatform::class); return $this->getMockBuilder(Connection::class) - ->setMethods(['executeUpdate']) + ->onlyMethods(['executeUpdate']) ->setConstructorArgs([['platform' => $platform], $driverMock]) ->getMock(); } @@ -145,8 +145,8 @@ public function testGetEventManager() : void public function testConnectDispatchEvent() : void { - $listenerMock = $this->getMockBuilder('ConnectDispatchEventListener') - ->setMethods(['postConnect']) + $listenerMock = $this->getMockBuilder($this->getMockClass('ConnectDispatchEventListener')) + ->addMethods(['postConnect']) ->getMock(); $listenerMock->expects($this->once())->method('postConnect'); @@ -566,7 +566,7 @@ public function testFetchAssoc() : void /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) - ->setMethods(['executeQuery']) + ->onlyMethods(['executeQuery']) ->setConstructorArgs([[], $driverMock]) ->getMock(); @@ -602,7 +602,7 @@ public function testFetchArray() : void /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) - ->setMethods(['executeQuery']) + ->onlyMethods(['executeQuery']) ->setConstructorArgs([[], $driverMock]) ->getMock(); @@ -639,7 +639,7 @@ public function testFetchColumn() : void /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) - ->setMethods(['executeQuery']) + ->onlyMethods(['executeQuery']) ->setConstructorArgs([[], $driverMock]) ->getMock(); @@ -674,7 +674,7 @@ public function testFetchAll() : void /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) - ->setMethods(['executeQuery']) + ->onlyMethods(['executeQuery']) ->setConstructorArgs([[], $driverMock]) ->getMock(); @@ -756,7 +756,7 @@ public function testCallConnectOnce(string $method, array $params) : void $conn = $this->getMockBuilder(Connection::class) ->setConstructorArgs([['pdo' => $pdoMock, 'platform' => $platformMock], $driverMock]) - ->setMethods(['connect']) + ->onlyMethods(['connect']) ->getMock(); $conn->expects($this->once())->method('connect'); diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php index 45d0c45264c..f90f86d6eb3 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php @@ -36,7 +36,7 @@ protected function setUp() : void public function testExecute(array $params) : void { $statement = $this->getMockBuilder(OCI8Statement::class) - ->setMethods(['bindValue', 'errorInfo']) + ->onlyMethods(['bindValue', 'errorInfo']) ->disableOriginalConstructor() ->getMock(); @@ -67,7 +67,7 @@ public function testExecute(array $params) : void // can't pass to constructor since we don't have a real database handle, // but execute must check the connection for the executeMode $conn = $this->getMockBuilder(OCI8Connection::class) - ->setMethods(['getExecuteMode']) + ->onlyMethods(['getExecuteMode']) ->disableOriginalConstructor() ->getMock(); $conn->expects($this->once()) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index e8580cba2b4..7b76f802612 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -367,10 +367,10 @@ public function testListTableColumnsDispatchEvent() : void $this->schemaManager->dropAndCreateTable($table); - $listenerMock = $this - ->getMockBuilder('ListTableColumnsDispatchEventListener') - ->setMethods(['onSchemaColumnDefinition']) + $listenerMock = $this->getMockBuilder($this->getMockClass('ListTableColumnsDispatchEventListener')) + ->addMethods(['onSchemaColumnDefinition']) ->getMock(); + $listenerMock ->expects($this->exactly(7)) ->method('onSchemaColumnDefinition'); @@ -395,9 +395,8 @@ public function testListTableIndexesDispatchEvent() : void $this->schemaManager->dropAndCreateTable($table); - $listenerMock = $this - ->getMockBuilder('ListTableIndexesDispatchEventListener') - ->setMethods(['onSchemaIndexDefinition']) + $listenerMock = $this->getMockBuilder($this->getMockClass('ListTableIndexesDispatchEventListener')) + ->addMethods(['onSchemaIndexDefinition']) ->getMock(); $listenerMock ->expects($this->exactly(3)) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 0c44d42a7b4..1ef4e65e322 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -380,8 +380,8 @@ public function testGetCustomColumnDeclarationSql() : void public function testGetCreateTableSqlDispatchEvent() : void { - $listenerMock = $this->getMockBuilder('GetCreateTableSqlDispatchEvenListener') - ->setMethods(['onSchemaCreateTable', 'onSchemaCreateTableColumn']) + $listenerMock = $this->getMockBuilder($this->getMockClass('GetCreateTableSqlDispatchEvenListener')) + ->addMethods(['onSchemaCreateTable', 'onSchemaCreateTableColumn']) ->getMock(); $listenerMock ->expects($this->once()) @@ -404,8 +404,8 @@ public function testGetCreateTableSqlDispatchEvent() : void public function testGetDropTableSqlDispatchEvent() : void { - $listenerMock = $this->getMockBuilder('GetDropTableSqlDispatchEventListener') - ->setMethods(['onSchemaDropTable']) + $listenerMock = $this->getMockBuilder($this->getMockClass('GetDropTableSqlDispatchEventListener')) + ->addMethods(['onSchemaDropTable']) ->getMock(); $listenerMock ->expects($this->once()) @@ -429,8 +429,8 @@ public function testGetAlterTableSqlDispatchEvent() : void 'onSchemaAlterTableRenameColumn', ]; - $listenerMock = $this->getMockBuilder('GetAlterTableSqlDispatchEvenListener') - ->setMethods($events) + $listenerMock = $this->getMockBuilder($this->getMockClass('GetAlterTableSqlDispatchEvenListener')) + ->addMethods($events) ->getMock(); $listenerMock ->expects($this->once()) diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index fecff1cbcfa..f73d1c6d1f4 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -1172,10 +1172,10 @@ public function testComparesNamespaces() : void { $comparator = new Comparator(); $fromSchema = $this->getMockBuilder(Schema::class) - ->setMethods(['getNamespaces', 'hasNamespace']) + ->onlyMethods(['getNamespaces', 'hasNamespace']) ->getMock(); $toSchema = $this->getMockBuilder(Schema::class) - ->setMethods(['getNamespaces', 'hasNamespace']) + ->onlyMethods(['getNamespaces', 'hasNamespace']) ->getMock(); $fromSchema->expects($this->once()) diff --git a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php index b5744fd672d..53f9a41cbda 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php @@ -30,7 +30,7 @@ protected function setUp() : void $platform = $this->createMock(DB2Platform::class); $this->conn = $this ->getMockBuilder(Connection::class) - ->setMethods(['fetchAll', 'quote']) + ->onlyMethods(['fetchAll', 'quote']) ->setConstructorArgs([['platform' => $platform], $driverMock, new Configuration(), $eventManager]) ->getMock(); $this->manager = new DB2SchemaManager($this->conn); diff --git a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php index 5c8881decb4..934b3e97bef 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php @@ -27,7 +27,7 @@ protected function setUp() : void $driverMock = $this->createMock(Driver::class); $platform = $this->createMock(MySqlPlatform::class); $this->conn = $this->getMockBuilder(Connection::class) - ->setMethods(['fetchAll']) + ->onlyMethods(['fetchAll']) ->setConstructorArgs([['platform' => $platform], $driverMock, new Configuration(), $eventManager]) ->getMock(); $this->manager = new MySqlSchemaManager($this->conn); diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php index b70d2193a37..88df92341ce 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -26,7 +26,7 @@ protected function setUp() : void parent::setUp(); $this->platformMock = $this->getMockBuilder(AbstractPlatform::class) - ->setMethods( + ->onlyMethods( [ 'getCreateForeignKeySQL', 'getCreateSchemaSQL', diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php index ea265396333..12e3678cbf6 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php @@ -23,7 +23,7 @@ public function testGetQueriesUsesAcceptedForeignKeys() : void $keyConstraintTwo = $this->getStubKeyConstraint('second'); $platform = $this->getMockBuilder(AbstractPlatform::class) - ->setMethods(['getDropForeignKeySQL']) + ->onlyMethods(['getDropForeignKeySQL']) ->getMockForAbstractClass(); $collector = new DropSchemaSqlCollector($platform); diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php index 34e2896de29..60c7f2a1f5b 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php @@ -11,7 +11,7 @@ class SchemaSqlCollectorTest extends TestCase public function testCreateSchema() : void { $platformMock = $this->getMockBuilder(MySqlPlatform::class) - ->setMethods(['getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql']) + ->onlyMethods(['getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql']) ->getMock(); $platformMock->expects($this->exactly(2)) ->method('getCreateTableSql') @@ -33,7 +33,7 @@ public function testCreateSchema() : void public function testDropSchema() : void { $platformMock = $this->getMockBuilder(MySqlPlatform::class) - ->setMethods(['getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql']) + ->onlyMethods(['getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql']) ->getMock(); $platformMock->expects($this->exactly(2)) ->method('getDropTableSql') diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php index 31a308e0393..eafbd69cfcb 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php @@ -16,7 +16,7 @@ class PoolingShardManagerTest extends TestCase private function createConnectionMock() : PoolingShardConnection { return $this->getMockBuilder(PoolingShardConnection::class) - ->setMethods(['connect', 'getParams', 'fetchAll']) + ->onlyMethods(['connect', 'getParams', 'fetchAll']) ->disableOriginalConstructor() ->getMock(); } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php index 6dcbad5f356..78d6afe593c 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php @@ -85,7 +85,7 @@ public function testSelectShard() : void private function createConnection(array $params) : Connection { $conn = $this->getMockBuilder(Connection::class) - ->setMethods(['getParams', 'exec', 'isTransactionActive']) + ->onlyMethods(['getParams', 'exec', 'isTransactionActive']) ->disableOriginalConstructor() ->getMock(); $conn->expects($this->at(0))->method('getParams')->will($this->returnValue($params)); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php b/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php index aa15f91d3cc..5b65deecc77 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php @@ -20,7 +20,7 @@ public function testPickShard() : void private function createConnectionMock() : PoolingShardConnection { return $this->getMockBuilder(PoolingShardConnection::class) - ->setMethods(['connect', 'getParams', 'fetchAll']) + ->onlyMethods(['connect', 'getParams', 'fetchAll']) ->disableOriginalConstructor() ->getMock(); } diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index 1d76e3aabe3..bb86e9cab3c 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -28,7 +28,7 @@ class StatementTest extends DbalTestCase protected function setUp() : void { $this->pdoStatement = $this->getMockBuilder(PDOStatement::class) - ->setMethods(['execute', 'bindParam', 'bindValue']) + ->onlyMethods(['execute', 'bindParam', 'bindValue']) ->getMock(); $driverConnection = $this->createMock(DriverConnection::class); From 9d144988498d67dbb820baa1109af7ac4f050a9e Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 28 Aug 2019 14:57:08 -0700 Subject: [PATCH 092/106] An error handler must return boolean, not void --- phpcs.xml.dist | 1 + .../Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 3a11021ffa3..482519c1b72 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -77,5 +77,6 @@ lib/Doctrine/DBAL/Types/ArrayType.php lib/Doctrine/DBAL/Types/ObjectType.php + tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php diff --git a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php index dcfbe715608..37a5ab1a32f 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php @@ -44,7 +44,7 @@ public function testDoesNotRequireQueryForServerVersion() : void public function testRestoresErrorHandlerOnException() : void { - $handler = static function () : void { + $handler = static function () : bool { self::fail('Never expected this to be called'); }; $default_handler = set_error_handler($handler); From 6a2bec0c5c4a85c571ec5296d19caba88ebe2d16 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 28 Aug 2019 14:57:51 -0700 Subject: [PATCH 093/106] Fixed platform detection in a test --- tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php index 161a32f1111..0a6c658ea8c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php @@ -296,7 +296,7 @@ public function testSyntaxErrorException() : void public function testConnectionExceptionSqLite() : void { - if ($this->connection instanceof SqlitePlatform) { + if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { $this->markTestSkipped('Only fails this way on sqlite'); } From 733b64bc907ab597e3cee4f18512a734dd9fa69a Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Sat, 31 Aug 2019 05:41:12 +0200 Subject: [PATCH 094/106] Quote collation on MySQL --- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 10 +++++- .../Schema/MySqlSchemaManagerTest.php | 3 ++ .../AbstractMySQLPlatformTestCase.php | 32 +++++++++---------- .../DBAL/Schema/MySqlInheritCharsetTest.php | 6 ++-- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 30b065e79d7..57c448ce93e 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -503,7 +503,7 @@ private function buildTableOptions(array $options) $options['collate'] = $options['charset'] . '_unicode_ci'; } - $tableOptions[] = sprintf('COLLATE %s', $options['collate']); + $tableOptions[] = $this->getColumnCollationDeclarationSQL($options['collate']); // Engine if (! isset($options['engine'])) { @@ -965,6 +965,14 @@ public function getColumnCharsetDeclarationSQL($charset) return 'CHARACTER SET ' . $charset; } + /** + * {@inheritDoc} + */ + public function getColumnCollationDeclarationSQL($collation) + { + return 'COLLATE ' . $this->quoteSingleIdentifier($collation); + } + /** * {@inheritDoc} */ diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index e9a88e52096..cf636a797ff 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Doctrine\Tests\Types\MySqlPointType; @@ -275,6 +276,7 @@ public function testColumnCollation() : void $table->addColumn('text', 'text'); $table->addColumn('foo', 'text')->setPlatformOption('collation', 'latin1_swedish_ci'); $table->addColumn('bar', 'text')->setPlatformOption('collation', 'utf8_general_ci'); + $table->addColumn('baz', 'text')->setPlatformOption('collation', 'binary'); $this->schemaManager->dropAndCreateTable($table); $columns = $this->schemaManager->listTableColumns('test_collation'); @@ -283,6 +285,7 @@ public function testColumnCollation() : void self::assertEquals('latin1_swedish_ci', $columns['text']->getPlatformOption('collation')); self::assertEquals('latin1_swedish_ci', $columns['foo']->getPlatformOption('collation')); self::assertEquals('utf8_general_ci', $columns['bar']->getPlatformOption('collation')); + self::assertInstanceOf(BlobType::class, $columns['baz']->getType()); } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index bc71767a766..bbae08c5b2c 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -28,12 +28,12 @@ public function testGenerateMixedCaseTableCreate() : void $table->addColumn('Bar', 'integer'); $sql = $this->platform->getCreateTableSQL($table); - self::assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', array_shift($sql)); + self::assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB', array_shift($sql)); } public function getGenerateTableSql() : string { - return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'; + return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'; } /** @@ -41,7 +41,7 @@ public function getGenerateTableSql() : string */ public function getGenerateTableWithMultiColumnUniqueIndexSql() : array { - return ['CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA (foo, bar)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; + return ['CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA (foo, bar)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB']; } /** @@ -209,7 +209,7 @@ public function testGetDateTimeTypeDeclarationSql() : void */ public function getCreateTableColumnCommentsSQL() : array { - return ["CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"]; + return ["CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB"]; } /** @@ -225,7 +225,7 @@ public function getAlterTableColumnCommentsSQL() : array */ public function getCreateTableColumnTypeCommentsSQL() : array { - return ["CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"]; + return ["CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB"]; } /** @@ -250,7 +250,7 @@ public function testChangeIndexWithForeignKeys() : void */ protected function getQuotedColumnInPrimaryKeySQL() : array { - return ['CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, PRIMARY KEY(`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; + return ['CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, PRIMARY KEY(`create`)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB']; } /** @@ -258,7 +258,7 @@ protected function getQuotedColumnInPrimaryKeySQL() : array */ protected function getQuotedColumnInIndexSQL() : array { - return ['CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, INDEX IDX_22660D028FD6E0FB (`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; + return ['CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, INDEX IDX_22660D028FD6E0FB (`create`)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB']; } /** @@ -266,7 +266,7 @@ protected function getQuotedColumnInIndexSQL() : array */ protected function getQuotedNameInIndexSQL() : array { - return ['CREATE TABLE test (column1 VARCHAR(255) NOT NULL, INDEX `key` (column1)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; + return ['CREATE TABLE test (column1 VARCHAR(255) NOT NULL, INDEX `key` (column1)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB']; } /** @@ -275,7 +275,7 @@ protected function getQuotedNameInIndexSQL() : array protected function getQuotedColumnInForeignKeySQL() : array { return [ - 'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, `bar` VARCHAR(255) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', + 'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, `bar` VARCHAR(255) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB', 'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foreign` (`create`, bar, `foo-bar`)', 'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES foo (`create`, bar, `foo-bar`)', 'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foo-bar` (`create`, bar, `foo-bar`)', @@ -293,7 +293,7 @@ public function testCreateTableWithFulltextIndex() : void $index->addFlag('fulltext'); $sql = $this->platform->getCreateTableSQL($table); - self::assertEquals(['CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'], $sql); + self::assertEquals(['CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = MyISAM'], $sql); } public function testCreateTableWithSpatialIndex() : void @@ -307,7 +307,7 @@ public function testCreateTableWithSpatialIndex() : void $index->addFlag('spatial'); $sql = $this->platform->getCreateTableSQL($table); - self::assertEquals(['CREATE TABLE spatial_table (point LONGTEXT NOT NULL, SPATIAL INDEX spatial_text (point)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'], $sql); + self::assertEquals(['CREATE TABLE spatial_table (point LONGTEXT NOT NULL, SPATIAL INDEX spatial_text (point)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = MyISAM'], $sql); } public function testClobTypeDeclarationSQL() : void @@ -571,7 +571,7 @@ public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() $table->addOption('engine', 'MyISAM'); self::assertSame( - ['CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'], + ['CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = MyISAM'], $this->platform->getCreateTableSQL( $table, AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS @@ -583,7 +583,7 @@ public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() self::assertSame( [ - 'CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', + 'CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB', 'ALTER TABLE foreign_table ADD CONSTRAINT FK_5690FFE2A57719D0 FOREIGN KEY (fk_id) REFERENCES foreign_table (id)', ], $this->platform->getCreateTableSQL( @@ -708,7 +708,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() : v $table->addColumn('def_blob_null', 'blob', ['notnull' => false, 'default' => 'def']); self::assertSame( - ['CREATE TABLE text_blob_default_value (def_text LONGTEXT NOT NULL, def_text_null LONGTEXT DEFAULT NULL, def_blob LONGBLOB NOT NULL, def_blob_null LONGBLOB DEFAULT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'], + ['CREATE TABLE text_blob_default_value (def_text LONGTEXT NOT NULL, def_text_null LONGTEXT DEFAULT NULL, def_blob LONGBLOB NOT NULL, def_blob_null LONGBLOB DEFAULT NULL) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'], $this->platform->getCreateTableSQL($table) ); @@ -979,7 +979,7 @@ public function testSupportsColumnCollation() : void public function testColumnCollationDeclarationSQL() : void { self::assertSame( - 'COLLATE ascii_general_ci', + 'COLLATE `ascii_general_ci`', $this->platform->getColumnCollationDeclarationSQL('ascii_general_ci') ); } @@ -991,7 +991,7 @@ public function testGetCreateTableSQLWithColumnCollation() : void $table->addColumn('column_collation', 'string')->setPlatformOption('collation', 'ascii_general_ci'); self::assertSame( - ['CREATE TABLE foo (no_collation VARCHAR(255) NOT NULL, column_collation VARCHAR(255) NOT NULL COLLATE ascii_general_ci) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'], + ['CREATE TABLE foo (no_collation VARCHAR(255) NOT NULL, column_collation VARCHAR(255) NOT NULL COLLATE `ascii_general_ci`) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'], $this->platform->getCreateTableSQL($table), 'Column "no_collation" will use the default collation from the table/database and "column_collation" overwrites the collation on this column' ); diff --git a/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php b/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php index b9c0f1d73ec..e65507b7826 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php @@ -45,7 +45,7 @@ public function testTableOptions() : void $table = new Table('foobar', [new Column('aa', Type::getType('integer'))]); self::assertSame( $platform->getCreateTableSQL($table), - ['CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'] + ['CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'] ); // explicit utf8 @@ -53,7 +53,7 @@ public function testTableOptions() : void $table->addOption('charset', 'utf8'); self::assertSame( $platform->getCreateTableSQL($table), - ['CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'] + ['CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'] ); // explicit utf8mb4 @@ -61,7 +61,7 @@ public function testTableOptions() : void $table->addOption('charset', 'utf8mb4'); self::assertSame( $platform->getCreateTableSQL($table), - ['CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'] + ['CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'] ); } From f932579d44d2b51ca4161e83982f41898726f95c Mon Sep 17 00:00:00 2001 From: loilo Date: Tue, 10 Sep 2019 10:51:50 +0200 Subject: [PATCH 095/106] Add missing MySQL 8.0 keywords --- lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php index 4b595d53a08..ec1562d2433 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php @@ -28,6 +28,7 @@ protected function getKeywords() $keywords = array_merge($keywords, [ 'ADMIN', + 'ARRAY', 'CUBE', 'CUME_DIST', 'DENSE_RANK', @@ -40,7 +41,9 @@ protected function getKeywords() 'JSON_TABLE', 'LAG', 'LAST_VALUE', + 'LATERAL', 'LEAD', + 'MEMBER', 'NTH_VALUE', 'NTILE', 'OF', From 442c684336b77491d94110089504e6f803d45eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Mon, 16 Sep 2019 17:07:46 +0200 Subject: [PATCH 096/106] Relax statement type declaration fetch() is part of the ResultStatement interface. Using Statement as a type declaration needlessly constrains people to use this class only with implementations of Statement. --- lib/Doctrine/DBAL/Driver/StatementIterator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/StatementIterator.php b/lib/Doctrine/DBAL/Driver/StatementIterator.php index 5246b38a448..6b3307da2af 100644 --- a/lib/Doctrine/DBAL/Driver/StatementIterator.php +++ b/lib/Doctrine/DBAL/Driver/StatementIterator.php @@ -6,10 +6,10 @@ class StatementIterator implements IteratorAggregate { - /** @var Statement */ + /** @var ResultStatement */ private $statement; - public function __construct(Statement $statement) + public function __construct(ResultStatement $statement) { $this->statement = $statement; } From 1ff5163013877f80d1ea8576fadb797296a4d819 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 6 Oct 2019 09:12:37 -0700 Subject: [PATCH 097/106] Temporarily disable the usage of PHPUnit 8.4 due to a regression See https://github.com/sebastianbergmann/phpunit/issues/3879 --- composer.json | 2 +- composer.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 2d09887ce4c..fb2402a45aa 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "doctrine/coding-standard": "^6.0", "jetbrains/phpstorm-stubs": "^2019.1", "phpstan/phpstan": "^0.11.3", - "phpunit/phpunit": "^8.3.3", + "phpunit/phpunit": "^8.3.3, <8.4.0", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0" }, "suggest": { diff --git a/composer.lock b/composer.lock index 5e29b96ee83..d34e6af55c7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1d397d6d064efda6d4150edce78e283a", + "content-hash": "7502364f1cb482daff6265017e5e9f4f", "packages": [ { "name": "doctrine/cache", From 7a991332e80861b5ab7d78dbd83f23607a9e1262 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 8 Jul 2019 05:55:22 +0300 Subject: [PATCH 098/106] Fixed query result caching when FetchMode::COLUMN is used Internally, ArrayStatement expects every row to be represented as an array regardless of the fetch mode, however FetchMode::COLUMN produces one value per row. --- lib/Doctrine/DBAL/Cache/ResultCacheStatement.php | 10 +++++++++- .../Tests/DBAL/Functional/ResultCacheTest.php | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 8fbae62de29..f04c8524974 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -167,7 +167,15 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { - $this->data = $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs); + $data = $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs); + + if ($fetchMode === FetchMode::COLUMN) { + foreach ($data as $key => $value) { + $data[$key] = [$value]; + } + } + + $this->data = $data; $this->emptied = true; return $this->data; diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index 35ce061b5b9..8d0a17c9b43 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -177,6 +177,22 @@ public function testFetchAllAndFinishSavesCache() : void self::assertCount(1, $layerCache->fetch('testcachekey')); } + public function testFetchAllColumn() : void + { + $query = $this->connection->getDatabasePlatform() + ->getDummySelectSQL('1'); + + $qcp = new QueryCacheProfile(0, 0, new ArrayCache()); + + $stmt = $this->connection->executeCacheQuery($query, [], [], $qcp); + $stmt->fetchAll(FetchMode::COLUMN); + $stmt->closeCursor(); + + $stmt = $this->connection->executeCacheQuery($query, [], [], $qcp); + + self::assertEquals([1], $stmt->fetchAll(FetchMode::COLUMN)); + } + /** * @param array> $expectedResult */ From 0a4494dcb53f3c9289baf3f741b9c848a179ecae Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 7 Oct 2019 16:26:24 -0700 Subject: [PATCH 099/106] Updated PHPUnit to 8.4.1 $ composer update phpunit/phpunit --with-all-dependencies --- composer.json | 2 +- composer.lock | 189 +++++++++++++++++++++++++------------------------- 2 files changed, 94 insertions(+), 97 deletions(-) diff --git a/composer.json b/composer.json index fb2402a45aa..4a426e4881a 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "doctrine/coding-standard": "^6.0", "jetbrains/phpstorm-stubs": "^2019.1", "phpstan/phpstan": "^0.11.3", - "phpunit/phpunit": "^8.3.3, <8.4.0", + "phpunit/phpunit": "^8.4.1", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0" }, "suggest": { diff --git a/composer.lock b/composer.lock index d34e6af55c7..aa0428c2019 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7502364f1cb482daff6265017e5e9f4f", + "content-hash": "120172ae44052999ec9a50b1121414cc", "packages": [ { "name": "doctrine/cache", @@ -475,16 +475,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.9.1", + "version": "1.9.3", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72" + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72", - "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea", + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea", "shasum": "" }, "require": { @@ -519,7 +519,7 @@ "object", "object graph" ], - "time": "2019-04-07T13:18:21+00:00" + "time": "2019-08-09T12:45:53+00:00" }, { "name": "nette/bootstrap", @@ -1249,35 +1249,33 @@ }, { "name": "phpdocumentor/reflection-common", - "version": "1.0.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", "shasum": "" }, "require": { - "php": ">=5.5" + "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "^4.6" + "phpunit/phpunit": "~6" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src" - ] + "phpDocumentor\\Reflection\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -1299,30 +1297,30 @@ "reflection", "static analysis" ], - "time": "2017-09-11T18:02:19+00:00" + "time": "2018-08-07T13:53:10+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.1", + "version": "4.3.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c" + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", - "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e", "shasum": "" }, "require": { "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0.0", - "phpdocumentor/type-resolver": "^0.4.0", + "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", + "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", "webmozart/assert": "^1.0" }, "require-dev": { - "doctrine/instantiator": "~1.0.5", + "doctrine/instantiator": "^1.0.5", "mockery/mockery": "^1.0", "phpunit/phpunit": "^6.4" }, @@ -1350,41 +1348,40 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2019-04-30T17:48:53+00:00" + "time": "2019-09-12T14:27:41+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.4.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0", - "phpdocumentor/reflection-common": "^1.0" + "php": "^7.1", + "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^5.2||^4.8.24" + "ext-tokenizer": "^7.1", + "mockery/mockery": "~1", + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -1397,26 +1394,27 @@ "email": "me@mikevanriel.com" } ], - "time": "2017-07-14T14:27:02+00:00" + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "time": "2019-08-22T18:11:29+00:00" }, { "name": "phpspec/prophecy", - "version": "1.8.1", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", - "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203", + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", "sebastian/comparator": "^1.1|^2.0|^3.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, @@ -1460,7 +1458,7 @@ "spy", "stub" ], - "time": "2019-06-13T12:50:23+00:00" + "time": "2019-10-03T11:07:50+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -1586,16 +1584,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "7.0.7", + "version": "7.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "7743bbcfff2a907e9ee4a25be13d0f8ec5e73800" + "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7743bbcfff2a907e9ee4a25be13d0f8ec5e73800", - "reference": "7743bbcfff2a907e9ee4a25be13d0f8ec5e73800", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa0d179a13284c7420fc281fc32750e6cc7c9e2f", + "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f", "shasum": "" }, "require": { @@ -1604,7 +1602,7 @@ "php": "^7.2", "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.1.0", + "phpunit/php-token-stream": "^3.1.1", "sebastian/code-unit-reverse-lookup": "^1.0.1", "sebastian/environment": "^4.2.2", "sebastian/version": "^2.0.1", @@ -1634,8 +1632,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "role": "lead", - "email": "sebastian@phpunit.de" + "email": "sebastian@phpunit.de", + "role": "lead" } ], "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", @@ -1645,7 +1643,7 @@ "testing", "xunit" ], - "time": "2019-07-25T05:31:54+00:00" + "time": "2019-09-17T06:24:36+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1789,16 +1787,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "3.1.0", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a" + "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e899757bb3df5ff6e95089132f32cd59aac2220a", - "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/995192df77f63a59e47f025390d2d1fdf8f425ff", + "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff", "shasum": "" }, "require": { @@ -1834,20 +1832,20 @@ "keywords": [ "tokenizer" ], - "time": "2019-07-25T05:29:42+00:00" + "time": "2019-09-17T06:23:10+00:00" }, { "name": "phpunit/phpunit", - "version": "8.3.3", + "version": "8.4.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c319d08ebd31e137034c84ad7339054709491485" + "reference": "366a4a0f2b971fd43b7c351d621e8dd7d7131869" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c319d08ebd31e137034c84ad7339054709491485", - "reference": "c319d08ebd31e137034c84ad7339054709491485", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/366a4a0f2b971fd43b7c351d621e8dd7d7131869", + "reference": "366a4a0f2b971fd43b7c351d621e8dd7d7131869", "shasum": "" }, "require": { @@ -1870,7 +1868,7 @@ "sebastian/comparator": "^3.0.2", "sebastian/diff": "^3.0.2", "sebastian/environment": "^4.2.2", - "sebastian/exporter": "^3.1.0", + "sebastian/exporter": "^3.1.1", "sebastian/global-state": "^3.0.0", "sebastian/object-enumerator": "^3.0.3", "sebastian/resource-operations": "^2.0.1", @@ -1891,7 +1889,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "8.3-dev" + "dev-master": "8.4-dev" } }, "autoload": { @@ -1906,8 +1904,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "role": "lead", - "email": "sebastian@phpunit.de" + "email": "sebastian@phpunit.de", + "role": "lead" } ], "description": "The PHP Unit Testing framework.", @@ -1917,7 +1915,7 @@ "testing", "xunit" ], - "time": "2019-08-03T15:41:47+00:00" + "time": "2019-10-07T12:57:41+00:00" }, { "name": "psr/log", @@ -2186,16 +2184,16 @@ }, { "name": "sebastian/exporter", - "version": "3.1.0", + "version": "3.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "234199f4528de6d12aaa58b612e98f7d36adb937" + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937", - "reference": "234199f4528de6d12aaa58b612e98f7d36adb937", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", "shasum": "" }, "require": { @@ -2222,6 +2220,10 @@ "BSD-3-Clause" ], "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, { "name": "Jeff Welch", "email": "whatthejeff@gmail.com" @@ -2230,17 +2232,13 @@ "name": "Volker Dusch", "email": "github@wallbash.com" }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, { "name": "Adam Harvey", "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" } ], "description": "Provides the functionality to export PHP variables for visualization", @@ -2249,7 +2247,7 @@ "export", "exporter" ], - "time": "2017-04-03T13:19:02+00:00" + "time": "2019-09-14T09:02:43+00:00" }, { "name": "sebastian/global-state", @@ -2919,16 +2917,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.11.0", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "82ebae02209c21113908c229e9883c419720738a" + "reference": "550ebaac289296ce228a706d0867afc34687e3f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", - "reference": "82ebae02209c21113908c229e9883c419720738a", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4", "shasum": "" }, "require": { @@ -2940,7 +2938,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11-dev" + "dev-master": "1.12-dev" } }, "autoload": { @@ -2956,13 +2954,13 @@ "MIT" ], "authors": [ - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - }, { "name": "Gert de Pagter", "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony polyfill for ctype functions", @@ -2973,7 +2971,7 @@ "polyfill", "portable" ], - "time": "2019-02-06T07:57:58+00:00" + "time": "2019-08-06T08:03:45+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -3076,16 +3074,16 @@ }, { "name": "webmozart/assert", - "version": "1.4.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", + "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4", "shasum": "" }, "require": { @@ -3093,8 +3091,7 @@ "symfony/polyfill-ctype": "^1.8" }, "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" + "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "type": "library", "extra": { @@ -3123,7 +3120,7 @@ "check", "validate" ], - "time": "2018-12-25T11:19:39+00:00" + "time": "2019-08-24T08:43:50+00:00" } ], "aliases": [], From f90c29973a15190267cf2160e174e1ce8d2c70b5 Mon Sep 17 00:00:00 2001 From: Bingo-Soft Date: Sun, 13 Oct 2019 20:43:24 +0300 Subject: [PATCH 100/106] Add support for DISTINCT clause --- docs/en/reference/query-builder.rst | 15 ++++++ lib/Doctrine/DBAL/Query/QueryBuilder.php | 53 ++++++++++++++----- .../Tests/DBAL/Query/QueryBuilderTest.php | 11 ++++ 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/docs/en/reference/query-builder.rst b/docs/en/reference/query-builder.rst index 427380679de..059a70bef5f 100644 --- a/docs/en/reference/query-builder.rst +++ b/docs/en/reference/query-builder.rst @@ -87,6 +87,21 @@ and ``delete($tableName)``: You can convert a query builder to its SQL string representation by calling ``$queryBuilder->getSQL()`` or casting the object to string. +DISTINCT-Clause +~~~~~~~~~~~~~~~ + +The ``SELECT`` statement can be specified with a ``DISTINCT`` clause: + +.. code-block:: php + + select('name') + ->distinct() + ->from('users') + ; + WHERE-Clause ~~~~~~~~~~~~ diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 50c08655ff3..587e26656ab 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -52,22 +52,28 @@ class QueryBuilder */ private $connection; + /* + * The default values of SQL parts collection + */ + private const SQL_PARTS_DEFAULTS = [ + 'select' => [], + 'distinct' => false, + 'from' => [], + 'join' => [], + 'set' => [], + 'where' => null, + 'groupBy' => [], + 'having' => null, + 'orderBy' => [], + 'values' => [], + ]; + /** * The array of SQL parts collected. * * @var mixed[] */ - private $sqlParts = [ - 'select' => [], - 'from' => [], - 'join' => [], - 'set' => [], - 'where' => null, - 'groupBy' => [], - 'having' => null, - 'orderBy' => [], - 'values' => [], - ]; + private $sqlParts = self::SQL_PARTS_DEFAULTS; /** * The complete SQL string for this query. @@ -469,6 +475,25 @@ public function select($select = null) return $this->add('select', $selects); } + /** + * Adds DISTINCT to the query. + * + * + * $qb = $conn->createQueryBuilder() + * ->select('u.id') + * ->distinct() + * ->from('users', 'u') + * + * + * @return $this This QueryBuilder instance. + */ + public function distinct() : self + { + $this->sqlParts['distinct'] = true; + + return $this; + } + /** * Adds an item that is to be returned in the query result. * @@ -1083,8 +1108,7 @@ public function resetQueryParts($queryPartNames = null) */ public function resetQueryPart($queryPartName) { - $this->sqlParts[$queryPartName] = is_array($this->sqlParts[$queryPartName]) - ? [] : null; + $this->sqlParts[$queryPartName] = self::SQL_PARTS_DEFAULTS[$queryPartName]; $this->state = self::STATE_DIRTY; @@ -1098,7 +1122,8 @@ public function resetQueryPart($queryPartName) */ private function getSQLForSelect() { - $query = 'SELECT ' . implode(', ', $this->sqlParts['select']); + $query = 'SELECT ' . ($this->sqlParts['distinct'] ? 'DISTINCT ' : '') . + implode(', ', $this->sqlParts['select']); $query .= ($this->sqlParts['from'] ? ' FROM ' . implode(', ', $this->getFromClauses()) : '') . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : '') diff --git a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php index 610abc319a9..a210ef2fe73 100644 --- a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php @@ -50,6 +50,17 @@ public function testSimpleSelect() : void self::assertEquals('SELECT u.id FROM users u', (string) $qb); } + public function testSimpleSelectWithDistinct() : void + { + $qb = new QueryBuilder($this->conn); + + $qb->select('u.id') + ->distinct() + ->from('users', 'u'); + + self::assertEquals('SELECT DISTINCT u.id FROM users u', (string) $qb); + } + public function testSelectWithSimpleWhere() : void { $qb = new QueryBuilder($this->conn); From b55087988d6818b739136c7c80f15c2e2ed131ce Mon Sep 17 00:00:00 2001 From: Konstantin Kalinin Date: Fri, 20 Sep 2019 12:59:32 +0300 Subject: [PATCH 101/106] Reset transaction nesting level on connection loss. When the connection is lost or is closed, subsequent transaction will no longer be nested because they started in a brand new session. Our internal representation of the nesting shold take this into account --- lib/Doctrine/DBAL/Connection.php | 2 ++ .../Tests/DBAL/Functional/ConnectionTest.php | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 7fef4e8628a..d5e6b7a048b 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -354,6 +354,8 @@ public function connect() $this->_conn = $this->_driver->connect($this->params, $user, $password, $driverOptions); $this->isConnected = true; + $this->transactionNestingLevel = 0; + if ($this->autoCommit === false) { $this->beginTransaction(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index 9218d35e0ab..f9b067ad4a4 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -70,6 +70,40 @@ public function testTransactionNestingBehavior() : void $this->connection->rollBack(); self::assertEquals(0, $this->connection->getTransactionNestingLevel()); } + + $this->connection->beginTransaction(); + $this->connection->close(); + $this->connection->beginTransaction(); + self::assertEquals(1, $this->connection->getTransactionNestingLevel()); + } + + public function testTransactionNestingLevelIsResetOnReconnect() : void + { + if ($this->connection->getDatabasePlatform()->getName() === 'sqlite') { + $params = $this->connection->getParams(); + $params['memory'] = false; + $params['path'] = '/tmp/test_nesting.sqlite'; + + $connection = DriverManager::getConnection( + $params, + $this->connection->getConfiguration(), + $this->connection->getEventManager() + ); + } else { + $connection = $this->connection; + } + + $connection->executeQuery('CREATE TABLE test_nesting(test int not null)'); + + $this->connection->beginTransaction(); + $this->connection->beginTransaction(); + $connection->close(); // connection closed in runtime (for example if lost or another application logic) + + $connection->beginTransaction(); + $connection->executeQuery('insert into test_nesting values (33)'); + $connection->rollback(); + + self::assertEquals(0, $connection->fetchColumn('select count(*) from test_nesting')); } public function testTransactionNestingBehaviorWithSavepoints() : void From 0dab22fd75ba655c35a04005c652fcf71cc3b59d Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 17 Oct 2019 09:28:26 -0700 Subject: [PATCH 102/106] Updated SQL Server extensions to fix build failures on PHP 7.4 --- .travis.yml | 3 --- lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php | 4 +++- tests/travis/install-mssql-pdo_sqlsrv.sh | 2 +- tests/travis/install-mssql-sqlsrv.sh | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index e0d87665991..cc516636cda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,9 +37,6 @@ after_script: fi jobs: - allow_failures: - - php: 7.4snapshot - include: - stage: Smoke Testing diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index d0c88f7fe76..35cdc45089a 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -340,7 +340,9 @@ public function listTableDetails($tableName) : Table $tableOptions = $this->_conn->fetchAssoc($sql); - $table->addOption('comment', $tableOptions['table_comment']); + if ($tableOptions !== false) { + $table->addOption('comment', $tableOptions['table_comment']); + } return $table; } diff --git a/tests/travis/install-mssql-pdo_sqlsrv.sh b/tests/travis/install-mssql-pdo_sqlsrv.sh index 9893d0f8c78..71e07aee231 100644 --- a/tests/travis/install-mssql-pdo_sqlsrv.sh +++ b/tests/travis/install-mssql-pdo_sqlsrv.sh @@ -4,4 +4,4 @@ set -ex echo "Installing extension" -pecl install pdo_sqlsrv +pecl install pdo_sqlsrv-5.7.0preview diff --git a/tests/travis/install-mssql-sqlsrv.sh b/tests/travis/install-mssql-sqlsrv.sh index 10132619c59..d44841360dc 100644 --- a/tests/travis/install-mssql-sqlsrv.sh +++ b/tests/travis/install-mssql-sqlsrv.sh @@ -4,4 +4,4 @@ set -ex echo "Installing extension" -pecl install sqlsrv +pecl install sqlsrv-5.7.0preview From 4ee89c62ad7f8fe4ef2186f16f8871b99c41f438 Mon Sep 17 00:00:00 2001 From: Federkun Date: Fri, 25 Oct 2019 01:16:50 +0100 Subject: [PATCH 103/106] Don't skip a test for sqlite when you are checking sqlite. --- tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php index 0a6c658ea8c..3b9649d5595 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php @@ -296,7 +296,7 @@ public function testSyntaxErrorException() : void public function testConnectionExceptionSqLite() : void { - if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { + if (! ($this->connection->getDatabasePlatform() instanceof SqlitePlatform)) { $this->markTestSkipped('Only fails this way on sqlite'); } @@ -327,7 +327,8 @@ public function testConnectionExceptionSqLite() : void $table->addColumn('id', 'integer'); $this->expectException(Exception\ReadOnlyException::class); - $this->expectExceptionMessage(<<expectExceptionMessage( + << Date: Mon, 28 Oct 2019 09:24:42 +0100 Subject: [PATCH 104/106] add missing exit codes to ensure Symfony 5 compatibility --- lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php | 4 ++-- lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php | 2 ++ tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index a45a60c6085..0cd2999c97a 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -58,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $fileNames = $input->getArgument('file'); if ($fileNames === null) { - return null; + return 0; } foreach ((array) $fileNames as $fileName) { @@ -133,6 +133,6 @@ protected function execute(InputInterface $input, OutputInterface $output) } } - return null; + return 0; } } diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php index 8aeb0ea2fba..b479baec2ee 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php @@ -68,5 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $output->write(Dumper::dump($resultSet, (int) $depth)); + + return 0; } } diff --git a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php index 21eab4203ba..202748be6d8 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php @@ -70,10 +70,11 @@ public function testSelectStatementsPrintsResult() : void { $this->expectConnectionFetchAll(); - $this->commandTester->execute([ + $exitCode = $this->commandTester->execute([ 'command' => $this->command->getName(), 'sql' => 'SELECT 1', ]); + $this->assertSame(0, $exitCode); self::assertRegExp('@int.*1.*@', $this->commandTester->getDisplay()); self::assertRegExp('@array.*1.*@', $this->commandTester->getDisplay()); From 1611dc3579966125e79b2d36c0ebf17724a142a9 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 29 Oct 2019 23:02:39 -0700 Subject: [PATCH 105/106] New deprecations for 2.10 --- UPGRADE.md | 37 +++++++++++++++++++ lib/Doctrine/DBAL/Connection.php | 8 ++++ lib/Doctrine/DBAL/Driver.php | 2 + .../DBAL/Event/ConnectionEventArgs.php | 6 +++ .../SchemaAlterTableAddColumnEventArgs.php | 9 ++--- .../SchemaAlterTableChangeColumnEventArgs.php | 9 ++--- .../DBAL/Event/SchemaAlterTableEventArgs.php | 9 ++--- .../SchemaAlterTableRemoveColumnEventArgs.php | 9 ++--- .../SchemaAlterTableRenameColumnEventArgs.php | 9 ++--- .../Event/SchemaColumnDefinitionEventArgs.php | 2 + .../SchemaCreateTableColumnEventArgs.php | 9 ++--- .../DBAL/Event/SchemaCreateTableEventArgs.php | 9 ++--- .../DBAL/Schema/AbstractSchemaManager.php | 6 +++ .../DBAL/Schema/OracleSchemaManager.php | 4 ++ .../DBAL/Schema/SqliteSchemaManager.php | 2 + 15 files changed, 95 insertions(+), 35 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index b79cc16c5b5..205bf991974 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,42 @@ # Upgrade to 2.10 +## Deprecated `Doctrine\DBAL\Event\ConnectionEventArgs` methods + +The usage of the `getDriver()`, `getDatabasePlatform()` and `getSchemaManager()` methods of the `ConnectionEventArgs` class has been deprecated. Obtain the underlying connection via `getConnection()` and call the corresponding methods on the connection instance. + +## Deprecated `Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs` methods + +The usage of the `getDatabasePlatform()` method of the `SchemaColumnDefinitionEventArgs` class has been deprecated. Obtain the underlying connection via `getConnection()` and call the corresponding method on the connection instance. + +## Deprecated `Doctrine\DBAL\Connection` methods + +The usage of the `getHost()`, `getPort()`, `getUsername()` and `getPassword()` methods of the `Connection` class has been deprecated as they leak implementation details. + +## Deprecated array of statements in `addSql()` of `SchemaEventArgs`-based classes. + +Passing multiple SQL statements as an array to `SchemaAlterTableAddColumnEventArgs::addSql()` and the same method in other `SchemaEventArgs`-based classes is deprecated. Pass each statement as an individual argument instead. + +## Deprecated calling `AbstractSchemaManager::tablesExist()` with a string argument. + +Instead of passing a string, pass a one-element array. + +## Deprecated calling `OracleSchemaManager::createDatabase()` without an argument or by passing NULL. + +In order to create a database, always pass the database name. + +## Deprecated unused schema manager methods. + +The following methods have been deprecated as unused: + +- `AbstractSchemaManager::_getPortableFunctionsList()`, +- `AbstractSchemaManager::_getPortableFunctionDefinition()`, +- `OracleSchemaManager::_getPortableFunctionDefinition()`, +- `SqliteSchemaManager::_getPortableTableIndexDefinition()`. + +# Deprecations in `Doctrine\DBAL\Driver` + +- The usage of NULL to indicate empty `$username` or `$password` when calling `connect()` is deprecated. Use an empty string instead. + ## Deprecated `Doctrine\DBAL\Platforms::_getAlterTableIndexForeignKeySQL()` Method `Doctrine\DBAL\Platforms::_getAlterTableIndexForeignKeySQL()` has been deprecated as no longer used. diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index d5e6b7a048b..ee6c08635ce 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -242,6 +242,8 @@ public function getDatabase() /** * Gets the hostname of the currently connected database. * + * @deprecated + * * @return string|null */ public function getHost() @@ -252,6 +254,8 @@ public function getHost() /** * Gets the port of the currently connected database. * + * @deprecated + * * @return mixed */ public function getPort() @@ -262,6 +266,8 @@ public function getPort() /** * Gets the username used by this connection. * + * @deprecated + * * @return string|null */ public function getUsername() @@ -272,6 +278,8 @@ public function getUsername() /** * Gets the password used by this connection. * + * @deprecated + * * @return string|null */ public function getPassword() diff --git a/lib/Doctrine/DBAL/Driver.php b/lib/Doctrine/DBAL/Driver.php index 8a80d4a428a..57493e633bb 100644 --- a/lib/Doctrine/DBAL/Driver.php +++ b/lib/Doctrine/DBAL/Driver.php @@ -14,6 +14,8 @@ interface Driver /** * Attempts to create a connection with the database. * + * The usage of NULL to indicate empty username or password is deprecated. Use an empty string instead. + * * @param mixed[] $params All connection parameters passed by the user. * @param string|null $username The username to use when connecting. * @param string|null $password The password to use when connecting. diff --git a/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php b/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php index bb0ca886d99..5c71992cc05 100644 --- a/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php @@ -30,6 +30,8 @@ public function getConnection() } /** + * @deprecated Use ConnectionEventArgs::getConnection() and Connection::getDriver() instead. + * * @return Driver */ public function getDriver() @@ -38,6 +40,8 @@ public function getDriver() } /** + * @deprecated Use ConnectionEventArgs::getConnection() and Connection::getDatabasePlatform() instead. + * * @return AbstractPlatform */ public function getDatabasePlatform() @@ -46,6 +50,8 @@ public function getDatabasePlatform() } /** + * @deprecated Use ConnectionEventArgs::getConnection() and Connection::getSchemaManager() instead. + * * @return AbstractSchemaManager */ public function getSchemaManager() diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php index 2f9edfea688..ff86a93d632 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\TableDiff; use function array_merge; +use function func_get_args; use function is_array; /** @@ -57,17 +58,15 @@ public function getPlatform() } /** + * Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. + * * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs */ public function addSql($sql) { - if (is_array($sql)) { - $this->sql = array_merge($this->sql, $sql); - } else { - $this->sql[] = $sql; - } + $this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args()); return $this; } diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php index 55661d5d307..354eb68bc6b 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\TableDiff; use function array_merge; +use function func_get_args; use function is_array; /** @@ -57,17 +58,15 @@ public function getPlatform() } /** + * Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. + * * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs */ public function addSql($sql) { - if (is_array($sql)) { - $this->sql = array_merge($this->sql, $sql); - } else { - $this->sql[] = $sql; - } + $this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args()); return $this; } diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php index 8f5f0ecf563..b10bc7a60a2 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\TableDiff; use function array_merge; +use function func_get_args; use function is_array; /** @@ -44,17 +45,15 @@ public function getPlatform() } /** + * Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. + * * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaAlterTableEventArgs */ public function addSql($sql) { - if (is_array($sql)) { - $this->sql = array_merge($this->sql, $sql); - } else { - $this->sql[] = $sql; - } + $this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args()); return $this; } diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php index 1bc9f590187..6e3d6a757c7 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\TableDiff; use function array_merge; +use function func_get_args; use function is_array; /** @@ -57,17 +58,15 @@ public function getPlatform() } /** + * Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. + * * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs */ public function addSql($sql) { - if (is_array($sql)) { - $this->sql = array_merge($this->sql, $sql); - } else { - $this->sql[] = $sql; - } + $this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args()); return $this; } diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php index 911ea8b4ab6..27e2825314c 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\TableDiff; use function array_merge; +use function func_get_args; use function is_array; /** @@ -72,17 +73,15 @@ public function getPlatform() } /** + * Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. + * * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs */ public function addSql($sql) { - if (is_array($sql)) { - $this->sql = array_merge($this->sql, $sql); - } else { - $this->sql[] = $sql; - } + $this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args()); return $this; } diff --git a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php index 19d9f93a329..80d9abe73a5 100644 --- a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php @@ -97,6 +97,8 @@ public function getConnection() } /** + * @deprecated Use SchemaColumnDefinitionEventArgs::getConnection() and Connection::getDatabasePlatform() instead. + * * @return AbstractPlatform */ public function getDatabasePlatform() diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php index 9d24b8b9049..6d78aae5c11 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table; use function array_merge; +use function func_get_args; use function is_array; /** @@ -57,17 +58,15 @@ public function getPlatform() } /** + * Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. + * * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs */ public function addSql($sql) { - if (is_array($sql)) { - $this->sql = array_merge($this->sql, $sql); - } else { - $this->sql[] = $sql; - } + $this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args()); return $this; } diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php index 954f77aa55a..927a4e4efe1 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Table; use function array_merge; +use function func_get_args; use function is_array; /** @@ -72,17 +73,15 @@ public function getPlatform() } /** + * Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. + * * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaCreateTableEventArgs */ public function addSql($sql) { - if (is_array($sql)) { - $this->sql = array_merge($this->sql, $sql); - } else { - $this->sql[] = $sql; - } + $this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args()); return $this; } diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 259803c423f..8e4ffa5f966 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -188,6 +188,8 @@ public function listTableIndexes($table) /** * Returns true if all the given tables exist. * + * The usage of a string $tableNames is deprecated. Pass a one-element array instead. + * * @param string|string[] $tableNames * * @return bool @@ -683,6 +685,8 @@ protected function getPortableNamespaceDefinition(array $namespace) } /** + * @deprecated + * * @param mixed[][] $functions * * @return mixed[][] @@ -704,6 +708,8 @@ protected function _getPortableFunctionsList($functions) } /** + * @deprecated + * * @param mixed[] $function * * @return mixed diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index 38889e37407..afe610ddbc4 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -264,6 +264,8 @@ protected function _getPortableSequenceDefinition($sequence) /** * {@inheritdoc} + * + * @deprecated */ protected function _getPortableFunctionDefinition($function) { @@ -284,6 +286,8 @@ protected function _getPortableDatabaseDefinition($database) /** * {@inheritdoc} + * + * Calling this method without an argument or by passing NULL is deprecated. */ public function createDatabase($database = null) { diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 605a68be187..ac758015a0f 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -224,6 +224,8 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null /** * {@inheritdoc} + * + * @deprecated */ protected function _getPortableTableIndexDefinition($tableIndex) { From 0c9a646775ef549eb0a213a4f9bd4381d9b4d934 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 3 Nov 2019 08:50:43 -0800 Subject: [PATCH 106/106] Release v2.10.0 --- lib/Doctrine/DBAL/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Version.php b/lib/Doctrine/DBAL/Version.php index 93be3a1dfba..2b1c0f23b79 100644 --- a/lib/Doctrine/DBAL/Version.php +++ b/lib/Doctrine/DBAL/Version.php @@ -14,7 +14,7 @@ class Version /** * Current Doctrine Version. */ - public const VERSION = '2.10.0-DEV'; + public const VERSION = '2.10.0'; /** * Compares a Doctrine version with the current one.